Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group message data #1537

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 18 additions & 48 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,27 +975,28 @@ def mock_external_classes(
"Tue Mar 13 10:55:22",
"Tue Mar 13 10:55:37",
]
self.message = message_fixture
self.msg_info_view = MsgInfoView(
self.controller,
message_fixture,
self.message,
"Message Information",
OrderedDict(),
OrderedDict(),
list(),
)

def test_init(self, message_fixture: Message) -> None:
assert self.msg_info_view.msg == message_fixture
def test_init(self) -> None:
assert self.msg_info_view.msg == self.message
assert self.msg_info_view.topic_links == OrderedDict()
assert self.msg_info_view.message_links == OrderedDict()
assert self.msg_info_view.time_mentions == list()

def test_pop_up_info_order(self, message_fixture: Message) -> None:
def test_pop_up_info_order(self) -> None:
topic_links = OrderedDict([("https://bar.com", ("topic", 1, True))])
message_links = OrderedDict([("image.jpg", ("image", 1, True))])
msg_info_view = MsgInfoView(
self.controller,
message_fixture,
self.message,
title="Message Information",
topic_links=topic_links,
message_links=message_links,
Expand Down Expand Up @@ -1029,7 +1030,6 @@ def test_keypress_any_key(
)
def test_keypress_edit_history(
self,
message_fixture: Message,
key: str,
widget_size: Callable[[Widget], urwid_Size],
realm_allow_edit_history: bool,
Expand All @@ -1041,21 +1041,13 @@ def test_keypress_edit_history(
self.controller.model.initial_data = {
"realm_allow_edit_history": realm_allow_edit_history,
}
msg_info_view = MsgInfoView(
self.controller,
message_fixture,
title="Message Information",
topic_links=OrderedDict(),
message_links=OrderedDict(),
time_mentions=list(),
)
size = widget_size(msg_info_view)
size = widget_size(self.msg_info_view)

msg_info_view.keypress(size, key)
self.msg_info_view.keypress(size, key)

if msg_info_view.show_edit_history_label:
if self.msg_info_view.show_edit_history_label:
self.controller.show_edit_history.assert_called_once_with(
message=message_fixture,
message=self.message,
topic_links=OrderedDict(),
message_links=OrderedDict(),
time_mentions=list(),
Expand All @@ -1065,51 +1057,29 @@ def test_keypress_edit_history(

@pytest.mark.parametrize("key", keys_for_command("FULL_RENDERED_MESSAGE"))
def test_keypress_full_rendered_message(
self,
message_fixture: Message,
key: str,
widget_size: Callable[[Widget], urwid_Size],
self, key: str, widget_size: Callable[[Widget], urwid_Size]
) -> None:
msg_info_view = MsgInfoView(
self.controller,
message_fixture,
title="Message Information",
topic_links=OrderedDict(),
message_links=OrderedDict(),
time_mentions=list(),
)
size = widget_size(msg_info_view)
size = widget_size(self.msg_info_view)

msg_info_view.keypress(size, key)
self.msg_info_view.keypress(size, key)

self.controller.show_full_rendered_message.assert_called_once_with(
message=message_fixture,
message=self.message,
topic_links=OrderedDict(),
message_links=OrderedDict(),
time_mentions=list(),
)

@pytest.mark.parametrize("key", keys_for_command("FULL_RAW_MESSAGE"))
def test_keypress_full_raw_message(
self,
message_fixture: Message,
key: str,
widget_size: Callable[[Widget], urwid_Size],
self, key: str, widget_size: Callable[[Widget], urwid_Size]
) -> None:
msg_info_view = MsgInfoView(
self.controller,
message_fixture,
title="Message Information",
topic_links=OrderedDict(),
message_links=OrderedDict(),
time_mentions=list(),
)
size = widget_size(msg_info_view)
size = widget_size(self.msg_info_view)

msg_info_view.keypress(size, key)
self.msg_info_view.keypress(size, key)

self.controller.show_full_raw_message.assert_called_once_with(
message=message_fixture,
message=self.message,
topic_links=OrderedDict(),
message_links=OrderedDict(),
time_mentions=list(),
Expand Down
28 changes: 14 additions & 14 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ def __init__(
self.time_mentions = time_mentions
self.server_url = controller.model.server_url
date_and_time = controller.model.formatted_local_time(
msg["timestamp"], show_seconds=True, show_year=True
self.msg["timestamp"], show_seconds=True, show_year=True
)
view_in_browser_keys = "[{}]".format(
", ".join(map(str, display_keys_for_command("VIEW_IN_BROWSER")))
Expand All @@ -1602,8 +1602,8 @@ def __init__(
"",
[
("Date & Time", date_and_time),
("Sender", msg["sender_full_name"]),
("Sender's Email ID", msg["sender_email"]),
("Sender", self.msg["sender_full_name"]),
("Sender's Email ID", self.msg["sender_email"]),
],
)
]
Expand Down Expand Up @@ -1632,13 +1632,13 @@ def __init__(
)
msg_info[1][1].append(("Edit History", keys))
# Render the category using the existing table methods if links exist.
if message_links:
if self.message_links:
msg_info.append(("Message Links", []))
if topic_links:
if self.topic_links:
msg_info.append(("Topic Links", []))
if time_mentions:
msg_info.append(("Time mentions", time_mentions))
if msg["reactions"]:
if self.time_mentions:
msg_info.append(("Time mentions", self.time_mentions))
if self.msg["reactions"]:
reactions = sorted(
(reaction["emoji_name"], reaction["user"]["full_name"])
for reaction in msg["reactions"]
Expand All @@ -1658,9 +1658,9 @@ def __init__(
# computing their slice indexes
self.button_widgets: List[Any] = []

if message_links:
if self.message_links:
message_link_widgets, message_link_width = self.create_link_buttons(
controller, message_links
controller, self.message_links
)

# slice_index = Number of labels before message links + 1 newline
Expand All @@ -1669,24 +1669,24 @@ def __init__(
slice_index = len(msg_info[0][1]) + len(msg_info[1][1]) + 2 + 2

slice_index += sum([len(w) + 2 for w in self.button_widgets])
self.button_widgets.append(message_links)
self.button_widgets.append(self.message_links)

widgets = (
widgets[:slice_index] + message_link_widgets + widgets[slice_index:]
)
popup_width = max(popup_width, message_link_width)

if topic_links:
if self.topic_links:
topic_link_widgets, topic_link_width = self.create_link_buttons(
controller, topic_links
controller, self.topic_links
)

# slice_index = Number of labels before topic links + 1 newline
# + 1 'Topic Links' category label.
# + 2 for Viewing Actions category label and its newline
slice_index = len(msg_info[0][1]) + len(msg_info[1][1]) + 2 + 2
slice_index += sum([len(w) + 2 for w in self.button_widgets])
self.button_widgets.append(topic_links)
self.button_widgets.append(self.topic_links)

widgets = widgets[:slice_index] + topic_link_widgets + widgets[slice_index:]
popup_width = max(popup_width, topic_link_width)
Expand Down