move database suspending logic when handling calls in background after writeAsync

pull/687/head
ryanzhao 2 years ago
parent 9419f83f43
commit 7c1d332763

@ -278,8 +278,8 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
let duration: TimeInterval = self.duration
let hasStartedConnecting: Bool = self.hasStartedConnecting
// Don't know whether there will be an impact if we don't write async
Storage.shared.write { db in
Storage.shared.writeAsync(
updates: { db in
guard let interaction: Interaction = try? Interaction.fetchOne(db, id: callInteractionId) else {
return
}
@ -327,8 +327,17 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
includingOlder: false,
trySendReadReceipt: false
)
},
completion: { _, _ in
if CurrentAppContext().isInBackground() {
// Stop all jobs except for message sending and when completed suspend the database
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend) {
NotificationCenter.default.post(name: Database.suspendNotification, object: self)
}
}
}
)
}
// MARK: - Renderer

@ -136,12 +136,6 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
func handleCallEnded() {
WebRTCSession.current = nil
UserDefaults.sharedLokiProject?.set(false, forKey: "isCallOngoing")
if CurrentAppContext().isInBackground() {
// Stop all jobs except for message sending and when completed suspend the database
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend) {
NotificationCenter.default.post(name: Database.suspendNotification, object: self)
}
}
}
guard let call = currentCall else {

Loading…
Cancel
Save