2023-09-05 09:33:46 +00:00
|
|
|
use actix_web::web::{Data, Json};
|
2023-09-21 10:42:28 +00:00
|
|
|
use lemmy_api_common::{context::LemmyContext, person::GetRepliesResponse};
|
2022-04-13 18:12:25 +00:00
|
|
|
use lemmy_db_schema::source::{
|
2022-07-30 03:55:59 +00:00
|
|
|
comment_reply::CommentReply,
|
2022-04-13 18:12:25 +00:00
|
|
|
person_mention::PersonMention,
|
|
|
|
private_message::PrivateMessage,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn mark_all_notifications_read(
|
|
|
|
context: Data<LemmyContext>,
|
2023-09-21 10:42:28 +00:00
|
|
|
local_user_view: LocalUserView,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Json<GetRepliesResponse>> {
|
2023-09-05 09:33:46 +00:00
|
|
|
let person_id = local_user_view.person.id;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
// Mark all comment_replies as read
|
|
|
|
CommentReply::mark_all_as_read(&mut context.pool(), person_id)
|
|
|
|
.await
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
// Mark all user mentions as read
|
|
|
|
PersonMention::mark_all_as_read(&mut context.pool(), person_id)
|
|
|
|
.await
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
// Mark all private_messages as read
|
|
|
|
PrivateMessage::mark_all_as_read(&mut context.pool(), person_id)
|
|
|
|
.await
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
2023-09-05 09:33:46 +00:00
|
|
|
Ok(Json(GetRepliesResponse { replies: vec![] }))
|
2022-04-13 18:12:25 +00:00
|
|
|
}
|