From 55b9aa40890b96309cbbe9c2c17d83ee4b8a3958 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 22 Feb 2018 15:11:29 -0500 Subject: [PATCH] Preserve 'classic' Signal notification and ringtone for legacy users. --- Signal.xcodeproj/project.pbxproj | 8 +++++ SignalMessaging/environment/OWSSounds.h | 3 ++ SignalMessaging/environment/OWSSounds.m | 20 ++++++++++++ .../migrations/OWS107LegacySounds.h | 13 ++++++++ .../migrations/OWS107LegacySounds.m | 31 +++++++++++++++++++ .../migrations/OWSDatabaseMigration.m | 19 +++++++++--- .../migrations/OWSDatabaseMigrationRunner.m | 4 ++- 7 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 SignalMessaging/environment/migrations/OWS107LegacySounds.h create mode 100644 SignalMessaging/environment/migrations/OWS107LegacySounds.m diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index ccd66c588..508eff81f 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -245,6 +245,8 @@ 34E3EF101EFC2684007F6822 /* DebugUIPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E3EF0F1EFC2684007F6822 /* DebugUIPage.m */; }; 34E8BF381EE9E2FD00F5F4CA /* FingerprintViewScanController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34E8BF371EE9E2FD00F5F4CA /* FingerprintViewScanController.m */; }; 34F308A21ECB469700BB7697 /* OWSBezierPathView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F308A11ECB469700BB7697 /* OWSBezierPathView.m */; }; + 34F77040203F55D000C7CBB7 /* OWS107LegacySounds.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F7703E203F55D000C7CBB7 /* OWS107LegacySounds.m */; }; + 34F77041203F55D000C7CBB7 /* OWS107LegacySounds.h in Headers */ = {isa = PBXBuildFile; fileRef = 34F7703F203F55D000C7CBB7 /* OWS107LegacySounds.h */; }; 34FD93701E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 34FD936F1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m */; }; 4505C2BF1E648EA300CEBF41 /* ExperienceUpgrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4505C2BE1E648EA300CEBF41 /* ExperienceUpgrade.swift */; }; 450998651FD8A34D00D89EB3 /* DeviceSleepManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */; }; @@ -849,6 +851,8 @@ 34E8BF371EE9E2FD00F5F4CA /* FingerprintViewScanController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FingerprintViewScanController.m; sourceTree = ""; }; 34F308A01ECB469700BB7697 /* OWSBezierPathView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSBezierPathView.h; sourceTree = ""; }; 34F308A11ECB469700BB7697 /* OWSBezierPathView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSBezierPathView.m; sourceTree = ""; }; + 34F7703E203F55D000C7CBB7 /* OWS107LegacySounds.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWS107LegacySounds.m; sourceTree = ""; }; + 34F7703F203F55D000C7CBB7 /* OWS107LegacySounds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWS107LegacySounds.h; sourceTree = ""; }; 34FD936E1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSAnyTouchGestureRecognizer.h; path = views/OWSAnyTouchGestureRecognizer.h; sourceTree = ""; }; 34FD936F1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSAnyTouchGestureRecognizer.m; path = views/OWSAnyTouchGestureRecognizer.m; sourceTree = ""; }; 435EAC2E5E22D3F087EB3192 /* Pods-SignalShareExtension.app store release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalShareExtension.app store release.xcconfig"; path = "Pods/Target Support Files/Pods-SignalShareExtension/Pods-SignalShareExtension.app store release.xcconfig"; sourceTree = ""; }; @@ -1386,6 +1390,8 @@ 346129F31FD5F31400532771 /* OWS105AttachmentFilePaths.h */, 346129EA1FD5F31300532771 /* OWS105AttachmentFilePaths.m */, 346129F11FD5F31400532771 /* OWS106EnsureProfileComplete.swift */, + 34F7703F203F55D000C7CBB7 /* OWS107LegacySounds.h */, + 34F7703E203F55D000C7CBB7 /* OWS107LegacySounds.m */, 346129931FD1E30000532771 /* OWSDatabaseMigration.h */, 346129941FD1E30000532771 /* OWSDatabaseMigration.m */, 346129E51FD5C0C600532771 /* OWSDatabaseMigrationRunner.h */, @@ -2208,6 +2214,7 @@ 34480B551FD0A7A400BC14EF /* DebugLogger.h in Headers */, 344F248420069E9C00CFB4F4 /* CountryCodeViewController.h in Headers */, 346129CA1FD2072E00532771 /* UIImage+OWS.h in Headers */, + 34F77041203F55D000C7CBB7 /* OWS107LegacySounds.h in Headers */, 346129711FD1D74C00532771 /* SignalKeyingStorage.h in Headers */, 34612A011FD5F31400532771 /* OWS104CreateRecipientIdentities.h in Headers */, 450998691FD8C10200D89EB3 /* AttachmentSharing.h in Headers */, @@ -2959,6 +2966,7 @@ files = ( 45F59A0A2029140500E8D2B0 /* OWSVideoPlayer.swift in Sources */, 344F249B200FD03300CFB4F4 /* SharingThreadPickerViewController.m in Sources */, + 34F77040203F55D000C7CBB7 /* OWS107LegacySounds.m in Sources */, 45194F951FD7216600333B2C /* TSUnreadIndicatorInteraction.m in Sources */, 45BE4EA22012AD2000935E59 /* DisappearingTimerConfigurationView.swift in Sources */, 346129F71FD5F31400532771 /* OWS105AttachmentFilePaths.m in Sources */, diff --git a/SignalMessaging/environment/OWSSounds.h b/SignalMessaging/environment/OWSSounds.h index e01d09053..ea4540658 100644 --- a/SignalMessaging/environment/OWSSounds.h +++ b/SignalMessaging/environment/OWSSounds.h @@ -64,6 +64,7 @@ typedef NS_ENUM(NSUInteger, OWSSound) { @class AVAudioPlayer; @class TSThread; +@class YapDatabaseReadWriteTransaction; @interface OWSSounds : NSObject @@ -81,6 +82,7 @@ typedef NS_ENUM(NSUInteger, OWSSound) { + (OWSSound)globalNotificationSound; + (void)setGlobalNotificationSound:(OWSSound)sound; ++ (void)setGlobalNotificationSound:(OWSSound)sound transaction:(YapDatabaseReadWriteTransaction *)transaction; + (OWSSound)notificationSoundForThread:(TSThread *)thread; + (void)setNotificationSound:(OWSSound)sound forThread:(TSThread *)thread; @@ -91,6 +93,7 @@ typedef NS_ENUM(NSUInteger, OWSSound) { + (OWSSound)globalRingtoneSound; + (void)setGlobalRingtoneSound:(OWSSound)sound; ++ (void)setGlobalRingtoneSound:(OWSSound)sound transaction:(YapDatabaseReadWriteTransaction *)transaction; + (OWSSound)ringtoneSoundForThread:(TSThread *)thread; + (void)setRingtoneSound:(OWSSound)sound forThread:(TSThread *)thread; diff --git a/SignalMessaging/environment/OWSSounds.m b/SignalMessaging/environment/OWSSounds.m index d092f1775..f25a80512 100644 --- a/SignalMessaging/environment/OWSSounds.m +++ b/SignalMessaging/environment/OWSSounds.m @@ -7,6 +7,7 @@ #import #import #import +#import NSString *const kOWSSoundsStorageNotificationCollection = @"kOWSSoundsStorageNotificationCollection"; NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlobalNotificationKey"; @@ -388,6 +389,15 @@ NSString *const kOWSSoundsStorageGlobalRingtoneKey = @"kOWSSoundsStorageGlobalRi inCollection:kOWSSoundsStorageNotificationCollection]; } ++ (void)setGlobalNotificationSound:(OWSSound)sound transaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction); + + [transaction setObject:@(sound) + forKey:kOWSSoundsStorageGlobalNotificationKey + inCollection:kOWSSoundsStorageNotificationCollection]; +} + + (OWSSound)notificationSoundForThread:(TSThread *)thread { OWSSounds *instance = OWSSounds.sharedManager; @@ -429,6 +439,16 @@ NSString *const kOWSSoundsStorageGlobalRingtoneKey = @"kOWSSoundsStorageGlobalRi inCollection:kOWSSoundsStorageRingtoneCollection]; } + ++ (void)setGlobalRingtoneSound:(OWSSound)sound transaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction); + + [transaction setObject:@(sound) + forKey:kOWSSoundsStorageGlobalRingtoneKey + inCollection:kOWSSoundsStorageRingtoneCollection]; +} + + (OWSSound)ringtoneSoundForThread:(TSThread *)thread { OWSSounds *instance = OWSSounds.sharedManager; diff --git a/SignalMessaging/environment/migrations/OWS107LegacySounds.h b/SignalMessaging/environment/migrations/OWS107LegacySounds.h new file mode 100644 index 000000000..f6e75f382 --- /dev/null +++ b/SignalMessaging/environment/migrations/OWS107LegacySounds.h @@ -0,0 +1,13 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +#import "OWSDatabaseMigration.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OWS107LegacySounds : OWSDatabaseMigration + +@end + +NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/environment/migrations/OWS107LegacySounds.m b/SignalMessaging/environment/migrations/OWS107LegacySounds.m new file mode 100644 index 000000000..4150483c8 --- /dev/null +++ b/SignalMessaging/environment/migrations/OWS107LegacySounds.m @@ -0,0 +1,31 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +#import "OWS107LegacySounds.h" +#import "OWSSounds.h" +#import + +NS_ASSUME_NONNULL_BEGIN + +// Increment a similar constant for every future DBMigration +static NSString *const OWS107LegacySoundsMigrationId = @"107"; + +@implementation OWS107LegacySounds + ++ (NSString *)migrationId +{ + return OWS107LegacySoundsMigrationId; +} + +- (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction); + + [OWSSounds setGlobalNotificationSound:OWSSound_ClassicNotification transaction:transaction]; + [OWSSounds setGlobalRingtoneSound:OWSSound_ClassicRingtone transaction:transaction]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/environment/migrations/OWSDatabaseMigration.m b/SignalMessaging/environment/migrations/OWSDatabaseMigration.m index a40a25158..052370c6b 100644 --- a/SignalMessaging/environment/migrations/OWSDatabaseMigration.m +++ b/SignalMessaging/environment/migrations/OWSDatabaseMigration.m @@ -50,10 +50,21 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(completion); - [self.storageManager.newDatabaseConnection - asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { - [self runUpWithTransaction:transaction]; - } + OWSDatabaseConnection *dbConnection = (OWSDatabaseConnection *)self.storageManager.newDatabaseConnection; + // These migrations won't be run until storage registrations are enqueued, + // but this transaction might begin before all registrations are marked as + // complete, so disable this checking. + // + // TODO: Once we move "app readiness" into AppSetup, we should explicitly + // not start these migrations until storage is ready. We can then remove + // this statement which disables checking. +#ifdef DEBUG + dbConnection.canWriteBeforeStorageReady = YES; +#endif + + [dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { + [self runUpWithTransaction:transaction]; + } completionBlock:^{ DDLogInfo(@"Completed migration %@", self.uniqueId); [self save]; diff --git a/SignalMessaging/environment/migrations/OWSDatabaseMigrationRunner.m b/SignalMessaging/environment/migrations/OWSDatabaseMigrationRunner.m index 88863cae4..c44054702 100644 --- a/SignalMessaging/environment/migrations/OWSDatabaseMigrationRunner.m +++ b/SignalMessaging/environment/migrations/OWSDatabaseMigrationRunner.m @@ -8,6 +8,7 @@ #import "OWS103EnableVideoCalling.h" #import "OWS104CreateRecipientIdentities.h" #import "OWS105AttachmentFilePaths.h" +#import "OWS107LegacySounds.h" #import "OWSDatabaseMigration.h" #import #import @@ -38,7 +39,8 @@ NS_ASSUME_NONNULL_BEGIN [[OWS103EnableVideoCalling alloc] initWithStorageManager:storageManager], [[OWS104CreateRecipientIdentities alloc] initWithStorageManager:storageManager], [[OWS105AttachmentFilePaths alloc] initWithStorageManager:storageManager], - [[OWS106EnsureProfileComplete alloc] initWithStorageManager:storageManager] + [[OWS106EnsureProfileComplete alloc] initWithStorageManager:storageManager], + [[OWS107LegacySounds alloc] initWithStorageManager:storageManager], ]; }