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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.6 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2022-10-09 17:25:06 +02:00
use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId};
2023-02-20 22:59:45 +01:00
use super::PduCount;
2022-10-05 20:34:31 +02:00
use crate::{PduEvent, Result};
2023-02-20 22:59:45 +01:00
pub(crate) trait Data: Send + Sync {
2023-02-20 22:59:45 +01:00
fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result<PduCount>;
2022-06-19 22:56:14 +02:00
/// Returns the `count` of this pdu's id.
2023-02-20 22:59:45 +01:00
fn get_pdu_count(&self, event_id: &EventId) -> Result<Option<PduCount>>;
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>>;
2022-06-19 22:56:14 +02:00
/// Returns the json of a pdu.
2022-10-05 20:34:31 +02:00
fn get_non_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>>;
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>>>;
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>>;
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>>;
2022-10-05 20:33:55 +02:00
/// Returns the pdu as a `BTreeMap<String, CanonicalJsonValue>`.
2022-10-05 20:34:31 +02:00
fn get_pdu_json_from_id(&self, pdu_id: &[u8]) -> Result<Option<CanonicalJsonObject>>;
2022-10-05 20:34:31 +02:00
/// Adds a new pdu to the timeline
fn append_pdu(&self, pdu_id: &[u8], pdu: &PduEvent, json: &CanonicalJsonObject, count: u64) -> Result<()>;
2023-02-20 22:59:45 +01:00
// Adds a new pdu to the backfilled timeline
fn prepend_backfill_pdu(&self, pdu_id: &[u8], event_id: &EventId, json: &CanonicalJsonObject) -> Result<()>;
2020-06-09 15:13:17 +02:00
/// Removes a pdu and creates a new one with the same id.
2023-06-25 19:31:40 +02:00
fn replace_pdu(&self, pdu_id: &[u8], pdu_json: &CanonicalJsonObject, pdu: &PduEvent) -> Result<()>;
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.
#[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>>;
2023-02-20 22:59:45 +01:00
/// 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>>;
2022-10-05 20:34:31 +02:00
fn increment_notification_counts(
2022-10-09 17:25:06 +02:00
&self, room_id: &RoomId, notifies: Vec<OwnedUserId>, highlights: Vec<OwnedUserId>,
2022-10-05 20:34:31 +02:00
) -> Result<()>;
}