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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use ruma_identifiers::RoomVersionId;
use crate::{Error, Result};
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub enum RoomDisposition {
Stable,
#[allow(dead_code)]
Unstable,
}
#[derive(Debug)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum EventFormatVersion {
V1,
V2,
V3,
}
#[derive(Debug)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum StateResolutionVersion {
V1,
V2,
}
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct RoomVersion {
pub version: RoomVersionId,
pub disposition: RoomDisposition,
pub event_format: EventFormatVersion,
pub state_res: StateResolutionVersion,
pub enforce_key_validity: bool,
pub special_case_aliases_auth: bool,
pub strict_canonicaljson: bool,
pub limit_notifications_power_levels: bool,
pub extra_redaction_checks: bool,
}
impl RoomVersion {
pub fn new(version: &RoomVersionId) -> Result<Self> {
Ok(match version {
RoomVersionId::Version1 => Self::version_1(),
RoomVersionId::Version2 => Self::version_2(),
RoomVersionId::Version3 => Self::version_3(),
RoomVersionId::Version4 => Self::version_4(),
RoomVersionId::Version5 => Self::version_5(),
RoomVersionId::Version6 => Self::version_6(),
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
})
}
pub fn version_1() -> Self {
Self {
version: RoomVersionId::Version1,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V1,
state_res: StateResolutionVersion::V1,
enforce_key_validity: false,
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: false,
}
}
pub fn version_2() -> Self {
Self {
version: RoomVersionId::Version2,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V1,
state_res: StateResolutionVersion::V2,
enforce_key_validity: false,
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: false,
}
}
pub fn version_3() -> Self {
Self {
version: RoomVersionId::Version3,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V2,
state_res: StateResolutionVersion::V2,
enforce_key_validity: false,
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: true,
}
}
pub fn version_4() -> Self {
Self {
version: RoomVersionId::Version4,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V3,
state_res: StateResolutionVersion::V2,
enforce_key_validity: false,
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: true,
}
}
pub fn version_5() -> Self {
Self {
version: RoomVersionId::Version5,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V3,
state_res: StateResolutionVersion::V2,
enforce_key_validity: true,
special_case_aliases_auth: true,
strict_canonicaljson: false,
limit_notifications_power_levels: false,
extra_redaction_checks: true,
}
}
pub fn version_6() -> Self {
Self {
version: RoomVersionId::Version6,
disposition: RoomDisposition::Stable,
event_format: EventFormatVersion::V3,
state_res: StateResolutionVersion::V2,
enforce_key_validity: true,
special_case_aliases_auth: false,
strict_canonicaljson: true,
limit_notifications_power_levels: true,
extra_redaction_checks: true,
}
}
}