Mark contact acceptance notifications as read automatically
This commit is contained in:
parent
fce09e8c92
commit
4a0358a513
6 changed files with 99 additions and 7 deletions
|
@ -150,6 +150,28 @@ impl Database {
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn mark_notification_as_read_by_id(
|
||||
&self,
|
||||
recipient_id: UserId,
|
||||
notification_id: NotificationId,
|
||||
) -> Result<NotificationBatch> {
|
||||
self.transaction(|tx| async move {
|
||||
let row = notification::Entity::update(notification::ActiveModel {
|
||||
id: ActiveValue::Unchanged(notification_id),
|
||||
recipient_id: ActiveValue::Unchanged(recipient_id),
|
||||
is_read: ActiveValue::Set(true),
|
||||
..Default::default()
|
||||
})
|
||||
.exec(&*tx)
|
||||
.await?;
|
||||
Ok(model_to_proto(self, row)
|
||||
.map(|notification| (recipient_id, notification))
|
||||
.into_iter()
|
||||
.collect())
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
async fn mark_notification_as_read_internal(
|
||||
&self,
|
||||
recipient_id: UserId,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue