2022-09-06 23:15:09 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use ruma::{signatures::CanonicalJsonObject, EventId, UserId, RoomId};
|
|
|
|
|
2022-09-07 13:25:51 +02:00
|
|
|
use crate::{Result, PduEvent};
|
2022-09-06 23:15:09 +02:00
|
|
|
|
2022-10-05 15:33:57 +02:00
|
|
|
pub trait Data: Send + Sync {
|
2022-08-07 19:42:22 +02:00
|
|
|
fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result<u64>;
|
2021-08-17 16:06:09 +02:00
|
|
|
|
2022-06-19 22:56:14 +02:00
|
|
|
/// Returns the `count` of this pdu's id.
|
2022-08-07 19:42:22 +02:00
|
|
|
fn get_pdu_count(&self, event_id: &EventId) -> Result<Option<u64>>;
|
2021-08-11 19:15:38 +02:00
|
|
|
|
2022-06-19 22:56:14 +02:00
|
|
|
/// Returns the json of a pdu.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn get_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>>;
|
2021-08-12 23:04:00 +02:00
|
|
|
|
2022-06-19 22:56:14 +02:00
|
|
|
/// Returns the json of a pdu.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn get_non_outlier_pdu_json(
|
|
|
|
&self,
|
|
|
|
event_id: &EventId,
|
|
|
|
) -> Result<Option<CanonicalJsonObject>>;
|
2021-07-15 19:54:04 +02:00
|
|
|
|
2020-05-26 10:27:51 +02:00
|
|
|
/// Returns the pdu's id.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>>;
|
2020-05-26 10:27:51 +02:00
|
|
|
|
2021-03-26 11:10:45 +01:00
|
|
|
/// Returns the pdu.
|
|
|
|
///
|
|
|
|
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn get_non_outlier_pdu(&self, event_id: &EventId) -> Result<Option<PduEvent>>;
|
2021-03-26 11:10:45 +01:00
|
|
|
|
2020-05-24 18:25:52 +02:00
|
|
|
/// Returns the pdu.
|
2021-02-01 12:44:30 -05:00
|
|
|
///
|
|
|
|
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>>;
|
2021-01-29 21:45:33 -05:00
|
|
|
|
2020-05-26 10:27:51 +02:00
|
|
|
/// Returns the pdu.
|
2021-02-03 20:00:01 -05:00
|
|
|
///
|
|
|
|
/// This does __NOT__ check the outliers `Tree`.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result<Option<PduEvent>>;
|
2020-05-26 10:27:51 +02:00
|
|
|
|
2020-11-30 14:46:47 -05:00
|
|
|
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result<Option<CanonicalJsonObject>>;
|
2020-09-15 16:13:54 +02:00
|
|
|
|
2022-06-19 22:56:14 +02:00
|
|
|
/// Returns the `count` of this pdu's id.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn pdu_count(&self, pdu_id: &[u8]) -> Result<u64>;
|
2022-06-19 22:56:14 +02:00
|
|
|
|
2020-06-09 15:13:17 +02:00
|
|
|
/// Removes a pdu and creates a new one with the same id.
|
2022-08-07 19:42:22 +02:00
|
|
|
fn replace_pdu(&self, pdu_id: &[u8], pdu: &PduEvent) -> Result<()>;
|
2020-05-03 17:25:31 +02:00
|
|
|
|
2021-06-08 18:10:00 +02:00
|
|
|
/// Returns an iterator over all events in a room that happened after the event with id `since`
|
2020-07-29 17:37:26 +02:00
|
|
|
/// in chronological order.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn pdus_since<'a>(
|
2021-06-08 18:10:00 +02:00
|
|
|
&'a self,
|
2020-06-16 12:11:38 +02:00
|
|
|
user_id: &UserId,
|
2020-05-03 17:25:31 +02:00
|
|
|
room_id: &RoomId,
|
|
|
|
since: u64,
|
2022-09-07 13:25:51 +02:00
|
|
|
) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, PduEvent)>>>>;
|
2020-05-03 17:25:31 +02:00
|
|
|
|
2020-07-26 17:34:12 +02:00
|
|
|
/// Returns an iterator over all events and their tokens in a room that happened before the
|
|
|
|
/// event with id `until` in reverse-chronological order.
|
2022-09-06 23:15:09 +02:00
|
|
|
fn pdus_until<'a>(
|
2021-06-08 18:10:00 +02:00
|
|
|
&'a self,
|
2020-06-16 12:11:38 +02:00
|
|
|
user_id: &UserId,
|
2020-05-03 17:25:31 +02:00
|
|
|
room_id: &RoomId,
|
|
|
|
until: u64,
|
2022-09-07 13:25:51 +02:00
|
|
|
) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, PduEvent)>>>>;
|
2020-05-03 17:25:31 +02:00
|
|
|
|
2022-09-06 23:15:09 +02:00
|
|
|
fn pdus_after<'a>(
|
2021-06-08 18:10:00 +02:00
|
|
|
&'a self,
|
2020-06-16 12:11:38 +02:00
|
|
|
user_id: &UserId,
|
2020-06-04 13:58:55 +02:00
|
|
|
room_id: &RoomId,
|
|
|
|
from: u64,
|
2022-09-07 13:25:51 +02:00
|
|
|
) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, PduEvent)>>>>;
|
2022-08-07 19:42:22 +02:00
|
|
|
}
|