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-07-04 03:26:19 +00:00
|
|
|
use conduit::Result;
|
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-07-18 06:37:47 +00:00
|
|
|
use crate::{sending, Dep};
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-07-18 06:37:47 +00:00
|
|
|
services: Services,
|
2024-05-27 03:17:20 +00:00
|
|
|
db: Data,
|
2020-05-03 17:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 06:37:47 +00:00
|
|
|
struct Services {
|
|
|
|
|
sending: Dep<sending::Service>,
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 03:26:19 +00:00
|
|
|
impl crate::Service for Service {
|
|
|
|
|
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
|
|
|
|
Ok(Arc::new(Self {
|
2024-07-18 06:37:47 +00:00
|
|
|
services: Services {
|
|
|
|
|
sending: args.depend::<sending::Service>("sending"),
|
|
|
|
|
},
|
|
|
|
|
db: Data::new(&args),
|
2024-07-04 03:26:19 +00:00
|
|
|
}))
|
2024-05-27 03:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-04 03:26:19 +00:00
|
|
|
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Service {
|
2022-06-25 16:12:23 +02:00
|
|
|
/// Replaces the previous read receipt.
|
2024-06-28 23:23:59 +00: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)?;
|
2024-07-18 06:37:47 +00:00
|
|
|
self.services.sending.flush_room(room_id)?;
|
2024-03-29 00:27:10 -07:00
|
|
|
|
|
|
|
|
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`.
|
2024-07-07 19:03:15 +00:00
|
|
|
#[tracing::instrument(skip(self), level = "debug")]
|
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`.
|
2024-07-07 19:03:15 +00:00
|
|
|
#[tracing::instrument(skip(self), level = "debug")]
|
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.
|
2024-07-07 19:03:15 +00:00
|
|
|
#[tracing::instrument(skip(self), level = "debug")]
|
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
|
|
|
}
|