Skip to content

Commit b221f0b

Browse files
Sliding Sync: Add receipts extension (MSC3960) (#17489)
[MSC3960](matrix-org/matrix-spec-proposals#3960): Receipts extension Based on [MSC3575](matrix-org/matrix-spec-proposals#3575): Sliding Sync
1 parent b2c55bd commit b221f0b

File tree

7 files changed

+1072
-270
lines changed

7 files changed

+1072
-270
lines changed

changelog.d/17489.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add receipts extension support to experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint.

synapse/handlers/receipts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,10 @@ async def get_new_events(
286286
room_ids: Iterable[str],
287287
is_guest: bool,
288288
explicit_room_id: Optional[str] = None,
289+
to_key: Optional[MultiWriterStreamToken] = None,
289290
) -> Tuple[List[JsonMapping], MultiWriterStreamToken]:
290-
to_key = self.get_current_key()
291+
if to_key is None:
292+
to_key = self.get_current_key()
291293

292294
if from_key == to_key:
293295
return [], to_key

synapse/handlers/sliding_sync.py

Lines changed: 208 additions & 60 deletions
Large diffs are not rendered by default.

synapse/rest/client/sync.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,12 @@ async def encode_extensions(
11501150
},
11511151
}
11521152

1153+
if extensions.receipts is not None:
1154+
serialized_extensions["receipts"] = {
1155+
# Same as the the top-level `account_data.events` field in Sync v2.
1156+
"rooms": extensions.receipts.room_id_to_receipt_map,
1157+
}
1158+
11531159
return serialized_extensions
11541160

11551161

synapse/types/handlers/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class SlidingSyncResult:
152152
Attributes:
153153
next_pos: The next position token in the sliding window to request (next_batch).
154154
lists: Sliding window API. A map of list key to list results.
155-
rooms: Room subscription API. A map of room ID to room subscription to room results.
155+
rooms: Room subscription API. A map of room ID to room results.
156156
extensions: Extensions API. A map of extension key to extension results.
157157
"""
158158

@@ -361,12 +361,28 @@ def __bool__(self) -> bool:
361361
self.global_account_data_map or self.account_data_by_room_map
362362
)
363363

364+
@attr.s(slots=True, frozen=True, auto_attribs=True)
365+
class ReceiptsExtension:
366+
"""The Receipts extension (MSC3960)
367+
368+
Attributes:
369+
room_id_to_receipt_map: Mapping from room_id to `m.receipt` event (type, content)
370+
"""
371+
372+
room_id_to_receipt_map: Mapping[str, JsonMapping]
373+
374+
def __bool__(self) -> bool:
375+
return bool(self.room_id_to_receipt_map)
376+
364377
to_device: Optional[ToDeviceExtension] = None
365378
e2ee: Optional[E2eeExtension] = None
366379
account_data: Optional[AccountDataExtension] = None
380+
receipts: Optional[ReceiptsExtension] = None
367381

368382
def __bool__(self) -> bool:
369-
return bool(self.to_device or self.e2ee or self.account_data)
383+
return bool(
384+
self.to_device or self.e2ee or self.account_data or self.receipts
385+
)
370386

371387
next_pos: SlidingSyncStreamToken
372388
lists: Dict[str, SlidingWindowList]

synapse/types/rest/client/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,27 @@ class AccountDataExtension(RequestBodyModel):
342342
# Process all room subscriptions defined in the Room Subscription API. (This is the default.)
343343
rooms: Optional[List[StrictStr]] = ["*"]
344344

345+
class ReceiptsExtension(RequestBodyModel):
346+
"""The Receipts extension (MSC3960)
347+
348+
Attributes:
349+
enabled
350+
lists: List of list keys (from the Sliding Window API) to apply this
351+
extension to.
352+
rooms: List of room IDs (from the Room Subscription API) to apply this
353+
extension to.
354+
"""
355+
356+
enabled: Optional[StrictBool] = False
357+
# Process all lists defined in the Sliding Window API. (This is the default.)
358+
lists: Optional[List[StrictStr]] = ["*"]
359+
# Process all room subscriptions defined in the Room Subscription API. (This is the default.)
360+
rooms: Optional[List[StrictStr]] = ["*"]
361+
345362
to_device: Optional[ToDeviceExtension] = None
346363
e2ee: Optional[E2eeExtension] = None
347364
account_data: Optional[AccountDataExtension] = None
365+
receipts: Optional[ReceiptsExtension] = None
348366

349367
conn_id: Optional[str]
350368

0 commit comments

Comments
 (0)