Skip to content

Commit

Permalink
views: Append topic links in message info view.
Browse files Browse the repository at this point in the history
This is a wrapper commit that appends topic links in message info
view (if present). If the link text is empty, the link is appended
in a single line.

Tests amended.
Fixes #709.
  • Loading branch information
Ezio-Sarthak committed Apr 8, 2021
1 parent 8b0c634 commit fb6e5d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 10 additions & 1 deletion tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,16 @@ def test_height_reactions(self, message_fixture, to_vary_in_each_message):
{None: 'popup_contrast'},
{None: 'selected'},
15,
)],
), (
OrderedDict([('https://foo.com', ('', 1, True))]),
'1: https://foo.com',
{None: 'popup_contrast'},
{None: 'selected'},
18,
)], ids=[
'link_with_link_text',
'link_without_link_text',
]
)
def test_create_link_buttons(self, initial_link, expected_text,
expected_attr_map, expected_focus_map,
Expand Down
22 changes: 21 additions & 1 deletion zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,8 @@ def __init__(self, controller: Any, msg: Message, title: str,
('Edit History', f"Press {keys} to view")
)
# Render the category using the existing table methods if links exist.
if topic_links:
msg_info.append(('Topic Links', []))
if message_links:
msg_info.append(('Message Links', []))
if time_mentions:
Expand All @@ -1276,6 +1278,21 @@ def __init__(self, controller: Any, msg: Message, title: str,
# computing their slice indexes
button_widgets = [] # type: List[Any]

if topic_links:
topic_link_widgets, topic_link_width = (
self.create_link_buttons(controller, topic_links)
)

# slice_index = Number of labels before topic links + 1 newline
# + 1 'Topic Links' category label.
slice_index = len(msg_info[0][1]) + 2
slice_index += sum([len(w) + 2 for w in button_widgets])
button_widgets.append(topic_links)

widgets = (widgets[:slice_index] + topic_link_widgets
+ widgets[slice_index:])
popup_width = max(popup_width, topic_link_width)

if message_links:
message_link_widgets, message_link_width = (
self.create_link_buttons(controller, message_links)
Expand Down Expand Up @@ -1303,7 +1320,10 @@ def create_link_buttons(

for index, link in enumerate(links):
text, link_index, _ = links[link]
caption = f"{link_index}: {text}\n{link}"
if text:
caption = f"{link_index}: {text}\n{link}"
else:
caption = f"{link_index}: {link}"
link_width = max(
link_width,
len(max(caption.split('\n'), key=len))
Expand Down

0 comments on commit fb6e5d2

Please sign in to comment.