2023-07-28 14:39:38 +00:00
|
|
|
use actix_web::web::{Data, Json};
|
2023-10-20 00:15:55 +00:00
|
|
|
use lemmy_api_common::{
|
|
|
|
context::LemmyContext,
|
|
|
|
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
|
|
|
};
|
2022-10-27 09:24:07 +00:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::comment_reply::{CommentReply, CommentReplyUpdateForm},
|
|
|
|
traits::Crud,
|
|
|
|
};
|
2023-09-21 10:42:28 +00:00
|
|
|
use lemmy_db_views::structs::LocalUserView;
|
2023-10-20 00:15:55 +00:00
|
|
|
use lemmy_db_views_actor::structs::CommentReplyView;
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};
|
2022-07-30 03:55:59 +00:00
|
|
|
|
2023-07-28 14:39:38 +00:00
|
|
|
#[tracing::instrument(skip(context))]
|
|
|
|
pub async fn mark_reply_as_read(
|
|
|
|
data: Json<MarkCommentReplyAsRead>,
|
|
|
|
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<CommentReplyResponse>> {
|
2023-07-28 14:39:38 +00:00
|
|
|
let comment_reply_id = data.comment_reply_id;
|
|
|
|
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
|
2022-07-30 03:55:59 +00:00
|
|
|
|
2023-07-28 14:39:38 +00:00
|
|
|
if local_user_view.person.id != read_comment_reply.recipient_id {
|
2023-08-31 13:01:08 +00:00
|
|
|
Err(LemmyErrorType::CouldntUpdateComment)?
|
2023-07-28 14:39:38 +00:00
|
|
|
}
|
2022-07-30 03:55:59 +00:00
|
|
|
|
2023-07-28 14:39:38 +00:00
|
|
|
let comment_reply_id = read_comment_reply.id;
|
|
|
|
let read = Some(data.read);
|
2022-11-09 10:05:00 +00:00
|
|
|
|
2023-07-28 14:39:38 +00:00
|
|
|
CommentReply::update(
|
|
|
|
&mut context.pool(),
|
|
|
|
comment_reply_id,
|
|
|
|
&CommentReplyUpdateForm { read },
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
2022-07-30 03:55:59 +00:00
|
|
|
|
2023-10-20 00:15:55 +00:00
|
|
|
let comment_reply_id = read_comment_reply.id;
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
let comment_reply_view =
|
|
|
|
CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
|
|
|
|
|
|
|
|
Ok(Json(CommentReplyResponse { comment_reply_view }))
|
2022-07-30 03:55:59 +00:00
|
|
|
}
|