mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
94 lines
2.7 KiB
Rust
94 lines
2.7 KiB
Rust
use std::sync::Arc;
|
|
|
|
use ruma::{CanonicalJsonObject, EventId, RoomId, UserId};
|
|
|
|
use super::PduCount;
|
|
use crate::{service::rooms::timeline::PduId, PduEvent, Result};
|
|
|
|
pub(crate) trait Data: Send + Sync {
|
|
/// Returns the `count` of this pdu's id.
|
|
fn get_pdu_count(&self, event_id: &EventId) -> Result<Option<PduCount>>;
|
|
|
|
/// Returns the json of a pdu.
|
|
fn get_pdu_json(
|
|
&self,
|
|
event_id: &EventId,
|
|
) -> Result<Option<CanonicalJsonObject>>;
|
|
|
|
/// Returns the json of a pdu.
|
|
fn get_non_outlier_pdu_json(
|
|
&self,
|
|
event_id: &EventId,
|
|
) -> Result<Option<CanonicalJsonObject>>;
|
|
|
|
/// Returns the pdu's id.
|
|
fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<PduId>>;
|
|
|
|
/// Returns the pdu.
|
|
///
|
|
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
|
fn get_non_outlier_pdu(
|
|
&self,
|
|
event_id: &EventId,
|
|
) -> Result<Option<PduEvent>>;
|
|
|
|
/// Returns the pdu.
|
|
///
|
|
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
|
fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>>;
|
|
|
|
/// Returns the pdu.
|
|
///
|
|
/// This does __NOT__ check the outliers `Tree`.
|
|
fn get_pdu_from_id(&self, pdu_id: &PduId) -> Result<Option<PduEvent>>;
|
|
|
|
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
|
|
fn get_pdu_json_from_id(
|
|
&self,
|
|
pdu_id: &PduId,
|
|
) -> Result<Option<CanonicalJsonObject>>;
|
|
|
|
/// Adds a new pdu to the timeline
|
|
fn append_pdu(
|
|
&self,
|
|
pdu_id: &PduId,
|
|
pdu: &PduEvent,
|
|
json: &CanonicalJsonObject,
|
|
) -> Result<()>;
|
|
|
|
// Adds a new pdu to the backfilled timeline
|
|
fn prepend_backfill_pdu(
|
|
&self,
|
|
pdu_id: &PduId,
|
|
event_id: &EventId,
|
|
json: &CanonicalJsonObject,
|
|
) -> Result<()>;
|
|
|
|
/// Removes a pdu and creates a new one with the same id.
|
|
fn replace_pdu(
|
|
&self,
|
|
pdu_id: &PduId,
|
|
pdu_json: &CanonicalJsonObject,
|
|
) -> Result<()>;
|
|
|
|
/// Returns an iterator over all events and their tokens in a room that
|
|
/// happened before the event with id `until` in reverse-chronological
|
|
/// order.
|
|
#[allow(clippy::type_complexity)]
|
|
fn pdus_until<'a>(
|
|
&'a self,
|
|
user_id: &UserId,
|
|
room_id: &RoomId,
|
|
until: PduCount,
|
|
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>>;
|
|
|
|
/// Returns an iterator over all events in a room that happened after the
|
|
/// event with id `from` in chronological order.
|
|
#[allow(clippy::type_complexity)]
|
|
fn pdus_after<'a>(
|
|
&'a self,
|
|
user_id: &UserId,
|
|
room_id: &RoomId,
|
|
from: PduCount,
|
|
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>>;
|
|
}
|