Skip to content

Commit e9bfc19

Browse files
committed
views: Markup stream description using MessageBox.transform_content().
Footlinks support is added in a subsequent commit. Test amended. Fixes zulip#743.
1 parent dcd5e96 commit e9bfc19

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

tests/ui_tools/test_popups.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,41 @@ def mock_external_classes(self, mocker, monkeypatch):
560560
self.controller.model.is_pinned_stream.return_value = False
561561
mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
562562
stream_id = 10
563-
self.controller.model.stream_dict = {stream_id: {'name': 'books',
564-
'description': 'hey'}}
563+
self.controller.model.stream_dict = {
564+
stream_id: {
565+
'name': 'books',
566+
'rendered_description': '<p>Hey</p>',
567+
}
568+
}
565569
self.stream_info_view = StreamInfoView(self.controller, stream_id)
566570

571+
@pytest.mark.parametrize('rendered_description, expected_markup', [
572+
(
573+
'<p>Simple</p>',
574+
(None, ['', '', 'Simple']),
575+
),
576+
(
577+
'<p>A city in Italy <a href="http://genericlink.com">ABC</a>'
578+
'<strong>Bold</strong>'
579+
'<time datetime="2020-08-29T02:30:00Z"> 8:00 IST</time></p>',
580+
(None, ['', '', 'A city in Italy ', ('msg_link', 'ABC'), ' ',
581+
('msg_link_index', '[1]'), ('msg_bold', 'Bold'),
582+
('msg_time', ' ⏱ Sat, Aug 29 2020, 8:00 (IST) ')]),
583+
),
584+
])
585+
def test_markup_descrption(self, rendered_description, expected_markup,
586+
stream_id=10):
587+
self.controller.model.stream_dict = {
588+
stream_id: {
589+
'name': 'ZT',
590+
'rendered_description': rendered_description,
591+
}
592+
}
593+
594+
stream_info_view = StreamInfoView(self.controller, stream_id)
595+
596+
assert stream_info_view.markup_desc == expected_markup
597+
567598
@pytest.mark.parametrize('key', {*keys_for_command('GO_BACK'),
568599
*keys_for_command('STREAM_DESC')})
569600
def test_keypress_exit_popup(self, key, widget_size):

zulipterminal/ui_tools/views.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from zulipterminal.helper import (
1717
Message, asynch, edit_mode_captions, match_stream, match_user,
1818
)
19-
from zulipterminal.ui_tools.boxes import PanelSearchBox
19+
from zulipterminal.ui_tools.boxes import MessageBox, PanelSearchBox
2020
from zulipterminal.ui_tools.buttons import (
2121
HomeButton, MentionedButton, MessageLinkButton, PMButton, StarredButton,
2222
StreamButton, TopicButton, UnreadPMButton, UserButton,
@@ -1078,8 +1078,11 @@ def __init__(self, controller: Any, stream_id: int) -> None:
10781078
self.controller = controller
10791079
stream = controller.model.stream_dict[stream_id]
10801080
title = '# {}'.format(stream['name'])
1081-
desc = stream['description']
1082-
stream_info_content = [('', [desc]), ('Stream settings', [])]
1081+
rendered_desc = stream['rendered_description']
1082+
1083+
stream_info_content = (
1084+
[('Stream settings', [])]
1085+
) # type: PopUpViewTableContent
10831086
popup_width, column_widths = self.calculate_table_widths(
10841087
stream_info_content, len(title))
10851088

@@ -1095,12 +1098,23 @@ def __init__(self, controller: Any, stream_id: int) -> None:
10951098
urwid.connect_signal(pinned_setting, 'change',
10961099
self.toggle_pinned_status)
10971100

1101+
self.markup_desc, *_ = MessageBox.transform_content(
1102+
rendered_desc,
1103+
self.controller.model.server_url,
1104+
)
1105+
desc = urwid.Text(self.markup_desc)
1106+
10981107
# Manual because calculate_table_widths does not support checkboxes.
10991108
# Add 4 to checkbox label to accomodate the checkbox itself.
11001109
popup_width = max(popup_width, len(muted_setting.label) + 4,
1101-
len(pinned_setting.label) + 4)
1110+
len(pinned_setting.label) + 4, desc.pack()[0])
11021111
self.widgets = self.make_table_with_categories(stream_info_content,
11031112
column_widths)
1113+
1114+
# Stream description.
1115+
self.widgets.insert(0, desc)
1116+
self.widgets.insert(1, urwid.Text('')) # Add a newline.
1117+
11041118
self.widgets.append(muted_setting)
11051119
self.widgets.append(pinned_setting)
11061120
super().__init__(controller, self.widgets, 'STREAM_DESC', popup_width,

0 commit comments

Comments
 (0)