diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index cd87ffa34..ad04d246d 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -561,8 +561,11 @@ // Dispatch the completion in order to let navigation stack refresh itself // It is required to display the auth VC at startup dispatch_async(dispatch_get_main_queue(), ^{ - completion(); - }); + if (completion) + { + completion(); + } + }); } } @@ -1164,6 +1167,15 @@ [self logout]; } }]; + + [[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionIgnoredUsersDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notif) { + + NSLog(@"[AppDelegate] kMXSessionIgnoredUsersDidChangeNotification received. Reload the app"); + + // Reload entirely the app when a user has been ignored or unignored + [[AppDelegate theDelegate] reloadMatrixSessions:YES]; + + }]; // Observe settings changes [[MXKAppSettings standardAppSettings] addObserver:self forKeyPath:@"showAllEventsInRoomHistory" options:0 context:nil]; diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index d4c71c6b3..e58936ac0 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -121,8 +121,10 @@ "room_participants_action_invite" = "Invite"; "room_participants_action_leave" = "Leave this room"; "room_participants_action_remove" = "Remove from this room"; -"room_participants_action_ban" = "Block"; -"room_participants_action_unban" = "Unblock"; +"room_participants_action_ban" = "Ban from this room"; +"room_participants_action_unban" = "Unban"; +"room_participants_action_ignore" = "Hide all messages from this user"; +"room_participants_action_unignore" = "Show all messages from this user"; "room_participants_action_set_default_power_level" = "Reset to normal user"; "room_participants_action_set_moderator" = "Make moderator"; "room_participants_action_set_admin" = "Make admin"; @@ -144,6 +146,9 @@ "room_event_action_share" = "Share"; "room_event_action_redact" = "Redact"; "room_event_action_permalink" = "Permalink"; +"room_event_action_report" = "Report content"; +"room_event_action_report_prompt_reason" = "Reason for reporting this content"; +"room_event_action_report_prompt_ignore_user" = "Do you want to hide all messages from this user?"; "room_event_action_save" = "Save"; "room_event_action_resend" = "Resend"; "room_event_action_delete" = "Delete"; diff --git a/Vector/ViewController/RoomMemberDetailsViewController.m b/Vector/ViewController/RoomMemberDetailsViewController.m index f3d8b50e8..daeb334a1 100644 --- a/Vector/ViewController/RoomMemberDetailsViewController.m +++ b/Vector/ViewController/RoomMemberDetailsViewController.m @@ -358,8 +358,22 @@ { [actionsArray addObject:@(MXKRoomMemberDetailsActionBan)]; } + + // Check whether the option Ignore may be presented + if (self.mxRoomMember.membership == MXMembershipJoin) + { + // is he already ignored ? + if (![self.mainSession isUserIgnored:self.mxRoomMember.userId]) + { + [actionsArray addObject:@(MXKRoomMemberDetailsActionIgnore)]; + } + else + { + [actionsArray addObject:@(MXKRoomMemberDetailsActionUnignore)]; + } + } break; - } + } case MXMembershipLeave: { // Check conditions to be able to invite someone @@ -414,6 +428,12 @@ case MXKRoomMemberDetailsActionUnban: title = NSLocalizedStringFromTable(@"room_participants_action_unban", @"Vector", nil); break; + case MXKRoomMemberDetailsActionIgnore: + title = NSLocalizedStringFromTable(@"room_participants_action_ignore", @"Vector", nil); + break; + case MXKRoomMemberDetailsActionUnignore: + title = NSLocalizedStringFromTable(@"room_participants_action_unignore", @"Vector", nil); + break; case MXKRoomMemberDetailsActionSetDefaultPowerLevel: title = NSLocalizedStringFromTable(@"room_participants_action_set_default_power_level", @"Vector", nil); break; diff --git a/Vector/ViewController/RoomViewController.m b/Vector/ViewController/RoomViewController.m index 441fdcd5b..75e43f472 100644 --- a/Vector/ViewController/RoomViewController.m +++ b/Vector/ViewController/RoomViewController.m @@ -98,8 +98,6 @@ CGPoint startScrollingPoint; } -@property (strong, nonatomic) MXKAlert *currentAlert; - @end @implementation RoomViewController @@ -277,10 +275,10 @@ [super viewWillDisappear:animated]; // hide action - if (self.currentAlert) + if (currentAlert) { - [self.currentAlert dismiss:NO]; - self.currentAlert = nil; + [currentAlert dismiss:NO]; + currentAlert = nil; } [self removeTypingNotificationsListener]; @@ -570,10 +568,10 @@ { self.navigationItem.rightBarButtonItem.enabled = NO; - if (self.currentAlert) + if (currentAlert) { - [self.currentAlert dismiss:NO]; - self.currentAlert = nil; + [currentAlert dismiss:NO]; + currentAlert = nil; } if (customizedRoomDataSource) @@ -1090,19 +1088,19 @@ if (selectedEvent) { - if (self.currentAlert) + if (currentAlert) { - [self.currentAlert dismiss:NO]; - self.currentAlert = nil; + [currentAlert dismiss:NO]; + currentAlert = nil; } __weak __typeof(self) weakSelf = self; - self.currentAlert = [[MXKAlert alloc] initWithTitle:nil message:nil style:MXKAlertStyleActionSheet]; + currentAlert = [[MXKAlert alloc] initWithTitle:nil message:nil style:MXKAlertStyleActionSheet]; // Add actions for a failed event if (selectedEvent.mxkState == MXKEventStateSendingFailed) { - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_resend", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_resend", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1112,7 +1110,7 @@ }]; - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_delete", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_delete", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1136,7 +1134,7 @@ selectedComponent = nil; } - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_copy", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_copy", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1145,7 +1143,7 @@ }]; - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_share", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_share", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1166,7 +1164,7 @@ { if (attachment.type == MXKAttachmentTypeImage || attachment.type == MXKAttachmentTypeVideo) { - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_save", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_save", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1194,7 +1192,7 @@ }]; } - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_copy", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_copy", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1220,7 +1218,7 @@ [roomBubbleTableViewCell startProgressUI]; }]; - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_share", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_share", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1258,7 +1256,7 @@ NSString *uploadId = roomBubbleTableViewCell.bubbleData.attachment.actualURL; if ([MXKMediaManager existingUploaderWithId:uploadId]) { - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_cancel_upload", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_cancel_upload", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1283,7 +1281,7 @@ NSString *cacheFilePath = roomBubbleTableViewCell.bubbleData.attachment.cacheFilePath; if ([MXKMediaManager existingDownloaderWithOutputFilePath:cacheFilePath]) { - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_cancel_download", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_cancel_download", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1301,7 +1299,7 @@ } } - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_redact", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_redact", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1325,7 +1323,7 @@ }]; }]; - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_permalink", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_permalink", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1341,9 +1339,97 @@ [[UIPasteboard generalPasteboard] setString:permalink]; }]; + + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_event_action_report", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + [strongSelf cancelEventSelection]; + + // Prompt user to enter a description of the problem content. + MXKAlert *reasonAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"room_event_action_report_prompt_reason", @"Vector", nil) message:nil style:MXKAlertStyleAlert]; + + [reasonAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.secureTextEntry = NO; + textField.placeholder = nil; + textField.keyboardType = UIKeyboardTypeDefault; + }]; + + [reasonAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + UITextField *textField = [alert textFieldAtIndex:0]; + + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + + [strongSelf startActivityIndicator]; + + [strongSelf.roomDataSource.room reportEvent:selectedEvent.eventId score:-100 reason:textField.text success:^{ + + __strong __typeof(weakSelf)strongSelf = weakSelf; + [strongSelf stopActivityIndicator]; + + // Prompt user to ignore content from this user + MXKAlert *ignoreAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"room_event_action_report_prompt_ignore_user", @"Vector", nil) message:nil style:MXKAlertStyleAlert]; + + [ignoreAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + + [strongSelf startActivityIndicator]; + + // Add the user to the blacklist: ignored users + [strongSelf.mainSession ignoreUsers:@[selectedEvent.sender] success:^{ + + __strong __typeof(weakSelf)strongSelf = weakSelf; + [strongSelf stopActivityIndicator]; + + } failure:^(NSError *error) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + [strongSelf stopActivityIndicator]; + + NSLog(@"[Vector RoomVC] Ignore user (%@) failed", selectedEvent.sender); + //Alert user + [[AppDelegate theDelegate] showErrorAsAlert:error]; + + }]; + + }]; + + ignoreAlert.cancelButtonIndex = [ignoreAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + }]; + + strongSelf->currentAlert = ignoreAlert; + [ignoreAlert showInViewController:strongSelf]; + + } failure:^(NSError *error) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + [strongSelf stopActivityIndicator]; + + NSLog(@"[Vector RoomVC] Report event (%@) failed", selectedEvent.eventId); + //Alert user + [[AppDelegate theDelegate] showErrorAsAlert:error]; + + }]; + }]; + + reasonAlert.cancelButtonIndex = [reasonAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + + __strong __typeof(weakSelf)strongSelf = weakSelf; + strongSelf->currentAlert = nil; + }]; + + strongSelf->currentAlert = reasonAlert; + [reasonAlert showInViewController:strongSelf]; + }]; } - self.currentAlert.cancelButtonIndex = [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf cancelEventSelection]; @@ -1351,14 +1437,14 @@ }]; // Do not display empty action sheet - if (self.currentAlert.cancelButtonIndex) + if (currentAlert.cancelButtonIndex) { - self.currentAlert.sourceView = roomBubbleTableViewCell; - [self.currentAlert showInViewController:self]; + currentAlert.sourceView = roomBubbleTableViewCell; + [currentAlert showInViewController:self]; } else { - self.currentAlert = nil; + currentAlert = nil; } } } @@ -1401,10 +1487,10 @@ - (void)cancelEventSelection { - if (self.currentAlert) + if (currentAlert) { - [self.currentAlert dismiss:NO]; - self.currentAlert = nil; + [currentAlert dismiss:NO]; + currentAlert = nil; } customizedRoomDataSource.selectedEventId = nil; @@ -1907,23 +1993,23 @@ } andIconTapGesture:^{ - if (self.currentAlert) + if (currentAlert) { - [self.currentAlert dismiss:NO]; + [currentAlert dismiss:NO]; } __weak __typeof(self) weakSelf = self; - self.currentAlert = [[MXKAlert alloc] initWithTitle:nil message:nil style:MXKAlertStyleActionSheet]; + currentAlert = [[MXKAlert alloc] initWithTitle:nil message:nil style:MXKAlertStyleActionSheet]; - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_resend_unsent_messages", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_resend_unsent_messages", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; [strongSelf resendAllUnsentMessages]; - strongSelf.currentAlert = nil; + strongSelf->currentAlert = nil; }]; - [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_delete_unsent_messages", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"room_delete_unsent_messages", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; @@ -1940,18 +2026,18 @@ index ++; } } - strongSelf.currentAlert = nil; + strongSelf->currentAlert = nil; }]; - self.currentAlert.cancelButtonIndex = [self.currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { + currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) { __strong __typeof(weakSelf)strongSelf = weakSelf; - strongSelf.currentAlert = nil; + strongSelf->currentAlert = nil; }]; - self.currentAlert.sourceView = roomActivitiesView; - [self.currentAlert showInViewController:self]; + currentAlert.sourceView = roomActivitiesView; + [currentAlert showInViewController:self]; }]; }