#![doc(html_favicon_url = "https://ruma.dev/favicon.ico")]
#![doc(html_logo_url = "https://ruma.dev/images/logo.png")]
#![warn(missing_docs)]
#[cfg(feature = "unstable-uniffi")]
uniffi::setup_scaffolding!();
use std::collections::BTreeSet;
use ruma_common::{EventEncryptionAlgorithm, OwnedUserId, room_version_rules::RedactionRules};
use serde::{Deserialize, Serialize, Serializer, de::IgnoredAny};
#[doc(hidden)]
pub mod _custom;
mod content;
mod enums;
mod kinds;
mod state_key;
mod unsigned;
extern crate self as ruma_events;
#[doc(hidden)]
pub mod exports {
pub use ruma_common;
pub use ruma_macros;
pub use serde;
pub use serde_json;
}
pub mod macros {
pub use ruma_macros::{Event, EventContent};
}
#[cfg(feature = "unstable-msc3927")]
pub mod audio;
#[cfg(feature = "unstable-msc3489")]
pub mod beacon;
#[cfg(feature = "unstable-msc3489")]
pub mod beacon_info;
pub mod call;
pub mod direct;
#[cfg(feature = "unstable-msc4359")]
pub mod do_not_disturb;
pub mod dummy;
#[cfg(feature = "unstable-msc3954")]
pub mod emote;
#[cfg(feature = "unstable-msc3956")]
pub mod encrypted;
#[cfg(feature = "unstable-msc3551")]
pub mod file;
pub mod forwarded_room_key;
pub mod fully_read;
pub mod identity_server;
pub mod ignored_user_list;
#[cfg(feature = "unstable-msc3552")]
pub mod image;
#[cfg(feature = "unstable-msc2545")]
pub mod image_pack;
pub mod invite_permission_config;
pub mod key;
pub mod key_backup;
#[cfg(feature = "unstable-msc3488")]
pub mod location;
pub mod marked_unread;
#[cfg(feature = "unstable-msc4278")]
pub mod media_preview_config;
#[cfg(feature = "unstable-msc4171")]
pub mod member_hints;
pub mod message;
pub mod policy;
#[cfg(feature = "unstable-msc3381")]
pub mod poll;
pub mod presence;
pub mod push_rules;
pub mod reaction;
pub mod receipt;
pub mod recent_emoji;
pub mod relation;
pub mod room;
pub mod room_key;
#[cfg(feature = "unstable-msc4268")]
pub mod room_key_bundle;
pub mod room_key_request;
#[cfg(feature = "unstable-msc4310")]
pub mod rtc;
pub mod secret;
pub mod secret_storage;
pub mod space;
#[cfg(feature = "unstable-msc3230")]
pub mod space_order;
pub mod sticker;
#[cfg(feature = "unstable-msc4471")]
pub mod stream;
pub mod tag;
pub mod typing;
#[cfg(feature = "unstable-msc3553")]
pub mod video;
#[cfg(feature = "unstable-msc3245")]
pub mod voice;
pub use self::{
content::*,
enums::*,
kinds::*,
relation::{BundledMessageLikeRelations, BundledStateRelations},
state_key::EmptyStateKey,
unsigned::{
AnyRedactionEvent, MessageLikeUnsigned, RedactedUnsigned, StateUnsigned,
UnsignedRoomRedactionEvent,
},
};
pub trait RedactContent {
type Redacted;
fn redact(self, rules: &RedactionRules) -> Self::Redacted;
}
#[doc(hidden)]
#[derive(Deserialize)]
#[allow(clippy::exhaustive_structs)]
pub struct EventTypeDeHelper<'a> {
#[serde(borrow, rename = "type")]
pub ev_type: std::borrow::Cow<'a, str>,
}
#[doc(hidden)]
#[derive(Deserialize)]
#[allow(clippy::exhaustive_structs)]
pub struct RedactionDeHelper {
pub unsigned: Option<UnsignedDeHelper>,
}
#[doc(hidden)]
#[derive(Deserialize)]
#[allow(clippy::exhaustive_structs)]
pub struct UnsignedDeHelper {
pub redacted_because: Option<IgnoredAny>,
}
#[doc(hidden)]
#[allow(clippy::ptr_arg)]
pub fn serialize_custom_event_error<T, S: Serializer>(_: &T, _: S) -> Result<S::Ok, S::Error> {
Err(serde::ser::Error::custom(
"Failed to serialize event [content] enum: Unknown event type.\n\
To send custom events, turn them into `Raw<EnumType>` by going through
`serde_json::value::to_raw_value` and `Raw::from_json`.",
))
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Mentions {
#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
pub user_ids: BTreeSet<OwnedUserId>,
#[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
pub room: bool,
}
impl Mentions {
pub fn new() -> Self {
Self::default()
}
pub fn with_user_ids(user_ids: impl IntoIterator<Item = OwnedUserId>) -> Self {
Self { user_ids: BTreeSet::from_iter(user_ids), ..Default::default() }
}
pub fn with_room_mention() -> Self {
Self { room: true, ..Default::default() }
}
fn add(&mut self, mentions: Self) {
self.user_ids.extend(mentions.user_ids);
self.room |= mentions.room;
}
}
ruma_common::priv_owned_str!(uniffi);