Skip to content

Commit 68ab15e

Browse files
committed
model: Add muted_users to intial_data_to_fetch.
The muted users are stored in muted_users list of Model class. Tests adapted. Co-authored by: Subhasish-Behera <[email protected]>
1 parent 7116761 commit 68ab15e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ def initial_data(
903903
}
904904
],
905905
"result": "success",
906+
"muted_users": {},
906907
"queue_id": "1522420755:786",
907908
"realm_users": users_fixture,
908909
"cross_realm_bots": [

tests/model/test_model.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,36 @@ def test_init_muted_topics(
190190

191191
assert model._muted_topics == locally_processed_data
192192

193+
@pytest.mark.parametrize(
194+
"server_response, ids, zulip_feature_level",
195+
[
196+
(
197+
[
198+
{"id": 32323, "timestamp": 1726810359},
199+
{"id": 37372, "timestamp": 214214214},
200+
],
201+
{32323, 37372},
202+
48,
203+
),
204+
([], set(), 0),
205+
],
206+
ids=[
207+
"zulip_feature_level:48",
208+
"zulip_feature_level:0",
209+
],
210+
)
211+
def test_init_muted_users(
212+
self, mocker, initial_data, server_response, ids, zulip_feature_level
213+
):
214+
mocker.patch(MODEL + ".get_messages", return_value="")
215+
initial_data["zulip_feature_level"] = zulip_feature_level
216+
initial_data["muted_users"] = server_response
217+
self.client.register = mocker.Mock(return_value=initial_data)
218+
219+
model = Model(self.controller)
220+
221+
assert model._muted_users == ids
222+
193223
def test_init_InvalidAPIKey_response(self, mocker, initial_data):
194224
# Both network calls indicate the same response
195225
mocker.patch(MODEL + ".get_messages", return_value="Invalid API key")
@@ -262,6 +292,7 @@ def test_register_initial_desired_events(self, mocker, initial_data):
262292
"realm_emoji",
263293
"custom_profile_fields",
264294
"zulip_version",
295+
"muted_users",
265296
]
266297
model.client.register.assert_called_once_with(
267298
event_types=event_types,

zulipterminal/model.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def __init__(self, controller: Any) -> None:
145145
# zulip_version and zulip_feature_level are always returned in
146146
# POST /register from Feature level 3.
147147
"zulip_version",
148+
"muted_users",
148149
]
149150

150151
# Events desired with their corresponding callback
@@ -208,6 +209,11 @@ def __init__(self, controller: Any) -> None:
208209
)
209210
for stream_name, topic, *date_muted in muted_topics
210211
}
212+
# NOTE: muted_users also contains timestamps, but we only store the user IDs
213+
# muted_users was added in ZFL 48, Zulip 4.0
214+
self._muted_users: Set[int] = set()
215+
if self.server_feature_level >= 48:
216+
self._update_muted_users(self.initial_data["muted_users"])
211217

212218
groups = self.initial_data["realm_user_groups"]
213219
self.user_group_by_id: Dict[int, Dict[str, Any]] = {}
@@ -1204,6 +1210,9 @@ def get_user_info(self, user_id: int) -> Optional[TidiedUserInfo]:
12041210

12051211
return user_info
12061212

1213+
def _update_muted_users(self, muted_users: List[Dict[int, int]]) -> None:
1214+
self._muted_users = {muted_user["id"] for muted_user in muted_users}
1215+
12071216
def _update_users_data_from_initial_data(self) -> None:
12081217
# Dict which stores the active/idle status of users (by email)
12091218
presences = self.initial_data["presences"]

0 commit comments

Comments
 (0)