Skip to content

Commit

Permalink
refactor check if device is registered
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan0xC committed Jan 16, 2024
1 parent 80e9f8f commit 83c8ee9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/api/core/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,8 @@ async fn put_device_token(uuid: &str, data: JsonUpcase<PushToken>, headers: Head
};

// if the device already has been registered
if device.push_uuid.is_some() {
// check if the provided token is the same token, that already has been registered
if device.is_registered() {
// check if the new token is the same as the registered token
if device.push_token.is_some() && device.push_token.unwrap() == token.clone() {
debug!("Device {} is already registered and token is the same", uuid);
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion src/api/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn get_auth_push_token() -> ApiResult<String> {
}

pub async fn register_push_device(device: &mut Device, conn: &mut crate::db::DbConn) -> EmptyResult {
if !CONFIG.push_enabled() || !device.is_push_device() || device.push_uuid.is_some() {
if !CONFIG.push_enabled() || !device.is_push_device() || device.is_registered() {
return Ok(());
}

Expand Down
4 changes: 4 additions & 0 deletions src/db/models/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ impl Device {
pub fn is_push_device(&self) -> bool {
matches!(DeviceType::from_i32(self.atype), DeviceType::Android | DeviceType::Ios)
}

pub fn is_registered(&self) -> bool {
self.push_uuid.is_some()
}
}

use crate::db::DbConn;
Expand Down

0 comments on commit 83c8ee9

Please sign in to comment.