Example #1
0
    def save_to_drafts(self, dict):
        with Db.get() as self._db:
            sender = UserService().get_by_email(dict['sender_email'])
            dict['creator_id'] = sender['id']

            #add message
            message_dict = MessageService().convert_to_message_dict(dict)
            message_object = MessageService().add(message_dict)

            dict['message_id'] = message_object.id

            #add mapping of sender with placeholder as Sent Mail
            dict['user_id'] = sender["id"]
            MessageService().add_user_message_mapping(dict, 'drafts')

            return message_dict
Example #2
0
    def compose(self, dict):
        with Db.get() as self._db:

            sender = UserService().get_by_email(dict['sender_email'])
            dict['creator_id'] = sender['id']

            #add message
            message_dict = MessageService().convert_to_message_dict(dict)
            message_object = MessageService().add(message_dict)

            dict['message_id'] = message_object.id

            #add mapping of sender with placeholder as Sent Mail
            dict['user_id'] = sender["id"]
            MessageService().add_user_message_mapping(dict, 'sent_mail')

            #add mapping of recipient with placeholder as Inbox
            to_emails = dict['recipient_email'].split(',')
            for email in to_emails:
                recipient = UserService().get_by_email(email.strip())
                dict['user_id'] = recipient["id"]
                MessageService().add_user_message_mapping(dict, 'inbox')

            return message_object
Example #3
0
def message():
    if request.method == 'POST':
        data = request.json
        Message.send_message(data[0], data[1], data[2], data[3])
    return jsonify(Message.get_messages())
Example #4
0
 def delete(self, mapping_id):
     with Db.get() as self._db:
         #update the user message mapping by updating the placeholder as trash
         placeholder = Placeholder.get_by_name(self._db, 'trash')
         return MessageService().update_user_message_mapping(
             mapping_id, {'placeholder_id': placeholder.id})
Example #5
0
 def forward(self, dict):
     with Db.get() as self._db:
         message = self.compose(dict)
         MessageService().update_message(dict['child_message_id'],
                                         {'parent_message_id': message.id})
         return
Example #6
0
def add_message():
    dict = request.get_json(force=True)
    return json_response(MessageService().add(dict))
Example #7
0
def update_message(id):
    dict = request.get_json(force=True)
    return json_response(MessageService().update_user_message_mapping(
        id, dict))
Example #8
0
def get_message(id):
    include = ['user', 'parent', 'children']
    return json_response(MessageService().get(id, include), include)
Example #9
0
 def get_placeholder_mails(self, user_id, placeholder_name):
     with Db.get() as self._db:
         return MessageService().get_user_message_mapping(user_id, placeholder_name)