Пример #1
0
    def on_message(self, body, message):
        response = None

        if body["query"] == "all_messages":
            response = list_messages()
        elif body["query"] == "user_messages":
            response = list_user_messages(body["user_id"])
        elif body["query"] == "search_messages":
            response = search_messages(body["search"])
        elif body["query"] == "post_message":
            response = post_message(body["user_id"], body["message"])

        if response is not None:
            response_prod = MessageResponseProducer(self.connection, messages_response_queue)
            response_prod.put_message(
                {"response": response, "message_id": body["message_id"]}, messages_response_exchange
            )
        message.ack()
Пример #2
0
    def on_message(self, body, message):
        response = None

        if body['query'] == 'all_messages':
            response = list_messages()
        elif body['query'] == 'user_messages':
            response = list_user_messages(body['user_id'])
        elif body['query'] == 'search_messages':
            response = search_messages(body['search'])
        elif body['query'] == 'post_message':
            response = post_message(body['user_id'], body['message'])

        if response is not None:
            response_prod = MessageResponseProducer(self.connection,
                                                    messages_response_queue)
            response_prod.put_message(
                {
                    'response': response,
                    'message_id': body['message_id']
                }, messages_response_exchange)
        message.ack()
Пример #3
0
def user_messages(user_id):
    messages = list_user_messages(user_id)

    return jsonify({'count': len(messages), 'messages': messages})