2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 get_local_user_view_from_jwt,
8 post::{MarkPostAsRead, PostResponse},
10 use lemmy_db_views::post_view::PostView;
11 use lemmy_utils::{ConnectionId, LemmyError};
12 use lemmy_websocket::LemmyContext;
14 #[async_trait::async_trait(?Send)]
15 impl Perform for MarkPostAsRead {
16 type Response = PostResponse;
18 #[tracing::instrument(skip(context, _websocket_id))]
21 context: &Data<LemmyContext>,
22 _websocket_id: Option<ConnectionId>,
23 ) -> Result<Self::Response, LemmyError> {
26 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
28 let post_id = data.post_id;
29 let person_id = local_user_view.person.id;
31 // Mark the post as read / unread
33 mark_post_as_read(person_id, post_id, context.pool()).await?;
35 mark_post_as_unread(person_id, post_id, context.pool()).await?;
39 let post_view = blocking(context.pool(), move |conn| {
40 PostView::read(conn, post_id, Some(person_id))
44 let res = Self::Response { post_view };