Skip to content

Commit 494707f

Browse files
author
Subhasish-Behera
committed
model: update _handle_update_messages_event.Tests added
Fixes #1253
1 parent 70f5c4b commit 494707f

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

tests/model/test_model.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
21302130
"topic_msg_ids": {
21312131
10: {"new subject": {1}, "old subject": {2}},
21322132
},
2133-
"edited_messages": {1},
2133+
"edited_messages": set(),
2134+
"moved_messages": {1},
21342135
"topics": {10: []},
21352136
},
21362137
False,
@@ -2163,7 +2164,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
21632164
"topic_msg_ids": {
21642165
10: {"new subject": {1, 2}, "old subject": set()},
21652166
},
2166-
"edited_messages": {1},
2167+
"edited_messages": set(),
2168+
"moved_messages": {1},
21672169
"topics": {10: []},
21682170
},
21692171
False,
@@ -2195,6 +2197,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
21952197
10: {"new subject": set(), "old subject": {1, 2}},
21962198
},
21972199
"edited_messages": {1},
2200+
"moved_messages": set(),
21982201
"topics": {10: ["new subject", "old subject"]},
21992202
},
22002203
False,
@@ -2228,7 +2231,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
22282231
"topic_msg_ids": {
22292232
10: {"new subject": {1}, "old subject": {2}},
22302233
},
2231-
"edited_messages": {1},
2234+
"edited_messages": set(),
2235+
"moved_messages": {1},
22322236
"topics": {10: []},
22332237
},
22342238
False,
@@ -2259,6 +2263,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
22592263
10: {"new subject": set(), "old subject": {1, 2}},
22602264
},
22612265
"edited_messages": {1},
2266+
"moved_messages": set(),
22622267
"topics": {10: ["new subject", "old subject"]},
22632268
},
22642269
False,
@@ -2293,6 +2298,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
22932298
10: {"new subject": {3}, "old subject": {1, 2}},
22942299
},
22952300
"edited_messages": set(),
2301+
"moved_messages": set(),
22962302
"topics": {10: []}, # This resets the cache
22972303
},
22982304
False,
@@ -2327,6 +2333,7 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
23272333
10: {"new subject": {3}, "old subject": {1, 2}},
23282334
},
23292335
"edited_messages": set(),
2336+
"moved_messages": set(),
23302337
"topics": {10: ["new subject", "old subject"]},
23312338
},
23322339
True,
@@ -2360,7 +2367,8 @@ def test_notify_users_hides_PM_content_based_on_user_setting(
23602367
"topic_msg_ids": {
23612368
10: {"new subject": {1}, "old subject": {2}},
23622369
},
2363-
"edited_messages": {1},
2370+
"edited_messages": set(),
2371+
"moved_messages": {1},
23642372
"topics": {10: ["new subject", "old subject"]},
23652373
},
23662374
True,
@@ -2393,6 +2401,7 @@ def test__handle_update_message_event(
23932401
10: {"new subject": set(), "old subject": {1, 2}},
23942402
},
23952403
"edited_messages": set(),
2404+
"moved_messages": set(),
23962405
"topics": {10: ["new subject", "old subject"]},
23972406
}
23982407
mocker.patch(MODEL + "._update_rendered_view")

zulipterminal/model.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
Subscription,
4343
)
4444
from zulipterminal.config.keys import primary_key_for_command
45-
from zulipterminal.config.symbols import STREAM_TOPIC_SEPARATOR
45+
from zulipterminal.config.symbols import CHECK_MARK, STREAM_TOPIC_SEPARATOR
4646
from zulipterminal.config.ui_mappings import (
4747
EDIT_TOPIC_POLICY,
4848
ROLE_BY_ID,
@@ -1589,9 +1589,33 @@ def _handle_update_message_event(self, event: Event) -> None:
15891589
# they are not all marked as edited, as per server optimization
15901590
message_id = event["message_id"]
15911591
indexed_message = self.index["messages"].get(message_id, None)
1592-
1592+
resolved_topic_prefix = CHECK_MARK + " "
15931593
if indexed_message:
1594-
self.index["edited_messages"].add(message_id)
1594+
if "orig_content" in event:
1595+
self.index["edited_messages"].add(message_id)
1596+
if "prev_stream" in event:
1597+
self.index["moved_messages"].add(message_id)
1598+
if "subject" in event:
1599+
if not event["subject"].startswith(resolved_topic_prefix):
1600+
if (
1601+
event["orig_subject"].startswith(resolved_topic_prefix)
1602+
and event["orig_subject"][2:] != event["subject"]
1603+
):
1604+
self.index["moved_messages"].add(message_id)
1605+
if not event["orig_subject"].startswith(
1606+
resolved_topic_prefix
1607+
) and not event["subject"].startswith(resolved_topic_prefix):
1608+
self.index["moved_messages"].add(message_id)
1609+
else:
1610+
if (
1611+
event["orig_subject"].startswith(resolved_topic_prefix)
1612+
and event["orig_subject"][2:] != event["subject"][2:]
1613+
):
1614+
self.index["moved_messages"].add(message_id)
1615+
else:
1616+
self.index["edited_messages"].add(message_id)
1617+
if message_id not in self.index["moved_messages"]:
1618+
self.index["edited_messages"].add(message_id)
15951619

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

0 commit comments

Comments
 (0)