1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Create client push notification token

This commit is contained in:
2021-04-11 17:32:50 +02:00
parent e5f9de0507
commit 9c6bd0a75a
3 changed files with 51 additions and 1 deletions

View File

@ -13,7 +13,7 @@ use crate::data::new_data_conservation_policy::NewDataConservationPolicy;
use crate::data::new_notifications_settings::NewNotificationsSettings;
use crate::data::security_settings::SecuritySettings;
use crate::data::user::{AccountImageVisibility, User, UserID, UserPageStatus};
use crate::data::user_token::UserAccessToken;
use crate::data::user_token::{PushNotificationToken, UserAccessToken};
use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, friends_helper, groups_helper, likes_helper, notifications_helper, posts_helper, survey_helper, user_helper};
use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo, RowResult, UpdateInfo};
use crate::helpers::events_helper::Event;
@ -57,6 +57,7 @@ pub fn login_user(email: &str, password: &str, client: &APIClient) -> ResultBoxE
token: rand_str(150),
last_refresh: time(),
timeout: client.default_expiration_time,
push_notifications_token: PushNotificationToken::UNDEFINED,
};
// Save it
@ -66,6 +67,7 @@ pub fn login_user(email: &str, password: &str, client: &APIClient) -> ResultBoxE
.add_str("token", &new_token.token)
.add_u64("last_refresh", new_token.last_refresh)
.add_u64("timeout", new_token.timeout)
.add_opt_str("push_notification_token", new_token.push_notifications_token.to_db().as_ref())
.insert_drop_result()?;
Ok(new_token.token)
@ -426,6 +428,8 @@ fn validate_password(user: &User, password: &str) -> Res<bool> {
}
fn db_to_user_access_token(res: &RowResult) -> Res<UserAccessToken> {
let push_notifications_token = PushNotificationToken::from_db(res.get_optional_str("push_notifications_token")?);
Ok(UserAccessToken {
id: res.get_u64("id")?,
client_id: res.get_u64("client_id")?,
@ -433,5 +437,6 @@ fn db_to_user_access_token(res: &RowResult) -> Res<UserAccessToken> {
token: res.get_str("token")?,
last_refresh: res.get_u64("last_refresh")?,
timeout: res.get_u64("timeout")?,
push_notifications_token,
})
}