2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 get_local_user_view_from_jwt,
6 person::{GetUnreadCount, GetUnreadCountResponse},
8 use lemmy_db_views::{comment_view::CommentView, private_message_view::PrivateMessageView};
9 use lemmy_db_views_actor::person_mention_view::PersonMentionView;
10 use lemmy_utils::{ConnectionId, LemmyError};
11 use lemmy_websocket::LemmyContext;
13 #[async_trait::async_trait(?Send)]
14 impl Perform for GetUnreadCount {
15 type Response = GetUnreadCountResponse;
17 #[tracing::instrument(skip(context, _websocket_id))]
20 context: &Data<LemmyContext>,
21 _websocket_id: Option<ConnectionId>,
22 ) -> Result<Self::Response, LemmyError> {
25 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
27 let person_id = local_user_view.person.id;
29 let replies = blocking(context.pool(), move |conn| {
30 CommentView::get_unread_replies(conn, person_id)
34 let mentions = blocking(context.pool(), move |conn| {
35 PersonMentionView::get_unread_mentions(conn, person_id)
39 let private_messages = blocking(context.pool(), move |conn| {
40 PrivateMessageView::get_unread_messages(conn, person_id)
44 let res = Self::Response {