ruma_events/room/
aliases.rsuse ruma_common::{OwnedRoomAliasId, OwnedServerName, RoomVersionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{EventContent, RedactContent, RedactedStateEventContent, StateEventType};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.room.aliases", kind = State, state_key_type = OwnedServerName, custom_redacted)]
pub struct RoomAliasesEventContent {
pub aliases: Vec<OwnedRoomAliasId>,
}
impl RoomAliasesEventContent {
pub fn new(aliases: Vec<OwnedRoomAliasId>) -> Self {
Self { aliases }
}
}
impl RedactContent for RoomAliasesEventContent {
type Redacted = RedactedRoomAliasesEventContent;
fn redact(self, version: &RoomVersionId) -> RedactedRoomAliasesEventContent {
let aliases = match version {
RoomVersionId::V1
| RoomVersionId::V2
| RoomVersionId::V3
| RoomVersionId::V4
| RoomVersionId::V5 => Some(self.aliases),
_ => None,
};
RedactedRoomAliasesEventContent { aliases }
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct RedactedRoomAliasesEventContent {
#[serde(skip_serializing_if = "Option::is_none")]
pub aliases: Option<Vec<OwnedRoomAliasId>>,
}
impl RedactedRoomAliasesEventContent {
pub fn new_v1(aliases: Vec<OwnedRoomAliasId>) -> Self {
Self { aliases: Some(aliases) }
}
pub fn new_v6() -> Self {
Self::default()
}
}
impl EventContent for RedactedRoomAliasesEventContent {
type EventType = StateEventType;
fn event_type(&self) -> StateEventType {
StateEventType::RoomAliases
}
}
impl RedactedStateEventContent for RedactedRoomAliasesEventContent {
type StateKey = OwnedServerName;
}