2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 person::{GetUnreadCount, GetUnreadCountResponse},
5 utils::{blocking, get_local_user_view_from_jwt},
7 use lemmy_db_views::structs::{CommentView, PrivateMessageView};
8 use lemmy_db_views_actor::structs::PersonMentionView;
9 use lemmy_utils::{ConnectionId, LemmyError};
10 use lemmy_websocket::LemmyContext;
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 = blocking(context.pool(), move |conn| {
29 CommentView::get_unread_replies(conn, person_id)
33 let mentions = blocking(context.pool(), move |conn| {
34 PersonMentionView::get_unread_mentions(conn, person_id)
38 let private_messages = blocking(context.pool(), move |conn| {
39 PrivateMessageView::get_unread_messages(conn, person_id)
43 let res = Self::Response {