diff --git a/tfw/components/frontend/message_sender.py b/tfw/components/frontend/message_sender.py index 72915c2..0f4f249 100644 --- a/tfw/components/frontend/message_sender.py +++ b/tfw/components/frontend/message_sender.py @@ -1,48 +1,30 @@ class MessageSender: - """ - Provides mechanisms to send messages to our frontend messaging component. - """ def __init__(self, uplink): self.uplink = uplink - self.key = 'message' - self.queue_key = 'queueMessages' - def send(self, originator, message): - """ - Sends a message. - :param originator: name of sender to be displayed on the frontend - :param message: message to send - """ + def send(self, message, originator=None): message = { - 'key': self.key, - 'data': { - 'originator': originator, - 'message': message - } + 'key': 'message.send', + 'message': message } + if originator: + message['originator'] = originator self.uplink.send_message(message) - def queue_messages(self, originator, messages): - """ - Queues a list of messages to be displayed in a chatbot-like manner. - :param originator: name of sender to be displayed on the frontend - :param messages: list of messages to queue - """ - message = { - 'key': self.queue_key, - 'data': { - 'messages': [ - {'message': message, 'originator': originator} - for message in messages - ] - } + def queue_messages(self, messages, originator=None): + message_queue = { + 'key': 'message.queue', + 'value': [] } - self.uplink.send_message(message) + for message in messages: + next_message = {'message': message} + if originator: + next_message['originator'] = originator + message_queue['value'].append(next_message) + self.uplink.send_message(message_queue) - @staticmethod - def generate_messages_from_queue(queue_message): - for message in queue_message['data']['messages']: - yield { - 'key': 'message', - 'data': message - } + def set_originator(self, originator): + self.uplink.send_message({ + 'key': 'message.config', + 'originator': originator + })