add more state event getters to store
This commit is contained in:
parent
dbf8cf231d
commit
cb6269d5ec
3 changed files with 91 additions and 0 deletions
|
@ -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(
|
async fn get_profile(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
@ -458,6 +485,18 @@ impl StateStore for MemoryStore {
|
||||||
self.get_state_event(room_id, event_type, state_key).await
|
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(
|
async fn get_profile(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
|
|
@ -133,6 +133,26 @@ pub trait StateStore: AsyncTraitDeps {
|
||||||
state_key: &str,
|
state_key: &str,
|
||||||
) -> Result<Option<Raw<AnySyncStateEvent>>>;
|
) -> 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.
|
/// Get the current profile for the given user in the given room.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|
|
@ -580,6 +580,26 @@ impl SledStore {
|
||||||
.transpose()?)
|
.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(
|
pub async fn get_profile(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
@ -801,6 +821,18 @@ impl StateStore for SledStore {
|
||||||
self.get_state_event(room_id, event_type, state_key).await
|
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(
|
async fn get_profile(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
|
Loading…
Reference in a new issue