Skip to content

Commit d3e242b

Browse files
committed
bugfix: model: Add updated message_ids to their new topic's set.
Prior to this commit, if a message's topic was changed, the corresponding `message_id` was not added to the new topic's set under the "topic_msg_ids" key of the model's index. This commit adds the updated `message_id` to that set, ensuring the accuracy of the new topic's set. Tests updated.
1 parent 9e4e661 commit d3e242b

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

tests/model/test_model.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ def test_notify_users_enabled(
16461646
},
16471647
},
16481648
"topic_msg_ids": {
1649-
10: {"old subject": {2}},
1649+
10: {"new subject": {1}, "old subject": {2}},
16501650
},
16511651
"edited_messages": {1},
16521652
"topics": {10: []},
@@ -1679,7 +1679,7 @@ def test_notify_users_enabled(
16791679
},
16801680
},
16811681
"topic_msg_ids": {
1682-
10: {"old subject": set()},
1682+
10: {"new subject": {1, 2}, "old subject": set()},
16831683
},
16841684
"edited_messages": {1},
16851685
"topics": {10: []},
@@ -1710,10 +1710,10 @@ def test_notify_users_enabled(
17101710
},
17111711
},
17121712
"topic_msg_ids": {
1713-
10: {"old subject": {1, 2}},
1713+
10: {"new subject": set(), "old subject": {1, 2}},
17141714
},
17151715
"edited_messages": {1},
1716-
"topics": {10: ["old subject"]},
1716+
"topics": {10: ["new subject", "old subject"]},
17171717
},
17181718
False,
17191719
id="Message content is updated",
@@ -1744,7 +1744,7 @@ def test_notify_users_enabled(
17441744
},
17451745
},
17461746
"topic_msg_ids": {
1747-
10: {"old subject": {2}},
1747+
10: {"new subject": {1}, "old subject": {2}},
17481748
},
17491749
"edited_messages": {1},
17501750
"topics": {10: []},
@@ -1774,10 +1774,10 @@ def test_notify_users_enabled(
17741774
},
17751775
},
17761776
"topic_msg_ids": {
1777-
10: {"old subject": {1, 2}},
1777+
10: {"new subject": set(), "old subject": {1, 2}},
17781778
},
17791779
"edited_messages": {1},
1780-
"topics": {10: ["old subject"]},
1780+
"topics": {10: ["new subject", "old subject"]},
17811781
},
17821782
False,
17831783
id="Some new type of update which we don't handle yet",
@@ -1808,7 +1808,7 @@ def test_notify_users_enabled(
18081808
},
18091809
},
18101810
"topic_msg_ids": {
1811-
10: {"old subject": {1, 2}},
1811+
10: {"new subject": {3}, "old subject": {1, 2}},
18121812
},
18131813
"edited_messages": set(),
18141814
"topics": {10: []}, # This resets the cache
@@ -1842,7 +1842,7 @@ def test_notify_users_enabled(
18421842
},
18431843
},
18441844
"topic_msg_ids": {
1845-
10: {"old subject": {1, 2}},
1845+
10: {"new subject": {3}, "old subject": {1, 2}},
18461846
},
18471847
"edited_messages": set(),
18481848
"topics": {10: ["new subject", "old subject"]},
@@ -1876,7 +1876,7 @@ def test_notify_users_enabled(
18761876
},
18771877
},
18781878
"topic_msg_ids": {
1879-
10: {"old subject": {2}},
1879+
10: {"new subject": {1}, "old subject": {2}},
18801880
},
18811881
"edited_messages": {1},
18821882
"topics": {10: ["new subject", "old subject"]},
@@ -1908,10 +1908,10 @@ def test__handle_update_message_event(
19081908
for message_id in [1, 2]
19091909
},
19101910
"topic_msg_ids": {
1911-
10: {"old subject": {1, 2}},
1911+
10: {"new subject": set(), "old subject": {1, 2}},
19121912
},
19131913
"edited_messages": set(),
1914-
"topics": {10: ["old subject"]},
1914+
"topics": {10: ["new subject", "old subject"]},
19151915
}
19161916
mocker.patch(MODEL + "._update_rendered_view")
19171917

zulipterminal/model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,11 @@ def _handle_update_message_event(self, event: Event) -> None:
13991399
msg_id
14001400
)
14011401

1402+
# Add the msg_id to the new topic's set, if the set has
1403+
# already been initiated.
1404+
if new_subject in self.index["topic_msg_ids"][stream_id]:
1405+
self.index["topic_msg_ids"][stream_id][new_subject].add(msg_id)
1406+
14021407
# Update and re-render indexed messages.
14031408
indexed_msg = self.index["messages"].get(msg_id)
14041409
if indexed_msg:

0 commit comments

Comments
 (0)