Merge branch 'tags'

master
Damir Jelić 2021-05-10 13:27:30 +02:00
commit da57061db0
4 changed files with 69 additions and 1 deletions

View File

@ -29,7 +29,8 @@ use matrix_sdk_common::{
guest_access::GuestAccess, history_visibility::HistoryVisibility, join_rules::JoinRule, guest_access::GuestAccess, history_visibility::HistoryVisibility, join_rules::JoinRule,
tombstone::TombstoneEventContent, tombstone::TombstoneEventContent,
}, },
AnyStateEventContent, AnySyncStateEvent, EventType, tag::Tags,
AnyBasicEvent, AnyStateEventContent, AnySyncStateEvent, EventType,
}, },
identifiers::{MxcUri, RoomAliasId, RoomId, UserId}, identifiers::{MxcUri, RoomAliasId, RoomId, UserId},
}; };
@ -447,6 +448,20 @@ impl Room {
display_name_ambiguous: ambiguous, display_name_ambiguous: ambiguous,
})) }))
} }
/// Get the `Tags` for this room.
pub async fn tags(&self) -> StoreResult<Option<Tags>> {
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. /// The underlying pure data structure for joined and left rooms.

View File

@ -314,6 +314,17 @@ impl MemoryStore {
.get(event_type.as_ref()) .get(event_type.as_ref())
.map(|e| e.clone())) .map(|e| e.clone()))
} }
async fn get_room_account_data_event(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> {
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))] #[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
@ -403,4 +414,12 @@ impl StateStore for MemoryStore {
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyBasicEvent>>> {
self.get_account_data_event(event_type).await self.get_account_data_event(event_type).await
} }
async fn get_room_account_data_event(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> {
self.get_room_account_data_event(room_id, event_type).await
}
} }

View File

@ -196,6 +196,20 @@ pub trait StateStore: AsyncTraitDeps {
&self, &self,
event_type: EventType, event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>>; ) -> Result<Option<Raw<AnyBasicEvent>>>;
/// 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<Option<Raw<AnyBasicEvent>>>;
} }
/// A state store wrapper for the SDK. /// A state store wrapper for the SDK.

View File

@ -597,6 +597,18 @@ impl SledStore {
.map(|m| self.deserialize_event(&m)) .map(|m| self.deserialize_event(&m))
.transpose()?) .transpose()?)
} }
pub async fn get_room_account_data_event(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> {
Ok(self
.room_account_data
.get((room_id.as_str(), event_type.as_str()).encode())?
.map(|m| self.deserialize_event(&m))
.transpose()?)
}
} }
#[async_trait] #[async_trait]
@ -681,6 +693,14 @@ impl StateStore for SledStore {
) -> Result<Option<Raw<AnyBasicEvent>>> { ) -> Result<Option<Raw<AnyBasicEvent>>> {
self.get_account_data_event(event_type).await self.get_account_data_event(event_type).await
} }
async fn get_room_account_data_event(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Option<Raw<AnyBasicEvent>>> {
self.get_room_account_data_event(room_id, event_type).await
}
} }
#[cfg(test)] #[cfg(test)]