]> Untitled Git - lemmy.git/blobdiff - crates/db_views_actor/src/person_mention_view.rs
Adding GetUnreadCount to the API. Fixes #1794 (#1842)
[lemmy.git] / crates / db_views_actor / src / person_mention_view.rs
index 421c60a401e796ca6f527e06ecaefb4e88e826d6..0d3cfc837ac6c1dac7786beae95401dad0ee4add 100644 (file)
@@ -163,6 +163,17 @@ impl PersonMentionView {
       my_vote,
     })
   }
+
+  /// Gets the number of unread mentions
+  pub fn get_unread_mentions(conn: &PgConnection, my_person_id: PersonId) -> Result<i64, Error> {
+    use diesel::dsl::*;
+
+    person_mention::table
+      .filter(person_mention::recipient_id.eq(my_person_id))
+      .filter(person_mention::read.eq(false))
+      .select(count(person_mention::id))
+      .first::<i64>(conn)
+  }
 }
 
 pub struct PersonMentionQueryBuilder<'a> {