Skip to content

Commit

Permalink
messages: Changes made in MessageBox for muted_messages.
Browse files Browse the repository at this point in the history
The content shown for the message is changed. The recepient header shows
muted_user instead of original name. The name of the author is also
changed to muted_user.

Tests Adapted.

Co-authored by: Subhasish-Behera <greendoor3000@gmail.com>
  • Loading branch information
rsashank committed Sep 20, 2024
1 parent a7d0d10 commit 3937ee2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def test_narrow_to_user(
controller.view.message_view = mocker.patch("urwid.ListBox")
controller.model.user_id = 5140
controller.model.user_email = "some@email"
controller.model._muted_users = set()
controller.model.user_dict = {
user_email: {
"user_id": user_id,
Expand Down Expand Up @@ -267,6 +268,7 @@ def test_narrow_to_all_messages(
controller.view.message_view = mocker.patch("urwid.ListBox")
controller.model.user_email = "some@email"
controller.model.user_id = 1
controller.model._muted_users = set()
controller.model.stream_dict = {
205: {
"color": "#ffffff",
Expand Down Expand Up @@ -295,6 +297,7 @@ def test_narrow_to_all_pm(
controller.view.message_view = mocker.patch("urwid.ListBox")
controller.model.user_id = 1
controller.model.user_email = "some@email"
controller.model._muted_users = set()

controller.narrow_to_all_pm() # FIXME: Add id narrowing test

Expand All @@ -316,6 +319,7 @@ def test_narrow_to_all_starred(
# FIXME: Expand upon is_muted_topic().
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
controller.model.user_email = "some@email"
controller.model._muted_users = set()
controller.model.stream_dict = {
205: {
"color": "#ffffff",
Expand Down Expand Up @@ -343,6 +347,7 @@ def test_narrow_to_all_mentions(
mocker.patch(MODEL + ".is_muted_topic", return_value=False)
controller.model.user_email = "some@email"
controller.model.user_id = 1
controller.model._muted_users = set()
controller.model.stream_dict = {
205: {
"color": "#ffffff",
Expand Down
6 changes: 6 additions & 0 deletions tests/ui_tools/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ def test_main_view(self, mocker, message, last_message):
"reactions": [],
"sender_full_name": "Alice",
"timestamp": 1532103879,
"sender_id": 32900,
}
],
)
Expand Down Expand Up @@ -814,6 +815,7 @@ def test_main_view_renders_slash_me(self, mocker, message, content, is_me_messag
"reactions": [],
"sender_full_name": "Alice",
"timestamp": 1532103879,
"sender_id": 32900,
}
],
)
Expand Down Expand Up @@ -867,6 +869,7 @@ def test_main_view_generates_stream_header(
"reactions": [],
"sender_full_name": "Alice",
"timestamp": 1532103879,
"sender_id": 32900,
},
],
)
Expand Down Expand Up @@ -1057,6 +1060,7 @@ def test_msg_generates_search_and_header_bar(
"reactions": [],
"sender_full_name": "alice",
"timestamp": 1532103879,
"sender_id": 32900,
}
],
)
Expand Down Expand Up @@ -1117,6 +1121,8 @@ def test_main_view_content_header_without_header(

msg_box = MessageBox(this_msg, self.model, last_msg)

self.model.is_muted_user.return_value = False

expected_header[2] = output_date_time
if current_year > 2018:
expected_header[2] = "2018 - " + expected_header[2]
Expand Down
17 changes: 15 additions & 2 deletions zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
else:
self.recipients_names = ", ".join(
[
recipient["full_name"]
"Muted user"
if self.model.is_muted_user(recipient["id"])
else recipient["full_name"]
for recipient in self.message["display_recipient"]
if recipient["email"] != self.model.user_email
]
Expand Down Expand Up @@ -687,7 +689,12 @@ def main_view(self) -> List[Any]:
text: Dict[str, urwid_MarkupTuple] = {key: (None, " ") for key in text_keys}

if any(different[key] for key in ("recipients", "author", "24h")):
text["author"] = ("msg_sender", message["this"]["author"])
text["author"] = (
"msg_sender",
"Muted user"
if self.model.is_muted_user(self.message["sender_id"])
else message["this"]["author"],
)

# TODO: Refactor to use user ids for look up instead of emails.
email = self.message.get("sender_email", "")
Expand Down Expand Up @@ -729,10 +736,16 @@ def main_view(self) -> List[Any]:
"/me", f"<strong>{self.message['sender_full_name']}</strong>", 1
)

muted_message_text = "This message was hidden because you have muted the sender"

# Transform raw message content into markup (As needed by urwid.Text)
content, self.message_links, self.time_mentions = self.transform_content(
self.message["content"], self.model.server_url
)

if self.model.is_muted_user(self.message["sender_id"]):
content = (None, muted_message_text)

self.content.set_text(content)

if self.message["id"] in self.model.index["edited_messages"]:
Expand Down

0 comments on commit 3937ee2

Please sign in to comment.