def hashExist(self, hash): i = 0 for h in MessageDAO().hashtagList()[0]: print(h) if hash == h: print(MessageDAO().hashtagList()[1][i]) return MessageDAO().hashtagList()[1][i] i+=1 return None
def getmessagelikes(self, mid): dao = MessageDAO().messageLikes(mid) if not dao: return jsonify(Error="NOT FOUND"), 404 result = [] for l in dao: result.append(self.maplikes(l)) return jsonify(LikesInMessage=result)
def getMessageReplies(self, mid): messages = MessageDAO().messageReply(mid) if not messages: return jsonify(Error="NOT FOUND"), 404 result = [] for m in messages: result.append(self.mapreply(m)) return jsonify(MessageReplies=result)
def getalldislikes(self): dao = MessageDAO().getDislikes() if not dao: return jsonify(Error="NOT FOUND"), 404 result = [] for l in dao: result.append(self.mapdislikesall(l)) return jsonify(AllDislikes=result)
def getMessagesFromUser(self, uid): messages = MessageDAO().messagesFromUser(uid) if not messages: return jsonify(Error="NOT FOUND"), 404 result = [] for m in messages: result.append(self.mapUserMessage(m)) return jsonify(MessagesFromUser=result)
def getMessagesFromChat(self, cid): messages = MessageDAO().messagesFromChat(cid) if not messages: return jsonify(Error="NOT FOUND"), 404 result = [] for m in messages: result.append(self.mapChatMessage(m)) return jsonify(MessagesFromChat=result)
def getAllMessages(self): messages = MessageDAO().allMessages() if not messages: return jsonify(Error="NOT FOUND"), 404 result = [] for m in messages: result.append(self.maptoDicMessage(m)) return jsonify(AllMessages=result)
def getMessageById(self, mid): messages = MessageDAO().messageById(mid) if not messages: return jsonify(Error="NOT FOUND"), 404 result = [] for m in messages: result.append(self.maptoDicMessage(m)) return jsonify(Message=result)
def searchmsgwithhashinchat(self, cid, hashname): searchresult = MessageDAO().searchHashInChatmsg(cid, hashname) if not searchresult: return jsonify(Error="NOT FOUND"), 404 result = [] for l in searchresult: result.append(self.searchDic(l)) return jsonify(SearchHash=result)
def postmessageh(self, msginfo): uid = msginfo['uid'] cid = msginfo['cid'] text = msginfo['text'] reply = msginfo['reply'] m = MessageDAO().postmessage(cid, uid, text) pieces = text.split(" ") hashtag = [] for txt in pieces: if txt[0] == "#": hash = txt[1:] print(hash) chk = self.hashExist(hash) print(chk) if chk == None: hid = MessageDAO().postHashtag(hash) else: hid = chk done = MessageDAO().insertHasHash(m, hid) if reply != None: t = MessageDAO().insertreply(reply, m) result = {'mid': m} return jsonify(result), 201
def getMessageRepliesCount(self, mid): messages = MessageDAO().countRepliesMessage(mid) if messages==None: return jsonify(Error="NOT FOUND"), 404 return jsonify(MessageReplies=messages)
def disliked(self, dislikeinfo): uid = dislikeinfo['uid'] mid = dislikeinfo['mid'] r = MessageDAO().insertdislike(uid, mid) return jsonify(Result=r), 200
def getmessagelikesCount(self, mid): dao = MessageDAO().countLikesMessage(mid) if dao == None: return jsonify(Error="NOT FOUND"), 404 return jsonify(LikesInMessage=dao)