1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-09-12 17:20:57 +00:00
continuwuity/src/service/rooms/timeline/data.rs

74 lines
2.5 KiB
Rust
Raw Normal View History

use std::sync::Arc;
use ruma::{signatures::CanonicalJsonObject, EventId, UserId, RoomId};
2022-09-07 13:25:51 +02:00
use crate::{Result, PduEvent};
2022-10-05 15:33:57 +02:00
pub trait Data: Send + Sync {
fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result<u64>;
2022-06-19 22:56:14 +02:00
/// Returns the `count` of this pdu's id.
fn get_pdu_count(&self, event_id: &EventId) -> Result<Option<u64>>;
2022-06-19 22:56:14 +02:00
/// Returns the json of a pdu.
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.
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.
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.
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.
fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>>;
2020-05-26 10:27:51 +02:00
/// Returns the pdu.
///
/// This does __NOT__ check the outliers `Tree`.
fn get_pdu_from_id(&self, pdu_id: &[u8]) -> Result<Option<PduEvent>>;
2020-05-26 10:27:51 +02:00
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
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.
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.
fn replace_pdu(&self, pdu_id: &[u8], pdu: &PduEvent) -> Result<()>;
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.
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,
room_id: &RoomId,
since: u64,
2022-09-07 13:25:51 +02:00
) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, PduEvent)>>>>;
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.
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,
room_id: &RoomId,
until: u64,
2022-09-07 13:25:51 +02:00
) -> Result<Box<dyn Iterator<Item = Result<(Vec<u8>, PduEvent)>>>>;
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)>>>>;
}