mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2025-12-13 02:39:02 -05:00
split state_accessor
Some checks are pending
CI and Artifacts / Test (push) Waiting to run
CI and Artifacts / Build (push) Waiting to run
CI and Artifacts / Build MacOS Binaries (push) Waiting to run
CI and Artifacts / variables (push) Waiting to run
CI and Artifacts / Docker publish (push) Blocked by required conditions
Documentation and GitHub Pages / Documentation and GitHub Pages (push) Waiting to run
Some checks are pending
CI and Artifacts / Test (push) Waiting to run
CI and Artifacts / Build (push) Waiting to run
CI and Artifacts / Build MacOS Binaries (push) Waiting to run
CI and Artifacts / variables (push) Waiting to run
CI and Artifacts / Docker publish (push) Blocked by required conditions
Documentation and GitHub Pages / Documentation and GitHub Pages (push) Waiting to run
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
106bcd30b7
commit
b3271e0d65
5 changed files with 684 additions and 620 deletions
90
src/service/rooms/state_accessor/room_state.rs
Normal file
90
src/service/rooms/state_accessor/room_state.rs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
use std::borrow::Borrow;
|
||||
|
||||
use conduwuit::{err, implement, PduEvent, Result};
|
||||
use futures::{Stream, StreamExt, TryFutureExt};
|
||||
use ruma::{events::StateEventType, EventId, RoomId};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Returns a single PDU from `room_id` with key (`event_type`,`state_key`).
|
||||
#[implement(super::Service)]
|
||||
pub async fn room_state_get_content<T>(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<T>
|
||||
where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
{
|
||||
self.room_state_get(room_id, event_type, state_key)
|
||||
.await
|
||||
.and_then(|event| event.get_content())
|
||||
}
|
||||
|
||||
/// Returns the full room state.
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub fn room_state_full<'a>(
|
||||
&'a self,
|
||||
room_id: &'a RoomId,
|
||||
) -> impl Stream<Item = Result<((StateEventType, String), PduEvent)>> + Send + 'a {
|
||||
self.services
|
||||
.state
|
||||
.get_room_shortstatehash(room_id)
|
||||
.map_ok(|shortstatehash| self.state_full(shortstatehash).map(Ok))
|
||||
.map_err(move |e| err!(Database("Missing state for {room_id:?}: {e:?}")))
|
||||
.try_flatten_stream()
|
||||
}
|
||||
|
||||
/// Returns the full room state pdus
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub fn room_state_full_pdus<'a>(
|
||||
&'a self,
|
||||
room_id: &'a RoomId,
|
||||
) -> impl Stream<Item = Result<PduEvent>> + Send + 'a {
|
||||
self.services
|
||||
.state
|
||||
.get_room_shortstatehash(room_id)
|
||||
.map_ok(|shortstatehash| self.state_full_pdus(shortstatehash).map(Ok))
|
||||
.map_err(move |e| err!(Database("Missing state for {room_id:?}: {e:?}")))
|
||||
.try_flatten_stream()
|
||||
}
|
||||
|
||||
/// Returns a single EventId from `room_id` with key (`event_type`,
|
||||
/// `state_key`).
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub async fn room_state_get_id<Id>(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<Id>
|
||||
where
|
||||
Id: for<'de> Deserialize<'de> + Sized + ToOwned,
|
||||
<Id as ToOwned>::Owned: Borrow<EventId>,
|
||||
{
|
||||
self.services
|
||||
.state
|
||||
.get_room_shortstatehash(room_id)
|
||||
.and_then(|shortstatehash| self.state_get_id(shortstatehash, event_type, state_key))
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns a single PDU from `room_id` with key (`event_type`,
|
||||
/// `state_key`).
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub async fn room_state_get(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_type: &StateEventType,
|
||||
state_key: &str,
|
||||
) -> Result<PduEvent> {
|
||||
self.services
|
||||
.state
|
||||
.get_room_shortstatehash(room_id)
|
||||
.and_then(|shortstatehash| self.state_get(shortstatehash, event_type, state_key))
|
||||
.await
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue