add: live browser notifications
This commit is contained in:
parent
58d206eb81
commit
98d6f21e6e
18 changed files with 291 additions and 15 deletions
|
@ -3,6 +3,7 @@ pub mod images;
|
|||
pub mod ipbans;
|
||||
pub mod profile;
|
||||
pub mod social;
|
||||
pub mod subscriptions;
|
||||
pub mod user_warnings;
|
||||
|
||||
use super::{LoginProps, RegisterProps};
|
||||
|
|
58
crates/app/src/routes/api/v1/auth/subscriptions.rs
Normal file
58
crates/app/src/routes/api/v1/auth/subscriptions.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
use axum::{extract::Path, response::IntoResponse, Extension, Json};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{ApiReturn, Error};
|
||||
use crate::{get_user_from_token, State};
|
||||
|
||||
pub async fn update_last_message_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Json((channel_id, message_id)): Json<(usize, usize)>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let mut user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
user.subscriptions.insert(channel_id, message_id);
|
||||
|
||||
if let Err(e) = data
|
||||
.update_user_subscriptions(user.id, user.subscriptions)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Subscription connection".to_string(),
|
||||
payload: (),
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn delete_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(channel): Path<usize>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let mut user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
user.subscriptions.remove(&channel);
|
||||
|
||||
if let Err(e) = data
|
||||
.update_user_subscriptions(user.id, user.subscriptions)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Subscription removed".to_string(),
|
||||
payload: (),
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue