Skip to content

Commit d0f4760

Browse files
committed
model/views: Show edit history using EditHistoryView.
This GETs 'message_history', using message id, from the server and displays it in the EditHistoryView. The EditHistoryView (popup) can be triggered with 'EDIT_HISTORY' key from the MsgInfoView. The following information is displayed in the view: * topic (with 'updated from' prefix if it's been updated) * timestamp * author name * tag (for current and original message) * content
1 parent 9b50bdb commit d0f4760

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

zulipterminal/model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ def get_messages(self, *,
356356
return ""
357357
return response['msg']
358358

359+
def get_message_history(self, message: Message) -> str:
360+
"""
361+
GETs 'message_history' using messsage id.
362+
"""
363+
response = self.client.get_message_history(message_id=message['id'])
364+
if response['result'] == 'success':
365+
message['message_history'] = response['message_history']
366+
return ''
367+
return response['msg']
368+
359369
def get_topics_in_stream(self, stream_list: Iterable[int]) -> str:
360370
"""
361371
Fetch all topics with specified stream_id's and

zulipterminal/ui_tools/views.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import threading
22
import time
33
from collections import OrderedDict
4-
from typing import Any, Callable, List, Optional, Tuple
4+
from typing import Any, Callable, Dict, List, Optional, Tuple
55

66
import urwid
77

@@ -940,8 +940,61 @@ def __init__(self, controller: Any, msg: Any) -> None:
940940
self.controller = controller
941941
self.msg = msg
942942
self.width = 64
943-
self.height = 0
944-
super().__init__(controller, [], 'MSG_INFO')
943+
self.height = 10
944+
945+
self.widgets = []
946+
# NOTE: 'edit_history' is likely to be changed to a boolean value in
947+
# the future.
948+
if 'edit_history' in self.msg:
949+
self.controller.model.get_message_history(self.msg)
950+
for index, snapshot in enumerate(self.msg['message_history']):
951+
if index == len(self.msg['message_history']) - 1:
952+
self.widgets.append(self.build_pile(snapshot, 'Current'))
953+
continue
954+
elif index == 0:
955+
self.widgets.append(self.build_pile(snapshot, 'Original'))
956+
else:
957+
self.widgets.append(self.build_pile(snapshot))
958+
self.widgets.append(urwid.Text('')) # Add newline.
959+
else:
960+
self.height = 1
961+
text = 'The content has not been edited.'
962+
self.widgets = [urwid.Text(text, align='center')]
963+
964+
super().__init__(controller, self.widgets, 'MSG_INFO')
965+
966+
def build_pile(self, snapshot: Dict[str, Any], tag: str='') -> Any:
967+
timestamp = time.ctime(snapshot['timestamp'])[:-5]
968+
full_name = self.get_full_name(snapshot['user_id'])
969+
topic = snapshot['topic']
970+
if 'prev_topic' in snapshot and topic != snapshot['prev_topic']:
971+
topic += ' (updated from {})'.format(snapshot['prev_topic'])
972+
973+
header = urwid.Columns([
974+
urwid.Text(('edit_topic', topic)),
975+
(19, urwid.Text(('edit_time', timestamp))),
976+
], dividechars=2,
977+
)
978+
subheader = urwid.Columns([
979+
urwid.Text(('edit_author', full_name)),
980+
(18, urwid.Text(('edit_tag', '({} Version)'.format(tag) if tag
981+
else ''), align='right')),
982+
], dividechars=2,
983+
)
984+
message = urwid.Text(snapshot['content'])
985+
return urwid.Pile([urwid.AttrWrap(header, 'popup_contrast'), subheader,
986+
message])
987+
988+
def get_full_name(self, user_id: int) -> str:
989+
if self.msg['sender_id'] == user_id:
990+
return self.msg['sender_full_name']
991+
else:
992+
for user in self.controller.view.users:
993+
if user['user_id'] == user_id:
994+
return user['full_name']
995+
# NOTE: This return statement is redundant and only put here to pass
996+
# mypy as a user with `user_id` will always exist.
997+
return ''
945998

946999
def keypress(self, size: urwid_Size, key: str) -> str:
9471000
if (is_command_key('GO_BACK', key)

0 commit comments

Comments
 (0)