diff --git a/matrix_sdk/src/lib.rs b/matrix_sdk/src/lib.rs index 23e14f8f..98a56188 100644 --- a/matrix_sdk/src/lib.rs +++ b/matrix_sdk/src/lib.rs @@ -68,8 +68,8 @@ compile_error!("only one of 'native-tls' or 'rustls-tls' features can be enabled #[cfg_attr(feature = "docs", doc(cfg(encryption)))] pub use matrix_sdk_base::crypto::LocalTrust; pub use matrix_sdk_base::{ - Error as BaseError, EventEmitter, InvitedRoom, JoinedRoom, LeftRoom, RoomInfo, RoomMember, - RoomState, Session, StoreError, + CustomEvent, Error as BaseError, EventEmitter, InvitedRoom, JoinedRoom, LeftRoom, RoomInfo, + RoomMember, RoomState, Session, StateChanges, StoreError, }; pub use matrix_sdk_common::*; diff --git a/matrix_sdk_base/src/lib.rs b/matrix_sdk_base/src/lib.rs index 15731b1a..32cffeaa 100644 --- a/matrix_sdk_base/src/lib.rs +++ b/matrix_sdk_base/src/lib.rs @@ -51,12 +51,12 @@ mod rooms; mod session; mod store; -pub use event_emitter::EventEmitter; +pub use event_emitter::{CustomEvent, EventEmitter}; pub use rooms::{ InvitedRoom, JoinedRoom, LeftRoom, Room, RoomInfo, RoomMember, RoomState, StrippedRoom, StrippedRoomInfo, }; -pub use store::{StateStore, Store, StoreError}; +pub use store::{StateChanges, StateStore, Store, StoreError}; pub use client::{BaseClient, BaseClientConfig, RoomStateType}; diff --git a/matrix_sdk_base/src/store/mod.rs b/matrix_sdk_base/src/store/mod.rs index de87554b..698efa13 100644 --- a/matrix_sdk_base/src/store/mod.rs +++ b/matrix_sdk_base/src/store/mod.rs @@ -355,26 +355,41 @@ impl Deref for Store { } } +/// Store state changes and pass them to the StateStore. #[derive(Debug, Default)] pub struct StateChanges { + /// The sync token that relates to this update. pub sync_token: Option, + /// A user session, containing an access token and information about the associated user account. pub session: Option, + /// A mapping of event type string to `AnyBasicEvent`. pub account_data: BTreeMap, + /// A mapping of `UserId` to `PresenceEvent`. pub presence: BTreeMap, + /// A mapping of `RoomId` to a map of users and their `MemberEvent`. pub members: BTreeMap>, + /// A mapping of `RoomId` to a map of users and their `MemberEventContent`. pub profiles: BTreeMap>, - pub ambiguity_maps: BTreeMap>>, + + pub(crate) ambiguity_maps: BTreeMap>>, + /// A mapping of `RoomId` to a map of event type string to a state key and `AnySyncStateEvent`. pub state: BTreeMap>>, + /// A mapping of `RoomId` to a map of event type string to `AnyBasicEvent`. pub room_account_data: BTreeMap>, + /// A map of `RoomId` to `RoomInfo`. pub room_infos: BTreeMap, + /// A mapping of `RoomId` to a map of event type to a map of state key to `AnyStrippedStateEvent`. pub stripped_state: BTreeMap>>, + /// A mapping of `RoomId` to a map of users and their `StrippedMemberEvent`. pub stripped_members: BTreeMap>, + /// A map of `RoomId` to `StrippedRoomInfo`. pub invited_room_info: BTreeMap, } impl StateChanges { + /// Create a new `StateChanges` struct with the given sync_token. pub fn new(sync_token: String) -> Self { Self { sync_token: Some(sync_token), @@ -382,25 +397,30 @@ impl StateChanges { } } + /// Update the `StateChanges` struct with the given `PresenceEvent`. pub fn add_presence_event(&mut self, event: PresenceEvent) { self.presence.insert(event.sender.clone(), event); } + /// Update the `StateChanges` struct with the given `RoomInfo`. pub fn add_room(&mut self, room: RoomInfo) { self.room_infos .insert(room.room_id.as_ref().to_owned(), room); } + /// Update the `StateChanges` struct with the given `StrippedRoomInfo`. pub fn add_stripped_room(&mut self, room: StrippedRoomInfo) { self.invited_room_info .insert(room.room_id.as_ref().to_owned(), room); } + /// Update the `StateChanges` struct with the given `AnyBasicEvent`. pub fn add_account_data(&mut self, event: AnyBasicEvent) { self.account_data .insert(event.content().event_type().to_owned(), event); } + /// Update the `StateChanges` struct with the given room with a new `AnyBasicEvent`. pub fn add_room_account_data(&mut self, room_id: &RoomId, event: AnyBasicEvent) { self.room_account_data .entry(room_id.to_owned()) @@ -408,6 +428,7 @@ impl StateChanges { .insert(event.content().event_type().to_owned(), event); } + /// Update the `StateChanges` struct with the given room with a new `AnyStrippedStateEvent`. pub fn add_stripped_state_event(&mut self, room_id: &RoomId, event: AnyStrippedStateEvent) { self.stripped_state .entry(room_id.to_owned()) @@ -417,6 +438,7 @@ impl StateChanges { .insert(event.state_key().to_string(), event); } + /// Update the `StateChanges` struct with the given room with a new `StrippedMemberEvent`. pub fn add_stripped_member(&mut self, room_id: &RoomId, event: StrippedMemberEvent) { let user_id = event.state_key.clone(); @@ -426,6 +448,7 @@ impl StateChanges { .insert(user_id, event); } + /// Update the `StateChanges` struct with the given room with a new `AnySyncStateEvent`. pub fn add_state_event(&mut self, room_id: &RoomId, event: AnySyncStateEvent) { self.state .entry(room_id.to_owned())