def update_messages(self, response: Dict[str, str]) -> None: if hasattr(self.controller, 'view'): cmsg = classify_message(self.client.email, [response]) key = list(cmsg.keys())[0] if ((self.narrow == []) or (self.narrow[0][1] == key)) and\ self.update: self.msg_list.log.append( urwid.AttrMap(MessageBox(cmsg[key][0], self), cmsg[key][0]['color'], 'msg_selected')) self.controller.loop.draw_screen() else: if hasattr(self, 'messages'): self.messages = classify_message(self.client.email, [response], self.messages) else: self.initial_update.append(response)
def load_old_messages(self, first_anchor: bool) -> List[Dict[str, str]]: request = { 'anchor': self.anchor, 'num_before': self.num_before, 'num_after': self.num_after, 'apply_markdown': False, 'use_first_unread_anchor': first_anchor, 'client_gravatar': False, 'narrow': json.dumps(self.narrow), } response = self.client.do_api_query(request, '/json/messages', method="GET") if response['result'] == 'success': if first_anchor: self.focus_narrow = response['anchor'] if self.narrow == []: self.focus_all_msg = response['anchor'] if (len(response['messages']) < 41): self.update = True return classify_message(self.client.email, response['messages'])
def __init__(self, controller: Any) -> None: self.controller = controller self.client = controller.client self.msg_view = None # List Walker of urwid self.anchor = 0 self.num_before = 30 self.num_after = 10 self.msg_list = None # Updated by MiddleColumnView (ListBox) self.narrow = [] self.update = False # ID of the message to select when viewing all messages. self.focus_all_msg = -1 # ID of the message to select when in a narrow. self.focus_narrow = -1 self.menu = [ u'All messages', u'Private messages', ] ''' Stores all the messages, type: Dict[str, Dict[Dict[str, Any]]] Example: { '*****@*****.**' : [ # Store other user's id in PM # (regardless of sender) # List of Messages { 'sender' : 'Aman Agrawal', 'time' : '8 AM', 'stream':[ # Actually recipient { 'full_name':'Hamlet of Denmark', 'email':'*****@*****.**', 'short_name':'hamlet', 'id':31572 }, { 'full_name': 'Aman Agrawal', 'email' : '*****@*****.**', 'short_name' : 'aman', 'id' : '123', } ], 'title' : '', 'content' : 'HI', 'type' : 'private', 'sender_email' : '*****@*****.**', }, ... ], '89' : [ # Stream ID { 'sender' : 'aman', 'time' : '8 AM', 'stream' : 'integrations', 'title' : 'zulip-terminal', 'content' : 'HI', 'type' : 'stream', 'sender_email' : '*****@*****.**', }, ... ], ... } ''' # TODO: make initial fetch async so that no message is lost # when the messages are being fetched. self.initial_update = list() self.update_new_message() self.messages = self.load_old_messages(first_anchor=True) self.messages = classify_message(self.client.email, self.initial_update, self.messages) self.initial_data = self.fetch_initial_data()
def test_classify_message(user_email, messages_successful_response, classified_message): result = classify_message(user_email, messages_successful_response['messages']) assert result == classified_message
def test_classify_message(user_email: str, messages_successful_response: MSR, classified_message: CMSG) -> None: result = classify_message(user_email, messages_successful_response['messages']) assert result == classified_message