remove getting every state event and add getters to room
This commit is contained in:
parent
cb6269d5ec
commit
4cc7237db3
4 changed files with 32 additions and 44 deletions
|
@ -8,6 +8,8 @@ use ruma::{
|
||||||
membership::{get_member_events, join_room_by_id, leave_room},
|
membership::{get_member_events, join_room_by_id, leave_room},
|
||||||
message::get_message_events,
|
message::get_message_events,
|
||||||
},
|
},
|
||||||
|
events::{AnySyncStateEvent, EventType},
|
||||||
|
serde::Raw,
|
||||||
UserId,
|
UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -324,4 +326,25 @@ impl Common {
|
||||||
.map(|member| RoomMember::new(self.client.clone(), member))
|
.map(|member| RoomMember::new(self.client.clone(), member))
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get all state events of a given type in this room.
|
||||||
|
pub async fn get_state_events(
|
||||||
|
&self,
|
||||||
|
event_type: EventType,
|
||||||
|
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
||||||
|
self.client.store().get_state_events(self.room_id(), event_type).await.map_err(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a specific state event in this room.
|
||||||
|
pub async fn get_state_event(
|
||||||
|
&self,
|
||||||
|
event_type: EventType,
|
||||||
|
state_key: &str,
|
||||||
|
) -> Result<Option<Raw<AnySyncStateEvent>>> {
|
||||||
|
self.client
|
||||||
|
.store()
|
||||||
|
.get_state_event(self.room_id(), event_type, state_key)
|
||||||
|
.await
|
||||||
|
.map_err(Into::into)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,19 +293,7 @@ impl MemoryStore {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_state_events(&self, room_id: &RoomId) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
async fn get_state_events(
|
||||||
#[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,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_type: EventType,
|
event_type: EventType,
|
||||||
|
@ -485,16 +473,12 @@ 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>>> {
|
async fn get_state_events(
|
||||||
self.get_state_events(room_id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_state_events_by_type(
|
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_type: EventType,
|
event_type: EventType,
|
||||||
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
||||||
self.get_state_events_by_type(room_id, event_type).await
|
self.get_state_events(room_id, event_type).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_profile(
|
async fn get_profile(
|
||||||
|
|
|
@ -133,21 +133,14 @@ 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.
|
/// Get a list of state events for a given room and `EventType`.
|
||||||
///
|
|
||||||
/// # 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
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `room_id` - The id of the room to find events for.
|
/// * `room_id` - The id of the room to find events for.
|
||||||
///
|
///
|
||||||
/// * `event_type` - The event type to find.
|
/// * `event_type` - The event type.
|
||||||
async fn get_state_events_by_type(
|
async fn get_state_events(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_type: EventType,
|
event_type: EventType,
|
||||||
|
|
|
@ -580,15 +580,7 @@ impl SledStore {
|
||||||
.transpose()?)
|
.transpose()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_state_events(&self, room_id: &RoomId) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
pub async fn get_state_events(
|
||||||
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,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_type: EventType,
|
event_type: EventType,
|
||||||
|
@ -821,16 +813,12 @@ 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>>> {
|
async fn get_state_events(
|
||||||
self.get_state_events(room_id).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_state_events_by_type(
|
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
event_type: EventType,
|
event_type: EventType,
|
||||||
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
) -> Result<Vec<Raw<AnySyncStateEvent>>> {
|
||||||
self.get_state_events_by_type(room_id, event_type).await
|
self.get_state_events(room_id, event_type).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_profile(
|
async fn get_profile(
|
||||||
|
|
Loading…
Reference in a new issue