1//! Types for the `m.room.aliases` event.
23use ruma_common::{room_version_rules::RedactionRules, OwnedRoomAliasId, OwnedServerName};
4use ruma_macros::EventContent;
5use serde::{Deserialize, Serialize};
67use crate::{EventContent, RedactContent, RedactedStateEventContent, StateEventType};
89/// The content of an `m.room.aliases` event.
10///
11/// Informs the room about what room aliases it has been given.
12#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
13#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
14#[ruma_event(type = "m.room.aliases", kind = State, state_key_type = OwnedServerName, custom_redacted)]
15pub struct RoomAliasesEventContent {
16/// A list of room aliases.
17pub aliases: Vec<OwnedRoomAliasId>,
18}
1920impl RoomAliasesEventContent {
21/// Create an `RoomAliasesEventContent` from the given aliases.
22pub fn new(aliases: Vec<OwnedRoomAliasId>) -> Self {
23Self { aliases }
24 }
25}
2627impl RedactContent for RoomAliasesEventContent {
28type Redacted = RedactedRoomAliasesEventContent;
2930fn redact(self, rules: &RedactionRules) -> RedactedRoomAliasesEventContent {
31let aliases = rules.keep_room_aliases_aliases.then_some(self.aliases);
32 RedactedRoomAliasesEventContent { aliases }
33 }
34}
3536/// An aliases event that has been redacted.
37#[derive(Clone, Debug, Default, Deserialize, Serialize)]
38#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
39pub struct RedactedRoomAliasesEventContent {
40/// A list of room aliases.
41 ///
42 /// According to the Matrix spec version 1 redaction rules allowed this field to be
43 /// kept after redaction, this was changed in version 6.
44#[serde(skip_serializing_if = "Option::is_none")]
45pub aliases: Option<Vec<OwnedRoomAliasId>>,
46}
4748impl RedactedRoomAliasesEventContent {
49/// Create a `RedactedAliasesEventContent` with the given aliases.
50 ///
51 /// This is only valid for room version 5 and below.
52pub fn new_v1(aliases: Vec<OwnedRoomAliasId>) -> Self {
53Self { aliases: Some(aliases) }
54 }
5556/// Create a `RedactedAliasesEventContent` with the given aliases.
57 ///
58 /// This is only valid for room version 6 and above.
59pub fn new_v6() -> Self {
60Self::default()
61 }
62}
6364impl EventContent for RedactedRoomAliasesEventContent {
65type EventType = StateEventType;
6667fn event_type(&self) -> StateEventType {
68 StateEventType::RoomAliases
69 }
70}
7172impl RedactedStateEventContent for RedactedRoomAliasesEventContent {
73type StateKey = OwnedServerName;
74}