Refine NSE completion.
This commit is contained in:
parent
fc45ec8f63
commit
f511ca35df
@ -58,14 +58,7 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
}
|
||||
Logger.flush()
|
||||
|
||||
let isSync = timeHasExpired
|
||||
if isSync {
|
||||
contentHandler(content)
|
||||
} else {
|
||||
DispatchQueue.global().asyncAfter(deadline: .now() + .milliseconds(1000)) {
|
||||
contentHandler(content)
|
||||
}
|
||||
}
|
||||
contentHandler(content)
|
||||
}
|
||||
|
||||
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
||||
@ -150,11 +143,17 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
}.catch { _ in
|
||||
// Do nothing, Promise.timeout() will log timeouts.
|
||||
}
|
||||
fetchPromise.then { [weak self] () -> Promise<Void> in
|
||||
fetchPromise.then(on: .global()) { [weak self] () -> Promise<Void> in
|
||||
Logger.info("Waiting for processing to complete.")
|
||||
guard let self = self else { return Promise.value(()) }
|
||||
let processingCompletePromise = self.messageProcessor.processingCompletePromise()
|
||||
processingCompletePromise.timeout(seconds: 20, description: "Message Processing Timeout.") {
|
||||
processingCompletePromise.then(on: .global()) {
|
||||
// Wait until all ACKs are enqueued.
|
||||
Self.messageFetcherJob.pendingAcksPromise()
|
||||
}.then(on: .global()) {
|
||||
// Wait until all outgoing messages are sent.
|
||||
Self.messageSender.pendingSendsPromise()
|
||||
}.timeout(seconds: 20, description: "Message Processing Timeout.") {
|
||||
NotificationServiceError.timeout
|
||||
}.catch { _ in
|
||||
// Do nothing, Promise.timeout() will log timeouts.
|
||||
|
||||
@ -273,6 +273,12 @@ public class MessageFetcherJob: NSObject {
|
||||
ackOperationQueue.addOperation(ackOperation)
|
||||
}
|
||||
|
||||
public func pendingAcksPromise() -> Promise<Void> {
|
||||
firstly(on: .global()) {
|
||||
self.ackOperationQueue.waitUntilAllOperationsAreFinished()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
typealias EnvelopeJob = MessageProcessor.EnvelopeJob
|
||||
|
||||
@ -654,15 +654,15 @@ private struct EncryptedEnvelope: PendingEnvelope, Dependencies {
|
||||
guard let other = other as? EncryptedEnvelope else {
|
||||
return false
|
||||
}
|
||||
// serverDeliveryTimestamp is a cheaper comparison and is likely
|
||||
// to eliminate most candidates.
|
||||
guard self.serverDeliveryTimestamp == other.serverDeliveryTimestamp else {
|
||||
guard let serverGuid = encryptedEnvelope.serverGuid else {
|
||||
owsFailDebug("Missing serverGuid.")
|
||||
return false
|
||||
}
|
||||
guard self.encryptedEnvelopeData == other.encryptedEnvelopeData else {
|
||||
guard let otherServerGuid = other.encryptedEnvelope.serverGuid else {
|
||||
owsFailDebug("Missing other.serverGuid.")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return serverGuid == otherServerGuid
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -101,6 +101,9 @@ NS_SWIFT_NAME(OutgoingAttachmentInfo)
|
||||
// TODO: Make this private.
|
||||
- (void)sendMessageToRecipient:(OWSMessageSend *)messageSend;
|
||||
|
||||
// TODO: Make this private.
|
||||
+ (NSOperationQueue *)globalSendingQueue;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@ -152,6 +152,12 @@ extension MessageSender {
|
||||
}
|
||||
return promises
|
||||
}
|
||||
|
||||
public func pendingSendsPromise() -> Promise<Void> {
|
||||
firstly(on: .global()) {
|
||||
Self.globalSendingQueue().waitUntilAllOperationsAreFinished()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
Loading…
Reference in New Issue
Block a user