From d79fcdc0af1fddd5732f73e704fcf3bc7c0b21c1 Mon Sep 17 00:00:00 2001 From: kkostiuk <kateryna.kostiuk@savoirfairelinux.com> Date: Fri, 28 May 2021 17:04:51 -0400 Subject: [PATCH] presence: fix updates when app returns to active state Change-Id: I2db33cb2efbdafe9bdb4b212abb89520d2b2c7d4 --- Ring/Ring/AppDelegate.swift | 7 +++++++ Ring/Ring/Services/PresenceService.swift | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/Ring/Ring/AppDelegate.swift b/Ring/Ring/AppDelegate.swift index 8e400b3e2..998c6bf5c 100644 --- a/Ring/Ring/AppDelegate.swift +++ b/Ring/Ring/AppDelegate.swift @@ -269,6 +269,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func applicationDidBecomeActive(_ application: UIApplication) { self.clearBadgeNumber() + guard let account = self.accountService.currentAccount else { return } + self.presenceService.subscribeBuddies(withAccount: account.id, withContacts: self.contactsService.contacts.value, subscribe: true) + } + + func applicationWillResignActive(_ application: UIApplication) { + guard let account = self.accountService.currentAccount else { return } + self.presenceService.subscribeBuddies(withAccount: account.id, withContacts: self.contactsService.contacts.value, subscribe: false) } func prepareVideoAcceleration() { diff --git a/Ring/Ring/Services/PresenceService.swift b/Ring/Ring/Services/PresenceService.swift index 8c7c8700a..86f086acd 100644 --- a/Ring/Ring/Services/PresenceService.swift +++ b/Ring/Ring/Services/PresenceService.swift @@ -57,6 +57,10 @@ class PresenceService { func subscribeBuddy(withAccountId accountId: String, withUri uri: String, withFlag flag: Bool) { + if flag && contactPresence[uri] != nil { + // already subscribed + return + } presenceAdapter.subscribeBuddy(withURI: uri, withAccountId: accountId, withFlag: flag) if !flag { contactPresence[uri] = nil -- GitLab