1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue as RawJsonValue;
use crate::{
    events::{
        EventContent, HasDeserializeFields, RedactContent, RedactedEventContent, StateEventContent,
        StateEventType,
    },
    OwnedRoomAliasId, OwnedServerName, RoomVersionId,
};
#[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 {
    
    
    
    
    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
    }
    fn from_parts(event_type: &str, content: &RawJsonValue) -> serde_json::Result<Self> {
        if event_type != "m.room.aliases" {
            return Err(::serde::de::Error::custom(format!(
                "expected event type `m.room.aliases`, found `{}`",
                event_type
            )));
        }
        serde_json::from_str(content.get())
    }
}
impl StateEventContent for RedactedRoomAliasesEventContent {
    type StateKey = OwnedServerName;
}
impl RedactedEventContent for RedactedRoomAliasesEventContent {
    fn has_serialize_fields(&self) -> bool {
        self.aliases.is_some()
    }
    fn has_deserialize_fields() -> HasDeserializeFields {
        HasDeserializeFields::Optional
    }
}