Report abusif content and Ignore user.

- Room member: Add new option Ignore to ignore content from a room member
- Chat screen: Add report option in the contextual per-message menu + Option to ignore the event sender
This commit is contained in:
giomfo
2016-05-03 18:29:54 +02:00
parent 8c3b8ffec8
commit 8168641c42
3 changed files with 143 additions and 44 deletions
+128 -42
View File
@@ -97,8 +97,6 @@
CGPoint startScrollingPoint;
}
@property (strong, nonatomic) MXKAlert *currentAlert;
@end
@implementation RoomViewController
@@ -276,10 +274,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];
@@ -569,10 +567,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)
@@ -1081,19 +1079,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];
@@ -1103,7 +1101,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];
@@ -1127,7 +1125,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];
@@ -1136,7 +1134,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];
@@ -1157,7 +1155,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];
@@ -1185,7 +1183,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];
@@ -1211,7 +1209,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];
@@ -1249,7 +1247,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];
@@ -1274,7 +1272,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];
@@ -1292,7 +1290,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];
@@ -1316,7 +1314,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];
@@ -1332,9 +1330,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 ignoreUser: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];
@@ -1342,14 +1428,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;
}
}
}
@@ -1392,10 +1478,10 @@
- (void)cancelEventSelection
{
if (self.currentAlert)
if (currentAlert)
{
[self.currentAlert dismiss:NO];
self.currentAlert = nil;
[currentAlert dismiss:NO];
currentAlert = nil;
}
customizedRoomDataSource.selectedEventId = nil;
@@ -1883,23 +1969,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;
@@ -1916,18 +2002,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];
}];
}