예제 #1
0
 def getAllMessages(self):
     dao = MessagesDAO()
     result = dao.getAllMessages()
     mapped_result = []
     for r in result:
         mapped_result.append(self.mapToMessagesDict(r))
     return jsonify(Messages=mapped_result)
예제 #2
0
 def getMessageByID(self, id):
     dao = MessagesDAO()
     result = dao.getMessageByID(id)
     if result == None:
         return jsonify(Error="MESSAGE NOT FOUND"), 404
     else:
         mapped = self.mapToMessagesDict(result)
         return jsonify(Message=mapped)
예제 #3
0
 def postMessageReply(self, form, chid, original):
     print(form)
     message_id = self.postMessagesByChatID(form, chid)
     print(message_id)
     dao = MessagesDAO()
     dao.reply(original, message_id)
     result = self.getMessageByID(message_id)
     return result
예제 #4
0
 def getAllUsersWhoDisliked(self, message_id):
     dao = MessagesDAO()
     if not dao.getMessageByID(message_id):
         return jsonify(Error="Message not found."), 404
     else:
         list = dao.getAllUsersWhoDisliked(message_id)
         mapped_result = []
         for r in list:
             mapped_result.append(self.mapToUserReactWithTimestamp(r))
         return jsonify(Dislikers=mapped_result)
예제 #5
0
 def getMessageDislikes(self, message_id):
     dao = MessagesDAO()
     if not dao.getMessageByID(message_id):
         return jsonify(Error="Message not found."), 404
     else:
         dislikes = dao.getMessageLikes(message_id)
         result = {}
         result['message_id'] = dislikes[0]
         result['dislikes'] = dislikes[1]
         print(result)
         return jsonify(Disikes=result)
예제 #6
0
    def getMessagesByChatID(self, id):

        dao = MessagesDAO()
        result = dao.getMessagesByChatID(id)
        mapped_result = []
        if result == None:
            return jsonify(Error="MESSAGE NOT FOUND"), 404
        # chat = ChatDAO().getChatByID(id)                      # comment these 3 lines to toggle dev ability
        # if chat == None:
        #     return jsonify(Error="CHAT NOT FOUND"), 404
        else:
            for r in result:
                mapped_result.append(self.mapToMessagesDict(r))
            return jsonify(Messages=mapped_result)
예제 #7
0
 def deleteMessageReaction(self, message_id):
     dao = MessagesDAO()
     if not dao.getMessageByID(message_id):
         return jsonify(Error="Message not found."), 404
     elif dao.validateReaction(message_id) == None:
         return jsonify(Error="You haven't reacted."), 404
     else:
         dao.deleteReaction(message_id)
         return jsonify(DeleteStatus="Message Reaction Deleted"), 200
예제 #8
0
 def addMessageDislike(self, message_id):
     dao = MessagesDAO()
     if not dao.getMessageByID(message_id):
         return jsonify(Error="Message not found."), 404
     elif dao.validateReaction(message_id) != None:
         return jsonify(Error="You already reacted."), 404
     else:
         dao.addDislike(message_id)
         return jsonify(Status="Message Dislike Added"), 200
예제 #9
0
    def postMessagesByChatID(self, form, chid):
        # cid = json['cid']
        # chid = form['chid']

        if form == None:
            return jsonify(Error="Malformed post request"), 400

        # if password is not in form or is empty
        if "message" in form:
            message = form['message']
            if message == '':
                return jsonify(Error="Missing message"), 400
        else:
            return jsonify(Error="Malformed post request"), 400

        # verify if email is not in form or left blank
        if "media" in form:
            media = form['media']
            if media == '':
                media = ' '
        else:
            media = ' '

        if message == ' ' and media == ' ':
            return jsonify(Error="Missing message or media"), 400
        if (media == ' '):
            dao = MessagesDAO()
            message_id = dao.insertWithoutMedia(chid, message)
            # result = self.getMessageByID(message_id)
            return message_id
        else:
            dao = MessagesDAO()
            media_id = dao.insertMedia(media)
            message_id = dao.insert(chid, message, media_id)
            # result = self.getMessageByID(message_id)
            return message_id