add more state event getters to store

master
Fisher Darling 2021-06-14 20:59:53 -06:00
parent dbf8cf231d
commit cb6269d5ec
3 changed files with 91 additions and 0 deletions

View File

@ -293,6 +293,33 @@ impl MemoryStore {
}))
}
async fn get_state_events(&self, room_id: &RoomId) -> Result<Vec<Raw<AnySyncStateEvent>>> {
#[allow(clippy::map_clone)]
Ok(self
.room_state
.get(room_id)
.map(|r| {
r.iter().flat_map(|t| t.clone().into_iter().map(|(_, e)| e.clone())).collect()
// e.get(event_type.as_ref()).map(|s| s.iter().map(|e| e.clone()).collect::<Vec<_>>())
})
.unwrap_or_default())
}
async fn get_state_events_by_type(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
#[allow(clippy::map_clone)]
Ok(self
.room_state
.get(room_id)
.and_then(|e| {
e.get(event_type.as_ref()).map(|s| s.iter().map(|e| e.clone()).collect::<Vec<_>>())
})
.unwrap_or_default())
}
async fn get_profile(
&self,
room_id: &RoomId,
@ -458,6 +485,18 @@ impl StateStore for MemoryStore {
self.get_state_event(room_id, event_type, state_key).await
}
async fn get_state_events(&self, room_id: &RoomId) -> Result<Vec<Raw<AnySyncStateEvent>>> {
self.get_state_events(room_id).await
}
async fn get_state_events_by_type(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
self.get_state_events_by_type(room_id, event_type).await
}
async fn get_profile(
&self,
room_id: &RoomId,

View File

@ -133,6 +133,26 @@ pub trait StateStore: AsyncTraitDeps {
state_key: &str,
) -> Result<Option<Raw<AnySyncStateEvent>>>;
/// Get all synced state events for a room.
///
/// # Arguments
///
/// * `room_id` - The id of the room to get state events for.
async fn get_state_events(&self, room_id: &RoomId) -> Result<Vec<Raw<AnySyncStateEvent>>>;
/// Get a list of state events for a given `EventType`.
///
/// # Arguments
///
/// * `room_id` - The id of the room to find events for.
///
/// * `event_type` - The event type to find.
async fn get_state_events_by_type(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Vec<Raw<AnySyncStateEvent>>>;
/// Get the current profile for the given user in the given room.
///
/// # Arguments

View File

@ -580,6 +580,26 @@ impl SledStore {
.transpose()?)
}
pub async fn get_state_events(&self, room_id: &RoomId) -> Result<Vec<Raw<AnySyncStateEvent>>> {
Ok(self
.room_state
.scan_prefix((room_id.as_str()).encode())
.flat_map(|e| e.map(|(_, e)| self.deserialize_event(&e)))
.collect::<Result<_, _>>()?)
}
pub async fn get_state_events_by_type(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
Ok(self
.room_state
.scan_prefix((room_id.as_str(), event_type.as_str()).encode())
.flat_map(|e| e.map(|(_, e)| self.deserialize_event(&e)))
.collect::<Result<_, _>>()?)
}
pub async fn get_profile(
&self,
room_id: &RoomId,
@ -801,6 +821,18 @@ impl StateStore for SledStore {
self.get_state_event(room_id, event_type, state_key).await
}
async fn get_state_events(&self, room_id: &RoomId) -> Result<Vec<Raw<AnySyncStateEvent>>> {
self.get_state_events(room_id).await
}
async fn get_state_events_by_type(
&self,
room_id: &RoomId,
event_type: EventType,
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
self.get_state_events_by_type(room_id, event_type).await
}
async fn get_profile(
&self,
room_id: &RoomId,