diff --git a/matrix_sdk_base/src/rooms/normal.rs b/matrix_sdk_base/src/rooms/normal.rs index d9dc8862..2587645e 100644 --- a/matrix_sdk_base/src/rooms/normal.rs +++ b/matrix_sdk_base/src/rooms/normal.rs @@ -29,7 +29,8 @@ use matrix_sdk_common::{ guest_access::GuestAccess, history_visibility::HistoryVisibility, join_rules::JoinRule, tombstone::TombstoneEventContent, }, - AnyStateEventContent, AnySyncStateEvent, EventType, + tag::Tags, + AnyBasicEvent, AnyStateEventContent, AnySyncStateEvent, EventType, }, identifiers::{MxcUri, RoomAliasId, RoomId, UserId}, }; @@ -447,6 +448,20 @@ impl Room { display_name_ambiguous: ambiguous, })) } + + /// Get the `Tags` for this room. + pub async fn tags(&self) -> StoreResult> { + if let Some(AnyBasicEvent::Tag(event)) = self + .store + .get_room_account_data_event(self.room_id(), EventType::Tag) + .await? + .and_then(|r| r.deserialize().ok()) + { + Ok(Some(event.content.tags)) + } else { + Ok(None) + } + } } /// The underlying pure data structure for joined and left rooms. diff --git a/matrix_sdk_base/src/store/memory_store.rs b/matrix_sdk_base/src/store/memory_store.rs index b8182cc1..8088d272 100644 --- a/matrix_sdk_base/src/store/memory_store.rs +++ b/matrix_sdk_base/src/store/memory_store.rs @@ -314,6 +314,17 @@ impl MemoryStore { .get(event_type.as_ref()) .map(|e| e.clone())) } + + async fn get_room_account_data_event( + &self, + room_id: &RoomId, + event_type: EventType, + ) -> Result>> { + Ok(self + .room_account_data + .get(room_id) + .and_then(|m| m.get(event_type.as_ref()).map(|e| e.clone()))) + } } #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] @@ -403,4 +414,12 @@ impl StateStore for MemoryStore { ) -> Result>> { self.get_account_data_event(event_type).await } + + async fn get_room_account_data_event( + &self, + room_id: &RoomId, + event_type: EventType, + ) -> Result>> { + self.get_room_account_data_event(room_id, event_type).await + } } diff --git a/matrix_sdk_base/src/store/mod.rs b/matrix_sdk_base/src/store/mod.rs index 2e017d22..be7245b5 100644 --- a/matrix_sdk_base/src/store/mod.rs +++ b/matrix_sdk_base/src/store/mod.rs @@ -196,6 +196,20 @@ pub trait StateStore: AsyncTraitDeps { &self, event_type: EventType, ) -> Result>>; + + /// Get an event out of the room account data store. + /// + /// # Arguments + /// + /// * `room_id` - The id of the room for which the room account data event should + /// be fetched. + /// + /// * `event_type` - The event type of the room account data event. + async fn get_room_account_data_event( + &self, + room_id: &RoomId, + event_type: EventType, + ) -> Result>>; } /// A state store wrapper for the SDK. diff --git a/matrix_sdk_base/src/store/sled_store/mod.rs b/matrix_sdk_base/src/store/sled_store/mod.rs index e14c0a0b..315f2a35 100644 --- a/matrix_sdk_base/src/store/sled_store/mod.rs +++ b/matrix_sdk_base/src/store/sled_store/mod.rs @@ -597,6 +597,18 @@ impl SledStore { .map(|m| self.deserialize_event(&m)) .transpose()?) } + + pub async fn get_room_account_data_event( + &self, + room_id: &RoomId, + event_type: EventType, + ) -> Result>> { + Ok(self + .room_account_data + .get((room_id.as_str(), event_type.as_str()).encode())? + .map(|m| self.deserialize_event(&m)) + .transpose()?) + } } #[async_trait] @@ -681,6 +693,14 @@ impl StateStore for SledStore { ) -> Result>> { self.get_account_data_event(event_type).await } + + async fn get_room_account_data_event( + &self, + room_id: &RoomId, + event_type: EventType, + ) -> Result>> { + self.get_room_account_data_event(room_id, event_type).await + } } #[cfg(test)]