2022-09-06 23:15:09 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-10-09 17:25:06 +02:00
|
|
|
use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId};
|
2022-09-06 23:15:09 +02:00
|
|
|
|
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
|
|
|
|
2024-04-22 23:48:57 -04: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>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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>>;
|
2024-03-05 19:48:54 -05: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>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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>>;
|
2024-03-05 19:48:54 -05: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>>>;
|
2024-03-05 19:48:54 -05: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>>;
|
2024-03-05 19:48:54 -05: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>>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2020-05-26 10:27:51 +02:00
|
|
|
/// Returns the pdu.
|
2021-02-03 20:00:01 -05:00
|
|
|
///
|
2020-11-30 14:46:47 -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>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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<()>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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<()>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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<()>;
|
2024-03-05 19:48:54 -05: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.
|
2024-03-02 20:55:02 -05:00
|
|
|
#[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>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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.
|
2024-03-02 20:55:02 -05:00
|
|
|
#[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>>;
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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<()>;
|
2022-08-07 19:42:22 +02:00
|
|
|
}
|