2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 post::{MarkPostAsRead, PostResponse},
5 utils::{blocking, get_local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
7 use lemmy_db_views::structs::PostView;
8 use lemmy_utils::{ConnectionId, LemmyError};
9 use lemmy_websocket::LemmyContext;
11 #[async_trait::async_trait(?Send)]
12 impl Perform for MarkPostAsRead {
13 type Response = PostResponse;
15 #[tracing::instrument(skip(context, _websocket_id))]
18 context: &Data<LemmyContext>,
19 _websocket_id: Option<ConnectionId>,
20 ) -> Result<Self::Response, LemmyError> {
23 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
25 let post_id = data.post_id;
26 let person_id = local_user_view.person.id;
28 // Mark the post as read / unread
30 mark_post_as_read(person_id, post_id, context.pool()).await?;
32 mark_post_as_unread(person_id, post_id, context.pool()).await?;
36 let post_view = blocking(context.pool(), move |conn| {
37 PostView::read(conn, post_id, Some(person_id))
41 let res = Self::Response { post_view };