Skip to content

Commit b5feeb7

Browse files
committed
model: Support API migration for muted topics.
This reflects the expected response change for muted_topics, from [stream, topic] to [stream_name, topic, date_muted] in Zulip version 3.0, Feature level 1 (see zulip/zulip@9340cd1). Test updated with support for multiple server versions.
1 parent 09487ee commit b5feeb7

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

tests/model/test_model.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,12 +1516,20 @@ def test_is_muted_stream(self, muted_streams, stream_id, is_muted,
15161516
((1, 'muted stream muted topic'), True),
15171517
((2, 'unmuted topic'), False),
15181518
])
1519-
def test_is_in_muted_topics(self, topic, is_muted, stream_dict, model):
1519+
def test_is_in_muted_topics(self, topic, is_muted, stream_dict, model,
1520+
zulip_version):
15201521
model.stream_dict = stream_dict
1521-
model.muted_topics = [
1522-
['Stream 2', 'muted topic'],
1523-
['Stream 1', 'muted stream muted topic'],
1524-
]
1522+
server_version, server_feature_level = zulip_version
1523+
if server_version == '3.0' and server_feature_level >= 1:
1524+
model.muted_topics = [
1525+
['Stream 2', 'muted topic', 1530129122],
1526+
['Stream 1', 'muted stream muted topic', 1530129122],
1527+
]
1528+
elif server_version == '2.1':
1529+
model.muted_topics = [
1530+
['Stream 2', 'muted topic'],
1531+
['Stream 1', 'muted stream muted topic'],
1532+
]
15251533

15261534
return_value = model.is_in_muted_topics(stream_id=topic[0],
15271535
topic=topic[1])

zulipterminal/model.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ def __init__(self, controller: Any) -> None:
115115
(self.stream_dict, self.muted_streams,
116116
self.pinned_streams, self.unpinned_streams) = stream_data
117117

118+
# NOTE: The expected response has been upgraded from
119+
# [stream_name, topic] to [stream_name, topic, date_muted] in
120+
# 3.0, Feature level 1.
118121
self.muted_topics = (
119-
self.initial_data['muted_topics']) # type: List[List[str]]
122+
self.initial_data['muted_topics']
123+
) # type: List[List[Union[str, int]]]
120124

121125
groups = self.initial_data['realm_user_groups']
122126
self.user_group_by_id = {} # type: Dict[int, Dict[str, Any]]
@@ -423,7 +427,14 @@ def is_in_muted_topics(self, stream_id: int, topic: str) -> bool:
423427
"""
424428
stream_name = self.stream_dict[stream_id]['name']
425429
topic_to_search = [stream_name, topic] # type: List[str]
426-
return topic_to_search in self.muted_topics
430+
# The intent is to use the following data structure locally for lookups
431+
# without having server version & feature level checks throughout the
432+
# codebase.
433+
muted_topics_lookup = [
434+
[stream_name, topic]
435+
for stream_name, topic, *_ in self.muted_topics
436+
]
437+
return topic_to_search in muted_topics_lookup
427438

428439
def _update_initial_data(self) -> None:
429440
# Thread Processes to reduce start time.

0 commit comments

Comments
 (0)