diff --git a/Riot/Modules/Common/Recents/RecentsViewController.m b/Riot/Modules/Common/Recents/RecentsViewController.m index 7fd29b1d0..c72a7a58b 100644 --- a/Riot/Modules/Common/Recents/RecentsViewController.m +++ b/Riot/Modules/Common/Recents/RecentsViewController.m @@ -539,11 +539,13 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro [self->currentAlert dismissViewControllerAnimated:NO completion:nil]; - self->currentAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n roomErrorJoinFailedTitle] message:msg preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n roomErrorJoinFailedTitle] + message:msg + preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [errorAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; @@ -553,7 +555,8 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro } }]]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [self presentViewController:errorAlert animated:YES completion:nil]; + currentAlert = errorAlert; } #pragma mark - Sticky Headers @@ -1202,13 +1205,13 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro } // confirm leave - currentAlert = [UIAlertController alertControllerWithTitle:title - message:message - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *leavePrompt = [UIAlertController alertControllerWithTitle:title + message:message + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * action) { + [leavePrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -1218,8 +1221,8 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n leave] - style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [leavePrompt addAction:[UIAlertAction actionWithTitle:[VectorL10n leave] + style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { if (weakSelf) { @@ -1280,8 +1283,9 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro }]]; - [currentAlert mxk_setAccessibilityIdentifier:@"LeaveEditedRoomAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [leavePrompt mxk_setAccessibilityIdentifier:@"LeaveEditedRoomAlert"]; + [self presentViewController:leavePrompt animated:YES completion:nil]; + currentAlert = leavePrompt; } } @@ -1836,11 +1840,11 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro [currentAlert dismissViewControllerAnimated:NO completion:nil]; - currentAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomRecentsStartChatWith] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n roomRecentsStartChatWith] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -1852,9 +1856,9 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomRecentsCreateEmptyRoom] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n roomRecentsCreateEmptyRoom] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -1866,9 +1870,9 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomRecentsJoinRoom] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n roomRecentsJoinRoom] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -1882,10 +1886,9 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro if (self.mainSession.callManager.supportsPSTN) { - [currentAlert addAction:[UIAlertAction - actionWithTitle:[VectorL10n roomOpenDialpad] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n roomOpenDialpad] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -1898,9 +1901,9 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro }]]; } - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * action) { + [actionSheet addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -1910,11 +1913,12 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro }]]; - [currentAlert popoverPresentationController].sourceView = plusButtonImageView; - [currentAlert popoverPresentationController].sourceRect = plusButtonImageView.bounds; + [actionSheet popoverPresentationController].sourceView = plusButtonImageView; + [actionSheet popoverPresentationController].sourceRect = plusButtonImageView.bounds; - [currentAlert mxk_setAccessibilityIdentifier:@"RecentsVCCreateRoomAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [actionSheet mxk_setAccessibilityIdentifier:@"RecentsVCCreateRoomAlert"]; + [self presentViewController:actionSheet animated:YES completion:nil]; + currentAlert = actionSheet; } - (void)openDialpad diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 09610a14a..d056b0267 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -2059,20 +2059,22 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [VectorL10n widgetStickerPickerNoStickerpacksAlert], [VectorL10n widgetStickerPickerNoStickerpacksAlertAddNow]]; - currentAlert = [UIAlertController alertControllerWithTitle:nil message:alertMessage preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *installPrompt = [UIAlertController alertControllerWithTitle:nil + message:alertMessage + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n no] - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * action) + [installPrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n no] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n yes] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) + [installPrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n yes] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; @@ -2087,8 +2089,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [self presentViewController:modularVC animated:NO completion:nil]; }]]; - [currentAlert mxk_setAccessibilityIdentifier:@"RoomVCStickerPickerAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [installPrompt mxk_setAccessibilityIdentifier:@"RoomVCStickerPickerAlert"]; + [self presentViewController:installPrompt animated:YES completion:nil]; + currentAlert = installPrompt; } } @@ -3142,14 +3145,14 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; } __weak __typeof(self) weakSelf = self; - currentAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertController *actionsMenu = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; // Add actions for a failed event if (selectedEvent.sentState == MXEventSentStateFailed) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n retry] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n retry] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3163,9 +3166,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionDelete] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionDelete] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3200,9 +3203,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; selectedEvent.sentState == MXEventSentStateEncrypting || selectedEvent.sentState == MXEventSentStateSending) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionCancelSend] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionCancelSend] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3220,9 +3223,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; } - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionForward] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionForward] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { self.shareManager = [[ShareManager alloc] initWithShareItemProvider:[[SimpleShareItemProvider alloc] initWithTextMessage:selectedComponent.textMessage] type:ShareManagerTypeForward]; @@ -3239,9 +3242,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; if (!isJitsiCallEvent) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionQuote] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionQuote] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3261,9 +3264,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; if (!isJitsiCallEvent && BuildSettings.messageDetailsAllowShare) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionShare] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionShare] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3295,9 +3298,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; attachment.type == MXKAttachmentTypeVideo || attachment.type == MXKAttachmentTypeVoiceMessage) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionForward] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionForward] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { self.shareManager = [[ShareManager alloc] initWithShareItemProvider:[[SimpleShareItemProvider alloc] initWithAttachment:attachment] type:ShareManagerTypeForward]; @@ -3317,9 +3320,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; { if (attachment.type == MXKAttachmentTypeImage || attachment.type == MXKAttachmentTypeVideo) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionSave] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionSave] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3362,9 +3365,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; NSString *uploadId = roomBubbleTableViewCell.bubbleData.attachment.contentURL; if ([MXMediaManager existingUploaderWithId:uploadId]) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionCancelSend] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionCancelSend] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { // Get again the loader MXMediaLoader *loader = [MXMediaManager existingUploaderWithId:uploadId]; @@ -3400,9 +3403,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; { if (BuildSettings.messageDetailsAllowShare) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionShare] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionShare] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3450,9 +3453,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; NSString *downloadId = roomBubbleTableViewCell.bubbleData.attachment.downloadId; if ([MXMediaManager existingDownloaderWithIdentifier:downloadId]) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionCancelDownload] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionCancelDownload] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3478,9 +3481,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; // because it breaks everything if (selectedEvent.eventType != MXEventTypeRoomEncryption) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionRedact] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionRedact] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3512,9 +3515,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; if (BuildSettings.messageDetailsAllowPermalink) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionPermalink] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionPermalink] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3541,9 +3544,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; // Add reaction history if event contains reactions if (roomBubbleTableViewCell.bubbleData.reactions[selectedEvent.eventId].aggregatedReactionsWithNonZeroCount) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionReactionHistory] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionReactionHistory] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { [self cancelEventSelection]; @@ -3554,9 +3557,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; if (BuildSettings.messageDetailsAllowViewSource) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionViewSource] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionViewSource] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3574,9 +3577,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; // Add "View Decrypted Source" for e2ee event we can decrypt if (selectedEvent.isEncrypted && selectedEvent.clearEvent) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionViewDecryptedSource] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionViewDecryptedSource] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3594,9 +3597,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; if (![selectedEvent.sender isEqualToString:self.mainSession.myUser.userId] && RiotSettings.shared.roomContextualMenuShowReportContentOption) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionReport] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionReport] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3605,15 +3608,15 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [self cancelEventSelection]; // Prompt user to enter a description of the problem content. - self->currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomEventActionReportPromptReason] message:nil preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *reportReasonAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomEventActionReportPromptReason] message:nil preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) { + [reportReasonAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.secureTextEntry = NO; textField.placeholder = nil; textField.keyboardType = UIKeyboardTypeDefault; }]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [reportReasonAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3629,9 +3632,11 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [self stopActivityIndicator]; // Prompt user to ignore content from this user - self->currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomEventActionReportPromptIgnoreUser] message:nil preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *ignoreUserAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomEventActionReportPromptIgnoreUser] + message:nil + preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n yes] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [ignoreUserAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n yes] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3660,7 +3665,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n no] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [ignoreUserAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n no] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3670,7 +3675,8 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [self presentViewController:ignoreUserAlert animated:YES completion:nil]; + self->currentAlert = ignoreUserAlert; } failure:^(NSError *error) { @@ -3686,7 +3692,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { + [reportReasonAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3696,7 +3702,8 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [self presentViewController:reportReasonAlert animated:YES completion:nil]; + self->currentAlert = reportReasonAlert; } }]]; @@ -3704,9 +3711,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; if (!isJitsiCallEvent && self.roomDataSource.room.summary.isEncrypted) { - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionViewEncryption] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionViewEncryption] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3721,9 +3728,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; } } - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * action) { + [actionsMenu addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3734,20 +3741,17 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; // Do not display empty action sheet - if (currentAlert.actions.count > 1) + if (actionsMenu.actions.count > 1) { NSInteger bubbleComponentIndex = [roomBubbleTableViewCell.bubbleData bubbleComponentIndexForEventId:selectedEvent.eventId]; CGRect sourceRect = [roomBubbleTableViewCell componentFrameInContentViewForIndex:bubbleComponentIndex]; - [currentAlert mxk_setAccessibilityIdentifier:@"RoomVCEventMenuAlert"]; - [currentAlert popoverPresentationController].sourceView = roomBubbleTableViewCell; - [currentAlert popoverPresentationController].sourceRect = sourceRect; - [self presentViewController:currentAlert animated:animated completion:nil]; - } - else - { - currentAlert = nil; + [actionsMenu mxk_setAccessibilityIdentifier:@"RoomVCEventMenuAlert"]; + [actionsMenu popoverPresentationController].sourceView = roomBubbleTableViewCell; + [actionsMenu popoverPresentationController].sourceRect = sourceRect; + [self presentViewController:actionsMenu animated:animated completion:nil]; + currentAlert = actionsMenu; } } @@ -4120,14 +4124,14 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; - (void)showVoiceCallActionSheet { // Ask the user the kind of the call: voice or dialpad? - currentAlert = [UIAlertController alertControllerWithTitle:nil - message:nil - preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertController *callActionSheet = [UIAlertController alertControllerWithTitle:nil + message:nil + preferredStyle:UIAlertControllerStyleActionSheet]; __weak typeof(self) weakSelf = self; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomPlaceVoiceCall] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [callActionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n roomPlaceVoiceCall] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -4139,9 +4143,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomOpenDialpad] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [callActionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n roomOpenDialpad] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -4153,9 +4157,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * action) { + [callActionSheet addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -4165,9 +4169,10 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert popoverPresentationController].barButtonItem = self.navigationItem.rightBarButtonItems.firstObject; - [currentAlert popoverPresentationController].permittedArrowDirections = UIPopoverArrowDirectionUp; - [self presentViewController:currentAlert animated:YES completion:nil]; + [callActionSheet popoverPresentationController].barButtonItem = self.navigationItem.rightBarButtonItems.firstObject; + [callActionSheet popoverPresentationController].permittedArrowDirections = UIPopoverArrowDirectionUp; + [self presentViewController:callActionSheet animated:YES completion:nil]; + currentAlert = callActionSheet; } - (void)placeCallWithVideo2:(BOOL)video @@ -4219,20 +4224,21 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; MXWeakify(self); [currentAlert dismissViewControllerAnimated:NO completion:nil]; - currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomNoPrivilegesToCreateGroupCall] - message:nil - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *unprivilegedAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomNoPrivilegesToCreateGroupCall] + message:nil + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) + [unprivilegedAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; }]]; - [currentAlert mxk_setAccessibilityIdentifier:@"RoomVCCallAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [unprivilegedAlert mxk_setAccessibilityIdentifier:@"RoomVCCallAlert"]; + [self presentViewController:unprivilegedAlert animated:YES completion:nil]; + currentAlert = unprivilegedAlert; } } } @@ -5160,6 +5166,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [VectorL10n roomUnsentMessagesUnknownDevicesNotification] : [VectorL10n roomUnsentMessagesNotification]; + MXWeakify(self); RoomActivitiesView *roomActivitiesView = (RoomActivitiesView*) self.activitiesView; self.activitiesViewExpanded = YES; [roomActivitiesView displayUnsentMessagesNotification:notification withResendLink:^{ @@ -5171,57 +5178,53 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [self cancelAllUnsentMessages]; } andIconTapGesture:^{ + MXStrongifyAndReturnIfNil(self); - if (currentAlert) + if (self->currentAlert) { - [currentAlert dismissViewControllerAnimated:NO completion:nil]; + [self->currentAlert dismissViewControllerAnimated:NO completion:nil]; } - __weak __typeof(self) weakSelf = self; - currentAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + MXWeakify(self); + UIAlertController *resendAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomResendUnsentMessages] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [resendAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomResendUnsentMessages] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { - if (weakSelf) - { - typeof(self) self = weakSelf; - [self resendAllUnsentMessages]; - self->currentAlert = nil; - } + MXStrongifyAndReturnIfNil(self); + + [self resendAllUnsentMessages]; + self->currentAlert = nil; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomDeleteUnsentMessages] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [resendAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomDeleteUnsentMessages] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { - if (weakSelf) - { - typeof(self) self = weakSelf; - [self cancelAllUnsentMessages]; - self->currentAlert = nil; - } + MXStrongifyAndReturnIfNil(self); + + [self cancelAllUnsentMessages]; + self->currentAlert = nil; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * action) { + [resendAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { - if (weakSelf) - { - typeof(self) self = weakSelf; - self->currentAlert = nil; - } + MXStrongifyAndReturnIfNil(self); + + self->currentAlert = nil; }]]; - [currentAlert mxk_setAccessibilityIdentifier:@"RoomVCUnsentMessagesMenuAlert"]; - [currentAlert popoverPresentationController].sourceView = roomActivitiesView; - [currentAlert popoverPresentationController].sourceRect = roomActivitiesView.bounds; - [self presentViewController:currentAlert animated:YES completion:nil]; + [resendAlert mxk_setAccessibilityIdentifier:@"RoomVCUnsentMessagesMenuAlert"]; + [resendAlert popoverPresentationController].sourceView = roomActivitiesView; + [resendAlert popoverPresentationController].sourceRect = roomActivitiesView.bounds; + [self presentViewController:resendAlert animated:YES completion:nil]; + self->currentAlert = resendAlert; }]; } @@ -5261,13 +5264,13 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; } } - currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n unknownDevicesAlertTitle] - message:[VectorL10n unknownDevicesAlert] - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *unknownDevicesAlert = [UIAlertController alertControllerWithTitle:[VectorL10n unknownDevicesAlertTitle] + message:[VectorL10n unknownDevicesAlert] + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n unknownDevicesVerify] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [unknownDevicesAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n unknownDevicesVerify] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -5279,9 +5282,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n unknownDevicesSendAnyway] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [unknownDevicesAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n unknownDevicesSendAnyway] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -5302,8 +5305,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert mxk_setAccessibilityIdentifier:@"RoomVCUnknownDevicesAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [unknownDevicesAlert mxk_setAccessibilityIdentifier:@"RoomVCUnknownDevicesAlert"]; + [self presentViewController:unknownDevicesAlert animated:YES completion:nil]; + currentAlert = unknownDevicesAlert; } } @@ -5365,15 +5369,17 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; - (void)cancelAllUnsentMessages { - currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomUnsentMessagesCancelTitle] message:[VectorL10n roomUnsentMessagesCancelMessage] preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *cancelAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomUnsentMessagesCancelTitle] + message:[VectorL10n roomUnsentMessagesCancelMessage] + preferredStyle:UIAlertControllerStyleAlert]; MXWeakify(self); - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { + [cancelAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n delete] style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) { + [cancelAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n delete] style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); // Remove unsent event ids for (NSUInteger index = 0; index < self.roomDataSource.room.outgoingMessages.count;) @@ -5390,9 +5396,11 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; } [self refreshActivitiesViewDisplay]; + self->currentAlert = nil; }]]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [self presentViewController:cancelAlert animated:YES completion:nil]; + currentAlert = cancelAlert; } # pragma mark - Encryption Information view @@ -5621,11 +5629,11 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; // Invite ? NSString *promptMsg = [VectorL10n roomParticipantsInvitePromptMsg:contact.displayName]; - currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomParticipantsInvitePromptTitle] - message:promptMsg - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *invitePrompt = [UIAlertController alertControllerWithTitle:[VectorL10n roomParticipantsInvitePromptTitle] + message:promptMsg + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] + [invitePrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { @@ -5637,7 +5645,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n invite] + [invitePrompt addAction:[UIAlertAction actionWithTitle:[VectorL10n invite] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { @@ -5732,8 +5740,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; }]]; - [currentAlert mxk_setAccessibilityIdentifier:@"RoomVCInviteAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [invitePrompt mxk_setAccessibilityIdentifier:@"RoomVCInviteAlert"]; + [self presentViewController:invitePrompt animated:YES completion:nil]; + currentAlert = invitePrompt; } #pragma mark - Re-request encryption keys @@ -5777,8 +5786,6 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; alert = [UIAlertController alertControllerWithTitle:VectorL10n.rerequestKeysAlertTitle message:[VectorL10n e2eRoomKeyRequestMessage:AppInfo.current.displayName] preferredStyle:UIAlertControllerStyleAlert]; - currentAlert = alert; - [alert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault @@ -5792,7 +5799,8 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; self->currentAlert = nil; }]]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [self presentViewController:alert animated:YES completion:nil]; + currentAlert = alert; } - (void)presentReviewUnverifiedSessionsAlert @@ -6066,18 +6074,19 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [self hideContextualMenuAnimated:YES cancelEventSelection:YES completion:^{ MXStrongifyAndReturnIfNil(self); - self->currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomEventActionDeleteConfirmationTitle] - message:[VectorL10n roomEventActionDeleteConfirmationMessage] - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *deleteConfirmation = [UIAlertController alertControllerWithTitle:[VectorL10n roomEventActionDeleteConfirmationTitle] + message:[VectorL10n roomEventActionDeleteConfirmationMessage] + preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [deleteConfirmation addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }]]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n delete] style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) { + [deleteConfirmation addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n delete] style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) { [self.roomDataSource removeEventWithEventId:event.eventId]; }]]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [self presentViewController:deleteConfirmation animated:YES completion:nil]; + self->currentAlert = deleteConfirmation; }]; }; diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 7ecfcb533..cee976ad2 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -991,9 +991,11 @@ TableViewSectionsDelegate> { MXWeakify(self); [currentAlert dismissViewControllerAnimated:NO completion:nil]; - currentAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountEmailValidationTitle] message:message preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *validationAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountEmailValidationTitle] + message:message + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [validationAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; [self stopActivityIndicator]; @@ -1002,14 +1004,15 @@ TableViewSectionsDelegate> self.newEmailEditingEnabled = NO; }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n continue] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [validationAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n continue] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); [self tryFinaliseAddEmailSession:threePidAddSession withAuthenticationParameters:authenticationParameters threePidAddManager:threePidAddManager]; }]]; - [currentAlert mxk_setAccessibilityIdentifier:@"SettingsVCEmailValidationAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [validationAlert mxk_setAccessibilityIdentifier:@"SettingsVCEmailValidationAlert"]; + [self presentViewController:validationAlert animated:YES completion:nil]; + currentAlert = validationAlert; } - (void)tryFinaliseAddEmailSession:(MX3PidAddSession*)threePidAddSession withAuthenticationParameters:(NSDictionary*)authParams threePidAddManager:(MX3PidAddManager*)threePidAddManager @@ -1049,11 +1052,13 @@ TableViewSectionsDelegate> MXLogDebug(@"[SettingsViewController] tryFinaliseAddEmailSession: Wrong credentials"); // Ask password again - self->currentAlert = [UIAlertController alertControllerWithTitle:nil - message:[VectorL10n settingsAdd3pidInvalidPasswordMessage] - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *passwordPrompt = [UIAlertController alertControllerWithTitle:nil + message:[VectorL10n settingsAdd3pidInvalidPasswordMessage] + preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n retry] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + MXWeakify(self); + [passwordPrompt addAction:[UIAlertAction actionWithTitle:[VectorL10n retry] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; [self showAuthenticationIfNeededForAdding:kMX3PIDMediumEmail withSession:self.mainSession completion:^(NSDictionary *authParams) { @@ -1061,7 +1066,8 @@ TableViewSectionsDelegate> }]; }]]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [self presentViewController:passwordPrompt animated:YES completion:nil]; + self->currentAlert = passwordPrompt; return; } @@ -1102,9 +1108,11 @@ TableViewSectionsDelegate> MXWeakify(self); [currentAlert dismissViewControllerAnimated:NO completion:nil]; - currentAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountMsisdnValidationTitle] message:message preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *validationAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountMsisdnValidationTitle] + message:message + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [validationAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; @@ -1115,13 +1123,13 @@ TableViewSectionsDelegate> self.newPhoneEditingEnabled = NO; }]]; - [currentAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) { + [validationAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.secureTextEntry = NO; textField.placeholder = nil; textField.keyboardType = UIKeyboardTypeDecimalPad; }]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n submit] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + [validationAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n submit] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { MXStrongifyAndReturnIfNil(self); @@ -1140,8 +1148,9 @@ TableViewSectionsDelegate> } }]]; - [currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCMsisdnValidationAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [validationAlert mxk_setAccessibilityIdentifier: @"SettingsVCMsisdnValidationAlert"]; + [self presentViewController:validationAlert animated:YES completion:nil]; + currentAlert = validationAlert; } - (void)finaliseAddPhoneNumberSession:(MX3PidAddSession*)threePidAddSession withToken:(NSString*)token andAuthenticationParameters:(NSDictionary*)authParams message:(NSString*)message threePidAddManager:(MX3PidAddManager*)threePidAddManager @@ -1180,11 +1189,13 @@ TableViewSectionsDelegate> MXLogDebug(@"[SettingsViewController] finaliseAddPhoneNumberSession: Wrong authentication credentials"); // Ask password again - self->currentAlert = [UIAlertController alertControllerWithTitle:nil - message:[VectorL10n settingsAdd3pidInvalidPasswordMessage] - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *passwordPrompt = [UIAlertController alertControllerWithTitle:nil + message:[VectorL10n settingsAdd3pidInvalidPasswordMessage] + preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n retry] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + MXWeakify(self); + [passwordPrompt addAction:[UIAlertAction actionWithTitle:[VectorL10n retry] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; [self showAuthenticationIfNeededForAdding:kMX3PIDMediumMSISDN withSession:self.mainSession completion:^(NSDictionary *authParams) { @@ -1192,7 +1203,8 @@ TableViewSectionsDelegate> }]; }]]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [self presentViewController:passwordPrompt animated:YES completion:nil]; + self->currentAlert = passwordPrompt; return; } @@ -1232,17 +1244,20 @@ TableViewSectionsDelegate> } - self->currentAlert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + MXWeakify(self); + [errorAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { + MXStrongifyAndReturnIfNil(self); self->currentAlert = nil; // Ask again the sms token [self showValidationMsisdnDialogWithMessage:message for3PidAddSession:threePidAddSession threePidAddManager:threePidAddManager authenticationParameters:authParams]; }]]; - [self->currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCErrorAlert"]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [errorAlert mxk_setAccessibilityIdentifier: @"SettingsVCErrorAlert"]; + [self presentViewController:errorAlert animated:YES completion:nil]; + self->currentAlert = errorAlert; } }]; } @@ -2606,11 +2621,11 @@ TableViewSectionsDelegate> __weak typeof(self) weakSelf = self; - currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n settingsUnignoreUser:ignoredUserId] message:nil preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *unignorePrompt = [UIAlertController alertControllerWithTitle:[VectorL10n settingsUnignoreUser:ignoredUserId] message:nil preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n yes] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [unignorePrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n yes] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -2639,9 +2654,9 @@ TableViewSectionsDelegate> }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n no] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [unignorePrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n no] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -2651,8 +2666,9 @@ TableViewSectionsDelegate> }]]; - [currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCUnignoreAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [unignorePrompt mxk_setAccessibilityIdentifier: @"SettingsVCUnignoreAlert"]; + [self presentViewController:unignorePrompt animated:YES completion:nil]; + currentAlert = unignorePrompt; } } else if (section == SECTION_TAG_ABOUT) @@ -2838,9 +2854,9 @@ TableViewSectionsDelegate> } // Remove ? - currentAlert = [UIAlertController alertControllerWithTitle:[VectorL10n settingsRemovePromptTitle] message:promptMsg preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *removePrompt = [UIAlertController alertControllerWithTitle:[VectorL10n settingsRemovePromptTitle] message:promptMsg preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] + [removePrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { @@ -2852,7 +2868,7 @@ TableViewSectionsDelegate> }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n remove] + [removePrompt addAction:[UIAlertAction actionWithTitle:[VectorL10n remove] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { @@ -2892,8 +2908,9 @@ TableViewSectionsDelegate> }]]; - [currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCRemove3PIDAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [removePrompt mxk_setAccessibilityIdentifier: @"SettingsVCRemove3PIDAlert"]; + [self presentViewController:removePrompt animated:YES completion:nil]; + currentAlert = removePrompt; } } } @@ -2915,9 +2932,9 @@ TableViewSectionsDelegate> NSString *title = [VectorL10n settingsNotificationsDisabledAlertTitle]; NSString *message = [VectorL10n settingsNotificationsDisabledAlertMessage]; - currentAlert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *showSettingsPrompt = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] + [showSettingsPrompt addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { @@ -2941,13 +2958,14 @@ TableViewSectionsDelegate> } }]; - [currentAlert addAction:settingsAction]; - currentAlert.preferredAction = settingsAction; + [showSettingsPrompt addAction:settingsAction]; + showSettingsPrompt.preferredAction = settingsAction; - [currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCPushNotificationsAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [showSettingsPrompt mxk_setAccessibilityIdentifier: @"SettingsVCPushNotificationsAlert"]; + [self presentViewController:showSettingsPrompt animated:YES completion:nil]; + currentAlert = showSettingsPrompt; - // Keep off the switch + // Keep the the switch off. sender.on = NO; } else if ([MXKAccountManager sharedManager].activeAccounts.count) @@ -3336,11 +3354,11 @@ TableViewSectionsDelegate> [currentAlert dismissViewControllerAnimated:NO completion:nil]; - currentAlert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [errorAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n cancel] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3361,9 +3379,9 @@ TableViewSectionsDelegate> }]]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n retry] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [errorAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n retry] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3377,8 +3395,9 @@ TableViewSectionsDelegate> }]]; - [currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCSaveChangesFailedAlert"]; - [rootViewController presentViewController:currentAlert animated:YES completion:nil]; + [errorAlert mxk_setAccessibilityIdentifier: @"SettingsVCSaveChangesFailedAlert"]; + [rootViewController presentViewController:errorAlert animated:YES completion:nil]; + currentAlert = errorAlert; } } @@ -3399,13 +3418,13 @@ TableViewSectionsDelegate> [currentAlert dismissViewControllerAnimated:NO completion:nil]; - currentAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountErrorEmailWrongTitle] - message:[MatrixKitL10n accountErrorEmailWrongDescription] - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountErrorEmailWrongTitle] + message:[MatrixKitL10n accountErrorEmailWrongDescription] + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { + [errorAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { if (weakSelf) { @@ -3416,8 +3435,9 @@ TableViewSectionsDelegate> }]]; - [currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCAddEmailAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [errorAlert mxk_setAccessibilityIdentifier: @"SettingsVCAddEmailAlert"]; + [self presentViewController:errorAlert animated:YES completion:nil]; + currentAlert = errorAlert; return; } @@ -3509,11 +3529,11 @@ TableViewSectionsDelegate> [currentAlert dismissViewControllerAnimated:NO completion:nil]; __weak typeof(self) weakSelf = self; - currentAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountErrorMsisdnWrongTitle] - message:[MatrixKitL10n accountErrorMsisdnWrongDescription] - preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:[MatrixKitL10n accountErrorMsisdnWrongTitle] + message:[MatrixKitL10n accountErrorMsisdnWrongDescription] + preferredStyle:UIAlertControllerStyleAlert]; - [currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] + [errorAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { @@ -3525,8 +3545,9 @@ TableViewSectionsDelegate> }]]; - [currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCAddMsisdnAlert"]; - [self presentViewController:currentAlert animated:YES completion:nil]; + [errorAlert mxk_setAccessibilityIdentifier: @"SettingsVCAddMsisdnAlert"]; + [self presentViewController:errorAlert animated:YES completion:nil]; + currentAlert = errorAlert; return; } @@ -3882,9 +3903,9 @@ TableViewSectionsDelegate> { [self->currentAlert dismissViewControllerAnimated:NO completion:nil]; - self->currentAlert = [UIAlertController alertControllerWithTitle:nil message:[VectorL10n settingsPasswordUpdated] preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *successAlert = [UIAlertController alertControllerWithTitle:nil message:[VectorL10n settingsPasswordUpdated] preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] + [successAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { @@ -3904,8 +3925,9 @@ TableViewSectionsDelegate> }]]; - [self->currentAlert mxk_setAccessibilityIdentifier:@"SettingsVCOnPasswordUpdatedAlert"]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; + [successAlert mxk_setAccessibilityIdentifier:@"SettingsVCOnPasswordUpdatedAlert"]; + [self presentViewController:successAlert animated:YES completion:nil]; + self->currentAlert = successAlert; } else { @@ -3930,9 +3952,9 @@ TableViewSectionsDelegate> { [self->currentAlert dismissViewControllerAnimated:NO completion:nil]; - self->currentAlert = [UIAlertController alertControllerWithTitle:nil message:[VectorL10n settingsFailToUpdatePassword] preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:nil message:[VectorL10n settingsFailToUpdatePassword] preferredStyle:UIAlertControllerStyleAlert]; - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] + [errorAlert addAction:[UIAlertAction actionWithTitle:[MatrixKitL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { @@ -3953,8 +3975,9 @@ TableViewSectionsDelegate> }]]; - [self->currentAlert mxk_setAccessibilityIdentifier:@"SettingsVCPasswordChangeFailedAlert"]; - [rootViewController presentViewController:self->currentAlert animated:YES completion:nil]; + [errorAlert mxk_setAccessibilityIdentifier:@"SettingsVCPasswordChangeFailedAlert"]; + [rootViewController presentViewController:errorAlert animated:YES completion:nil]; + self->currentAlert = errorAlert; } } diff --git a/changelog.d/5071.bugfix b/changelog.d/5071.bugfix new file mode 100644 index 000000000..40e26a7da --- /dev/null +++ b/changelog.d/5071.bugfix @@ -0,0 +1 @@ +Ensure alerts with weak references are retained until they've been presented. \ No newline at end of file