2022-08-14 13:38:21 +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-08-08 17:18:30 +00:00
|
|
|
use futures::{pin_mut, Stream, StreamExt};
|
|
|
|
use ruma::{RoomId, UserId};
|
2021-04-12 12:40:16 +02:00
|
|
|
|
2024-07-18 06:37:47 +00:00
|
|
|
use self::data::Data;
|
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
db: Data,
|
2022-08-14 13:38:21 +02:00
|
|
|
}
|
2021-04-13 15:00:45 +02:00
|
|
|
|
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
|
|
|
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 {
|
2024-08-08 17:18:30 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) {
|
|
|
|
self.db.reset_notification_counts(user_id, room_id);
|
2021-04-13 15:00:45 +02:00
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[inline]
|
|
|
|
pub async fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> u64 {
|
|
|
|
self.db.notification_count(user_id, room_id).await
|
2020-05-25 23:24:13 +02:00
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[inline]
|
|
|
|
pub async fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> u64 {
|
|
|
|
self.db.highlight_count(user_id, room_id).await
|
2020-05-24 08:30:57 +02:00
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[inline]
|
|
|
|
pub async fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> u64 {
|
|
|
|
self.db.last_notification_read(user_id, room_id).await
|
2022-10-30 20:36:14 +01:00
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[inline]
|
|
|
|
pub async fn associate_token_shortstatehash(&self, room_id: &RoomId, token: u64, shortstatehash: u64) {
|
2024-03-25 17:05:11 -04:00
|
|
|
self.db
|
|
|
|
.associate_token_shortstatehash(room_id, token, shortstatehash)
|
2024-08-08 17:18:30 +00:00
|
|
|
.await;
|
2022-06-19 22:56:14 +02:00
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[inline]
|
|
|
|
pub async fn get_token_shortstatehash(&self, room_id: &RoomId, token: u64) -> Result<u64> {
|
|
|
|
self.db.get_token_shortstatehash(room_id, token).await
|
2020-08-21 21:22:59 +02:00
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn get_shared_rooms<'a>(
|
|
|
|
&'a self, user_a: &'a UserId, user_b: &'a UserId,
|
|
|
|
) -> impl Stream<Item = &RoomId> + Send + 'a {
|
|
|
|
self.db.get_shared_rooms(user_a, user_b)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn has_shared_rooms<'a>(&'a self, user_a: &'a UserId, user_b: &'a UserId) -> bool {
|
|
|
|
let get_shared_rooms = self.get_shared_rooms(user_a, user_b);
|
|
|
|
|
|
|
|
pin_mut!(get_shared_rooms);
|
|
|
|
get_shared_rooms.next().await.is_some()
|
2020-08-18 12:15:27 +02:00
|
|
|
}
|
2022-08-14 13:38:21 +02:00
|
|
|
}
|