Files
continuwuity/src/core/config/experiments.rs
T

195 lines
7.1 KiB
Rust

use conduwuit_macros::config_example_generator;
use serde::Deserialize;
/// Configuration for experimental features.
#[derive(Debug, Deserialize, Default, Clone)]
#[config_example_generator(
filename = "conduwuit-example.toml",
section = "global.experiments",
subheader = r##"# Continuwuity's experimental features are frequently updated.
# If you got this configuration via a package manager, chances are it's outdated.
# Check out the configuration reference online to see a fresh version:
# https://continuwuity.org/reference/config.html#:~:text=global.experiments
#
# Please keep in mind that experiments are used to enable unstable features.
# You probably don't need to enable any of these unless you know what they are,
# and consequently know why you should enable them."##
)]
pub struct Experiments {
/// MSC2815: Proposal to allow room moderators to view redacted event
/// content
///
/// See [`MSC2815`] for details.
///
/// display: nested
#[serde(default)]
pub msc2815: Option<MSC2815>,
/// MSC3814: Dehydrated devices with SSSS
///
/// Enables server-side support for "dehydrated devices", which are
/// server-side devices (created by supporting clients) that can collect
/// encryption keys when there are no online devices, which supporting
/// clients can then "hydrate" to download any encryption keys that were
/// sent while they were offline.
///
/// Important: this is NOT required to receive encrypted messages while you
/// are offline. Devices can still receive encrypted messages while they are
/// offline, but to share those keys with new devices, they have to be
/// online. Dehydrated devices work around this by providing a "shared"
/// device new sessions can bootstrap from, to receive keys from before they
/// logged in that haven't been uploaded to the server-side key backup yet.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/3814
///
/// default: false
#[serde(default)]
pub msc3814: SimpleExperiment,
/// MSC4155: Invite filtering
///
/// Provides advanced invite filtering rules for users, allowing complex
/// configurations that can allow, ignore, and reject invites from users and
/// servers broadly.
///
/// Requires a supporting client to set up on an account.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4155
///
/// default: false
#[serde(default)]
pub msc4155: SimpleExperiment,
/// MSC4174: Web push
///
/// Adds server-side support for web push, allowing web clients to receive
/// push notifications directly without the need for an intermediary push
/// gateway like Sygnal.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4174
///
/// default: false
#[serde(default)]
pub msc4174: SimpleExperiment,
/// MSC4406: `M_SENDER_IGNORED` error code
///
/// Introduces a new error code that explicitly informs clients the reason
/// they cannot access an event if it is sent by an ignored user. Without
/// this proposal, clients will simply get a "not found" or "forbidden"
/// error when requesting events sent by users that have been ignored, which
/// leads to replies being shown as "this message could not be found".
/// The new error code allows clients to distinguish unknown/forbidden
/// events from ignored senders, allowing them to display an error message
/// like "you have blocked this sender" instead.
///
/// Requires a supporting client to be useful.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4406
///
/// default: false
#[serde(default)]
pub msc4406: SimpleExperiment,
/// MSC4484: Server Administration OAuth Scope
///
/// Adds a new OAuth2 scope that explicitly grants a token temporary
/// homeserver administrator privileges, granting temporary token access
/// to administrator endpoints like locking & suspension.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4484
///
/// default: false
#[serde(default)]
pub msc4484: SimpleExperiment,
/// MSC4494: Membership-based invite blocking
///
/// Adds a new invite blocking action that will reject all invites coming
/// from users who do not share a room with the invitee that is not `public`
/// (the join rule).
///
/// This is not related to MSC4155, this proposal instead builds on the
/// "invite blocking" proposal that landed in the specification in v1.17,
/// which simply allows enabling or disabling invites altogether.
///
/// MSC4494 is a good middle-ground between the allowlisting possible with
/// MSC4155, and the general desire to block invites from users you may not
/// know.
///
/// Requires a supporting client to enable on an account.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4494
///
/// default: false
#[serde(default)]
pub msc4494: SimpleExperiment,
/// MSC4560: Stripped state requests over federation
///
/// Implements a more efficient way for servers to acquire and serve
/// "stripped state" to clients, which is typically only used for displaying
/// rooms. The display of space hierarchies and room summaries is
/// significantly faster when this proposal is enabled and used.
///
/// https://github.com/matrix-org/matrix-spec-proposals/pull/4560
///
/// default: false
#[serde(default)]
pub msc4560: SimpleExperiment,
}
/// Represents a "simple" experiment, which is either disabled or enabled.
///
/// More complex experiments that require configuration should define their own
/// type and implement `ToggledExperiment` instead.
#[derive(Debug, Deserialize, Default, Clone, Copy)]
pub struct SimpleExperiment(Option<bool>);
pub trait ToggledExperiment {
/// Returns true if this experiment is explicitly enabled.
#[must_use]
fn is_enabled(&self) -> bool;
}
impl ToggledExperiment for SimpleExperiment {
#[inline]
fn is_enabled(&self) -> bool { self.0.is_some_and(crate::is_true!()) }
}
/// Configuration for [MSC2815]: Proposal to allow room moderators to view
/// redacted event content
///
/// MSC2815: https://github.com/matrix-org/matrix-spec-proposals/pull/2815
#[derive(Debug, Deserialize, Default, Clone, Copy)]
#[config_example_generator(
filename = "conduwuit-example.toml",
section = "global.experiments.msc2815",
optional = "true",
subheader = r#"# MSC2815: Proposal to allow room moderators to view redacted event content
#
# Allows the server to retain unredacted copies of events that have been
# redacted for a limited period of time, which allows room moderators and
# server administrators to reveal redacted contents. Useful for moderation
# and investigating reports.
#
# Requires a supporting client to use.
#
# https://github.com/matrix-org/matrix-spec-proposals/pull/2815"#
)]
pub struct MSC2815 {
/// Whether to enable MSC2815.
///
/// default: false
#[serde(default)]
pub enabled: bool,
/// How long, in seconds, to retain the original content of redacted
/// events before it is permanently erased. Defaults to 90 days.
///
/// default: 7776000
#[serde(default = "default_unredacted_content_max_age_secs")]
pub unredacted_content_max_age_secs: u64,
}
#[inline]
fn default_unredacted_content_max_age_secs() -> u64 { 7_776_000 }
impl ToggledExperiment for Option<MSC2815> {
#[inline]
fn is_enabled(&self) -> bool { self.is_some_and(|config| config.enabled) }
}