Skip to content

Commit

Permalink
Sliding Sync: Add receipts extension (MSC3960) (#17489)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods authored Jul 30, 2024
1 parent b2c55bd commit b221f0b
Show file tree
Hide file tree
Showing 7 changed files with 1,072 additions and 270 deletions.
1 change: 1 addition & 0 deletions changelog.d/17489.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add receipts extension support to experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint.
4 changes: 3 additions & 1 deletion synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ async def get_new_events(
room_ids: Iterable[str],
is_guest: bool,
explicit_room_id: Optional[str] = None,
to_key: Optional[MultiWriterStreamToken] = None,
) -> Tuple[List[JsonMapping], MultiWriterStreamToken]:
to_key = self.get_current_key()
if to_key is None:
to_key = self.get_current_key()

if from_key == to_key:
return [], to_key
Expand Down
268 changes: 208 additions & 60 deletions synapse/handlers/sliding_sync.py

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions synapse/rest/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ async def encode_extensions(
},
}

if extensions.receipts is not None:
serialized_extensions["receipts"] = {
# Same as the the top-level `account_data.events` field in Sync v2.
"rooms": extensions.receipts.room_id_to_receipt_map,
}

return serialized_extensions


Expand Down
20 changes: 18 additions & 2 deletions synapse/types/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class SlidingSyncResult:
Attributes:
next_pos: The next position token in the sliding window to request (next_batch).
lists: Sliding window API. A map of list key to list results.
rooms: Room subscription API. A map of room ID to room subscription to room results.
rooms: Room subscription API. A map of room ID to room results.
extensions: Extensions API. A map of extension key to extension results.
"""

Expand Down Expand Up @@ -361,12 +361,28 @@ def __bool__(self) -> bool:
self.global_account_data_map or self.account_data_by_room_map
)

@attr.s(slots=True, frozen=True, auto_attribs=True)
class ReceiptsExtension:
"""The Receipts extension (MSC3960)
Attributes:
room_id_to_receipt_map: Mapping from room_id to `m.receipt` event (type, content)
"""

room_id_to_receipt_map: Mapping[str, JsonMapping]

def __bool__(self) -> bool:
return bool(self.room_id_to_receipt_map)

to_device: Optional[ToDeviceExtension] = None
e2ee: Optional[E2eeExtension] = None
account_data: Optional[AccountDataExtension] = None
receipts: Optional[ReceiptsExtension] = None

def __bool__(self) -> bool:
return bool(self.to_device or self.e2ee or self.account_data)
return bool(
self.to_device or self.e2ee or self.account_data or self.receipts
)

next_pos: SlidingSyncStreamToken
lists: Dict[str, SlidingWindowList]
Expand Down
18 changes: 18 additions & 0 deletions synapse/types/rest/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,27 @@ class AccountDataExtension(RequestBodyModel):
# Process all room subscriptions defined in the Room Subscription API. (This is the default.)
rooms: Optional[List[StrictStr]] = ["*"]

class ReceiptsExtension(RequestBodyModel):
"""The Receipts extension (MSC3960)
Attributes:
enabled
lists: List of list keys (from the Sliding Window API) to apply this
extension to.
rooms: List of room IDs (from the Room Subscription API) to apply this
extension to.
"""

enabled: Optional[StrictBool] = False
# Process all lists defined in the Sliding Window API. (This is the default.)
lists: Optional[List[StrictStr]] = ["*"]
# Process all room subscriptions defined in the Room Subscription API. (This is the default.)
rooms: Optional[List[StrictStr]] = ["*"]

to_device: Optional[ToDeviceExtension] = None
e2ee: Optional[E2eeExtension] = None
account_data: Optional[AccountDataExtension] = None
receipts: Optional[ReceiptsExtension] = None

conn_id: Optional[str]

Expand Down
Loading

0 comments on commit b221f0b

Please sign in to comment.