Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit eba431c

Browse files
authored
Revert "Leave out optional keys from /sync (#9919)" (#9940)
This reverts commit e9eb354.
1 parent a8803e2 commit eba431c

File tree

4 files changed

+50
-51
lines changed

4 files changed

+50
-51
lines changed

changelog.d/9919.feature

Lines changed: 0 additions & 1 deletion
This file was deleted.

synapse/rest/client/v2_alpha/sync.py

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import itertools
1616
import logging
17-
from collections import defaultdict
1817
from typing import TYPE_CHECKING, Tuple
1918

2019
from synapse.api.constants import PresenceState
@@ -230,49 +229,24 @@ async def encode_response(self, time_now, sync_result, access_token_id, filter):
230229
)
231230

232231
logger.debug("building sync response dict")
233-
234-
response: dict = defaultdict(dict)
235-
response["next_batch"] = await sync_result.next_batch.to_string(self.store)
236-
237-
if sync_result.account_data:
238-
response["account_data"] = {"events": sync_result.account_data}
239-
if sync_result.presence:
240-
response["presence"] = SyncRestServlet.encode_presence(
241-
sync_result.presence, time_now
242-
)
243-
244-
if sync_result.to_device:
245-
response["to_device"] = {"events": sync_result.to_device}
246-
247-
if sync_result.device_lists.changed:
248-
response["device_lists"]["changed"] = list(sync_result.device_lists.changed)
249-
if sync_result.device_lists.left:
250-
response["device_lists"]["left"] = list(sync_result.device_lists.left)
251-
252-
if sync_result.device_one_time_keys_count:
253-
response[
254-
"device_one_time_keys_count"
255-
] = sync_result.device_one_time_keys_count
256-
if sync_result.device_unused_fallback_key_types:
257-
response[
258-
"org.matrix.msc2732.device_unused_fallback_key_types"
259-
] = sync_result.device_unused_fallback_key_types
260-
261-
if joined:
262-
response["rooms"]["join"] = joined
263-
if invited:
264-
response["rooms"]["invite"] = invited
265-
if archived:
266-
response["rooms"]["leave"] = archived
267-
268-
if sync_result.groups.join:
269-
response["groups"]["join"] = sync_result.groups.join
270-
if sync_result.groups.invite:
271-
response["groups"]["invite"] = sync_result.groups.invite
272-
if sync_result.groups.leave:
273-
response["groups"]["leave"] = sync_result.groups.leave
274-
275-
return response
232+
return {
233+
"account_data": {"events": sync_result.account_data},
234+
"to_device": {"events": sync_result.to_device},
235+
"device_lists": {
236+
"changed": list(sync_result.device_lists.changed),
237+
"left": list(sync_result.device_lists.left),
238+
},
239+
"presence": SyncRestServlet.encode_presence(sync_result.presence, time_now),
240+
"rooms": {"join": joined, "invite": invited, "leave": archived},
241+
"groups": {
242+
"join": sync_result.groups.join,
243+
"invite": sync_result.groups.invite,
244+
"leave": sync_result.groups.leave,
245+
},
246+
"device_one_time_keys_count": sync_result.device_one_time_keys_count,
247+
"org.matrix.msc2732.device_unused_fallback_key_types": sync_result.device_unused_fallback_key_types,
248+
"next_batch": await sync_result.next_batch.to_string(self.store),
249+
}
276250

277251
@staticmethod
278252
def encode_presence(events, time_now):

tests/rest/client/v2_alpha/test_sync.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,35 @@ def test_sync_argless(self):
3737
channel = self.make_request("GET", "/sync")
3838

3939
self.assertEqual(channel.code, 200)
40-
self.assertIn("next_batch", channel.json_body)
40+
self.assertTrue(
41+
{
42+
"next_batch",
43+
"rooms",
44+
"presence",
45+
"account_data",
46+
"to_device",
47+
"device_lists",
48+
}.issubset(set(channel.json_body.keys()))
49+
)
50+
51+
def test_sync_presence_disabled(self):
52+
"""
53+
When presence is disabled, the key does not appear in /sync.
54+
"""
55+
self.hs.config.use_presence = False
56+
57+
channel = self.make_request("GET", "/sync")
58+
59+
self.assertEqual(channel.code, 200)
60+
self.assertTrue(
61+
{
62+
"next_batch",
63+
"rooms",
64+
"account_data",
65+
"to_device",
66+
"device_lists",
67+
}.issubset(set(channel.json_body.keys()))
68+
)
4169

4270

4371
class SyncFilterTestCase(unittest.HomeserverTestCase):

tests/server_notices/test_resource_limits_server_notices.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ def test_no_invite_without_notice(self):
306306

307307
channel = self.make_request("GET", "/sync?timeout=0", access_token=tok)
308308

309-
self.assertNotIn(
310-
"rooms", channel.json_body, "Got invites without server notice"
311-
)
309+
invites = channel.json_body["rooms"]["invite"]
310+
self.assertEqual(len(invites), 0, invites)
312311

313312
def test_invite_with_notice(self):
314313
"""Tests that, if the MAU limit is hit, the server notices user invites each user
@@ -365,8 +364,7 @@ def _trigger_notice_and_join(self):
365364
# We could also pick another user and sync with it, which would return an
366365
# invite to a system notices room, but it doesn't matter which user we're
367366
# using so we use the last one because it saves us an extra sync.
368-
if "rooms" in channel.json_body:
369-
invites = channel.json_body["rooms"]["invite"]
367+
invites = channel.json_body["rooms"]["invite"]
370368

371369
# Make sure we have an invite to process.
372370
self.assertEqual(len(invites), 1, invites)

0 commit comments

Comments
 (0)