fix: do not try to register non-iOS tokens for heartbeats

Notification server uses APNS server
for heartbeat notifications,
so registering FCM tokens there
will result in failing to notify them
and unregistering them anyway.
This commit is contained in:
link2xt
2024-07-01 14:13:54 +00:00
parent 170cbb6635
commit 7a5dca2645

View File

@@ -5,7 +5,6 @@ use anyhow::Result;
use tokio::sync::RwLock;
use crate::context::Context;
use crate::net::http;
/// Manages subscription to Apple Push Notification services.
///
@@ -48,7 +47,10 @@ impl PushSubscriber {
}
/// Subscribes for heartbeat notifications with previously set device token.
#[cfg(target_os = "ios")]
pub(crate) async fn subscribe(&self) -> Result<()> {
use crate::net::http;
let mut state = self.inner.write().await;
if state.heartbeat_subscribed {
@@ -73,6 +75,14 @@ impl PushSubscriber {
Ok(())
}
/// Placeholder to skip subscribing to heartbeat notifications outside iOS.
#[cfg(not(target_os = "ios"))]
pub(crate) async fn subscribe(&self) -> Result<()> {
let mut state = self.inner.write().await;
state.heartbeat_subscribed = true;
Ok(())
}
pub(crate) async fn heartbeat_subscribed(&self) -> bool {
self.inner.read().await.heartbeat_subscribed
}