diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 223573e4e..dd905600a 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -68,7 +68,6 @@ 34B3F89F1E8DF5490035BE1A /* OWSTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */; }; 34B3F8A21E8EA6040035BE1A /* ViewControllerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F8A11E8EA6040035BE1A /* ViewControllerUtils.m */; }; 34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */; }; - 34D5CCA61EA934A4005515DB /* NSTimer+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA51EA934A4005515DB /* NSTimer+OWS.m */; }; 34D5CCA91EAE3D30005515DB /* GroupViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */; }; 34D5CCB11EAE7E7F005515DB /* SelectRecipientViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */; }; 34DFCB851E8E04B500053165 /* AddToBlockListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DFCB841E8E04B500053165 /* AddToBlockListViewController.m */; }; @@ -452,8 +451,8 @@ 34B3F86E1E8DF1700035BE1A /* SignalsNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SignalsNavigationController.m; sourceTree = ""; }; 34B3F86F1E8DF1700035BE1A /* SignalsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SignalsViewController.h; sourceTree = ""; }; 34B3F8701E8DF1700035BE1A /* SignalsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SignalsViewController.m; sourceTree = ""; }; - 34B3F89A1E8DF3270035BE1A /* BlockListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockListViewController.h; sourceTree = ""; }; 34B3F8981E8DF1B90035BE1A /* TSMessageAdapterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSMessageAdapterTest.m; sourceTree = ""; }; + 34B3F89A1E8DF3270035BE1A /* BlockListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockListViewController.h; sourceTree = ""; }; 34B3F89B1E8DF3270035BE1A /* BlockListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BlockListViewController.m; sourceTree = ""; }; 34B3F89D1E8DF5490035BE1A /* OWSTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSTableViewController.h; sourceTree = ""; }; 34B3F89E1E8DF5490035BE1A /* OWSTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSTableViewController.m; sourceTree = ""; }; @@ -463,8 +462,6 @@ 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsSyncing.m; sourceTree = ""; }; 34D5CC981EA6EB79005515DB /* OWSMessageCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageCollectionViewCell.h; sourceTree = ""; }; 34D5CC9B1EA6ED17005515DB /* OWSMessageMediaAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageMediaAdapter.h; sourceTree = ""; }; - 34D5CCA41EA934A4005515DB /* NSTimer+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTimer+OWS.h"; sourceTree = ""; }; - 34D5CCA51EA934A4005515DB /* NSTimer+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSTimer+OWS.m"; sourceTree = ""; }; 34D5CCA71EAE3D30005515DB /* GroupViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GroupViewHelper.h; sourceTree = ""; }; 34D5CCA81EAE3D30005515DB /* GroupViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GroupViewHelper.m; sourceTree = ""; }; 34D5CCAB1EAE7136005515DB /* OWSConversationSettingsViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSConversationSettingsViewDelegate.h; sourceTree = ""; }; @@ -1249,8 +1246,6 @@ 76EB04EB18170B33006006FC /* FunctionalUtil.m */, B62F5E0E1C2980B4000D370C /* NSData+ows_StripToken.h */, B62F5E0F1C2980B4000D370C /* NSData+ows_StripToken.m */, - 34D5CCA41EA934A4005515DB /* NSTimer+OWS.h */, - 34D5CCA51EA934A4005515DB /* NSTimer+OWS.m */, 76EB04EC18170B33006006FC /* NumberUtil.h */, 76EB04ED18170B33006006FC /* NumberUtil.m */, BFB074C519A5611000F2947C /* ObservableValue.h */, @@ -2120,7 +2115,6 @@ 34B3F88D1E8DF1700035BE1A /* OWSQRCodeScanningViewController.m in Sources */, 34B3F8811E8DF1700035BE1A /* LockInteractionController.m in Sources */, 45F659731E1BD99C00444429 /* CallKitCallUIAdaptee.swift in Sources */, - 34D5CCA61EA934A4005515DB /* NSTimer+OWS.m in Sources */, 45BB93381E688E14001E3939 /* UIDevice+featureSupport.swift in Sources */, 458DE9D61DEE3FD00071BB03 /* PeerConnectionClient.swift in Sources */, 451DE9FD1DC1A28200810E42 /* SyncPushTokensJob.swift in Sources */, diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index b3289cdfa..5f8dde919 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -153,8 +153,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; preferences:[Environment preferences] showAlerts:NO]; - // Clean up any messages that expired since last launch. - [[[OWSDisappearingMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]] run]; + // Clean up any messages that expired since last launch immediately + // and continue cleaning in the background. + [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; // Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully // sent before the app exited should be marked as failures. diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index 53aa1c54b..55fde2b9e 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -12,7 +12,6 @@ #import "FingerprintViewController.h" #import "FullImageViewController.h" #import "NSDate+millisecondTimeStamp.h" -#import "NSTimer+OWS.h" #import "NewGroupViewController.h" #import "OWSAudioAttachmentPlayer.h" #import "OWSCall.h" @@ -61,6 +60,7 @@ #import #import #import +#import #import #import #import @@ -557,7 +557,6 @@ typedef enum : NSUInteger { @property (nonatomic, readonly) ContactsUpdater *contactsUpdater; @property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) TSStorageManager *storageManager; -@property (nonatomic, readonly) OWSDisappearingMessagesJob *disappearingMessagesJob; @property (nonatomic, readonly) TSMessagesManager *messagesManager; @property (nonatomic, readonly) TSNetworkManager *networkManager; @property (nonatomic, readonly) OutboundCallInitiator *outboundCallInitiator; @@ -617,7 +616,6 @@ typedef enum : NSUInteger { _messageSender = [Environment getCurrent].messageSender; _outboundCallInitiator = [Environment getCurrent].outboundCallInitiator; _storageManager = [TSStorageManager sharedManager]; - _disappearingMessagesJob = [[OWSDisappearingMessagesJob alloc] initWithStorageManager:_storageManager]; _messagesManager = [TSMessagesManager sharedManager]; _networkManager = [TSNetworkManager sharedManager]; _blockingManager = [OWSBlockingManager sharedManager]; @@ -3257,9 +3255,10 @@ typedef enum : NSUInteger { - (void)markAllMessagesAsRead { [self.thread markAllAsRead]; + // In theory this should be unnecessary as read-status starts expiration // but in practice I've seen messages not have their timer started. - [self.disappearingMessagesJob setExpirationsForThread:self.thread]; + [OWSDisappearingMessagesJob setExpirationsForThread:self.thread]; } - (BOOL)collectionView:(UICollectionView *)collectionView diff --git a/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m b/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m index bca418e2b..afd67594d 100644 --- a/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m +++ b/Signal/src/ViewControllers/OWSAudioAttachmentPlayer.m @@ -3,11 +3,11 @@ // #import "OWSAudioAttachmentPlayer.h" -#import "NSTimer+OWS.h" #import "TSAttachment.h" #import "TSAttachmentStream.h" #import "TSVideoAttachmentAdapter.h" #import "ViewControllerUtils.h" +#import #import NS_ASSUME_NONNULL_BEGIN diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index abcf37aa5..ba1a589cd 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -19,6 +19,7 @@ #import "UIUtil.h" #import "VersionMigrations.h" #import +#import #import #import #import @@ -318,6 +319,10 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS [self.experienceUpgradeFinder markAllAsSeenWithTransaction:transaction]; }]; [self ensureNotificationsUpToDate]; + + // Clean up any messages that expired since last launch immediately + // and continue cleaning in the background. + [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; } else { [self displayAnyUnseenUpgradeExperience]; } diff --git a/Signal/src/util/NSTimer+OWS.h b/Signal/src/util/NSTimer+OWS.h deleted file mode 100644 index e301b39b0..000000000 --- a/Signal/src/util/NSTimer+OWS.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. -// - -NS_ASSUME_NONNULL_BEGIN - -@interface NSTimer (OWS) - -// This method avoids the classic NSTimer retain cycle bug -// by using a weak reference to the target. -+ (NSTimer *)weakScheduledTimerWithTimeInterval:(NSTimeInterval)timeInterval - target:(id)target - selector:(SEL)selector - userInfo:(nullable id)userInfo - repeats:(BOOL)repeats; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Signal/src/util/NSTimer+OWS.m b/Signal/src/util/NSTimer+OWS.m deleted file mode 100644 index 6abc56790..000000000 --- a/Signal/src/util/NSTimer+OWS.m +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. -// - -#import "NSTimer+OWS.h" -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface NSTimerProxy : NSObject - -@property (nonatomic, weak) id target; -@property (nonatomic) SEL selector; - -@end - -#pragma mark - - -@implementation NSTimerProxy - -- (void)timerFired:(NSDictionary *)userInfo -{ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Warc-performSelector-leaks" - [self.target performSelector:self.selector withObject:userInfo]; -#pragma clang diagnostic pop -} - -@end - -#pragma mark - - -static void *kNSTimer_OWS_Proxy = &kNSTimer_OWS_Proxy; - -@implementation NSTimer (OWS) - -- (NSTimerProxy *)ows_proxy -{ - return objc_getAssociatedObject(self, kNSTimer_OWS_Proxy); -} - -- (void)ows_setProxy:(NSTimerProxy *)proxy -{ - OWSAssert(proxy); - - objc_setAssociatedObject(self, kNSTimer_OWS_Proxy, proxy, OBJC_ASSOCIATION_RETAIN); -} - -+ (NSTimer *)weakScheduledTimerWithTimeInterval:(NSTimeInterval)timeInterval - target:(id)target - selector:(SEL)selector - userInfo:(nullable id)userInfo - repeats:(BOOL)repeats -{ - NSTimerProxy *proxy = [NSTimerProxy new]; - proxy.target = target; - proxy.selector = selector; - NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval - target:proxy - selector:@selector(timerFired:) - userInfo:userInfo - repeats:repeats]; - [timer ows_setProxy:proxy]; - return timer; -} - -@end - -NS_ASSUME_NONNULL_END