From 80894bc198c92f912ef4af015630cb646cde1c9e Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 2 Sep 2022 17:04:15 +1000 Subject: [PATCH] suspend database when call is ended in background --- .../Calls/Call Management/SessionCallManager.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift index d825ba7fd..e6ec78ce9 100644 --- a/Session/Calls/Call Management/SessionCallManager.swift +++ b/Session/Calls/Call Management/SessionCallManager.swift @@ -135,9 +135,17 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { return } - guard let call = currentCall else { + func handleCallEnded() { WebRTCSession.current = nil UserDefaults.sharedLokiProject?.set(false, forKey: "isCallOngoing") + if CurrentAppContext().isInBackground() { + // Suspend the database + NotificationCenter.default.post(name: Database.suspendNotification, object: self) + } + } + + guard let call = currentCall else { + handleCallEnded() return } @@ -157,8 +165,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { call.webRTCSession.dropConnection() self.currentCall = nil - WebRTCSession.current = nil - UserDefaults.sharedLokiProject?.set(false, forKey: "isCallOngoing") + handleCallEnded() } // MARK: - Util