add: live browser notifications

This commit is contained in:
trisua 2025-05-02 20:08:35 -04:00
parent 58d206eb81
commit 98d6f21e6e
18 changed files with 291 additions and 15 deletions

View file

@ -1,8 +1,12 @@
use super::*;
use crate::cache::Cache;
use crate::model::socket::{CrudMessageType, PacketType, SocketMessage, SocketMethod};
use crate::model::{Error, Result, auth::Notification, auth::User, permissions::FinePermission};
use crate::{auto_method, execute, get, query_row, query_rows, params};
#[cfg(feature = "redis")]
use redis::Commands;
#[cfg(feature = "sqlite")]
use rusqlite::Row;
@ -78,6 +82,20 @@ impl DataManager {
// incr notification count
self.incr_user_notifications(data.owner).await.unwrap();
// post event
let mut con = self.2.get_con().await;
if let Err(e) = con.publish::<String, String, ()>(
format!("{}/notifs", data.owner),
serde_json::to_string(&SocketMessage {
method: SocketMethod::Packet(PacketType::Crud(CrudMessageType::Create)),
data: serde_json::to_string(&data).unwrap(),
})
.unwrap(),
) {
return Err(Error::MiscError(e.to_string()));
}
// return
Ok(())
}
@ -115,6 +133,20 @@ impl DataManager {
.unwrap();
}
// post event
let mut con = self.2.get_con().await;
if let Err(e) = con.publish::<String, String, ()>(
format!("{}/notifs", notification.owner),
serde_json::to_string(&SocketMessage {
method: SocketMethod::Packet(PacketType::Crud(CrudMessageType::Delete)),
data: notification.id.to_string(),
})
.unwrap(),
) {
return Err(Error::MiscError(e.to_string()));
}
// return
Ok(())
}