mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-09-25 22:29:45 +00:00
Notify about notifications number update
This commit is contained in:
@@ -6,11 +6,15 @@ use crate::api_data::notification_api::NotificationAPI;
|
||||
use crate::api_data::res_count_all_unreads::ResCountAllUnread;
|
||||
use crate::api_data::res_number_unread_notifications::ResNumberUnreadNotifications;
|
||||
use crate::controllers::routes::RequestResult;
|
||||
use crate::controllers::user_ws_controller;
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::error::{Res, ResultBoxError};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::notification::Notification;
|
||||
use crate::helpers::{conversations_helper, friends_helper, notifications_helper};
|
||||
use crate::data::user::UserID;
|
||||
use crate::data::user_ws_message::UserWsMessage;
|
||||
use crate::helpers::{conversations_helper, events_helper, friends_helper, notifications_helper};
|
||||
use crate::helpers::events_helper::Event;
|
||||
|
||||
impl HttpRequestHandler {
|
||||
/// Get the id of a notification included in the request
|
||||
@@ -79,4 +83,30 @@ pub fn delete_all(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
notifications_helper::delete_all_user(r.user_id_ref()?)?;
|
||||
|
||||
r.success("Notifications deleted.")
|
||||
}
|
||||
|
||||
/// Send new notifications number to a specific user
|
||||
pub fn send_new_notifications_number(user_id: &UserID) -> Res {
|
||||
if !user_ws_controller::is_user_connected(user_id) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
user_ws_controller::send_message_to_user(
|
||||
&UserWsMessage::no_id_message("number_notifs", notifications_helper::count_unread(user_id)?)?,
|
||||
user_id,
|
||||
)
|
||||
}
|
||||
|
||||
/// Events handler
|
||||
pub fn handle_event(e: &events_helper::Event) -> Res {
|
||||
match e {
|
||||
Event::UpdatedNotificationsNumber(users) => {
|
||||
for user in users.iter() {
|
||||
send_new_notifications_number(user)?;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user