2024-08-08 17:18:30 +00:00
|
|
|
use ruma::{RoomId, UserId};
|
2025-09-11 07:08:10 +00:00
|
|
|
use tuwunel_core::{
|
|
|
|
|
Result, implement, trace,
|
|
|
|
|
utils::stream::{ReadyExt, TryIgnore},
|
|
|
|
|
};
|
2025-10-27 15:55:55 +00:00
|
|
|
use tuwunel_database::{Deserialized, Interfix};
|
2024-07-18 06:37:47 +00:00
|
|
|
|
2025-10-27 15:55:55 +00:00
|
|
|
#[implement(super::Service)]
|
2025-10-22 07:05:03 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(self))]
|
2024-10-15 09:54:20 +00:00
|
|
|
pub fn reset_notification_counts(&self, user_id: &UserId, room_id: &RoomId) {
|
2025-07-24 00:15:33 +00:00
|
|
|
let count = self.services.globals.next_count();
|
|
|
|
|
|
2024-10-15 09:54:20 +00:00
|
|
|
let userroom_id = (user_id, room_id);
|
2025-04-22 04:42:26 +00:00
|
|
|
self.db
|
|
|
|
|
.userroomid_highlightcount
|
|
|
|
|
.put(userroom_id, 0_u64);
|
|
|
|
|
self.db
|
|
|
|
|
.userroomid_notificationcount
|
|
|
|
|
.put(userroom_id, 0_u64);
|
2021-04-12 12:40:16 +02:00
|
|
|
|
2024-10-15 09:54:20 +00:00
|
|
|
let roomuser_id = (room_id, user_id);
|
|
|
|
|
self.db
|
|
|
|
|
.roomuserid_lastnotificationread
|
2025-07-24 00:15:33 +00:00
|
|
|
.put(roomuser_id, *count);
|
2024-10-15 09:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
2025-10-27 15:55:55 +00:00
|
|
|
#[implement(super::Service)]
|
2025-10-27 14:56:04 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(self), ret(level = "trace"))]
|
2024-10-15 09:54:20 +00:00
|
|
|
pub async fn notification_count(&self, user_id: &UserId, room_id: &RoomId) -> u64 {
|
|
|
|
|
let key = (user_id, room_id);
|
|
|
|
|
self.db
|
|
|
|
|
.userroomid_notificationcount
|
|
|
|
|
.qry(&key)
|
|
|
|
|
.await
|
|
|
|
|
.deserialized()
|
|
|
|
|
.unwrap_or(0)
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-27 15:55:55 +00:00
|
|
|
#[implement(super::Service)]
|
2025-10-27 14:56:04 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(self), ret(level = "trace"))]
|
2024-10-15 09:54:20 +00:00
|
|
|
pub async fn highlight_count(&self, user_id: &UserId, room_id: &RoomId) -> u64 {
|
|
|
|
|
let key = (user_id, room_id);
|
|
|
|
|
self.db
|
|
|
|
|
.userroomid_highlightcount
|
|
|
|
|
.qry(&key)
|
|
|
|
|
.await
|
|
|
|
|
.deserialized()
|
|
|
|
|
.unwrap_or(0)
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-27 15:55:55 +00:00
|
|
|
#[implement(super::Service)]
|
2025-10-27 14:56:04 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(self), ret(level = "trace"))]
|
2025-10-29 22:11:42 +00:00
|
|
|
pub async fn last_notification_read(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
|
2024-10-15 09:54:20 +00:00
|
|
|
let key = (room_id, user_id);
|
|
|
|
|
self.db
|
|
|
|
|
.roomuserid_lastnotificationread
|
|
|
|
|
.qry(&key)
|
|
|
|
|
.await
|
|
|
|
|
.deserialized()
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-27 15:55:55 +00:00
|
|
|
#[implement(super::Service)]
|
2025-09-11 07:08:10 +00:00
|
|
|
pub async fn delete_room_notification_read(&self, room_id: &RoomId) -> Result {
|
|
|
|
|
let key = (room_id, Interfix);
|
|
|
|
|
self.db
|
|
|
|
|
.roomuserid_lastnotificationread
|
|
|
|
|
.keys_prefix_raw(&key)
|
|
|
|
|
.ignore_err()
|
|
|
|
|
.ready_for_each(|key| {
|
|
|
|
|
trace!("Removing key: {key:?}");
|
|
|
|
|
self.db
|
|
|
|
|
.roomuserid_lastnotificationread
|
|
|
|
|
.remove(key);
|
|
|
|
|
})
|
|
|
|
|
.await;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|