2022-06-25 16:12:23 +02:00
|
|
|
mod data;
|
2022-10-08 13:04:55 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2024-05-26 21:29:19 +00:00
|
|
|
use data::Data;
|
2022-10-09 17:25:06 +02:00
|
|
|
use ruma::{events::receipt::ReceiptEvent, serde::Raw, OwnedUserId, RoomId, UserId};
|
2022-09-07 13:25:51 +02:00
|
|
|
|
2024-03-29 00:27:10 -07:00
|
|
|
use crate::{services, Result};
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
|
|
|
|
pub 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.
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn readreceipt_update(&self, user_id: &UserId, room_id: &RoomId, event: ReceiptEvent) -> Result<()> {
|
2024-03-29 00:27:10 -07:00
|
|
|
self.db.readreceipt_update(user_id, room_id, event)?;
|
|
|
|
|
services().sending.flush_room(room_id)?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
2020-05-03 17:25:31 +02:00
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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))]
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn readreceipts_since<'a>(
|
2020-05-03 17:25:31 +02:00
|
|
|
&'a self, room_id: &RoomId, since: u64,
|
2021-11-26 20:36:40 +01:00
|
|
|
) -> impl Iterator<Item = Result<(OwnedUserId, 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
|
|
|
}
|
2024-03-05 19:48:54 -05: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))]
|
2024-05-09 15:59:08 -07: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
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
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))]
|
2024-05-09 15:59:08 -07: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
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2020-08-23 17:29:39 +02:00
|
|
|
/// Returns the count of the last typing update in this room.
|
2024-05-09 15:59:08 -07:00
|
|
|
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
|
|
|
}
|