Skip to content

Commit da89e1f

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 d52ec4c commit da89e1f

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

tests/ui/test_ui_tools.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,15 @@ def mock_external_classes(self, mocker, monkeypatch):
14281428
self.controller.model.is_muted_stream.return_value = False
14291429
self.controller.model.is_pinned_stream.return_value = False
14301430
mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
1431+
mocker.patch(VIEWS + '.MessageBox.transform_content',
1432+
return_value=('Hey', OrderedDict(), list()))
14311433
stream_id = 10
1432-
self.controller.model.stream_dict = {stream_id: {'name': 'books',
1433-
'description': 'hey'}}
1434+
self.controller.model.stream_dict = {
1435+
stream_id: {
1436+
'name': 'books',
1437+
'rendered_description': '<p>Hey</p>',
1438+
}
1439+
}
14341440
self.stream_info_view = StreamInfoView(self.controller, stream_id)
14351441

14361442
@pytest.mark.parametrize('key', {*keys_for_command('GO_BACK'),

zulipterminal/ui_tools/views.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
CHECK_MARK, LIST_TITLE_BAR_LINE, PINNED_STREAMS_DIVIDER,
1313
)
1414
from zulipterminal.helper import Message, asynch, match_stream, match_user
15-
from zulipterminal.ui_tools.boxes import PanelSearchBox
15+
from zulipterminal.ui_tools.boxes import MessageBox, PanelSearchBox
1616
from zulipterminal.ui_tools.buttons import (
1717
HomeButton, MentionedButton, MessageLinkButton, PMButton, StarredButton,
1818
StreamButton, TopicButton, UnreadPMButton, UserButton,
@@ -1045,8 +1045,11 @@ def __init__(self, controller: Any, stream_id: int) -> None:
10451045
self.controller = controller
10461046
stream = controller.model.stream_dict[stream_id]
10471047
title = '# {}'.format(stream['name'])
1048-
desc = stream['description']
1049-
stream_info_content = [('', [desc]), ('Stream settings', [])]
1048+
rendered_desc = stream['rendered_description']
1049+
1050+
stream_info_content = (
1051+
[('Stream settings', [])]
1052+
) # type: PopUpViewTableContent
10501053
popup_width, column_widths = self.calculate_table_widths(
10511054
stream_info_content, len(title))
10521055

@@ -1062,12 +1065,23 @@ def __init__(self, controller: Any, stream_id: int) -> None:
10621065
urwid.connect_signal(pinned_setting, 'change',
10631066
self.toggle_pinned_status)
10641067

1068+
markup_desc, *_ = MessageBox.transform_content(
1069+
rendered_desc,
1070+
self.controller.model.server_url,
1071+
)
1072+
desc = urwid.Text(markup_desc)
1073+
10651074
# Manual because calculate_table_widths does not support checkboxes.
10661075
# Add 4 to checkbox label to accomodate the checkbox itself.
10671076
popup_width = max(popup_width, len(muted_setting.label) + 4,
1068-
len(pinned_setting.label) + 4)
1077+
len(pinned_setting.label) + 4, desc.pack()[0])
10691078
self.widgets = self.make_table_with_categories(stream_info_content,
10701079
column_widths)
1080+
1081+
# Stream description.
1082+
self.widgets.insert(0, desc)
1083+
self.widgets.insert(1, urwid.Text('')) # Add a newline.
1084+
10711085
self.widgets.append(muted_setting)
10721086
self.widgets.append(pinned_setting)
10731087
super().__init__(controller, self.widgets, 'STREAM_DESC', popup_width,

0 commit comments

Comments
 (0)