Skip to content

Commit

Permalink
boxes/core/views: Set and pass topic links linkifier OrderedDict.
Browse files Browse the repository at this point in the history
This commit:
- sets the OrderedDict of topic links in a message.
  (using the new modernized `topic_links` response)
- passes argument topic links in suitable calls.

Tests updated.
  • Loading branch information
Ezio-Sarthak committed Apr 8, 2021
1 parent 54cf76d commit c597740
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
15 changes: 13 additions & 2 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand Down Expand Up @@ -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(),
)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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(),
)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
)
Expand Down
11 changes: 11 additions & 0 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,13 +661,23 @@ 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
if self.last_message is None:
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']
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit c597740

Please sign in to comment.