2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 person::{GetUnreadCount, GetUnreadCountResponse},
6 utils::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> {
23 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
25 let person_id = local_user_view.person.id;
27 let replies = CommentReplyView::get_unread_replies(context.pool(), person_id).await?;
29 let mentions = PersonMentionView::get_unread_mentions(context.pool(), person_id).await?;
31 let private_messages =
32 PrivateMessageView::get_unread_messages(context.pool(), person_id).await?;
34 let res = Self::Response {