fix: message notification deletion

This commit is contained in:
trisua 2025-09-07 17:07:25 -04:00
parent f3180989af
commit ff1c739367
4 changed files with 39 additions and 2 deletions

View file

@ -0,0 +1,26 @@
use super::DataManager;
use oiseau::{params, query_row};
use tetratto_core::model::{Error, Result};
impl DataManager {
/// Get the number of notifications a user has for the given tag.
pub async fn get_notifications_count_by_tag(&self, user: usize, tag: &str) -> Result<usize> {
let conn = match self.0.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
};
let res = query_row!(
&conn,
"SELECT COUNT(*)::int FROM notifications WHERE owner = $1 AND tag = $2",
params![&(user as i64), &tag],
|x| { Ok(x.get::<usize, i32>(0)) }
);
if let Err(e) = res {
return Err(Error::DatabaseError(e.to_string()));
}
Ok(res.unwrap() as usize)
}
}