From e0adc29903edc7d276ec68988408745ca69d5b8b Mon Sep 17 00:00:00 2001 From: Andy Uhnak Date: Fri, 11 Mar 2022 13:15:20 +0000 Subject: [PATCH 1/2] Ignore the sender of a room invite without needing to join the room first --- Riot/Assets/en.lproj/Vector.strings | 2 ++ Riot/Generated/Strings.swift | 8 +++++ Riot/Modules/Room/RoomViewController.m | 50 ++++++++++++++++++++++---- changelog.d/5807.change | 1 + 4 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 changelog.d/5807.change diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index ef355b183..9d6727dbb 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -497,6 +497,7 @@ Tap the + to start adding people."; "room_preview_unlinked_email_warning" = "This invitation was sent to %@, which is not associated with this account. You may wish to login with a different account, or add this email to your account."; "room_preview_try_join_an_unknown_room" = "You are trying to access %@. Would you like to join in order to participate in the discussion?"; "room_preview_try_join_an_unknown_room_default" = "a room"; +"room_preview_decline_invitation_options" = "Do you want to decline the invitation or ignore this user?"; // Settings "settings_title" = "Settings"; @@ -2032,6 +2033,7 @@ Tap the + to start adding people."; "end_call" = "End Call"; "resume_call" = "Resume"; "ignore" = "Ignore"; +"ignore_user" = "Ignore User"; "unignore" = "Unignore"; // Events formatter diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 755555512..cf2c25d68 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -2127,6 +2127,10 @@ public class VectorL10n: NSObject { public static var ignore: String { return VectorL10n.tr("Vector", "ignore") } + /// Ignore User + public static var ignoreUser: String { + return VectorL10n.tr("Vector", "ignore_user") + } /// Take photo public static var imagePickerActionCamera: String { return VectorL10n.tr("Vector", "image_picker_action_camera") @@ -5323,6 +5327,10 @@ public class VectorL10n: NSObject { public static var roomPredecessorLink: String { return VectorL10n.tr("Vector", "room_predecessor_link") } + /// Do you want to decline the invitation or ignore this user? + public static var roomPreviewDeclineInvitationOptions: String { + return VectorL10n.tr("Vector", "room_preview_decline_invitation_options") + } /// You have been invited to join this room by %@ public static func roomPreviewInvitationFormat(_ p1: String) -> String { return VectorL10n.tr("Vector", "room_preview_invitation_format", p1) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index ffe224ede..28431729c 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -4979,10 +4979,31 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; } else if (tappedView == previewHeader.leftButton) { - [self declineRoomInvitation]; + [self presentDeclineOptions]; } } +- (void)presentDeclineOptions +{ + UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:[VectorL10n roomPreviewDeclineInvitationOptions] + message:nil + preferredStyle:UIAlertControllerStyleActionSheet]; + [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n decline] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [self declineRoomInvitation]; + }]]; + [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n ignoreUser] + style:UIAlertActionStyleDestructive + handler:^(UIAlertAction * _Nonnull action) { + [self ignoreInviteSender]; + }]]; + [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] + style:UIAlertActionStyleCancel + handler:nil]]; + [self presentViewController:actionSheet animated:YES completion:nil]; +} + - (void)declineRoomInvitation { // 'Decline' button has been pressed @@ -4993,14 +5014,9 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; else { [self startActivityIndicator]; - [self.roomDataSource.room leave:^{ - [self stopActivityIndicator]; - - // We remove the current view controller. - // Pop to homes view controller - [[AppDelegate theDelegate] restoreInitialDisplay:^{}]; + [self popToHomeViewController]; } failure:^(NSError *error) { @@ -5011,6 +5027,26 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; } } +- (void)ignoreInviteSender +{ + [self startActivityIndicator]; + [self.roomDataSource.room ignoreInviteSender:^{ + [self stopActivityIndicator]; + [self popToHomeViewController]; + + } failure:^(NSError *error) { + [self stopActivityIndicator]; + MXLogDebug(@"[RoomVC] Failed to ignore inviter in room (%@)", self.roomDataSource.room.roomId); + }]; +} + +- (void)popToHomeViewController +{ + // We remove the current view controller. + // Pop to homes view controller + [[AppDelegate theDelegate] restoreInitialDisplay:^{}]; +} + #pragma mark - Typing management - (void)removeTypingNotificationsListener diff --git a/changelog.d/5807.change b/changelog.d/5807.change new file mode 100644 index 000000000..fa2b13524 --- /dev/null +++ b/changelog.d/5807.change @@ -0,0 +1 @@ +Room: Ignore the sender of a room invite without needing to join the room first From 9751d22772008fe8f55ae526fab0aa0331c6d883 Mon Sep 17 00:00:00 2001 From: Andy Uhnak Date: Mon, 14 Mar 2022 08:47:52 +0000 Subject: [PATCH 2/2] Anchor action sheet to source view --- Riot/Modules/Room/RoomViewController.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 28431729c..d8a02a9ae 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -4979,11 +4979,11 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; } else if (tappedView == previewHeader.leftButton) { - [self presentDeclineOptions]; + [self presentDeclineOptionsFromView:tappedView]; } } -- (void)presentDeclineOptions +- (void)presentDeclineOptionsFromView:(UIView *)view { UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:[VectorL10n roomPreviewDeclineInvitationOptions] message:nil @@ -5001,6 +5001,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; [actionSheet addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] style:UIAlertActionStyleCancel handler:nil]]; + actionSheet.popoverPresentationController.sourceView = view; [self presentViewController:actionSheet animated:YES completion:nil]; } @@ -5014,11 +5015,15 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; else { [self startActivityIndicator]; + MXWeakify(self); [self.roomDataSource.room leave:^{ + MXStrongifyAndReturnIfNil(self); + [self stopActivityIndicator]; [self popToHomeViewController]; } failure:^(NSError *error) { + MXStrongifyAndReturnIfNil(self); [self stopActivityIndicator]; MXLogDebug(@"[RoomVC] Failed to reject an invited room (%@) failed", self.roomDataSource.room.roomId); @@ -5030,11 +5035,16 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; - (void)ignoreInviteSender { [self startActivityIndicator]; + MXWeakify(self); [self.roomDataSource.room ignoreInviteSender:^{ + MXStrongifyAndReturnIfNil(self); + [self stopActivityIndicator]; [self popToHomeViewController]; } failure:^(NSError *error) { + MXStrongifyAndReturnIfNil(self); + [self stopActivityIndicator]; MXLogDebug(@"[RoomVC] Failed to ignore inviter in room (%@)", self.roomDataSource.room.roomId); }];