mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
resume ans suspend database properly in extensions
This commit is contained in:
parent
3cfee13768
commit
afc862d1c1
2 changed files with 16 additions and 4 deletions
|
@ -25,6 +25,9 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
|
||||||
self.contentHandler = contentHandler
|
self.contentHandler = contentHandler
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
|
// Resume database
|
||||||
|
NotificationCenter.default.post(name: Database.resumeNotification, object: self)
|
||||||
|
|
||||||
guard let notificationContent = request.content.mutableCopy() as? UNMutableNotificationContent else {
|
guard let notificationContent = request.content.mutableCopy() as? UNMutableNotificationContent else {
|
||||||
return self.completeSilenty()
|
return self.completeSilenty()
|
||||||
}
|
}
|
||||||
|
@ -237,6 +240,10 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
|
||||||
|
|
||||||
private func completeSilenty() {
|
private func completeSilenty() {
|
||||||
SNLog("Complete silenty")
|
SNLog("Complete silenty")
|
||||||
|
|
||||||
|
// Suspend the database
|
||||||
|
NotificationCenter.default.post(name: Database.suspendNotification, object: self)
|
||||||
|
|
||||||
self.contentHandler!(.init())
|
self.contentHandler!(.init())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,11 +305,10 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
|
||||||
SNLog("Add remote notification request")
|
SNLog("Add remote notification request")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleSuccess(for content: UNMutableNotificationContent) {
|
|
||||||
contentHandler!(content)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func handleFailure(for content: UNMutableNotificationContent) {
|
private func handleFailure(for content: UNMutableNotificationContent) {
|
||||||
|
// Suspend the database
|
||||||
|
NotificationCenter.default.post(name: Database.suspendNotification, object: self)
|
||||||
|
|
||||||
content.body = "You've got a new message"
|
content.body = "You've got a new message"
|
||||||
content.title = "Session"
|
content.title = "Session"
|
||||||
let userInfo: [String:Any] = [ NotificationServiceExtension.isFromRemoteKey : true ]
|
let userInfo: [String:Any] = [ NotificationServiceExtension.isFromRemoteKey : true ]
|
||||||
|
|
|
@ -220,6 +220,8 @@ final class ThreadPickerVC: UIViewController, UITableViewDataSource, UITableView
|
||||||
shareVC?.dismiss(animated: true, completion: nil)
|
shareVC?.dismiss(animated: true, completion: nil)
|
||||||
|
|
||||||
ModalActivityIndicatorViewController.present(fromViewController: shareVC!, canCancel: false, message: "vc_share_sending_message".localized()) { activityIndicator in
|
ModalActivityIndicatorViewController.present(fromViewController: shareVC!, canCancel: false, message: "vc_share_sending_message".localized()) { activityIndicator in
|
||||||
|
// Resume database
|
||||||
|
NotificationCenter.default.post(name: Database.resumeNotification, object: self)
|
||||||
Storage.shared
|
Storage.shared
|
||||||
.writeAsync { [weak self] db -> Promise<Void> in
|
.writeAsync { [weak self] db -> Promise<Void> in
|
||||||
guard let thread: SessionThread = try SessionThread.fetchOne(db, id: threadId) else {
|
guard let thread: SessionThread = try SessionThread.fetchOne(db, id: threadId) else {
|
||||||
|
@ -271,10 +273,14 @@ final class ThreadPickerVC: UIViewController, UITableViewDataSource, UITableView
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.done { [weak self] _ in
|
.done { [weak self] _ in
|
||||||
|
// Suspend the database
|
||||||
|
NotificationCenter.default.post(name: Database.suspendNotification, object: self)
|
||||||
activityIndicator.dismiss { }
|
activityIndicator.dismiss { }
|
||||||
self?.shareVC?.shareViewWasCompleted()
|
self?.shareVC?.shareViewWasCompleted()
|
||||||
}
|
}
|
||||||
.catch { [weak self] error in
|
.catch { [weak self] error in
|
||||||
|
// Suspend the database
|
||||||
|
NotificationCenter.default.post(name: Database.suspendNotification, object: self)
|
||||||
activityIndicator.dismiss { }
|
activityIndicator.dismiss { }
|
||||||
self?.shareVC?.shareViewFailed(error: error)
|
self?.shareVC?.shareViewFailed(error: error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue