2022-12-18 06:37:03 +01:00
|
|
|
use std::{collections::HashMap, sync::Arc};
|
2022-09-06 23:15:09 +02:00
|
|
|
|
2022-09-07 13:25:51 +02:00
|
|
|
use async_trait::async_trait;
|
2022-10-05 20:34:31 +02:00
|
|
|
use ruma::{events::StateEventType, EventId, RoomId};
|
2022-09-06 23:15:09 +02:00
|
|
|
|
2022-10-05 20:34:31 +02:00
|
|
|
use crate::{PduEvent, Result};
|
2022-09-06 23:15:09 +02:00
|
|
|
|
2022-09-07 13:25:51 +02:00
|
|
|
#[async_trait]
|
2024-04-22 23:48:57 -04:00
|
|
|
pub(crate) trait Data: Send + Sync {
|
2020-08-26 11:15:52 -04:00
|
|
|
/// Builds a StateMap by iterating over all keys that start
|
|
|
|
|
/// with state_hash, this gives the full state for the given state_hash.
|
2024-03-14 00:15:21 -04:00
|
|
|
#[allow(unused_qualifications)] // async traits
|
2022-12-18 06:37:03 +01:00
|
|
|
async fn state_full_ids(&self, shortstatehash: u64) -> Result<HashMap<u64, Arc<EventId>>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-03-14 00:15:21 -04:00
|
|
|
#[allow(unused_qualifications)] // async traits
|
2022-08-14 13:38:21 +02:00
|
|
|
async fn state_full(&self, shortstatehash: u64) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2020-09-17 14:44:47 +02:00
|
|
|
/// Returns a single PDU from `room_id` with key (`event_type`,
|
|
|
|
|
/// `state_key`).
|
2022-08-14 13:38:21 +02:00
|
|
|
fn state_get_id(
|
2022-04-06 21:31:29 +02:00
|
|
|
&self, shortstatehash: u64, event_type: &StateEventType, state_key: &str,
|
2022-08-14 13:38:21 +02:00
|
|
|
) -> Result<Option<Arc<EventId>>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2021-04-11 21:01:27 +02:00
|
|
|
/// Returns a single PDU from `room_id` with key (`event_type`,
|
|
|
|
|
/// `state_key`).
|
2022-08-14 13:38:21 +02:00
|
|
|
fn state_get(
|
2022-04-06 21:31:29 +02:00
|
|
|
&self, shortstatehash: u64, event_type: &StateEventType, state_key: &str,
|
2022-08-14 13:38:21 +02:00
|
|
|
) -> Result<Option<Arc<PduEvent>>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2021-01-16 16:37:20 -05:00
|
|
|
/// Returns the state hash for this pdu.
|
2022-08-14 13:38:21 +02:00
|
|
|
fn pdu_shortstatehash(&self, event_id: &EventId) -> Result<Option<u64>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2020-05-03 17:25:31 +02:00
|
|
|
/// Returns the full room state.
|
2024-03-14 00:15:21 -04:00
|
|
|
#[allow(unused_qualifications)] // async traits
|
2022-08-14 13:38:21 +02:00
|
|
|
async fn room_state_full(&self, room_id: &RoomId) -> Result<HashMap<(StateEventType, String), Arc<PduEvent>>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2021-04-11 21:01:27 +02:00
|
|
|
/// Returns a single PDU from `room_id` with key (`event_type`,
|
|
|
|
|
/// `state_key`).
|
2022-08-14 13:38:21 +02:00
|
|
|
fn room_state_get_id(
|
2022-04-06 21:31:29 +02:00
|
|
|
&self, room_id: &RoomId, event_type: &StateEventType, state_key: &str,
|
2022-08-14 13:38:21 +02:00
|
|
|
) -> Result<Option<Arc<EventId>>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2020-08-26 11:15:52 -04:00
|
|
|
/// Returns a single PDU from `room_id` with key (`event_type`,
|
|
|
|
|
/// `state_key`).
|
2022-08-14 13:38:21 +02:00
|
|
|
fn room_state_get(
|
2022-04-06 21:31:29 +02:00
|
|
|
&self, room_id: &RoomId, event_type: &StateEventType, state_key: &str,
|
2022-08-14 13:38:21 +02:00
|
|
|
) -> Result<Option<Arc<PduEvent>>>;
|
|
|
|
|
}
|