diff --git a/apps/ntf-server/Main.hs b/apps/ntf-server/Main.hs index abc4a4d5f..1c61bc247 100644 --- a/apps/ntf-server/Main.hs +++ b/apps/ntf-server/Main.hs @@ -69,7 +69,7 @@ ntfServerCLIConfig = apnsConfig = defaultAPNSPushClientConfig, inactiveClientExpiration = Nothing, storeLogFile, - resubscribeDelay = 100000, -- 100ms + resubscribeDelay = 50000, -- 50ms caCertificateFile = caCrtFile, privateKeyFile = serverKeyFile, certificateFile = serverCrtFile diff --git a/src/Simplex/Messaging/Notifications/Protocol.hs b/src/Simplex/Messaging/Notifications/Protocol.hs index 28421de66..d7f568509 100644 --- a/src/Simplex/Messaging/Notifications/Protocol.hs +++ b/src/Simplex/Messaging/Notifications/Protocol.hs @@ -412,6 +412,16 @@ data NtfSubStatus NSErr ByteString deriving (Eq, Show) +ntfShouldSubscribe :: NtfSubStatus -> Bool +ntfShouldSubscribe = \case + NSNew -> True + NSPending -> True + NSActive -> True + NSInactive -> True + NSEnd -> False + NSAuth -> False + NSErr _ -> False + instance Encoding NtfSubStatus where smpEncode = \case NSNew -> "NEW" diff --git a/src/Simplex/Messaging/Notifications/Server.hs b/src/Simplex/Messaging/Notifications/Server.hs index 0dca24d99..70c5832b3 100644 --- a/src/Simplex/Messaging/Notifications/Server.hs +++ b/src/Simplex/Messaging/Notifications/Server.hs @@ -80,9 +80,10 @@ ntfServer NtfServerConfig {transports} started = do resubscribe :: (MonadUnliftIO m, MonadReader NtfEnv m) => NtfSubscriber -> Map NtfSubscriptionId NtfSubData -> m () resubscribe NtfSubscriber {newSubQ} subs = do d <- asks $ resubscribeDelay . config - forM_ subs $ \sub -> do - atomically $ writeTBQueue newSubQ $ NtfSub sub - threadDelay d + forM_ subs $ \sub@NtfSubData {} -> + whenM (ntfShouldSubscribe <$> readTVarIO (subStatus sub)) $ do + atomically $ writeTBQueue newSubQ $ NtfSub sub + threadDelay d liftIO $ logInfo "SMP connections resubscribed" ntfSubscriber :: forall m. (MonadUnliftIO m, MonadReader NtfEnv m) => NtfSubscriber -> m ()