1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-29 16:56:28 +00:00

Can get current push notifications status for a token

This commit is contained in:
Pierre HUBERT 2021-04-11 18:58:34 +02:00
parent 93403e0ce2
commit c8c03d11e4
5 changed files with 52 additions and 4 deletions

View File

@ -70,3 +70,4 @@ pub mod removed_user_from_conv_message;
pub mod user_is_writing_message_in_conversation; pub mod user_is_writing_message_in_conversation;
pub mod res_create_conversation_for_group; pub mod res_create_conversation_for_group;
pub mod notification_settings_api; pub mod notification_settings_api;
pub mod push_notifications_status_api;

View File

@ -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<String>,
}
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,
},
}
}
}

View File

@ -1,4 +1,3 @@
pub mod server_controller; pub mod server_controller;
pub mod user_ws_controller; pub mod user_ws_controller;
pub mod rtc_relay_controller; pub mod rtc_relay_controller;
@ -18,3 +17,4 @@ pub mod virtual_directory_controller;
pub mod web_app_controller; pub mod web_app_controller;
pub mod calls_controller; pub mod calls_controller;
pub mod user_ws_actions; pub mod user_ws_actions;
pub mod push_notifications_controller;

View File

@ -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))
}

View File

@ -1,6 +1,6 @@
use std::error::Error; 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::data::http_request_handler::HttpRequestHandler;
use crate::routes::Method::{GET, POST}; use crate::routes::Method::{GET, POST};
@ -178,6 +178,9 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/settings/set_notifications", Box::new(settings_controller::set_notifications)), 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 // Friends controller
Route::post("/friends/getList", Box::new(friends_controller::get_list)), Route::post("/friends/getList", Box::new(friends_controller::get_list)),
Route::post("/friends/get_single_infos", Box::new(friends_controller::get_single_friendship_info)), Route::post("/friends/get_single_infos", Box::new(friends_controller::get_single_friendship_info)),