From b83766ef74d0c7bd90c00cb681445e244c6a7772 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 14 May 2019 15:54:39 +1000 Subject: [PATCH] Clean & fix conversation settings crash --- .../ConversationView/ConversationViewController.m | 2 +- .../OWSConversationSettingsViewController.m | 5 ++++- SignalMessaging/profiles/ProfileFetcherJob.swift | 3 ++- SignalMessaging/utils/ThreadUtil.h | 2 +- SignalMessaging/utils/ThreadUtil.m | 8 ++++---- .../src/Account/CreatePreKeysOperation.swift | 13 +++++++------ .../src/Account/PreKeyRefreshOperation.swift | 3 ++- .../src/Account/RotateSignedKeyOperation.swift | 3 ++- .../src/Loki/Extensions/TSOutgoingMessage.swift | 2 +- SignalServiceKit/src/Messages/OWSMessageSender.m | 3 +-- .../src/Network/WebSockets/OWSWebSocket.m | 2 +- .../AxolotlStore/OWSPrimaryStorage+PreKeyStore.h | 2 +- .../AxolotlStore/OWSPrimaryStorage+PreKeyStore.m | 2 +- 13 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index d4520a9c9..e564ed4b6 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -4294,7 +4294,7 @@ typedef enum : NSUInteger { - (void)acceptFriendRequest:(TSIncomingMessage *)friendRequest { - [ThreadUtil enqueueFriendRequestAcceptMessageInThread:self.thread]; + [ThreadUtil enqueueAcceptFriendRequestMessageInThread:self.thread]; } - (void)declineFriendRequest:(TSIncomingMessage *)friendRequest diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index 108067746..fc6da4104 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -260,7 +260,10 @@ const CGFloat kIconViewLength = 24; - (void)contactsViewHelperDidUpdateContacts { - [self updateTableContents]; + // Loki: Original code + // ======== + // [self updateTableContents]; + // ======== } #pragma mark - View Lifecycle diff --git a/SignalMessaging/profiles/ProfileFetcherJob.swift b/SignalMessaging/profiles/ProfileFetcherJob.swift index 94ab032ad..3d2e644d8 100644 --- a/SignalMessaging/profiles/ProfileFetcherJob.swift +++ b/SignalMessaging/profiles/ProfileFetcherJob.swift @@ -106,7 +106,8 @@ public class ProfileFetcherJob: NSObject { self.getAndUpdateProfile(recipientId: recipientId) } } - */ + * ================ + */ } enum ProfileFetcherJobError: Error { diff --git a/SignalMessaging/utils/ThreadUtil.h b/SignalMessaging/utils/ThreadUtil.h index 8e0be222d..229ccdc25 100644 --- a/SignalMessaging/utils/ThreadUtil.h +++ b/SignalMessaging/utils/ThreadUtil.h @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Durable Message Enqueue -+ (TSOutgoingMessage *)enqueueFriendRequestAcceptMessageInThread:(TSThread *)thread; ++ (TSOutgoingMessage *)enqueueAcceptFriendRequestMessageInThread:(TSThread *)thread; + (TSOutgoingMessage *)enqueueMessageWithText:(NSString *)fullMessageText inThread:(TSThread *)thread diff --git a/SignalMessaging/utils/ThreadUtil.m b/SignalMessaging/utils/ThreadUtil.m index 009131108..7021ba7a2 100644 --- a/SignalMessaging/utils/ThreadUtil.m +++ b/SignalMessaging/utils/ThreadUtil.m @@ -86,9 +86,9 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess #pragma mark - Durable Message Enqueue // Loki: TODO We may change this? -+ (TSOutgoingMessage *)enqueueFriendRequestAcceptMessageInThread:(TSThread *)thread ++ (TSOutgoingMessage *)enqueueAcceptFriendRequestMessageInThread:(TSThread *)thread { - TSOutgoingMessage *message = [TSOutgoingMessage emptyOutgoingMessageInThread:thread]; + TSOutgoingMessage *message = [TSOutgoingMessage createEmptyOutgoingMessageInThread:thread]; [self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { [self.messageSenderJobQueue addMessage:message transaction:transaction]; }]; @@ -186,8 +186,8 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess // Loki: If we're not friends then always set the message to a friend request message // If we're friends then the assumption is that we have the other user's pre-key bundle - NSString *messageClassString = [thread isFriend] ? @"TSOutgoingMessage" : @"OWSFriendRequestMessage"; - Class messageClass = NSClassFromString(messageClassString); + NSString *messageClassAsString = thread.isFriend ? @"TSOutgoingMessage" : @"OWSFriendRequestMessage"; + Class messageClass = NSClassFromString(messageClassAsString); TSOutgoingMessage *message = [[messageClass alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] diff --git a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift index 76e7e9aee..149ea3916 100644 --- a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift +++ b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift @@ -27,10 +27,10 @@ public class CreatePreKeysOperation: OWSOperation { self.identityKeyManager.generateNewIdentityKey() } - /// Loki: We don't generate PreKeyRecords here. - /// This is because we need the records to be linked to a contact since we don't have a central server. - /// It is done automatically when we generate a PreKeyBundle to send to a contact (`generatePreKeyBundleForContact:`). - /// You can use `getOrCreatePreKeyForContact:` to generate one if needed. + // Loki: We don't generate PreKeyRecords here. + // This is because we need the records to be linked to a contact since we don't have a central server. + // It is done automatically when we generate a PreKeyBundle to send to a contact (`generatePreKeyBundleForContact:`). + // You can use `getOrCreatePreKeyForContact:` to generate one if needed. let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() signedPreKeyRecord.markAsAcceptedByService() self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) @@ -40,7 +40,7 @@ public class CreatePreKeysOperation: OWSOperation { self.reportSuccess() /* Loki: Original code - * ================ + * ================ let identityKey: Data = self.identityKeyManager.identityKeyPair()!.publicKey let signedPreKeyRecord: SignedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() let preKeyRecords: [PreKeyRecord] = self.primaryStorage.generatePreKeyRecords() @@ -60,6 +60,7 @@ public class CreatePreKeysOperation: OWSOperation { }.catch { error in self.reportError(error) }.retainUntilComplete() - */ + * ================ + */ } } diff --git a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift index 9ae59add6..dc97becc4 100644 --- a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift +++ b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift @@ -90,7 +90,8 @@ public class RefreshPreKeysOperation: OWSOperation { }.catch { error in self.reportError(error) }.retainUntilComplete() - */ + * ================ + */ } public override func didSucceed() { diff --git a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift index e38133a10..4e973dcc4 100644 --- a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift +++ b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift @@ -62,7 +62,8 @@ public class RotateSignedPreKeyOperation: OWSOperation { }.catch { error in self.reportError(error) }.retainUntilComplete() - */ + * ================ + */ } override public func didFail(error: Error) { diff --git a/SignalServiceKit/src/Loki/Extensions/TSOutgoingMessage.swift b/SignalServiceKit/src/Loki/Extensions/TSOutgoingMessage.swift index e42513ed0..2bebcd6d4 100644 --- a/SignalServiceKit/src/Loki/Extensions/TSOutgoingMessage.swift +++ b/SignalServiceKit/src/Loki/Extensions/TSOutgoingMessage.swift @@ -2,7 +2,7 @@ @objc public extension TSOutgoingMessage { /// Loki: This is a message used to establish sessions - @objc public static func emptyOutgoingMessage(inThread thread: TSThread) -> TSOutgoingMessage { + @objc public static func createEmptyOutgoingMessage(inThread thread: TSThread) -> TSOutgoingMessage { return TSOutgoingMessage(outgoingMessageWithTimestamp: NSDate.ows_millisecondTimeStamp(), in: thread, messageBody: "", diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 2a43dad6e..63a4426c5 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1066,7 +1066,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; hasValidMessageType = [validMessageTypes containsObject:messageType]; /* Loki: Original code: - * ================ hasValidMessageType = ([messageType isEqualToNumber:@(TSEncryptedWhisperMessageType)] || [messageType isEqualToNumber:@(TSPreKeyWhisperMessageType)]); */ @@ -1620,7 +1619,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; __block NSException *_Nullable exception; /** Loki: Original code - * ================== + * ================ __block dispatch_semaphore_t sema = dispatch_semaphore_create(0); __block PreKeyBundle *_Nullable bundle; __block NSException *_Nullable exception; diff --git a/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m b/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m index 76c042e23..18a434808 100644 --- a/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m +++ b/SignalServiceKit/src/Network/WebSockets/OWSWebSocket.m @@ -910,7 +910,7 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O { OWSAssertIsOnMainThread(); - // Loki: Since we don't use web sockets, disable them. + // Loki: Since we don't use web sockets, disable them return NO; // Don't open socket in app extensions. diff --git a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.h b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.h index 7aba981e2..508daff95 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.h +++ b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.h @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @interface OWSPrimaryStorage (PreKeyStore) - (NSArray *)generatePreKeyRecords; -- (NSArray *)generatePreKeyRecords:(NSUInteger)batchSize; +- (NSArray *)generatePreKeyRecords:(int)batchSize; - (void)storePreKeyRecords:(NSArray *)preKeyRecords NS_SWIFT_NAME(storePreKeyRecords(_:)); @end diff --git a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m index 13c77e5f8..e46a31528 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN return [self generatePreKeyRecords:BATCH_SIZE]; } -- (NSArray *)generatePreKeyRecords:(NSUInteger)batchSize +- (NSArray *)generatePreKeyRecords:(int)batchSize { NSMutableArray *preKeyRecords = [NSMutableArray array];