base: Store the room creation content

The power level depends on a bunch of stuff, if no power level event
exists the default for a room creator is 100 while for every other user
is 0, thus we need to know the room creator.
This commit is contained in:
Damir Jelić 2021-01-04 12:32:54 +01:00
parent 4afc6b2567
commit e66add476f
3 changed files with 23 additions and 2 deletions

View file

@ -32,6 +32,7 @@ pub struct RoomMember {
pub(crate) presence: Arc<Option<PresenceEvent>>,
pub(crate) power_levles: Arc<Option<SyncStateEvent<PowerLevelsEventContent>>>,
pub(crate) max_power_level: i64,
pub(crate) is_room_creator: bool,
}
impl RoomMember {
@ -74,6 +75,6 @@ impl RoomMember {
.map(|p| (*p).into())
.unwrap_or_else(|| e.content.users_default.into())
})
.unwrap_or(0)
.unwrap_or_else(|| if self.is_room_creator { 100 } else { 0 })
}
}

View file

@ -2,7 +2,7 @@ mod members;
mod normal;
mod stripped;
use matrix_sdk_common::identifiers::UserId;
use matrix_sdk_common::{events::room::create::CreateEventContent, identifiers::UserId};
pub use normal::{Room, RoomInfo, RoomType};
pub use stripped::{StrippedRoom, StrippedRoomInfo};
@ -125,6 +125,7 @@ pub struct BaseRoomInfo {
pub topic: Option<String>,
pub encryption: Option<EncryptionEventContent>,
pub tombstone: Option<TombstoneEventContent>,
pub create: Option<CreateEventContent>,
pub max_power_level: i64,
}
@ -143,6 +144,14 @@ impl BaseRoomInfo {
self.name = n.name().map(|n| n.to_string());
true
}
AnyStateEventContent::RoomCreate(c) => {
if self.create.is_none() {
self.create = Some(c.clone());
true
} else {
false
}
}
AnyStateEventContent::RoomCanonicalAlias(a) => {
self.canonical_alias = a.alias.clone();
true
@ -179,6 +188,7 @@ impl Default for BaseRoomInfo {
encryption: None,
tombstone: None,
max_power_level: 100,
create: None,
}
}
}

View file

@ -287,6 +287,15 @@ impl Room {
let presence = self.store.get_presence_event(user_id).await;
let profile = self.store.get_profile(self.room_id(), user_id).await;
let max_power_level = self.max_power_level();
let is_room_creator = self
.inner
.read()
.unwrap()
.base_info
.create
.as_ref()
.map(|c| &c.creator == user_id)
.unwrap_or(false);
let power = self
.store
@ -310,6 +319,7 @@ impl Room {
presence: presence.into(),
power_levles: power.into(),
max_power_level,
is_room_creator,
})
}
}