Skip to content

Commit

Permalink
boxes: Add footlinks in MessageBox.
Browse files Browse the repository at this point in the history
The footlinks are shown below the message content with a style that is
different from the rest of the message content but similar to msg_links.

Test added.

Fixes zulip#618.
  • Loading branch information
preetmishra committed Jun 28, 2020
1 parent 8a05194 commit 27741d7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,26 @@ def test_reactions_view(self, message_fixture, to_vary_in_each_message):
('reaction_mine', 9),
]

@pytest.mark.parametrize(['message_links', 'expected_text',
'expected_attrib'], [
([('#T1', 'https://github.com/zulip/zulip-terminal/pull/1')],
'1: https://github.com/zulip/zulip-terminal/pull/1',
[('msg_footlink', 49)]),
([('Foo!', 'https://foo.com'), ('Bar!', 'https://bar.com')],
'1: https://foo.com\n2: https://bar.com',
[('msg_footlink', 37)]),
],
ids=['one_footlink', 'more_than_one_footlink']
)
def test_footlinks_view(self, message_fixture, message_links,
expected_text, expected_attrib):
msg_box = MessageBox(message_fixture, self.model, None)

footlinks = msg_box.footlinks_view(message_links)

assert footlinks.original_widget.text == expected_text
assert footlinks.original_widget.attrib == expected_attrib

@pytest.mark.parametrize(
'key', keys_for_command('ENTER'),
ids=lambda param: 'left_click-key:{}'.format(param)
Expand Down
21 changes: 21 additions & 0 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ def reactions_view(self, reactions: List[Dict[str, Any]]) -> Any:
except Exception:
return ''

def footlinks_view(self, message_links: List[Tuple[str, str]]) -> Any:
if not message_links:
return ''

indexed_links = [
'{}: {}\n'.format(index, link)
for index, (text, link) in enumerate(message_links, start=1)
]
indexed_links[-1] = indexed_links[-1][:-1] # Remove the last newline.

footlinks = [
('msg_footlink', indexed_link)
for indexed_link in indexed_links
]
return urwid.Padding(urwid.Text(footlinks), align='left', left=10,
width=('relative', 100), min_width=10, right=5)

def soup2markup(self, soup: Any, **state: Any) -> List[Any]:
# Ensure a string is provided, in case the soup finds none
# This could occur if eg. an image is removed or not shown
Expand Down Expand Up @@ -658,11 +675,15 @@ def main_view(self) -> List[Any]:
# Reactions
reactions = self.reactions_view(self.message['reactions'])

# Footlinks.
footlinks = self.footlinks_view(self.message_links)

# Build parts together and return
parts = [
(recipient_header, recipient_header is not None),
(content_header, any_differences),
(content, True),
(footlinks, footlinks != ''),
(reactions, reactions != ''),
]
return [part for part, condition in parts if condition]
Expand Down

0 comments on commit 27741d7

Please sign in to comment.