Imitate Android's behavior of delaying local notifications based on incoming sync messages.
This commit is contained in:
parent
7730b78d86
commit
21e9f57cbe
|
@ -9,6 +9,7 @@
|
|||
#import "Signal-Swift.h"
|
||||
#import "ThreadUtil.h"
|
||||
#import <SignalServiceKit/NSDate+OWS.h>
|
||||
#import <SignalServiceKit/OWSDevice.h>
|
||||
#import <SignalServiceKit/OWSMessageReceiver.h>
|
||||
#import <SignalServiceKit/OWSMessageSender.h>
|
||||
#import <SignalServiceKit/OWSReadReceiptManager.h>
|
||||
|
@ -440,10 +441,17 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
|
|||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
||||
if (checkForCancel && threadId != nil) {
|
||||
// The longer we wait, the more obsolete notifications we can suppress -
|
||||
// but the more lag we introduce to notification delivery.
|
||||
const CGFloat kDelaySeconds = 0.5f;
|
||||
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:kDelaySeconds];
|
||||
if ([[OWSDeviceManager sharedManager] hasReceivedSyncMessageInLastSeconds:60.f]) {
|
||||
// "If you’ve heard from desktop in last minute, wait 5 seconds."
|
||||
//
|
||||
// This provides a window in which we can cancel notifications
|
||||
// already viewed on desktop before they are presented here.
|
||||
const CGFloat kDelaySeconds = 5.f;
|
||||
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:kDelaySeconds];
|
||||
} else {
|
||||
notification.fireDate = [NSDate new];
|
||||
}
|
||||
|
||||
notification.timeZone = [NSTimeZone localTimeZone];
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ extern uint32_t const OWSDevicePrimaryDeviceId;
|
|||
- (BOOL)mayHaveLinkedDevices:(YapDatabaseConnection *)dbConnection;
|
||||
- (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection;
|
||||
|
||||
- (BOOL)hasReceivedSyncMessageInLastSeconds:(NSTimeInterval)intervalSeconds;
|
||||
- (void)setHasReceivedSyncMessage;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
|
|
@ -19,6 +19,7 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
|
|||
@interface OWSDeviceManager ()
|
||||
|
||||
@property (atomic, nullable) NSNumber *mayHaveLinkedDevicesCached;
|
||||
@property (atomic) NSDate *lastReceivedSyncMessage;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -73,6 +74,16 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)hasReceivedSyncMessageInLastSeconds:(NSTimeInterval)intervalSeconds
|
||||
{
|
||||
return (self.lastReceivedSyncMessage && fabs(self.lastReceivedSyncMessage.timeIntervalSinceNow) < intervalSeconds);
|
||||
}
|
||||
|
||||
- (void)setHasReceivedSyncMessage
|
||||
{
|
||||
self.lastReceivedSyncMessage = [NSDate new];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#import "OWSAttachmentsProcessor.h"
|
||||
#import "OWSBlockingManager.h"
|
||||
#import "OWSCallMessageHandler.h"
|
||||
#import "OWSDevice.h"
|
||||
#import "OWSDisappearingConfigurationUpdateInfoMessage.h"
|
||||
#import "OWSDisappearingMessagesConfiguration.h"
|
||||
#import "OWSDisappearingMessagesJob.h"
|
||||
|
@ -267,6 +268,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
if (content.hasSyncMessage) {
|
||||
[self handleIncomingEnvelope:envelope withSyncMessage:content.syncMessage transaction:transaction];
|
||||
|
||||
[[OWSDeviceManager sharedManager] setHasReceivedSyncMessage];
|
||||
} else if (content.hasDataMessage) {
|
||||
[self handleIncomingEnvelope:envelope withDataMessage:content.dataMessage transaction:transaction];
|
||||
} else if (content.hasCallMessage) {
|
||||
|
|
Loading…
Reference in New Issue