1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ use matrix_sdk_common:: ROOM_VERSION_RULES_FALLBACK ;
1516use ruma:: {
1617 assign,
1718 events:: {
@@ -70,18 +71,38 @@ pub struct RoomCreateWithCreatorEventContent {
7071 /// This is currently only used for spaces.
7172 #[ serde( skip_serializing_if = "Option::is_none" , rename = "type" ) ]
7273 pub room_type : Option < RoomType > ,
74+
75+ /// Additional room creators, considered to have "infinite" power level, in
76+ /// room versions 12 onwards.
77+ #[ serde( skip_serializing_if = "Vec::is_empty" , default ) ]
78+ pub additional_creators : Vec < OwnedUserId > ,
7379}
7480
7581impl RoomCreateWithCreatorEventContent {
7682 /// Constructs a `RoomCreateWithCreatorEventContent` with the given original
7783 /// content and sender.
7884 pub fn from_event_content ( content : RoomCreateEventContent , sender : OwnedUserId ) -> Self {
79- let RoomCreateEventContent { federate, room_version, predecessor, room_type, .. } = content;
80- Self { creator : sender, federate, room_version, predecessor, room_type }
85+ let RoomCreateEventContent {
86+ federate,
87+ room_version,
88+ predecessor,
89+ room_type,
90+ additional_creators,
91+ ..
92+ } = content;
93+ Self {
94+ creator : sender,
95+ federate,
96+ room_version,
97+ predecessor,
98+ room_type,
99+ additional_creators,
100+ }
81101 }
82102
83103 fn into_event_content ( self ) -> ( RoomCreateEventContent , OwnedUserId ) {
84- let Self { creator, federate, room_version, predecessor, room_type } = self ;
104+ let Self { creator, federate, room_version, predecessor, room_type, additional_creators } =
105+ self ;
85106
86107 #[ allow( deprecated) ]
87108 let content = assign ! ( RoomCreateEventContent :: new_v11( ) , {
@@ -90,10 +111,25 @@ impl RoomCreateWithCreatorEventContent {
90111 room_version,
91112 predecessor,
92113 room_type,
114+ additional_creators,
93115 } ) ;
94116
95117 ( content, creator)
96118 }
119+
120+ /// Get the creators of the room from this content, according to the room
121+ /// version.
122+ pub ( crate ) fn creators ( & self ) -> Vec < OwnedUserId > {
123+ let rules = self . room_version . rules ( ) . unwrap_or ( ROOM_VERSION_RULES_FALLBACK ) ;
124+
125+ if rules. authorization . explicitly_privilege_room_creators {
126+ std:: iter:: once ( self . creator . clone ( ) )
127+ . chain ( self . additional_creators . iter ( ) . cloned ( ) )
128+ . collect ( )
129+ } else {
130+ vec ! [ self . creator. clone( ) ]
131+ }
132+ }
97133}
98134
99135/// Redacted form of [`RoomCreateWithCreatorEventContent`].
0 commit comments