Skip to content

Commit

Permalink
Support MSC4140: Delayed events (Futures) (#17326)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr authored Sep 23, 2024
1 parent 75e2c17 commit 5173741
Show file tree
Hide file tree
Showing 21 changed files with 1,772 additions and 12 deletions.
2 changes: 2 additions & 0 deletions changelog.d/17326.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add initial implementation of delayed events as proposed by [MSC4140](https://github.com/matrix-org/matrix-spec-proposals/pull/4140).

3 changes: 3 additions & 0 deletions docker/complement/conf/workers-shared-extra.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ server_notices:
system_mxid_avatar_url: ""
room_name: "Server Alert"

# Enable delayed events (msc4140)
max_event_delay_duration: 24h


# Disable sync cache so that initial `/sync` requests are up-to-date.
caches:
Expand Down
13 changes: 13 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,19 @@ email:
password_reset: "[%(server_name)s] Password reset"
email_validation: "[%(server_name)s] Validate your email"
```
---
### `max_event_delay_duration`

The maximum allowed duration by which sent events can be delayed, as per
[MSC4140](https://github.com/matrix-org/matrix-spec-proposals/pull/4140).
Must be a positive value if set.

Defaults to no duration (`null`), which disallows sending delayed events.

Example configuration:
```yaml
max_event_delay_duration: 24h
```

## Homeserver blocking
Useful options for Synapse admins.
Expand Down
1 change: 1 addition & 0 deletions docs/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ information.
Additionally, the following REST endpoints can be handled for GET requests:

^/_matrix/client/(api/v1|r0|v3|unstable)/pushrules/
^/_matrix/client/unstable/org.matrix.msc4140/delayed_events

Pagination requests can also be handled, but all requests for a given
room must be routed to the same instance. Additionally, care must be taken to
Expand Down
1 change: 1 addition & 0 deletions scripts-dev/complement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ test_packages=(
./tests/msc3930
./tests/msc3902
./tests/msc3967
./tests/msc4140
)

# Enable dirty runs, so tests will reuse the same container where possible.
Expand Down
2 changes: 2 additions & 0 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
)
from synapse.storage.databases.main.censor_events import CensorEventsStore
from synapse.storage.databases.main.client_ips import ClientIpWorkerStore
from synapse.storage.databases.main.delayed_events import DelayedEventsStore
from synapse.storage.databases.main.deviceinbox import DeviceInboxWorkerStore
from synapse.storage.databases.main.devices import DeviceWorkerStore
from synapse.storage.databases.main.directory import DirectoryWorkerStore
Expand Down Expand Up @@ -161,6 +162,7 @@ class GenericWorkerStore(
TaskSchedulerWorkerStore,
ExperimentalFeaturesStore,
SlidingSyncStore,
DelayedEventsStore,
):
# Properties that multiple storage classes define. Tell mypy what the
# expected type is.
Expand Down
13 changes: 12 additions & 1 deletion synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is licensed under the Affero General Public License (AGPL) version 3.
#
# Copyright 2014-2021 The Matrix.org Foundation C.I.C.
# Copyright (C) 2023 New Vector, Ltd
# Copyright (C) 2023-2024 New Vector, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -780,6 +780,17 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
else:
self.delete_stale_devices_after = None

# The maximum allowed delay duration for delayed events (MSC4140).
max_event_delay_duration = config.get("max_event_delay_duration")
if max_event_delay_duration is not None:
self.max_event_delay_ms: Optional[int] = self.parse_duration(
max_event_delay_duration
)
if self.max_event_delay_ms <= 0:
raise ConfigError("max_event_delay_duration must be a positive value")
else:
self.max_event_delay_ms = None

def has_tls_listener(self) -> bool:
return any(listener.is_tls() for listener in self.listeners)

Expand Down
Loading

0 comments on commit 5173741

Please sign in to comment.