Skip to content

Commit 9051d4f

Browse files
committed
refactor: views/helper/core/messages: Group message info in a TypedDict.
Group the following fields that are shown in a message info popup, into a single piece of data. - topic_links - message_links - time_mentions Tests updated. Fixture added.
1 parent 9e5036e commit 9051d4f

File tree

5 files changed

+52
-32
lines changed

5 files changed

+52
-32
lines changed

tests/ui_tools/test_popups.py

+31-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
from zulipterminal.api_types import Message
1010
from zulipterminal.config.keys import is_command_key, keys_for_command
1111
from zulipterminal.config.ui_mappings import EDIT_MODE_CAPTIONS
12-
from zulipterminal.helper import CustomProfileData, TidiedUserInfo
12+
from zulipterminal.helper import (
13+
CustomProfileData,
14+
MessageInfoPopupContent,
15+
TidiedUserInfo,
16+
)
1317
from zulipterminal.ui_tools.messages import MessageBox
1418
from zulipterminal.ui_tools.views import (
1519
AboutView,
@@ -922,10 +926,22 @@ def test_keypress_exit_popup(
922926
assert self.controller.exit_popup.called
923927

924928

929+
@pytest.fixture
930+
def message_info_content() -> MessageInfoPopupContent:
931+
return MessageInfoPopupContent(
932+
topic_links=OrderedDict(),
933+
message_links=OrderedDict(),
934+
time_mentions=list(),
935+
)
936+
937+
925938
class TestMsgInfoView:
926939
@pytest.fixture(autouse=True)
927940
def mock_external_classes(
928-
self, mocker: MockerFixture, message_fixture: Message
941+
self,
942+
mocker: MockerFixture,
943+
message_fixture: Message,
944+
message_info_content: MessageInfoPopupContent,
929945
) -> None:
930946
self.controller = mocker.Mock()
931947
mocker.patch.object(
@@ -943,13 +959,12 @@ def mock_external_classes(
943959
"Tue Mar 13 10:55:37",
944960
]
945961
self.message = message_fixture
962+
self.message_info_content = message_info_content
946963
self.msg_info_view = MsgInfoView(
947964
self.controller,
948965
self.message,
949966
"Message Information",
950-
OrderedDict(),
951-
OrderedDict(),
952-
list(),
967+
self.message_info_content,
953968
)
954969

955970
def test_init(self) -> None:
@@ -961,16 +976,22 @@ def test_init(self) -> None:
961976
def test_pop_up_info_order(self) -> None:
962977
topic_links = OrderedDict([("https://bar.com", ("topic", 1, True))])
963978
message_links = OrderedDict([("image.jpg", ("image", 1, True))])
979+
message_info_content = MessageInfoPopupContent(
980+
topic_links=topic_links,
981+
message_links=message_links,
982+
time_mentions=list(),
983+
)
964984
msg_info_view = MsgInfoView(
965985
self.controller,
966986
self.message,
967987
title="Message Information",
968-
topic_links=topic_links,
969-
message_links=message_links,
970-
time_mentions=list(),
988+
message_info_content=message_info_content,
971989
)
972990
msg_links = msg_info_view.button_widgets
973-
assert msg_links == [message_links, topic_links]
991+
assert msg_links == [
992+
message_info_content["message_links"],
993+
message_info_content["topic_links"],
994+
]
974995

975996
def test_keypress_any_key(
976997
self, widget_size: Callable[[Widget], urwid_Size]
@@ -1139,9 +1160,7 @@ def test_height_reactions(
11391160
self.controller,
11401161
varied_message,
11411162
"Message Information",
1142-
OrderedDict(),
1143-
OrderedDict(),
1144-
list(),
1163+
self.message_info_content,
11451164
)
11461165
# 12 = 7 labels + 2 blank lines + 1 'Reactions' (category)
11471166
# + 4 reactions (excluding 'Message Links').

zulipterminal/core.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
MAX_LINEAR_SCALING_WIDTH,
2626
MIN_SUPPORTED_POPUP_WIDTH,
2727
)
28-
from zulipterminal.helper import asynch, suppress_output
28+
from zulipterminal.helper import MessageInfoPopupContent, asynch, suppress_output
2929
from zulipterminal.model import Model
3030
from zulipterminal.platform_code import PLATFORM
3131
from zulipterminal.ui import Screen, View
@@ -270,19 +270,10 @@ def show_topic_edit_mode(self, button: Any) -> None:
270270
self.show_pop_up(EditModeView(self, button), "area:msg")
271271

272272
def show_msg_info(
273-
self,
274-
msg: Message,
275-
topic_links: Dict[str, Tuple[str, int, bool]],
276-
message_links: Dict[str, Tuple[str, int, bool]],
277-
time_mentions: List[Tuple[str, str]],
273+
self, msg: Message, message_info_content: MessageInfoPopupContent
278274
) -> None:
279275
msg_info_view = MsgInfoView(
280-
self,
281-
msg,
282-
f"Message Information {SCROLL_PROMPT}",
283-
topic_links,
284-
message_links,
285-
time_mentions,
276+
self, msg, f"Message Information {SCROLL_PROMPT}", message_info_content
286277
)
287278
self.show_pop_up(msg_info_view, "area:msg")
288279

zulipterminal/helper.py

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class StreamData(TypedDict):
5757
description: str
5858

5959

60+
class MessageInfoPopupContent(TypedDict):
61+
topic_links: Dict[str, Tuple[str, int, bool]]
62+
message_links: Dict[str, Tuple[str, int, bool]]
63+
time_mentions: List[Tuple[str, str]]
64+
65+
6066
class EmojiData(TypedDict):
6167
code: str
6268
aliases: List[str]

zulipterminal/ui_tools/messages.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
TIME_MENTION_MARKER,
3030
)
3131
from zulipterminal.config.ui_mappings import STATE_ICON, STREAM_ACCESS_TYPE
32-
from zulipterminal.helper import get_unused_fence
32+
from zulipterminal.helper import MessageInfoPopupContent, get_unused_fence
3333
from zulipterminal.server_url import near_message_url
3434
from zulipterminal.ui_tools.tables import render_table
3535
from zulipterminal.urwid_types import urwid_MarkupTuple, urwid_Size
@@ -1121,7 +1121,12 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
11211121
self.model.controller.view.middle_column.set_focus("footer")
11221122
elif is_command_key("MSG_INFO", key):
11231123
self.model.controller.show_msg_info(
1124-
self.message, self.topic_links, self.message_links, self.time_mentions
1124+
self.message,
1125+
MessageInfoPopupContent(
1126+
topic_links=self.topic_links,
1127+
message_links=self.message_links,
1128+
time_mentions=self.time_mentions,
1129+
),
11251130
)
11261131
elif is_command_key("ADD_REACTION", key):
11271132
self.model.controller.show_emoji_picker(self.message)

zulipterminal/ui_tools/views.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
)
3737
from zulipterminal.config.ui_sizes import LEFT_WIDTH
3838
from zulipterminal.helper import (
39+
MessageInfoPopupContent,
3940
TidiedUserInfo,
4041
asynch,
4142
match_emoji,
@@ -1578,14 +1579,12 @@ def __init__(
15781579
controller: Any,
15791580
msg: Message,
15801581
title: str,
1581-
topic_links: Dict[str, Tuple[str, int, bool]],
1582-
message_links: Dict[str, Tuple[str, int, bool]],
1583-
time_mentions: List[Tuple[str, str]],
1582+
message_info_content: MessageInfoPopupContent,
15841583
) -> None:
15851584
self.msg = msg
1586-
self.topic_links = topic_links
1587-
self.message_links = message_links
1588-
self.time_mentions = time_mentions
1585+
self.topic_links = message_info_content["topic_links"]
1586+
self.message_links = message_info_content["message_links"]
1587+
self.time_mentions = message_info_content["time_mentions"]
15891588
self.server_url = controller.model.server_url
15901589
date_and_time = controller.model.formatted_local_time(
15911590
self.msg["timestamp"], show_seconds=True, show_year=True

0 commit comments

Comments
 (0)