diff --git a/tests/ui/test_ui_tools.py b/tests/ui/test_ui_tools.py index fdcc69edc5..ae790b9040 100644 --- a/tests/ui/test_ui_tools.py +++ b/tests/ui/test_ui_tools.py @@ -1292,6 +1292,8 @@ def test_init(self, mocker, message_type, set_fields): assert msg_box.last_message == defaultdict(dict) for field, invalid_default in set_fields: assert getattr(msg_box, field) != invalid_default + if message_type == 'stream': + assert msg_box.topic_links == OrderedDict() assert msg_box.message_links == OrderedDict() assert msg_box.time_mentions == list() diff --git a/tests/ui_tools/test_popups.py b/tests/ui_tools/test_popups.py index 01d1630bbc..a8d95e1c12 100644 --- a/tests/ui_tools/test_popups.py +++ b/tests/ui_tools/test_popups.py @@ -207,6 +207,7 @@ def mock_external_classes(self, mocker): self.edit_history_view = EditHistoryView( controller=self.controller, message=self.message, + topic_links=OrderedDict(), message_links=OrderedDict(), time_mentions=list(), title='Edit History', @@ -215,6 +216,7 @@ def mock_external_classes(self, mocker): def test_init(self): assert self.edit_history_view.controller == self.controller assert self.edit_history_view.message == self.message + assert self.edit_history_view.topic_links == OrderedDict() assert self.edit_history_view.message_links == OrderedDict() assert self.edit_history_view.time_mentions == list() self.controller.model.fetch_message_history.assert_called_once_with( @@ -246,6 +248,7 @@ def test_keypress_show_msg_info(self, key, widget_size): self.controller.show_msg_info.assert_called_once_with( msg=self.message, + topic_links=OrderedDict(), message_links=OrderedDict(), time_mentions=list(), ) @@ -450,7 +453,13 @@ def mock_external_classes(self, mocker, monkeypatch, message_fixture): ] self.msg_info_view = MsgInfoView(self.controller, message_fixture, 'Message Information', OrderedDict(), - list()) + OrderedDict(), list()) + + def test_init(self, message_fixture): + assert self.msg_info_view.msg == message_fixture + assert self.msg_info_view.topic_links == OrderedDict() + assert self.msg_info_view.message_links == OrderedDict() + assert self.msg_info_view.time_mentions == list() def test_keypress_any_key(self, widget_size): key = "a" @@ -482,6 +491,7 @@ def test_keypress_edit_history(self, message_fixture, key, widget_size, } msg_info_view = MsgInfoView(self.controller, message_fixture, title='Message Information', + topic_links=OrderedDict(), message_links=OrderedDict(), time_mentions=list()) size = widget_size(msg_info_view) @@ -491,6 +501,7 @@ def test_keypress_edit_history(self, message_fixture, key, widget_size, if msg_info_view.show_edit_history_label: self.controller.show_edit_history.assert_called_once_with( message=message_fixture, + topic_links=OrderedDict(), message_links=OrderedDict(), time_mentions=list(), ) @@ -552,7 +563,7 @@ def test_height_reactions(self, message_fixture, to_vary_in_each_message): varied_message = dict(message_fixture, **to_vary_in_each_message) self.msg_info_view = MsgInfoView(self.controller, varied_message, 'Message Information', OrderedDict(), - list()) + OrderedDict(), list()) # 9 = 3 labels + 1 blank line + 1 'Reactions' (category) + 4 reactions. expected_height = 9 assert self.msg_info_view.height == expected_height diff --git a/zulipterminal/core.py b/zulipterminal/core.py index 14db4ba311..346e8a8b42 100644 --- a/zulipterminal/core.py +++ b/zulipterminal/core.py @@ -205,12 +205,13 @@ def show_topic_edit_mode(self, button: Any) -> None: self.show_pop_up(EditModeView(self, button), 'area:msg') def show_msg_info(self, msg: Message, + topic_links: 'OrderedDict[str, Tuple[str, int, bool]]', message_links: 'OrderedDict[str, Tuple[str, int, bool]]', time_mentions: List[Tuple[str, str]], ) -> None: msg_info_view = MsgInfoView(self, msg, "Message Information (up/down scrolls)", - message_links, time_mentions) + topic_links, message_links, time_mentions) self.show_pop_up(msg_info_view, 'area:msg') def show_stream_info(self, stream_id: int) -> None: @@ -241,11 +242,13 @@ def show_about(self) -> None: def show_edit_history( self, message: Message, + topic_links: 'OrderedDict[str, Tuple[str, int, bool]]', message_links: 'OrderedDict[str, Tuple[str, int, bool]]', time_mentions: List[Tuple[str, str]], ) -> None: self.show_pop_up( - EditHistoryView(self, message, message_links, time_mentions, + EditHistoryView(self, message, topic_links, + message_links, time_mentions, 'Edit History (up/down scrolls)'), 'area:msg' ) diff --git a/zulipterminal/ui_tools/boxes.py b/zulipterminal/ui_tools/boxes.py index ee38d6007a..0bd47f806b 100644 --- a/zulipterminal/ui_tools/boxes.py +++ b/zulipterminal/ui_tools/boxes.py @@ -661,6 +661,9 @@ def __init__(self, message: Message, model: 'Model', self.message_links: 'OrderedDict[str, Tuple[str, int, bool]]' = ( OrderedDict() ) + self.topic_links: 'OrderedDict[str, Tuple[str, int, bool]]' = ( + OrderedDict() + ) self.time_mentions: List[Tuple[str, str]] = list() self.last_message = last_message # if this is the first message @@ -668,6 +671,13 @@ def __init__(self, message: Message, model: 'Model', self.last_message = defaultdict(dict) if self.message['type'] == 'stream': + # Set `topic_links` if present + for link in self.message.get('topic_links', []): + # Modernized response + self.topic_links[link['url']] = ( + link['text'], len(self.topic_links) + 1, True + ) + self.stream_name = self.message['display_recipient'] self.stream_id = self.message['stream_id'] self.topic_name = self.message['subject'] @@ -1549,6 +1559,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]: self.model.controller.view.middle_column.set_focus('footer') elif is_command_key('MSG_INFO', key): self.model.controller.show_msg_info(self.message, + self.topic_links, self.message_links, self.time_mentions) return key diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index 4c9819de44..53f9598d87 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1219,10 +1219,12 @@ def keypress(self, size: urwid_Size, key: str) -> str: class MsgInfoView(PopUpView): def __init__(self, controller: Any, msg: Message, title: str, + topic_links: 'OrderedDict[str, Tuple[str, int, bool]]', message_links: 'OrderedDict[str, Tuple[str, int, bool]]', time_mentions: List[Tuple[str, str]], ) -> None: self.msg = msg + self.topic_links = topic_links self.message_links = message_links self.time_mentions = time_mentions date_and_time = controller.model.formatted_local_time( @@ -1300,6 +1302,7 @@ def keypress(self, size: urwid_Size, key: str) -> str: and self.show_edit_history_label): self.controller.show_edit_history( message=self.msg, + topic_links=self.topic_links, message_links=self.message_links, time_mentions=self.time_mentions, ) @@ -1345,11 +1348,13 @@ def keypress(self, size: urwid_Size, key: str) -> str: class EditHistoryView(PopUpView): def __init__(self, controller: Any, message: Message, + topic_links: 'OrderedDict[str, Tuple[str, int, bool]]', message_links: 'OrderedDict[str, Tuple[str, int, bool]]', time_mentions: List[Tuple[str, str]], title: str) -> None: self.controller = controller self.message = message + self.topic_links = topic_links self.message_links = message_links self.time_mentions = time_mentions width = 64 @@ -1446,6 +1451,7 @@ def keypress(self, size: urwid_Size, key: str) -> str: or is_command_key('EDIT_HISTORY', key)): self.controller.show_msg_info( msg=self.message, + topic_links=self.topic_links, message_links=self.message_links, time_mentions=self.time_mentions, )