From 15545a7db2066c3b3c2d6edc358224ec42763e1d Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 18 Oct 2023 08:32:10 +0700 Subject: [PATCH] Reregister push notifications when needed --- src/common/pushnoti.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/common/pushnoti.rs b/src/common/pushnoti.rs index 67265ca..3a63078 100644 --- a/src/common/pushnoti.rs +++ b/src/common/pushnoti.rs @@ -20,6 +20,7 @@ use crate::AnyResult; pub(crate) struct PushNotiThread { pn_watcher: Arc>>, + registed_cameras: Vec, } // The push notification @@ -45,6 +46,7 @@ impl PushNotiThread { Ok(PushNotiThread { pn_watcher: Arc::new(pn_watcher), + registed_cameras: vec![], }) } @@ -116,6 +118,25 @@ impl PushNotiThread { }, vec![], ); + + for instance in self.registed_cameras.iter() { + let uid = uid.clone(); + let fcm_token = fcm_token.clone(); + let instance = instance.clone(); + tokio::task::spawn(async move { + let _ = instance + .run_task(|camera| { + let fcm_token = fcm_token.clone(); + let uid = uid.clone(); + Box::pin(async move { + camera.send_pushinfo_android(&fcm_token, &uid).await?; + AnyResult::Ok(()) + }) + }) + .await; + }); + } + tokio::select! { v = async { let r = listener.connect().await; @@ -150,6 +171,7 @@ impl PushNotiThread { PnRequest::Activate{instance, sender} => { let uid = uid.clone(); let fcm_token = fcm_token.clone(); + self.registed_cameras.push(instance.clone()); tokio::task::spawn(async move { let r = instance.run_task(|camera| { let fcm_token = fcm_token.clone();