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
43 changes: 31 additions & 12 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from zulipterminal.api_types import Message
from zulipterminal.config.keys import is_command_key, keys_for_command
from zulipterminal.config.ui_mappings import EDIT_MODE_CAPTIONS
from zulipterminal.helper import CustomProfileData, TidiedUserInfo
from zulipterminal.helper import (
CustomProfileData,
MessageInfoPopupContent,
TidiedUserInfo,
)
from zulipterminal.ui_tools.messages import MessageBox
from zulipterminal.ui_tools.views import (
AboutView,
Expand Down Expand Up @@ -922,10 +926,22 @@ def test_keypress_exit_popup(
assert self.controller.exit_popup.called


@pytest.fixture
def message_info_content() -> MessageInfoPopupContent:
return MessageInfoPopupContent(
topic_links=OrderedDict(),
message_links=OrderedDict(),
time_mentions=list(),
)


class TestMsgInfoView:
@pytest.fixture(autouse=True)
def mock_external_classes(
self, mocker: MockerFixture, message_fixture: Message
self,
mocker: MockerFixture,
message_fixture: Message,
message_info_content: MessageInfoPopupContent,
) -> None:
self.controller = mocker.Mock()
mocker.patch.object(
Expand All @@ -943,13 +959,12 @@ def mock_external_classes(
"Tue Mar 13 10:55:37",
]
self.message = message_fixture
self.message_info_content = message_info_content
self.msg_info_view = MsgInfoView(
self.controller,
self.message,
"Message Information",
OrderedDict(),
OrderedDict(),
list(),
self.message_info_content,
)

def test_init(self) -> None:
Expand All @@ -961,16 +976,22 @@ def test_init(self) -> 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))])
message_info_content = MessageInfoPopupContent(
topic_links=topic_links,
message_links=message_links,
time_mentions=list(),
)
msg_info_view = MsgInfoView(
self.controller,
self.message,
title="Message Information",
topic_links=topic_links,
message_links=message_links,
time_mentions=list(),
message_info_content=message_info_content,
)
msg_links = msg_info_view.button_widgets
assert msg_links == [message_links, topic_links]
assert msg_links == [
message_info_content["message_links"],
message_info_content["topic_links"],
]

def test_keypress_any_key(
self, widget_size: Callable[[Widget], urwid_Size]
Expand Down Expand Up @@ -1139,9 +1160,7 @@ def test_height_reactions(
self.controller,
varied_message,
"Message Information",
OrderedDict(),
OrderedDict(),
list(),
self.message_info_content,
)
# 12 = 7 labels + 2 blank lines + 1 'Reactions' (category)
# + 4 reactions (excluding 'Message Links').
Expand Down
15 changes: 3 additions & 12 deletions zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
MAX_LINEAR_SCALING_WIDTH,
MIN_SUPPORTED_POPUP_WIDTH,
)
from zulipterminal.helper import asynch, suppress_output
from zulipterminal.helper import MessageInfoPopupContent, asynch, suppress_output
from zulipterminal.model import Model
from zulipterminal.platform_code import PLATFORM
from zulipterminal.ui import Screen, View
Expand Down Expand Up @@ -270,19 +270,10 @@ def show_topic_edit_mode(self, button: Any) -> None:
self.show_pop_up(EditModeView(self, button), "area:msg")

def show_msg_info(
self,
msg: Message,
topic_links: Dict[str, Tuple[str, int, bool]],
message_links: Dict[str, Tuple[str, int, bool]],
time_mentions: List[Tuple[str, str]],
self, msg: Message, message_info_content: MessageInfoPopupContent
) -> None:
msg_info_view = MsgInfoView(
self,
msg,
f"Message Information {SCROLL_PROMPT}",
topic_links,
message_links,
time_mentions,
self, msg, f"Message Information {SCROLL_PROMPT}", message_info_content
)
self.show_pop_up(msg_info_view, "area:msg")

Expand Down
6 changes: 6 additions & 0 deletions zulipterminal/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class StreamData(TypedDict):
description: str


class MessageInfoPopupContent(TypedDict):
topic_links: Dict[str, Tuple[str, int, bool]]
message_links: Dict[str, Tuple[str, int, bool]]
time_mentions: List[Tuple[str, str]]
Comment on lines +60 to +63
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is now a much smaller part of this PR - but still helpful, if not perhaps as urgent a commit to merge, tidying-wise 👍

This particular change may be better-placed in messages.py, ie. where all the messages-UI code is located. The connected aspect is that this is mostly data from the result of soup2markup or similar, I believe? This name is an improvement - but I'd likely (also) consider the source of the data, ie. this is indexed/extracted data. That can be focused on before merging though.



class EmojiData(TypedDict):
code: str
aliases: List[str]
Expand Down
9 changes: 7 additions & 2 deletions zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
TIME_MENTION_MARKER,
)
from zulipterminal.config.ui_mappings import STATE_ICON, STREAM_ACCESS_TYPE
from zulipterminal.helper import get_unused_fence
from zulipterminal.helper import MessageInfoPopupContent, get_unused_fence
from zulipterminal.server_url import near_message_url
from zulipterminal.ui_tools.tables import render_table
from zulipterminal.urwid_types import urwid_MarkupTuple, urwid_Size
Expand Down Expand Up @@ -1121,7 +1121,12 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.model.controller.view.middle_column.set_focus("footer")
elif is_command_key("MSG_INFO", key):
self.model.controller.show_msg_info(
self.message, self.topic_links, self.message_links, self.time_mentions
self.message,
MessageInfoPopupContent(
topic_links=self.topic_links,
message_links=self.message_links,
time_mentions=self.time_mentions,
),
)
elif is_command_key("ADD_REACTION", key):
self.model.controller.show_emoji_picker(self.message)
Expand Down
11 changes: 5 additions & 6 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)
from zulipterminal.config.ui_sizes import LEFT_WIDTH
from zulipterminal.helper import (
MessageInfoPopupContent,
TidiedUserInfo,
asynch,
match_emoji,
Expand Down Expand Up @@ -1578,14 +1579,12 @@ def __init__(
controller: Any,
msg: Message,
title: str,
topic_links: Dict[str, Tuple[str, int, bool]],
message_links: Dict[str, Tuple[str, int, bool]],
time_mentions: List[Tuple[str, str]],
message_info_content: MessageInfoPopupContent,
) -> None:
self.msg = msg
self.topic_links = topic_links
self.message_links = message_links
self.time_mentions = time_mentions
self.topic_links = message_info_content["topic_links"]
self.message_links = message_info_content["message_links"]
self.time_mentions = message_info_content["time_mentions"]
Comment on lines 1584 to +1587
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the unpacking into separate variables - and more to come! - suggests to me that it may be simpler to unpack 'on demand', and/or use a dataclass to make the syntax much easier to read :)

self.server_url = controller.model.server_url
date_and_time = controller.model.formatted_local_time(
self.msg["timestamp"], show_seconds=True, show_year=True
Expand Down
Loading