From 6d2d48a35adeba7a079f9217251690f9146e328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 8 Dec 2020 09:52:27 +0100 Subject: [PATCH] base: WIP inivted rooms handling. --- matrix_sdk_base/src/responses.rs | 22 ++++++++++++++++++---- matrix_sdk_base/src/store.rs | 12 +++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/matrix_sdk_base/src/responses.rs b/matrix_sdk_base/src/responses.rs index 471f8765..345aec4f 100644 --- a/matrix_sdk_base/src/responses.rs +++ b/matrix_sdk_base/src/responses.rs @@ -6,8 +6,8 @@ use matrix_sdk_common::{ DeviceLists, UnreadNotificationsCount as RumaUnreadNotificationsCount, }, events::{ - presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, - AnySyncStateEvent, AnyToDeviceEvent, + presence::PresenceEvent, AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, + AnySyncRoomEvent, AnySyncStateEvent, AnyToDeviceEvent, }, identifiers::{DeviceKeyAlgorithm, RoomId}, }; @@ -69,8 +69,8 @@ pub struct Rooms { pub leave: BTreeMap, /// The rooms that the user has joined. pub join: BTreeMap, - // /// The rooms that the user has been invited to. - // pub invite: BTreeMap, + /// The rooms that the user has been invited to. + pub invite: BTreeMap, } /// Updates to joined rooms. @@ -109,6 +109,20 @@ impl JoinedRoom { } } +/// Updates to the rooms that the user has been invited to. +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +pub struct InvitedRoom { + /// The state of a room that the user has been invited to. + pub invite_state: InviteState, +} + +/// The state of a room that the user has been invited to. +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +pub struct InviteState { + /// A list of state events. + pub events: Vec, +} + /// Counts of unread notifications for a room. #[derive(Copy, Clone, Debug, Default, Deserialize, Serialize)] pub struct UnreadNotificationsCount { diff --git a/matrix_sdk_base/src/store.rs b/matrix_sdk_base/src/store.rs index 72ec3ab5..f0a7d3f2 100644 --- a/matrix_sdk_base/src/store.rs +++ b/matrix_sdk_base/src/store.rs @@ -17,7 +17,8 @@ use matrix_sdk_common::{ encryption::EncryptionEventContent, member::MemberEventContent, power_levels::PowerLevelsEventContent, }, - AnyBasicEvent, AnySyncStateEvent, EventContent, EventType, SyncStateEvent, + AnyBasicEvent, AnyStrippedStateEvent, AnySyncStateEvent, EventContent, EventType, + SyncStateEvent, }, identifiers::{RoomAliasId, RoomId, UserId}, }; @@ -55,6 +56,8 @@ pub struct StateChanges { pub invited_user_ids: BTreeMap>, pub removed_user_ids: BTreeMap, pub presence: BTreeMap, + pub invitest_state: BTreeMap>, + pub invited_room_info: BTreeMap, } impl StateChanges { @@ -111,6 +114,13 @@ impl StateChanges { .insert(event.content().event_type().to_owned(), event); } + pub fn add_invited_state(&mut self, room_id: &RoomId, event: AnyStrippedStateEvent) { + self.invitest_state + .entry(room_id.to_owned()) + .or_insert_with(BTreeMap::new) + .insert(event.state_key().to_string(), event); + } + pub fn add_state_event(&mut self, room_id: &RoomId, event: AnySyncStateEvent) { self.state .entry(room_id.to_owned())