Beispiel #1
0
def SaveMessage(emailSender, emailRecipient, m):
    if (user.findUserByEmail(emailSender) is None):
        return results.Result.NOT_FOUND
    else:
        senderId = user.findUserByEmail(emailSender)['id']

    if (user.findUserByEmail(emailRecipient) is None):
        return results.Result.NOT_FOUND
    else:
        recipientId = user.findUserByEmail(emailRecipient)['id']

    if (len(m) <= 0):
        return results.Result.EMPTY_MESSAGE

    ts = time.time()

    if (len(messages) <= 0):
        mId = 1  # The first message will have 1 as ID
    else:
        mId = len(messages) + 1  # Increment the messageId value by 1

    message = {
        'messageId': mId,
        'senderId': senderId,
        'recipientId': recipientId,
        'message': m,
        'timestamp': ts
    }

    messages.append(message.copy())
    return results.Result.OK
def SaveMessage(sender: str, recipient: str, content: str) -> (Result, dict):
    id = uuid.uuid4()

    senderData = user.findUserByEmail(sender)
    if senderData is None:
        return Result.NOT_FOUND, None

    recipientData = user.findUserByEmail(recipient)
    if recipientData is None:
        return Result.NOT_FOUND, None

    senderID = senderData['id']
    recipientID = recipientData['id']

    message = {
        'id': id,
        'sender': senderID,
        'recipient': recipientID,
        'content': content,
        'created': datetime.utcnow().isoformat()
    }

    messages.append(message.copy())

    response = {
        'id': message['id'],
        'sender': sender,
        'recipient': recipient,
        'content': message['content'],
        'created': message['created']
    }

    return Result.OK, response
def GetMessages(reader: str) -> (Result, list):
    readerData = user.findUserByEmail(reader)
    if readerData is None:
        return Result.NOT_FOUND, None

    inbox = findMessages(readerData['id'])

    return Result.OK, inbox
Beispiel #4
0
def GetMessages(email: str) -> (Result, dict):
    usr_data = findUserByEmail(email)
    if not usr_data:
        return Result.NOT_FOUND, None
    usr_msgs = []
    for msg in messages:
        if msg['dest'] == usr_data['email']:
            # modificare i tag di ritorno e risolvere le email
            usr_msgs.append(msg)

    return Result.OK, jsonify(usr_msgs)
Beispiel #5
0
def SaveMessage(sender: str, receiver: str,
                content: str) -> (statusLabels, dict):
    if (user.findUserByEmail(sender) is not None):
        senderID = user.findUserByEmail(receiver)['id']
    else:
        return statusLabels.Result.NOT_FOUND, None

    if (user.findUserByEmail(receiver) is not None):
        receiverID = user.findUserByEmail(receiver)['id']
    else:
        return statusLabels.Result.NOT_FOUND, None

    id = len(messages)  #messageID
    message = {
        'messageID': id,
        'created': datetime.utcnow().isoformat(),
        'emailSender': senderID,
        'emailReceiver': receiverID,
        'contentMess': content
    }

    messages.append(message.copy())
    return statusLabels.Result.OK, message
Beispiel #6
0
def SaveMessage(mitt: str,
                dest: str,
                msg: str,
                chat_id=None) -> (Result, dict):
    # check auth
    # check if the chatId is
    if not chat_id:
        chat_id = uuid.uuid4()

    msg_id = uuid.uuid4()

    muser = findUserByEmail(mitt)
    duser = findUserByEmail(dest)
    if not muser or not duser:
        print("one of the users has not been found")
        return Result.NOT_FOUND, None

    message = {
        'id': msg_id,
        'chatId': chat_id,
        'mitt': muser['email'],
        'dest': duser['email'],
        'msg': msg,
        'created': dt.utcnow().isoformat()
    }

    messages.append(message.copy())
    message['mitt'] = muser['email']
    message['dest'] = duser['email']

    #store
    written = utils.fileDbWrite('messages.db', messages)
    if not written:
        return Result.NOT_FOUND, None

    return Result.OK, message
Beispiel #7
0
def findUser ():
    data = request.get_json()
    credential = request.args.get('cred')
    #Auth here 
    u = user.findUserByEmail(credential)
    #Check response
    #First email than password
    if u is None:
          u = user.findUserByID(credential)
          if u is None:
                code = 404 
                return 'User not found', code
          else:
                return 'User {0}{1} found'.format(u["name"], u["surname"]), 201
    else:
        return 'User {0}{1} found'.format(u["name"], u["surname"]), 201
Beispiel #8
0
def retrieveConversation():
    data = request.get_json()
    user = Auth()
    #Get mail from sender and receiver
    receiverEmail = data.args.get('receiver')
    receiver = user.findUserByEmail(receiverEmail)
    if receiver is not None:
        receiver_id = receiver["id"]
        sender_id = user["id"]
        try: 
          message = message.retrieveConversation(receiverEmail, senderEmail)
          if message is None:
              return "Conversation is Empty", 200
          else: 
              return message, 200
        except: 
            return "A problem occured during creation"
    else:    
       return "User not Found", 404