From 4b83b4afc5fb6d6855f12ffe7ac3ede80fd576e1 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 23 Apr 2018 11:04:46 -0400 Subject: [PATCH] Rework outgoing message state. --- Signal.xcodeproj/project.pbxproj | 8 ++++ .../migrations/OWS109OutgoingMessageState.h | 13 +++++ .../migrations/OWS109OutgoingMessageState.m | 47 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 SignalMessaging/environment/migrations/OWS109OutgoingMessageState.h create mode 100644 SignalMessaging/environment/migrations/OWS109OutgoingMessageState.m diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 7ba4351de..19a99d0c1 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -214,6 +214,8 @@ 34D2CCDA2062E7D000CB1A14 /* OWSScreenLockUI.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D2CCD92062E7D000CB1A14 /* OWSScreenLockUI.m */; }; 34D2CCDF206939B400CB1A14 /* DebugUIMessagesAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D2CCDB206939B100CB1A14 /* DebugUIMessagesAction.m */; }; 34D2CCE0206939B400CB1A14 /* DebugUIMessagesAssetLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D2CCDC206939B200CB1A14 /* DebugUIMessagesAssetLoader.m */; }; + 34D5872F208E2C4200D2255A /* OWS109OutgoingMessageState.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5872D208E2C4100D2255A /* OWS109OutgoingMessageState.m */; }; + 34D58730208E2C4200D2255A /* OWS109OutgoingMessageState.h in Headers */ = {isa = PBXBuildFile; fileRef = 34D5872E208E2C4100D2255A /* OWS109OutgoingMessageState.h */; }; 34D5CCA91EAE3D30005515DB /* AvatarViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* AvatarViewHelper.m */; }; 34D8C0271ED3673300188D7C /* DebugUIMessages.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C0241ED3673300188D7C /* DebugUIMessages.m */; }; 34D8C0281ED3673300188D7C /* DebugUITableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C0261ED3673300188D7C /* DebugUITableViewController.m */; }; @@ -847,6 +849,8 @@ 34D2CCDD206939B200CB1A14 /* DebugUIMessagesAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIMessagesAction.h; sourceTree = ""; }; 34D2CCDE206939B400CB1A14 /* DebugUIMessagesAssetLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIMessagesAssetLoader.h; sourceTree = ""; }; 34D2CCE220693A1700CB1A14 /* DebugUIMessagesUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIMessagesUtils.h; sourceTree = ""; }; + 34D5872D208E2C4100D2255A /* OWS109OutgoingMessageState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWS109OutgoingMessageState.m; sourceTree = ""; }; + 34D5872E208E2C4100D2255A /* OWS109OutgoingMessageState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWS109OutgoingMessageState.h; sourceTree = ""; }; 34D5CCA71EAE3D30005515DB /* AvatarViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AvatarViewHelper.h; sourceTree = ""; }; 34D5CCA81EAE3D30005515DB /* AvatarViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AvatarViewHelper.m; sourceTree = ""; }; 34D8C0231ED3673300188D7C /* DebugUIMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugUIMessages.h; sourceTree = ""; }; @@ -1525,6 +1529,8 @@ 4503F1C1204711D200CEE724 /* OWS107LegacySounds.m */, 4598198C204E2F28009414F2 /* OWS108CallLoggingPreference.h */, 4598198D204E2F28009414F2 /* OWS108CallLoggingPreference.m */, + 34D5872E208E2C4100D2255A /* OWS109OutgoingMessageState.h */, + 34D5872D208E2C4100D2255A /* OWS109OutgoingMessageState.m */, 346129931FD1E30000532771 /* OWSDatabaseMigration.h */, 346129941FD1E30000532771 /* OWSDatabaseMigration.m */, 346129E51FD5C0C600532771 /* OWSDatabaseMigrationRunner.h */, @@ -2379,6 +2385,7 @@ 34480B611FD0A98800BC14EF /* UIColor+OWS.h in Headers */, 453518961FC63DBF00210559 /* SignalMessaging.h in Headers */, 3461295A1FD1D74C00532771 /* Environment.h in Headers */, + 34D58730208E2C4200D2255A /* OWS109OutgoingMessageState.h in Headers */, 4598198E204E2F28009414F2 /* OWS108CallLoggingPreference.h in Headers */, 34480B631FD0A98800BC14EF /* UIView+OWS.h in Headers */, 451F8A4B1FD715E1005CB9DA /* OWSGroupAvatarBuilder.h in Headers */, @@ -3045,6 +3052,7 @@ 451F8A3D1FD713CA005CB9DA /* ThreadViewHelper.m in Sources */, 346129AD1FD1F34E00532771 /* ImageCache.swift in Sources */, 452C7CA72037628B003D51A5 /* Weak.swift in Sources */, + 34D5872F208E2C4200D2255A /* OWS109OutgoingMessageState.m in Sources */, 451F8A341FD710C3005CB9DA /* ConversationSearcher.swift in Sources */, 346129341FD1A88700532771 /* OWSSwiftUtils.swift in Sources */, 346129FE1FD5F31400532771 /* OWS106EnsureProfileComplete.swift in Sources */, diff --git a/SignalMessaging/environment/migrations/OWS109OutgoingMessageState.h b/SignalMessaging/environment/migrations/OWS109OutgoingMessageState.h new file mode 100644 index 000000000..b50e89d0c --- /dev/null +++ b/SignalMessaging/environment/migrations/OWS109OutgoingMessageState.h @@ -0,0 +1,13 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +#import "OWSDatabaseMigration.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OWS109OutgoingMessageState : OWSDatabaseMigration + +@end + +NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/environment/migrations/OWS109OutgoingMessageState.m b/SignalMessaging/environment/migrations/OWS109OutgoingMessageState.m new file mode 100644 index 000000000..50296180e --- /dev/null +++ b/SignalMessaging/environment/migrations/OWS109OutgoingMessageState.m @@ -0,0 +1,47 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +#import "OWS109OutgoingMessageState.h" +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +// Increment a similar constant for every future DBMigration +static NSString *const OWS109OutgoingMessageStateMigrationId = @"109"; + +@implementation OWS109OutgoingMessageState + ++ (NSString *)migrationId +{ + return OWS109OutgoingMessageStateMigrationId; +} + +- (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +{ + OWSAssert(transaction); + + NSMutableArray *outgoingMessages = [NSMutableArray new]; + [transaction enumerateKeysAndObjectsInCollection:TSOutgoingMessage.collection + usingBlock:^(NSString *key, id value, BOOL *stop) { + if (![value isKindOfClass:[TSOutgoingMessage class]]) { + return; + } + TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)value; + [outgoingMessages addObject:outgoingMessage]; + }]; + + DDLogInfo(@"Saving %zd outgoing messages.", outgoingMessages.count); + + // Persist the migration of the outgoing message state. + // For performance, we want to upgrade all existing outgoing messages in + // a single transaction. + for (TSOutgoingMessage *outgoingMessage in outgoingMessages) { + [outgoingMessage saveWithTransaction:transaction]; + } +} + +@end + +NS_ASSUME_NONNULL_END