diff --git a/tests/model/test_model.py b/tests/model/test_model.py index 68bea8bc18..9a02a77a86 100644 --- a/tests/model/test_model.py +++ b/tests/model/test_model.py @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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") diff --git a/zulipterminal/model.py b/zulipterminal/model.py index 148e999ebe..0f466bff61 100644 --- a/zulipterminal/model.py +++ b/zulipterminal/model.py @@ -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, @@ -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: