1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-06-27 16:35:59 +00:00
conduit/src/service/rooms/state_accessor/mod.rs

87 lines
2.6 KiB
Rust
Raw Normal View History

mod data;
use std::{sync::Arc, collections::{HashMap, BTreeMap}};
pub use data::Data;
use ruma::{events::StateEventType, RoomId, EventId};
2022-09-07 13:25:51 +02:00
use crate::{Result, PduEvent};
2022-10-05 12:45:54 +02:00
pub struct Service {
db: Box<dyn Data>,
}
2022-10-05 12:45:54 +02:00
impl Service {
/// Builds a StateMap by iterating over all keys that start
/// with state_hash, this gives the full state for the given state_hash.
#[tracing::instrument(skip(self))]
2022-06-18 16:38:41 +02:00
pub async fn state_full_ids(&self, shortstatehash: u64) -> Result<BTreeMap<u64, Arc<EventId>>> {
self.db.state_full_ids(shortstatehash)
2021-03-17 22:30:25 +01:00
}
#[tracing::instrument(skip(self))]
2022-06-18 16:38:41 +02:00
pub async fn state_full(
2021-03-17 22:30:25 +01:00
&self,
shortstatehash: u64,
2022-04-06 21:31:29 +02:00
) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> {
self.db.state_full(shortstatehash)
}
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
2021-02-28 12:41:03 +01:00
#[tracing::instrument(skip(self))]
2021-04-11 21:01:27 +02:00
pub fn state_get_id(
&self,
2021-03-17 22:30:25 +01:00
shortstatehash: u64,
2022-04-06 21:31:29 +02:00
event_type: &StateEventType,
state_key: &str,
) -> Result<Option<Arc<EventId>>> {
self.db.state_get_id(shortstatehash, event_type, state_key)
}
2021-04-11 21:01:27 +02:00
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
#[tracing::instrument(skip(self))]
pub fn state_get(
&self,
shortstatehash: u64,
2022-04-06 21:31:29 +02:00
event_type: &StateEventType,
2021-04-11 21:01:27 +02:00
state_key: &str,
2021-06-30 09:52:01 +02:00
) -> Result<Option<Arc<PduEvent>>> {
self.db.pdu_state_get(shortstatehash, event_type, state_key)
2021-04-11 21:01:27 +02:00
}
/// Returns the state hash for this pdu.
2021-03-17 22:30:25 +01:00
pub fn pdu_shortstatehash(&self, event_id: &EventId) -> Result<Option<u64>> {
self.db.pdu_shortstatehash(event_id)
}
/// Returns the full room state.
2021-02-28 12:41:03 +01:00
#[tracing::instrument(skip(self))]
2022-06-18 16:38:41 +02:00
pub async fn room_state_full(
&self,
room_id: &RoomId,
2022-04-06 21:31:29 +02:00
) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>> {
self.db.room_state_full(room_id)
}
2021-04-11 21:01:27 +02:00
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
#[tracing::instrument(skip(self))]
pub fn room_state_get_id(
&self,
room_id: &RoomId,
2022-04-06 21:31:29 +02:00
event_type: &StateEventType,
2021-04-11 21:01:27 +02:00
state_key: &str,
) -> Result<Option<Arc<EventId>>> {
self.db.room_state_get_id(room_id, event_type, state_key)
2021-04-11 21:01:27 +02:00
}
/// Returns a single PDU from `room_id` with key (`event_type`, `state_key`).
2021-02-28 12:41:03 +01:00
#[tracing::instrument(skip(self))]
2020-06-12 13:18:25 +02:00
pub fn room_state_get(
&self,
room_id: &RoomId,
2022-04-06 21:31:29 +02:00
event_type: &StateEventType,
2020-06-12 13:18:25 +02:00
state_key: &str,
2021-06-30 09:52:01 +02:00
) -> Result<Option<Arc<PduEvent>>> {
self.db.room_state_get(room_id, event_type, state_key)
2020-06-12 13:18:25 +02:00
}
}