Mark contact acceptance notifications as read automatically

This commit is contained in:
Max Brunsfeld 2023-10-22 11:57:01 +02:00
parent fce09e8c92
commit 4a0358a513
6 changed files with 99 additions and 7 deletions

View file

@ -4,7 +4,7 @@ use crate::{
auth,
db::{
self, BufferId, ChannelId, ChannelVisibility, ChannelsForUser, CreatedChannelMessage,
Database, MessageId, ProjectId, RoomId, ServerId, User, UserId,
Database, MessageId, NotificationId, ProjectId, RoomId, ServerId, User, UserId,
},
executor::Executor,
AppState, Result,
@ -273,6 +273,7 @@ impl Server {
.add_request_handler(get_channel_messages)
.add_request_handler(get_channel_messages_by_id)
.add_request_handler(get_notifications)
.add_request_handler(mark_notification_as_read)
.add_request_handler(link_channel)
.add_request_handler(unlink_channel)
.add_request_handler(move_channel)
@ -3187,6 +3188,27 @@ async fn get_notifications(
Ok(())
}
async fn mark_notification_as_read(
request: proto::MarkNotificationRead,
response: Response<proto::MarkNotificationRead>,
session: Session,
) -> Result<()> {
let database = &session.db().await;
let notifications = database
.mark_notification_as_read_by_id(
session.user_id,
NotificationId::from_proto(request.notification_id),
)
.await?;
send_notifications(
&*session.connection_pool().await,
&session.peer,
notifications,
);
response.send(proto::Ack {})?;
Ok(())
}
async fn update_diff_base(request: proto::UpdateDiffBase, session: Session) -> Result<()> {
let project_id = ProjectId::from_proto(request.project_id);
let project_connection_ids = session