Skip to content

Commit f830ed4

Browse files
committed
views: Show author name in EditHistoryView.
This adds get_author, a method that gets the author's full name in constant time/O(1), to show the author's full name in EditHistoryView. In addition to that, a minimal author_prefix ('Posted' and 'Edited') has also been added. Test added and amended. O(1)-lookup-suggested-by: Sumanth V Rao <[email protected]>
1 parent 71af92f commit f830ed4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

tests/ui/test_ui_tools.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,13 +1242,15 @@ def test_keypress_navigation(self, mocker,
12421242
class TestEditHistoryView:
12431243
@pytest.fixture(autouse=True)
12441244
def mock_external_classes(self, mocker, message_fixture,
1245-
message_history_fixture):
1245+
message_history_fixture, user_dict):
12461246
self.controller = mocker.Mock()
12471247
mocker.patch.object(self.controller, 'maximum_popup_dimensions',
12481248
return_value=(64, 64))
12491249
self.controller.model.get_message_history = (
12501250
mocker.Mock(return_value='')
12511251
)
1252+
self.controller.model.user_id_email_dict = {1001: '[email protected]'}
1253+
self.controller.model.user_dict = user_dict
12521254
message_fixture['message_history'] = message_history_fixture
12531255
mocker.patch(VIEWS + '.urwid.SimpleFocusListWalker', return_value=[])
12541256
self.edit_history_view = EditHistoryView(self.controller,
@@ -1261,6 +1263,11 @@ def test_init(self, mocker, message_fixture):
12611263
(self.controller.model.get_message_history.
12621264
assert_called_once_with(message_fixture))
12631265

1266+
@pytest.mark.parametrize('user_id, full_name', [(1001, 'Human Myself')])
1267+
def test_get_author(self, user_id, full_name):
1268+
result = self.edit_history_view.get_author(user_id)
1269+
assert result == full_name
1270+
12641271
@pytest.mark.parametrize('key', keys_for_command('MSG_INFO'))
12651272
def test_keypress_exit_popup(self, key):
12661273
size = (200, 20)
@@ -1295,7 +1302,8 @@ def test_edit_block(self, message_history_fixture):
12951302
assert isinstance(contents[0][0], Text) # Header: Topic.
12961303
assert isinstance(contents[0][1], Text) # Header: Timestamp.
12971304
assert isinstance(contents[1], Columns) # Subheader.
1298-
assert isinstance(contents[1][0], Text) # Subheader: Tag.
1305+
assert isinstance(contents[1][0], Text) # Subheader: Author.
1306+
assert isinstance(contents[1][1], Text) # Subheader: Tag.
12991307
assert isinstance(contents[2], Text) # Content.
13001308

13011309

zulipterminal/ui_tools/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,18 @@ def edit_block(self, snapshot: Dict[str, Any], state: str) -> Any:
10181018

10191019
tag = '({} Version)'.format(state) if state else ''
10201020

1021+
author_prefix = 'Posted' if state == 'Original' else 'Edited'
1022+
author = '{} by {}'.format(author_prefix,
1023+
self.get_author(snapshot['user_id']))
1024+
10211025
header = [
10221026
urwid.Text(('edit_topic', topic)),
10231027
(19, urwid.Text(('edit_time', timestamp))), # 19 = len(timestamp).
10241028
]
10251029
subheader = [
1030+
urwid.Text(('edit_author', author)),
10261031
# 18 = max(len(tag)); len('(Original Version)').
1027-
(18, urwid.Text(('edit_tag', tag))),
1032+
(18, urwid.Text(('edit_tag', tag), align='right')),
10281033
]
10291034

10301035
edit_block = [
@@ -1035,6 +1040,11 @@ def edit_block(self, snapshot: Dict[str, Any], state: str) -> Any:
10351040
]
10361041
return urwid.Pile(edit_block)
10371042

1043+
def get_author(self, user_id: int) -> str:
1044+
user_email = self.controller.model.user_id_email_dict[user_id]
1045+
full_name = self.controller.model.user_dict[user_email]['full_name']
1046+
return full_name
1047+
10381048
def keypress(self, size: urwid_Size, key: str) -> str:
10391049
if (is_command_key('GO_BACK', key)
10401050
or is_command_key('EDIT_HISTORY', key)):

0 commit comments

Comments
 (0)