2022-06-25 16:12:23 +02:00
|
|
|
mod data;
|
2022-10-05 18:36:12 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2022-06-25 16:12:23 +02:00
|
|
|
pub use data::Data;
|
2022-09-07 13:25:51 +02:00
|
|
|
|
2022-09-06 23:15:09 +02:00
|
|
|
use ruma::{RoomId, UserId, events::receipt::ReceiptEvent, serde::Raw};
|
2022-09-07 13:25:51 +02:00
|
|
|
use crate::Result;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
pub struct Service {
|
2022-10-05 18:36:12 +02:00
|
|
|
db: Arc<dyn Data>,
|
2020-05-03 17:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
impl Service {
|
2022-06-25 16:12:23 +02:00
|
|
|
/// Replaces the previous read receipt.
|
2020-08-23 17:29:39 +02:00
|
|
|
pub fn readreceipt_update(
|
2020-05-03 17:25:31 +02:00
|
|
|
&self,
|
|
|
|
|
user_id: &UserId,
|
|
|
|
|
room_id: &RoomId,
|
2022-02-12 01:58:36 +01:00
|
|
|
event: ReceiptEvent,
|
2020-05-03 17:25:31 +02:00
|
|
|
) -> Result<()> {
|
2022-09-06 23:15:09 +02:00
|
|
|
self.db.readreceipt_update(user_id, room_id, event)
|
2020-05-03 17:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns an iterator over the most recent read_receipts in a room that happened after the event with id `since`.
|
2021-02-28 12:41:03 +01:00
|
|
|
#[tracing::instrument(skip(self))]
|
2021-06-08 18:10:00 +02:00
|
|
|
pub fn readreceipts_since<'a>(
|
|
|
|
|
&'a self,
|
2020-05-03 17:25:31 +02:00
|
|
|
room_id: &RoomId,
|
|
|
|
|
since: u64,
|
2021-11-26 20:36:40 +01:00
|
|
|
) -> impl Iterator<
|
|
|
|
|
Item = Result<(
|
|
|
|
|
Box<UserId>,
|
|
|
|
|
u64,
|
|
|
|
|
Raw<ruma::events::AnySyncEphemeralRoomEvent>,
|
|
|
|
|
)>,
|
|
|
|
|
> + 'a {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.readreceipts_since(room_id, since)
|
2020-05-03 17:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-23 17:29:39 +02:00
|
|
|
/// Sets a private read marker at `count`.
|
2022-09-06 23:15:09 +02:00
|
|
|
#[tracing::instrument(skip(self))]
|
2022-07-10 14:37:34 +02:00
|
|
|
pub fn private_read_set(&self, room_id: &RoomId, user_id: &UserId, count: u64) -> Result<()> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.private_read_set(room_id, user_id, count)
|
2020-08-23 17:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns the private read marker.
|
2021-02-28 12:41:03 +01:00
|
|
|
#[tracing::instrument(skip(self))]
|
2020-08-23 17:29:39 +02:00
|
|
|
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.private_read_get(room_id, user_id)
|
2020-08-23 17:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns the count of the last typing update in this room.
|
|
|
|
|
pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
|
2022-06-25 16:12:23 +02:00
|
|
|
self.db.last_privateread_update(user_id, room_id)
|
2020-08-23 17:29:39 +02:00
|
|
|
}
|
2020-05-03 17:25:31 +02:00
|
|
|
}
|