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 committed Mar 25, 2023
1 parent 70f5c4b commit 494707f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 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
30 changes: 27 additions & 3 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
Subscription,
)
from zulipterminal.config.keys import primary_key_for_command
from zulipterminal.config.symbols import STREAM_TOPIC_SEPARATOR
from zulipterminal.config.symbols import CHECK_MARK, STREAM_TOPIC_SEPARATOR
from zulipterminal.config.ui_mappings import (
EDIT_TOPIC_POLICY,
ROLE_BY_ID,
Expand Down Expand Up @@ -1589,9 +1589,33 @@ def _handle_update_message_event(self, event: Event) -> None:
# they are not all marked as edited, as per server optimization
message_id = event["message_id"]
indexed_message = self.index["messages"].get(message_id, None)

resolved_topic_prefix = CHECK_MARK + " "
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 494707f

Please sign in to comment.