Skip to content

Commit

Permalink
model: update _handle_update_messages_event.Tests added
Browse files Browse the repository at this point in the history
Fixes #1253.
  • Loading branch information
Subhasish-Behera authored and Subhasish-Behera committed Mar 25, 2023
1 parent 30f857b commit d56cffc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
17 changes: 13 additions & 4 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
"topic_msg_ids": {
10: {"new subject": {1}, "old subject": {2}},
},
"edited_messages": {1},
"edited_messages": set(),
"moved_messages": {1},
"topics": {10: []},
},
False,
Expand Down Expand Up @@ -2163,7 +2164,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
"topic_msg_ids": {
10: {"new subject": {1, 2}, "old subject": set()},
},
"edited_messages": {1},
"edited_messages": set(),
"moved_messages": {1},
"topics": {10: []},
},
False,
Expand Down Expand Up @@ -2195,6 +2197,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
10: {"new subject": set(), "old subject": {1, 2}},
},
"edited_messages": {1},
"moved_messages": set(),
"topics": {10: ["new subject", "old subject"]},
},
False,
Expand Down Expand Up @@ -2228,7 +2231,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
"topic_msg_ids": {
10: {"new subject": {1}, "old subject": {2}},
},
"edited_messages": {1},
"edited_messages": set(),
"moved_messages": {1},
"topics": {10: []},
},
False,
Expand Down Expand Up @@ -2259,6 +2263,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
10: {"new subject": set(), "old subject": {1, 2}},
},
"edited_messages": {1},
"moved_messages": set(),
"topics": {10: ["new subject", "old subject"]},
},
False,
Expand Down Expand Up @@ -2293,6 +2298,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
10: {"new subject": {3}, "old subject": {1, 2}},
},
"edited_messages": set(),
"moved_messages": set(),
"topics": {10: []}, # This resets the cache
},
False,
Expand Down Expand Up @@ -2327,6 +2333,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
10: {"new subject": {3}, "old subject": {1, 2}},
},
"edited_messages": set(),
"moved_messages": set(),
"topics": {10: ["new subject", "old subject"]},
},
True,
Expand Down Expand Up @@ -2360,7 +2367,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
"topic_msg_ids": {
10: {"new subject": {1}, "old subject": {2}},
},
"edited_messages": {1},
"edited_messages": set(),
"moved_messages": {1},
"topics": {10: ["new subject", "old subject"]},
},
True,
Expand Down Expand Up @@ -2393,6 +2401,7 @@ def test__handle_update_message_event(
10: {"new subject": set(), "old subject": {1, 2}},
},
"edited_messages": set(),
"moved_messages": set(),
"topics": {10: ["new subject", "old subject"]},
}
mocker.patch(MODEL + "._update_rendered_view")
Expand Down
28 changes: 27 additions & 1 deletion zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
from zulipterminal.ui_tools.utils import create_msg_box_list


RESOLVED_TOPIC_PREFIX = "✔ "

OFFLINE_THRESHOLD_SECS = 140

# Adapted from zerver/models.py
Expand Down Expand Up @@ -1591,7 +1593,31 @@ def _handle_update_message_event(self, event: Event) -> None:
indexed_message = self.index["messages"].get(message_id, None)

if indexed_message:
self.index["edited_messages"].add(message_id)
if "orig_content" in event:
self.index["edited_messages"].add(message_id)
if "prev_stream" in event:
self.index["moved_messages"].add(message_id)
if "subject" in event:
if not event["subject"].startswith(RESOLVED_TOPIC_PREFIX):
if (
event["orig_subject"].startswith(RESOLVED_TOPIC_PREFIX)
and event["orig_subject"][2:] != event["subject"]
):
self.index["moved_messages"].add(message_id)
if not event["orig_subject"].startswith(
RESOLVED_TOPIC_PREFIX
) and not event["subject"].startswith(RESOLVED_TOPIC_PREFIX):
self.index["moved_messages"].add(message_id)
else:
if (
event["orig_subject"].startswith(RESOLVED_TOPIC_PREFIX)
and event["orig_subject"][2:] != event["subject"][2:]
):
self.index["moved_messages"].add(message_id)
else:
self.index["edited_messages"].add(message_id)
if message_id not in self.index["moved_messages"]:
self.index["edited_messages"].add(message_id)

# Update the rendered content, if the message is indexed
if "rendered_content" in event and indexed_message:
Expand Down

0 comments on commit d56cffc

Please sign in to comment.