feat: add undocumented org.matrix.room.preview_urls room state event

this is an undocumented room state event that at least Element uses to
disable/enable URL previews by default for the entire room. we'd like
to use this to disable URL previews in the conduwuit admin room where we
have large message blocks with some text that clients may render as URLs,
or a list of domains from the server config output.

also see https://github.com/matrix-org/matrix-spec/issues/394

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-05-12 17:12:19 -04:00
parent 9e29e07ae1
commit 62aca1e976
3 changed files with 30 additions and 0 deletions

View File

@ -130,6 +130,8 @@ event_enum! {
#[cfg(feature = "unstable-msc3401")]
#[ruma_enum(alias = "m.call.member")]
"org.matrix.msc3401.call.member" => super::call::member,
#[ruma_enum(alias = "m.room.preview_urls")]
"org.matrix.room.preview_urls" => super::room::preview_url,
}
/// Any to-device event.

View File

@ -25,6 +25,7 @@ pub mod message;
pub mod name;
pub mod pinned_events;
pub mod power_levels;
pub mod preview_url;
pub mod redaction;
pub mod server_acl;
pub mod third_party_invite;

View File

@ -0,0 +1,27 @@
//! Types for the undocumented [`org.matrix.room.preview_urls`] event.
//!
//! [`org.matrix.room.preview_url`]: https://github.com/matrix-org/matrix-spec/issues/394
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::EmptyStateKey;
/// The content of an `org.matrix.room.preview_urls` event.
///
/// An event to indicate whether URL previews are disabled by default for the room or not.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "org.matrix.room.preview_urls", kind = State, state_key_type = EmptyStateKey)]
pub struct RoomPreviewUrlsEventContent {
/// Whether URL previews are disabled for the entire room
#[serde(default)]
pub disabled: bool,
}
impl RoomPreviewUrlsEventContent {
/// Creates a new preview_url event with URL previews enabled by default (disabled: false)
pub fn new(disabled: bool) -> Self {
Self { disabled }
}
}