tuwunel_core/config/rooms.rs
1//! Configures room creation, access, and lifecycle.
2//!
3//! Defaults govern newly created rooms and supported versions. Dedicated
4//! settings cover joins, invites, relations, redaction, policy servers, and
5//! extremities.
6
7use regex::RegexSet;
8use ruma::RoomVersionId;
9use serde::Deserialize;
10use serde_json::Value;
11use tuwunel_macros::config_example_generator;
12
13use super::true_fn;
14
15/// Room creation, versions and lifecycle
16///
17/// Defaults for rooms created here (version, federation, power levels), who
18/// may create rooms and aliases, which room versions this server accepts,
19/// and what happens when users leave. Creation defaults apply only to rooms
20/// created after a change. The room directory is configured separately in
21/// `[global.directory.rooms]`.
22///
23/// Sub-sections:
24///
25/// - `[global.rooms.delayed_events]`: events scheduled to be sent later
26/// (MSC4140).
27/// - `[global.rooms.extremities]`: forward-extremity pruning.
28/// - `[global.rooms.invites]`: invite restrictions and automatic acceptance.
29/// - `[global.rooms.joins]`: server selection when joining remote rooms.
30/// - `[global.rooms.policy_server]`: room policy servers (MSC4284).
31/// - `[global.rooms.redaction]`: redaction, retained originals, erasure.
32/// - `[global.rooms.relations]`: optional edit and reference bundles.
33///
34/// Tips:
35/// - Startup fails when `default_version` names a version that is not
36/// enabled. Stable versions (6 and later) always are; 3 to 5 only while
37/// `allow_unstable_versions` is on (the default).
38/// - `default_power_level_content_override` must be a table, such as
39/// `{ users_default = 50 }`; any other value fails startup.
40/// - `forbidden_alias_names` entries are regular expressions. An entry that
41/// reads as a dotted name draws a startup warning; escape the dot
42/// (`"a\\.b"`) to match it literally.
43#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
44#[derive(Clone, Debug, Deserialize)]
45#[config_example_generator(
46 filename = "tuwunel-example.toml",
47 section = "global.rooms",
48 group = "true",
49 ignore = "delayed_events extremities invites joins policy_server redaction relations"
50)]
51pub struct Rooms {
52 /// Sets the default `m.federate` property for newly created rooms when the
53 /// client does not request one.
54 ///
55 /// When both this setting and `federation.enable` are false, we always
56 /// override the client-requested `m.federate` value to false. Rooms
57 /// permanently retain the setting chosen at creation, so changing this
58 /// value affects only new rooms.
59 ///
60 /// reloadable: yes
61 /// legacy: federate_created_rooms
62 #[serde(default = "true_fn")]
63 pub federate_by_default: bool,
64
65 /// Calls `/forget` on the user's behalf whenever they leave a room.
66 ///
67 /// This implements
68 /// [MSC4267](https://github.com/matrix-org/matrix-spec-proposals/pull/4267),
69 /// automatically forgetting rooms on leave.
70 ///
71 /// reloadable: yes
72 /// legacy: forget_forced_upon_leave
73 #[serde(default)]
74 pub forget_forced_upon_leave: bool,
75
76 /// Requires local departures to be forgotten before pruning a room.
77 ///
78 /// Disabling this lets `prune-empty` delete rooms local users left without
79 /// forgetting. Its force option bypasses this protection; local joins,
80 /// invites, and pending knocks always prevent pruning.
81 ///
82 /// reloadable: yes
83 /// default: true
84 #[serde(default = "true_fn")]
85 pub prune_require_forgotten: bool,
86
87 /// Allows standard users to create rooms.
88 ///
89 /// Appservices and admins can always create rooms.
90 ///
91 /// reloadable: yes
92 /// legacy: allow_room_creation
93 #[serde(default = "true_fn")]
94 pub allow_creation: bool,
95
96 /// Allows standard users to create room aliases.
97 ///
98 /// Appservices and admins can always create room aliases.
99 ///
100 /// reloadable: yes
101 /// default: true
102 /// legacy: allow_room_alias_creation
103 #[serde(default = "true_fn")]
104 pub allow_alias_creation: bool,
105
106 /// Allows joining or creating room versions we do not officially support.
107 ///
108 /// Unstable versions may have flawed specifications or a non-conforming
109 /// implementation, so correct operation is not guaranteed even when
110 /// incorrect behavior is tolerable or unnoticed. We officially support
111 /// versions 6 and later, with slightly experimental support for versions 3
112 /// through 5 that works in practice. Set to false to disable these
113 /// unsupported versions.
114 ///
115 /// reloadable: yes
116 /// default: true
117 /// legacy: allow_unstable_room_versions
118 #[serde(default = "true_fn")]
119 pub allow_unstable_versions: bool,
120
121 /// Enables experimental room versions for developer use.
122 ///
123 /// Unlike unstable versions, these may be under development, prototype
124 /// specification changes, or present serious risks to server operation or
125 /// database integrity. Set to true only for developer use.
126 ///
127 /// reloadable: yes
128 /// legacy: allow_experimental_room_versions
129 #[serde(default)]
130 pub allow_experimental_versions: bool,
131
132 /// Selects the room version used by default when creating rooms.
133 ///
134 /// The default follows the specification but may follow developer
135 /// recommendations.
136 /// Override it only with an understanding that doing so precludes updates
137 /// to newer versions.
138 ///
139 /// reloadable: yes
140 /// legacy: default_room_version
141 #[serde(default = "default_default_version")]
142 pub default_version: RoomVersionId,
143
144 /// Sets default power-level overrides for newly created rooms.
145 ///
146 /// This uses the client `/createRoom` parameter's
147 /// `power_level_content_override` shape and is merged before per-request
148 /// overrides, so clients can still override it per room. Only new rooms
149 /// are affected. Top-level keys replace wholesale rather than deep-merge,
150 /// matching the client parameter: `users` or `events` replaces that entire
151 /// computed default submap.
152 ///
153 /// reloadable: yes
154 /// default: unset
155 /// config-example: { users_default = 50 }
156 /// legacy: default_power_level_content_override
157 #[serde(default)]
158 pub default_power_level_content_override: Option<Value>,
159
160 /// Deactivates users who try to join banned rooms or forbidden room
161 /// aliases or server names.
162 ///
163 /// This includes room aliases or IDs with forbidden server names and makes
164 /// the user leave all rooms; federation activity such as remote invites is
165 /// ignored. It can remove the need for admin intervention when banned
166 /// lists contain only toxic rooms or servers that no good-faith user would
167 /// try to join. The default is false because rooms may be banned for
168 /// non-moderation reasons and this performs full account deactivation.
169 ///
170 /// reloadable: yes
171 /// legacy: auto_deactivate_banned_room_attempts
172 #[serde(default)]
173 pub auto_deactivate_banned_room_attempts: bool,
174
175 /// Forbids room aliases and room IDs matching listed regular expressions.
176 ///
177 /// Patterns can use regular expressions or simple words for containment
178 /// matches, as in the example. Checks run on room alias creation and
179 /// custom room ID creation, with startup warnings for existing database
180 /// aliases with forbidden aliases or IDs.
181 ///
182 /// reloadable: yes
183 /// example: ["19dollarfortnitecards", "b[4a]droom", "badphrase"]
184 ///
185 /// default: []
186 /// legacy: forbidden_alias_names
187 #[serde(default, with = "serde_regex")]
188 pub forbidden_alias_names: RegexSet,
189
190 /// Deletes rooms after the last local user leaves.
191 ///
192 /// This experimental feature is disabled by default to avoid surprises,
193 /// but deployments conserving space may enable it; it may default to true
194 /// in a future release. Some paths that remove the last local user do not
195 /// yet invoke deletion, so a room can remain afterward.
196 ///
197 /// reloadable: yes
198 /// default: false
199 /// legacy: delete_rooms_after_leave
200 #[serde(default)]
201 pub delete_after_leave: bool,
202
203 /// Settings for rooms delayed events.
204 ///
205 /// display: section
206 #[serde(default)]
207 pub delayed_events: DelayedEvents,
208
209 /// Settings for rooms extremities.
210 ///
211 /// display: section
212 #[serde(default)]
213 pub extremities: Extremities,
214
215 /// Settings for rooms invites.
216 ///
217 /// display: section
218 #[serde(default)]
219 pub invites: Invites,
220
221 /// Settings for rooms joins.
222 ///
223 /// display: section
224 #[serde(default)]
225 pub joins: Joins,
226
227 /// Settings for rooms policy server.
228 ///
229 /// display: section
230 #[serde(default)]
231 pub policy_server: PolicyServer,
232
233 /// Settings for rooms redaction.
234 ///
235 /// display: section
236 #[serde(default)]
237 pub redaction: Redaction,
238
239 /// Settings for rooms relations.
240 ///
241 /// display: section
242 #[serde(default)]
243 pub relations: Relations,
244}
245
246/// Delayed events (MSC4140)
247///
248/// Lets clients schedule an event to be sent later, then restart its delay,
249/// cancel it or send it early. Element Call schedules a leave this way, so a
250/// caller whose client crashes still leaves the call. Scheduled events
251/// survive a restart, and any that fell due meanwhile are sent on startup.
252///
253/// Tips:
254/// - Setting either limit to 0 disables delayed events and stops
255/// advertising them to clients.
256#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
257#[derive(Clone, Copy, Debug, Deserialize)]
258#[config_example_generator(
259 filename = "tuwunel-example.toml",
260 section = "global.rooms.delayed_events",
261 group = "true"
262)]
263pub struct DelayedEvents {
264 /// Limits how far ahead an event may be scheduled, in seconds.
265 ///
266 /// reloadable: yes
267 /// default: 86400
268 #[serde(default = "default_max_delay_s")]
269 pub max_delay_s: u64,
270
271 /// Limits how many events one user may have scheduled at once.
272 ///
273 /// reloadable: yes
274 /// default: 100
275 #[serde(default = "default_max_scheduled")]
276 pub max_scheduled: usize,
277
278 /// Checks a change to the sender's own membership against the room's
279 /// rules when it is scheduled, as every other delayed event is.
280 ///
281 /// When false, such a change is checked only when it is sent, which lets
282 /// a user schedule a join they could not make yet.
283 ///
284 /// reloadable: yes
285 /// default: true
286 #[serde(default = "true_fn")]
287 pub check_own_membership: bool,
288}
289
290/// Forward-extremity pruning
291///
292/// Forward extremities are a room's newest events that no later event
293/// references yet; events this server creates cite them as `prev_events`.
294/// Busy federated rooms can pile them up, so these keys trim the set while
295/// incoming federation events are processed. The defaults suit most servers.
296///
297/// Tips:
298/// - `!admin rooms list-extremities` and `!admin rooms prune-extremities`
299/// inspect and trim one room on demand.
300#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
301#[derive(Clone, Copy, Debug, Deserialize)]
302#[config_example_generator(
303 filename = "tuwunel-example.toml",
304 section = "global.rooms.extremities",
305 group = "true"
306)]
307pub struct Extremities {
308 /// Sets the soft cap on forward extremities tracked per room.
309 ///
310 /// When applying an incoming federation event would exceed this cap, we
311 /// prune the least useful leaves from the tracked frontier until it meets
312 /// the cap. Pruned events remain stored and referenceable by other
313 /// servers; we only stop citing them as frontier tips. Events created by
314 /// this server are never pruned, and 0 disables automatic pruning.
315 ///
316 /// reloadable: yes
317 /// default: 60
318 /// legacy: forward_extremities_max
319 #[serde(default = "default_max")]
320 pub max: usize,
321
322 /// Sets the emergency bound on a room's forward extremities.
323 ///
324 /// A larger frontier is cut down to this bound in one step, ignoring the
325 /// per-event pruning batch limit. Values at or below
326 /// `rooms.extremities.max` remove pacing entirely and prune straight to
327 /// the cap.
328 ///
329 /// reloadable: yes
330 /// default: 256
331 /// legacy: forward_extremities_emergency_max
332 #[serde(default = "default_emergency_max")]
333 pub emergency_max: usize,
334
335 /// Limits forward extremities pruned by one incoming event between the
336 /// soft cap and emergency bound.
337 ///
338 /// This spreads convergence across events to bound each event's work. A
339 /// value of 0 stops paced pruning and leaves only the emergency bound.
340 ///
341 /// reloadable: yes
342 /// default: 32
343 /// legacy: forward_extremities_prune_batch
344 #[serde(default = "default_prune_batch")]
345 pub prune_batch: usize,
346}
347
348/// Room invites
349///
350/// Restricts who may send and receive invites, and can accept invites on
351/// users' behalf. At the defaults neither applies: invites follow the normal
352/// room rules and wait for the user to answer.
353///
354/// Tips:
355/// - `auto_accept_direct_only` and `auto_accept_local_only` only narrow
356/// `auto_accept`; with `auto_accept = false` they do nothing.
357/// - `auto_accept` on its own also accepts invites from users on other
358/// servers, joining local users to remote rooms; add
359/// `auto_accept_local_only` to prevent that.
360/// - These keys do not filter by server. To refuse everything from a
361/// server, invites included, use `federation.forbidden_remote_server_names`.
362#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
363#[derive(Clone, Copy, Debug, Default, Deserialize)]
364#[config_example_generator(
365 filename = "tuwunel-example.toml",
366 section = "global.rooms.invites",
367 group = "true"
368)]
369pub struct Invites {
370 /// Blocks non-admin local users from sending local or remote invites and
371 /// non-admin users from receiving remote invites.
372 ///
373 /// Admins can always send and receive all room invites.
374 ///
375 /// reloadable: yes
376 /// legacy: block_non_admin_invites
377 #[serde(default)]
378 pub block_non_admin: bool,
379
380 /// Automatically joins local users to any room they are invited to.
381 ///
382 /// The join runs in the background once the invite is recorded, and is
383 /// retried for a short while when a federated invite has not yet settled
384 /// on the inviting server. Users who are deactivated, suspended, or locked
385 /// are never joined.
386 ///
387 /// reloadable: yes
388 /// legacy: auto_accept_invites
389 #[serde(default)]
390 pub auto_accept: bool,
391
392 /// Restricts automatic invite acceptance to direct-message invites.
393 ///
394 /// This restricts `rooms.invites.auto_accept`. The invite must carry
395 /// `is_direct` in its membership content, which clients set when starting
396 /// a direct chat. Invites to any other room are left for the user to
397 /// answer.
398 ///
399 /// reloadable: yes
400 /// legacy: auto_accept_invites_direct_only
401 #[serde(default)]
402 pub auto_accept_direct_only: bool,
403
404 /// Restricts automatic invite acceptance to invites sent by local users.
405 ///
406 /// This restricts `rooms.invites.auto_accept`. Invites arriving from
407 /// another server are left for the user to answer.
408 ///
409 /// reloadable: yes
410 /// legacy: auto_accept_invites_local_only
411 #[serde(default)]
412 pub auto_accept_local_only: bool,
413}
414
415/// Joining remote rooms
416///
417/// Controls which resident servers this server asks, and how many, when
418/// joining a room through other servers. At the defaults, servers matching
419/// `matrix\.org` are tried last and a join request gives up after three
420/// failed attempts.
421///
422/// Tips:
423/// - `deprioritize_servers` entries are regular expressions matched against
424/// server names. An entry that reads as a dotted name draws a startup
425/// warning; write `"example\\.org"`, not `"example.org"`.
426#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
427#[derive(Clone, Debug, Deserialize)]
428#[config_example_generator(
429 filename = "tuwunel-example.toml",
430 section = "global.rooms.joins",
431 group = "true"
432)]
433pub struct Joins {
434 /// Lists server names to try last when joining rooms.
435 ///
436 /// Client-requested joins through these servers try them last, which can
437 /// prevent failed joins caused by a particular server's timeouts.
438 ///
439 /// reloadable: yes
440 /// default: ["matrix\.org"]
441 /// config-example: ["matrix\\.org"]
442 /// legacy: deprioritize_joins_through_servers
443 #[serde(
444 default = "default_deprioritize_servers",
445 with = "serde_regex"
446 )]
447 pub deprioritize_servers: RegexSet,
448
449 /// Limits `make_join` requests within each join attempt.
450 ///
451 /// Each request tries a different server, with each server tried only once
452 /// per attempt. Servers can be retried when the entire join request is
453 /// retried.
454 ///
455 /// reloadable: yes
456 /// default: 48
457 /// legacy: max_make_join_attempts_per_join_attempt
458 #[serde(default = "default_max_make_join_per_attempt")]
459 pub max_make_join_per_attempt: usize,
460
461 /// Limits join attempts per client join request.
462 ///
463 /// Each attempt contains one or more `make_join` requests bounded by
464 /// `rooms.joins.max_make_join_per_attempt` and one `send_join` request.
465 /// Additional attempts let more servers act as the join server before
466 /// returning the last error to the client.
467 /// The default exceeds one while limiting the risk of exceeding the
468 /// client's request timeout, although exceeding it may sometimes be
469 /// unavoidable.
470 ///
471 /// reloadable: yes
472 /// default: 3
473 /// legacy: max_join_attempts_per_join_request
474 #[serde(default = "default_max_attempts_per_request")]
475 pub max_attempts_per_request: usize,
476}
477
478/// Room policy servers (MSC4284)
479///
480/// A room can name a policy server in its `m.room.policy` state event; that
481/// server is asked to sign each event before it federates. These keys decide
482/// whether this server takes part. Off by default, in which case policy
483/// servers are ignored: outgoing events are not sent for signing and
484/// incoming events are not checked.
485///
486/// Tips:
487/// - When enabled, an outgoing event the policy server refuses is not sent
488/// and the client request fails; an incoming event it refuses is
489/// soft-failed. When the policy server cannot be reached, events pass.
490/// - `request_timeout` has no effect unless `enable = true`.
491#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
492#[derive(Clone, Copy, Debug, Deserialize)]
493#[config_example_generator(
494 filename = "tuwunel-example.toml",
495 section = "global.rooms.policy_server",
496 group = "true"
497)]
498pub struct PolicyServer {
499 /// Requests policy-server signatures for outgoing events under
500 /// [MSC4284](https://github.com/matrix-org/matrix-spec-proposals/pull/4284).
501 ///
502 /// For a room with a valid `m.room.policy` state event, we request a
503 /// signature from its policy server's federation `/sign` endpoint before
504 /// federating each event. Refusal aborts the local request; network and
505 /// timeout failures fail open with a warning log so a transient outage
506 /// does not silently take the room offline.
507 ///
508 /// reloadable: yes
509 /// default: false
510 /// legacy: enable_policy_servers
511 #[serde(default)]
512 pub enable: bool,
513
514 /// Sets the policy-server request timeout in seconds under
515 /// [MSC4284](https://github.com/matrix-org/matrix-spec-proposals/pull/4284).
516 ///
517 /// This applies to outbound `/sign` calls and inbound signature fetches.
518 ///
519 /// reloadable: yes
520 /// default: 5
521 /// legacy: policy_server_request_timeout
522 #[serde(default = "default_request_timeout")]
523 pub request_timeout: u64,
524}
525
526/// Redaction, retained originals and erasure
527///
528/// Governs redactions and what survives them. By default the server keeps
529/// each redacted event's original content for 60 days, readable by server
530/// admins and by users whose power level reaches `redact`, and serves erased
531/// users' events as pruned copies to servers that had no user in the room.
532///
533/// Tips:
534/// - `retention_seconds = 0` keeps originals forever; otherwise expired
535/// originals are removed in an hourly pass.
536/// - Turning off `save_unredacted_events` stops new copies only; copies
537/// already kept stay until `retention_seconds` expires them.
538/// - `thread_latest_reply_search_limit = 0` fails startup.
539#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
540#[derive(Clone, Copy, Debug, Deserialize)]
541#[config_example_generator(
542 filename = "tuwunel-example.toml",
543 section = "global.rooms.redaction",
544 group = "true"
545)]
546pub struct Redaction {
547 /// Limits relation rows read by each thread scan during redaction.
548 ///
549 /// Replacing a redacted latest thread reply, and correcting each of a
550 /// member's unread counters after a redacted reply, each read at most this
551 /// many rows; missing, malformed, unrelated, and redacted events consume
552 /// the budget before event filtering. When it runs out, the thread summary
553 /// is omitted and the thread's unread count may stay one too high until a
554 /// thread or unthreaded receipt clears it.
555 ///
556 /// reloadable: yes
557 /// default: 1024
558 /// legacy: thread_latest_reply_search_limit
559 #[serde(default = "default_thread_latest_reply_search_limit")]
560 pub thread_latest_reply_search_limit: usize,
561
562 /// Saves original events before applying redactions.
563 ///
564 /// Retrieve them with `admin debug get-retained-pdu` or
565 /// [MSC2815](https://github.com/matrix-org/matrix-spec-proposals/pull/2815).
566 ///
567 /// reloadable: yes
568 /// default: true
569 /// legacy: save_unredacted_events
570 #[serde(default = "true_fn")]
571 pub save_unredacted_events: bool,
572
573 /// Sets the redaction retention period in seconds.
574 ///
575 /// By default the unredacted events are stored for 60 days.
576 ///
577 /// reloadable: yes
578 /// default: 5184000
579 /// legacy: redaction_retention_seconds
580 #[serde(default = "default_retention_seconds")]
581 pub retention_seconds: u64,
582
583 /// Allows users with `redact` power level to request unredacted events
584 /// under
585 /// [MSC2815](https://github.com/matrix-org/matrix-spec-proposals/pull/2815).
586 ///
587 /// Server admins can request unredacted events regardless of this setting.
588 ///
589 /// reloadable: yes
590 /// default: true
591 /// legacy: allow_room_admins_to_request_unredacted_events
592 #[serde(default = "true_fn")]
593 pub allow_room_admins_to_request_unredacted_events: bool,
594
595 /// Prevents local users from sending redactions.
596 ///
597 /// This check does not apply to server admins.
598 ///
599 /// reloadable: yes
600 /// legacy: disable_local_redactions
601 #[serde(default)]
602 pub disable_local: bool,
603
604 /// Serves erased senders' events as pruned copies over federation under
605 /// [MSC4025](https://github.com/matrix-org/matrix-spec-proposals/pull/4025).
606 ///
607 /// A requesting server retains the unredacted view only when one of its
608 /// users was joined in the room state at the event. Join handshakes are
609 /// not gated.
610 ///
611 /// reloadable: yes
612 /// default: true
613 /// legacy: enforce_erasure_over_federation
614 #[serde(default = "true_fn")]
615 pub enforce_erasure_over_federation: bool,
616}
617
618/// Relation bundles
619///
620/// Adds optional edit and reference summaries to events served to clients.
621/// Both are off by default; most clients build these themselves, so enable
622/// one only for a client that relies on it. Thread summaries are always
623/// bundled and do not depend on these keys.
624#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
625#[derive(Clone, Copy, Debug, Default, Deserialize)]
626#[config_example_generator(
627 filename = "tuwunel-example.toml",
628 section = "global.rooms.relations",
629 group = "true"
630)]
631pub struct Relations {
632 /// Bundles the latest message edit under
633 /// [MSC3925](https://github.com/matrix-org/matrix-spec-proposals/pull/3925).
634 ///
635 /// Client read endpoints fold the most recent `m.replace` relation into
636 /// `unsigned.m.relations` as the full replacement event. This is opt-in
637 /// and disabled by default because it adds a typed index seek per served
638 /// event and a server-authoritative summary most clients reconstruct
639 /// locally.
640 ///
641 /// reloadable: yes
642 /// default: false
643 /// legacy: bundle_edit_relations
644 #[serde(default)]
645 pub bundle_edits: bool,
646
647 /// Bundles reference relations under
648 /// [MSC2675](https://github.com/matrix-org/matrix-spec-proposals/pull/2675)
649 /// and
650 /// [MSC3267](https://github.com/matrix-org/matrix-spec-proposals/pull/3267).
651 ///
652 /// Client read endpoints fold `m.reference` relations into
653 /// `unsigned.m.relations` as `{ chunk: [{ event_id }, ...] }`. This is
654 /// disabled by default and adds read-time work when enabled; clients can
655 /// resolve references for polls, beacons, and verification directly.
656 ///
657 /// reloadable: yes
658 /// default: false
659 /// legacy: bundle_reference_relations
660 #[serde(default)]
661 pub bundle_references: bool,
662}
663
664impl Default for Rooms {
665 fn default() -> Self {
666 Self {
667 federate_by_default: true_fn(),
668 forget_forced_upon_leave: Default::default(),
669 prune_require_forgotten: true_fn(),
670 allow_creation: true_fn(),
671 allow_alias_creation: true_fn(),
672 allow_unstable_versions: true_fn(),
673 allow_experimental_versions: Default::default(),
674 default_version: default_default_version(),
675 default_power_level_content_override: Default::default(),
676 auto_deactivate_banned_room_attempts: Default::default(),
677 forbidden_alias_names: Default::default(),
678 delete_after_leave: Default::default(),
679 delayed_events: DelayedEvents::default(),
680 extremities: Extremities::default(),
681 invites: Invites::default(),
682 joins: Joins::default(),
683 policy_server: PolicyServer::default(),
684 redaction: Redaction::default(),
685 relations: Relations::default(),
686 }
687 }
688}
689
690impl Default for DelayedEvents {
691 fn default() -> Self {
692 Self {
693 max_delay_s: default_max_delay_s(),
694 max_scheduled: default_max_scheduled(),
695 check_own_membership: true_fn(),
696 }
697 }
698}
699
700impl Default for Extremities {
701 fn default() -> Self {
702 Self {
703 max: default_max(),
704 emergency_max: default_emergency_max(),
705 prune_batch: default_prune_batch(),
706 }
707 }
708}
709
710impl Default for Joins {
711 fn default() -> Self {
712 Self {
713 deprioritize_servers: default_deprioritize_servers(),
714 max_make_join_per_attempt: default_max_make_join_per_attempt(),
715 max_attempts_per_request: default_max_attempts_per_request(),
716 }
717 }
718}
719
720impl Default for PolicyServer {
721 fn default() -> Self {
722 Self {
723 enable: Default::default(),
724 request_timeout: default_request_timeout(),
725 }
726 }
727}
728
729impl Default for Redaction {
730 fn default() -> Self {
731 Self {
732 thread_latest_reply_search_limit: default_thread_latest_reply_search_limit(),
733 save_unredacted_events: true_fn(),
734 retention_seconds: default_retention_seconds(),
735 allow_room_admins_to_request_unredacted_events: true_fn(),
736 disable_local: Default::default(),
737 enforce_erasure_over_federation: true_fn(),
738 }
739 }
740}
741
742/// Returns the default Matrix room version.
743///
744/// Room version 12 is selected when `rooms.default_version` is omitted. The
745/// value is returned without consulting runtime configuration.
746#[must_use]
747#[inline]
748pub fn default_default_version() -> RoomVersionId { RoomVersionId::V12 }
749
750fn default_max_delay_s() -> u64 { 86_400 }
751
752fn default_max_scheduled() -> usize { 100 }
753
754fn default_max() -> usize { 60 }
755
756fn default_emergency_max() -> usize { 256 }
757
758fn default_prune_batch() -> usize { 32 }
759
760fn default_deprioritize_servers() -> RegexSet {
761 RegexSet::new([r"matrix\.org"]).expect("valid set of regular expressions")
762}
763
764fn default_max_make_join_per_attempt() -> usize { 48 }
765
766fn default_max_attempts_per_request() -> usize { 3 }
767
768fn default_request_timeout() -> u64 { 5 }
769
770fn default_thread_latest_reply_search_limit() -> usize { 1024 }
771
772fn default_retention_seconds() -> u64 { 5_184_000 }