base: Expose and document the stripped room info

master
Damir Jelić 2021-01-28 14:59:57 +01:00
parent 92f0523e37
commit b66c666997
2 changed files with 30 additions and 7 deletions

View File

@ -52,7 +52,10 @@ mod session;
mod store; mod store;
pub use event_emitter::EventEmitter; pub use event_emitter::EventEmitter;
pub use rooms::{InvitedRoom, JoinedRoom, LeftRoom, Room, RoomInfo, RoomMember, RoomState}; pub use rooms::{
InvitedRoom, JoinedRoom, LeftRoom, Room, RoomInfo, RoomMember, RoomState, StrippedRoom,
StrippedRoomInfo,
};
pub use store::{StateStore, Store, StoreError}; pub use store::{StateStore, Store, StoreError};
pub use client::{BaseClient, BaseClientConfig, RoomStateType}; pub use client::{BaseClient, BaseClientConfig, RoomStateType};

View File

@ -24,6 +24,7 @@ use crate::store::StateStore;
use super::BaseRoomInfo; use super::BaseRoomInfo;
/// The underlying room data structure collecting state for invited rooms.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct StrippedRoom { pub struct StrippedRoom {
room_id: Arc<RoomId>, room_id: Arc<RoomId>,
@ -33,7 +34,11 @@ pub struct StrippedRoom {
} }
impl StrippedRoom { impl StrippedRoom {
pub fn new(own_user_id: &UserId, store: Arc<Box<dyn StateStore>>, room_id: &RoomId) -> Self { pub(crate) fn new(
own_user_id: &UserId,
store: Arc<Box<dyn StateStore>>,
room_id: &RoomId,
) -> Self {
let room_id = Arc::new(room_id.clone()); let room_id = Arc::new(room_id.clone());
let info = StrippedRoomInfo { let info = StrippedRoomInfo {
@ -44,7 +49,7 @@ impl StrippedRoom {
Self::restore(own_user_id, store, info) Self::restore(own_user_id, store, info)
} }
pub fn restore( pub(crate) fn restore(
own_user_id: &UserId, own_user_id: &UserId,
store: Arc<Box<dyn StateStore>>, store: Arc<Box<dyn StateStore>>,
room_info: StrippedRoomInfo, room_info: StrippedRoomInfo,
@ -72,6 +77,12 @@ impl StrippedRoom {
} }
} }
/// Get the unique room id of the room.
pub fn room_id(&self) -> &RoomId {
&self.room_id
}
/// Get our own user id.
pub fn own_user_id(&self) -> &UserId { pub fn own_user_id(&self) -> &UserId {
&self.own_user_id &self.own_user_id
} }
@ -80,22 +91,31 @@ impl StrippedRoom {
(*self.inner.lock().unwrap()).clone() (*self.inner.lock().unwrap()).clone()
} }
/// Is the room encrypted.
pub fn is_encrypted(&self) -> bool { pub fn is_encrypted(&self) -> bool {
self.inner.lock().unwrap().base_info.encryption.is_some() self.inner.lock().unwrap().base_info.encryption.is_some()
} }
pub fn room_id(&self) -> &RoomId { /// Calculate the canonical display name of the room, taking into account
&self.room_id /// its name, aliases and members.
} ///
/// The display name is calculated according to [this algorithm][spec].
///
/// [spec]: <https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room>
pub async fn display_name(&self) -> String { pub async fn display_name(&self) -> String {
self.calculate_name().await self.calculate_name().await
} }
} }
/// The underlying pure data structure for invited rooms.
///
/// Holds all the info needed to persist a room into the state store.
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StrippedRoomInfo { pub struct StrippedRoomInfo {
/// The unique room id of the room.
pub room_id: Arc<RoomId>, pub room_id: Arc<RoomId>,
/// Base room info which holds some basic event contents important for the
/// room state.
pub base_info: BaseRoomInfo, pub base_info: BaseRoomInfo,
} }