2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{GetRepliesResponse, MarkAllAsRead},
5 utils::get_local_user_view_from_jwt,
8 use lemmy_db_schema::source::{
9 comment_reply::CommentReply,
10 person_mention::PersonMention,
11 private_message::PrivateMessage,
13 use lemmy_utils::{error::LemmyError, ConnectionId};
15 #[async_trait::async_trait(?Send)]
16 impl Perform for MarkAllAsRead {
17 type Response = GetRepliesResponse;
19 #[tracing::instrument(skip(context, _websocket_id))]
22 context: &Data<LemmyContext>,
23 _websocket_id: Option<ConnectionId>,
24 ) -> Result<GetRepliesResponse, LemmyError> {
25 let data: &MarkAllAsRead = self;
27 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
28 let person_id = local_user_view.person.id;
30 // Mark all comment_replies as read
31 CommentReply::mark_all_as_read(context.pool(), person_id)
33 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
35 // Mark all user mentions as read
36 PersonMention::mark_all_as_read(context.pool(), person_id)
38 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
40 // Mark all private_messages as read
41 PrivateMessage::mark_all_as_read(context.pool(), person_id)
43 .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
45 Ok(GetRepliesResponse { replies: vec![] })