2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{GetUnreadCount, GetUnreadCountResponse},
5 utils::get_local_user_view_from_jwt,
8 use lemmy_db_views::structs::PrivateMessageView;
9 use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
10 use lemmy_utils::{error::LemmyError, ConnectionId};
12 #[async_trait::async_trait(?Send)]
13 impl Perform for GetUnreadCount {
14 type Response = GetUnreadCountResponse;
16 #[tracing::instrument(skip(context, _websocket_id))]
19 context: &Data<LemmyContext>,
20 _websocket_id: Option<ConnectionId>,
21 ) -> Result<Self::Response, LemmyError> {
24 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
26 let person_id = local_user_view.person.id;
28 let replies = CommentReplyView::get_unread_replies(context.pool(), person_id).await?;
30 let mentions = PersonMentionView::get_unread_mentions(context.pool(), person_id).await?;
32 let private_messages =
33 PrivateMessageView::get_unread_messages(context.pool(), person_id).await?;
35 let res = Self::Response {