diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index 4f968c4..a61204a 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -69,4 +69,5 @@ pub mod res_check_password_token; pub mod removed_user_from_conv_message; pub mod user_is_writing_message_in_conversation; pub mod res_create_conversation_for_group; -pub mod notification_settings_api; \ No newline at end of file +pub mod notification_settings_api; +pub mod push_notifications_status_api; \ No newline at end of file diff --git a/src/api_data/push_notifications_status_api.rs b/src/api_data/push_notifications_status_api.rs new file mode 100644 index 0000000..2e7fcd9 --- /dev/null +++ b/src/api_data/push_notifications_status_api.rs @@ -0,0 +1,29 @@ +//! # Push notification status API + +use serde::Serialize; + +use crate::data::user_token::PushNotificationToken; + +#[derive(Serialize)] +pub struct PushNotificationsStatusAPI { + pub status: String, + pub independent_push_token: Option, +} + +impl PushNotificationsStatusAPI { + pub fn new(t: &PushNotificationToken) -> Self { + Self { + status: match t { + PushNotificationToken::UNDEFINED => "undefined", + PushNotificationToken::NONE => "disabled", + PushNotificationToken::INDEPENDENT(_) => "independent", + PushNotificationToken::FIREBASE(_) => "firebase", + }.to_string(), + + independent_push_token: match t { + PushNotificationToken::INDEPENDENT(i) => Some(i.to_string()), + _ => None, + }, + } + } +} \ No newline at end of file diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs index 3dea0f8..1cdf875 100644 --- a/src/controllers/mod.rs +++ b/src/controllers/mod.rs @@ -1,4 +1,3 @@ - pub mod server_controller; pub mod user_ws_controller; pub mod rtc_relay_controller; @@ -17,4 +16,5 @@ pub mod notifications_controller; pub mod virtual_directory_controller; pub mod web_app_controller; pub mod calls_controller; -pub mod user_ws_actions; \ No newline at end of file +pub mod user_ws_actions; +pub mod push_notifications_controller; \ No newline at end of file diff --git a/src/controllers/push_notifications_controller.rs b/src/controllers/push_notifications_controller.rs new file mode 100644 index 0000000..fd0da10 --- /dev/null +++ b/src/controllers/push_notifications_controller.rs @@ -0,0 +1,15 @@ +//! # Push notifications controller +//! +//! @author Pierre Hubert + +use crate::api_data::push_notifications_status_api::PushNotificationsStatusAPI; +use crate::data::base_request_handler::BaseRequestHandler; +use crate::data::http_request_handler::HttpRequestHandler; +use crate::routes::RequestResult; + +/// Get current push notifications status for a connection +pub fn get_status(r: &mut HttpRequestHandler) -> RequestResult { + let status = &r.user_access_token().unwrap().push_notifications_token.clone(); + + r.set_response(PushNotificationsStatusAPI::new(status)) +} \ No newline at end of file diff --git a/src/routes.rs b/src/routes.rs index 8a97daf..a0b7591 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,6 +1,6 @@ use std::error::Error; -use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller}; +use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, push_notifications_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller}; use crate::data::http_request_handler::HttpRequestHandler; use crate::routes::Method::{GET, POST}; @@ -178,6 +178,9 @@ pub fn get_routes() -> Vec { Route::post("/settings/set_notifications", Box::new(settings_controller::set_notifications)), + // Push notifications controller + Route::post("/push_notifications/status", Box::new(push_notifications_controller::get_status)), + // Friends controller Route::post("/friends/getList", Box::new(friends_controller::get_list)), Route::post("/friends/get_single_infos", Box::new(friends_controller::get_single_friendship_info)),