+ .load::<PersonMentionViewTuple>(&mut conn)
+ .await
+ };
+
+ Queries::new(read, list)
+}
+
+impl PersonMentionView {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ person_mention_id: PersonMentionId,
+ my_person_id: Option<PersonId>,
+ ) -> Result<Self, Error> {
+ queries()
+ .read(pool, (person_mention_id, my_person_id))
+ .await
+ }
+
+ /// Gets the number of unread mentions
+ pub async fn get_unread_mentions(
+ pool: &mut DbPool<'_>,
+ my_person_id: PersonId,
+ ) -> Result<i64, Error> {
+ use diesel::dsl::count;
+ let conn = &mut get_conn(pool).await?;
+
+ person_mention::table
+ .inner_join(comment::table)
+ .filter(person_mention::recipient_id.eq(my_person_id))
+ .filter(person_mention::read.eq(false))
+ .filter(comment::deleted.eq(false))
+ .filter(comment::removed.eq(false))
+ .select(count(person_mention::id))
+ .first::<i64>(conn)
+ .await
+ }
+}
+
+#[derive(Default)]
+pub struct PersonMentionQuery {
+ pub my_person_id: Option<PersonId>,
+ pub recipient_id: Option<PersonId>,
+ pub sort: Option<CommentSortType>,
+ pub unread_only: Option<bool>,
+ pub show_bot_accounts: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+}