From 6f1f1fac80c220bac3a60800387075f0ca78ef6a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Jun 2017 15:09:47 -0400 Subject: [PATCH] Improve handling of group creation failures. // FREEBIE --- Podfile | 4 +-- Podfile.lock | 9 ++---- .../ConversationView/MessagesViewController.m | 29 ++++++++++++++++-- .../ViewControllers/NewGroupViewController.m | 30 ++++++++++++------- Signal/src/views/OWSSystemMessageCell.m | 1 + .../translations/en.lproj/Localizable.strings | 4 +-- 6 files changed, 54 insertions(+), 23 deletions(-) diff --git a/Podfile b/Podfile index 55d7dcd08..624665393 100644 --- a/Podfile +++ b/Podfile @@ -5,8 +5,8 @@ target 'Signal' do pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' #pod 'AxolotlKit', path: '../SignalProtocolKit' - pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' - #pod 'SignalServiceKit', path: '../SignalServiceKit' + #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' + pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'OpenSSL' pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu' #pod 'JSQMessagesViewController' path: '../JSQMessagesViewController' diff --git a/Podfile.lock b/Podfile.lock index 6a0a4b298..0f8ef4e41 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -114,7 +114,7 @@ DEPENDENCIES: - OpenSSL - PureLayout - Reachability - - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`) + - SignalServiceKit (from `../SignalServiceKit`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`) EXTERNAL SOURCES: @@ -124,7 +124,7 @@ EXTERNAL SOURCES: :branch: mkirk/position-edit-menu :git: https://github.com/WhisperSystems/JSQMessagesViewController.git SignalServiceKit: - :git: https://github.com/WhisperSystems/SignalServiceKit.git + :path: ../SignalServiceKit SocketRocket: :git: https://github.com/facebook/SocketRocket.git @@ -135,9 +135,6 @@ CHECKOUT OPTIONS: JSQMessagesViewController: :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :git: https://github.com/WhisperSystems/JSQMessagesViewController.git - SignalServiceKit: - :commit: 7052b97c72c7d9601883c55ba8ad6a5729b8f504 - :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf :git: https://github.com/facebook/SocketRocket.git @@ -164,6 +161,6 @@ SPEC CHECKSUMS: UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266 -PODFILE CHECKSUM: 48e80d7f1e049bbf544a689fdfdf33e8196c640a +PODFILE CHECKSUM: 6f9ef5d9fa17469569e127a9f5719dafa11631b9 COCOAPODS: 1.2.1 diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 4051b5089..7de5a3268 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -2388,6 +2388,9 @@ typedef enum : NSUInteger { OWSAssert([message isKindOfClass:[OWSUnknownContactBlockOfferMessage class]]); [self tappedUnknownContactBlockOfferMessage:(OWSUnknownContactBlockOfferMessage *)message]; return; + case TSErrorMessageGroupCreationFailed: + [self resendGroupUpdateForErrorMessage:message]; + return; } DDLogWarn(@"%@ Unhandled tap for error message:%@", self.tag, message); @@ -3660,7 +3663,7 @@ typedef enum : NSUInteger { [messageData performEditingAction:action]; } -- (void)updateGroupModelTo:(TSGroupModel *)newGroupModel +- (void)updateGroupModelTo:(TSGroupModel *)newGroupModel successCompletion:(void (^_Nullable)())successCompletion { __block TSGroupThread *groupThread; __block TSOutgoingMessage *message; @@ -3686,6 +3689,9 @@ typedef enum : NSUInteger { inMessage:message success:^{ DDLogDebug(@"%@ Successfully sent group update with avatar", self.tag); + if (successCompletion) { + successCompletion(); + } } failure:^(NSError *_Nonnull error) { DDLogError(@"%@ Failed to send group avatar update with error: %@", self.tag, error); @@ -3694,6 +3700,9 @@ typedef enum : NSUInteger { [self.messageSender sendMessage:message success:^{ DDLogDebug(@"%@ Successfully sent group update", self.tag); + if (successCompletion) { + successCompletion(); + } } failure:^(NSError *_Nonnull error) { DDLogError(@"%@ Failed to send group update with error: %@", self.tag, error); @@ -4014,6 +4023,22 @@ typedef enum : NSUInteger { #pragma mark - OWSConversationSettingsViewDelegate +- (void)resendGroupUpdateForErrorMessage:(TSErrorMessage *)message +{ + OWSAssert([NSThread isMainThread]); + OWSAssert([_thread isKindOfClass:[TSGroupThread class]]); + OWSAssert(message); + + TSGroupThread *groupThread = (TSGroupThread *)self.thread; + TSGroupModel *groupModel = groupThread.groupModel; + [self updateGroupModelTo:groupModel + successCompletion:^{ + DDLogInfo(@"Group updated, removing group creation error."); + + [message remove]; + }]; +} + - (void)groupWasUpdated:(TSGroupModel *)groupModel { OWSAssert(groupModel); @@ -4021,7 +4046,7 @@ typedef enum : NSUInteger { NSMutableSet *groupMemberIds = [NSMutableSet setWithArray:groupModel.groupMemberIds]; [groupMemberIds addObject:[TSAccountManager localNumber]]; groupModel.groupMemberIds = [NSMutableArray arrayWithArray:[groupMemberIds allObjects]]; - [self updateGroupModelTo:groupModel]; + [self updateGroupModelTo:groupModel successCompletion:nil]; [self.collectionView.collectionViewLayout invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]]; [self.collectionView reloadData]; diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 13481b808..5585503ea 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -450,26 +450,33 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; }]; OWSAssert(thread); - void (^popToThread)() = ^{ + void (^successHandler)() = ^{ + DDLogError(@"Group creation successful."); + dispatch_async(dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:^{ + // Pop to new group thread. [Environment messageGroup:thread]; }]; }); }; - void (^removeThreadWithError)(NSError *error) = ^(NSError *error) { - [thread remove]; + void (^failureHandler)(NSError *error) = ^(NSError *error) { + DDLogError(@"Group creation failed: %@", error); + dispatch_async(dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:^{ - [OWSAlerts - showAlertWithTitle: - NSLocalizedString(@"GROUP_CREATING_FAILED", - "Title of alert indicating that new group could not be created.") - message:error.localizedDescription]; + // Add an error message to the new group indicating + // that group creation didn't succeed. + [[[TSErrorMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + failedMessageType:TSErrorMessageGroupCreationFailed] + save]; + + [Environment messageGroup:thread]; }]; }); }; @@ -489,15 +496,16 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; // This will save the message. [message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)]; + if (model.groupImage) { [self.messageSender sendAttachmentData:UIImagePNGRepresentation(model.groupImage) contentType:OWSMimeTypeImagePng sourceFilename:nil inMessage:message - success:popToThread - failure:removeThreadWithError]; + success:successHandler + failure:failureHandler]; } else { - [self.messageSender sendMessage:message success:popToThread failure:removeThreadWithError]; + [self.messageSender sendMessage:message success:successHandler failure:failureHandler]; } }]; } diff --git a/Signal/src/views/OWSSystemMessageCell.m b/Signal/src/views/OWSSystemMessageCell.m index 2aa2712b9..37c1eec5d 100644 --- a/Signal/src/views/OWSSystemMessageCell.m +++ b/Signal/src/views/OWSSystemMessageCell.m @@ -124,6 +124,7 @@ NS_ASSUME_NONNULL_BEGIN case TSErrorMessageDuplicateMessage: case TSErrorMessageInvalidVersion: case TSErrorMessageUnknownContactBlockOffer: + case TSErrorMessageGroupCreationFailed: result = [UIImage imageNamed:@"system_message_info"]; break; } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 5a77ba966..3e5108dd7 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -553,8 +553,8 @@ /* No comment provided by engineer. */ "GROUP_CREATING" = "Creating new group"; -/* Title of alert indicating that new group could not be created. */ -"GROUP_CREATING_FAILED" = "Group creation failed"; +/* Message shown in conversation view that indicates there were issues with group creation. */ +"GROUP_CREATION_FAILED" = "Not all members could be added to the group. Tap to retry."; /* Conversation settings table section title */ "GROUP_MANAGEMENT_SECTION" = "Group Management";