diff --git a/Ring/Ring/AppDelegate.swift b/Ring/Ring/AppDelegate.swift index 8e400b3e258b87b193834a56c1e22580bb08edf6..998c6bf5cbbe5381a7ef91d350e02bb9755e09f1 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 8c7c8700a53c4915c48c76b8fa8e9dcad94d04a3..86f086acd55b9134cfc777465827bee1e243d6ac 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