Skip to content

Commit

Permalink
Merge pull request #7805 from element-hq/stefan/reportRooms
Browse files Browse the repository at this point in the history
Report rooms
  • Loading branch information
stefanceriu authored Jun 12, 2024
2 parents 7e71a84 + 249478e commit 09f75af
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ Tap the + to start adding people.";
"room_action_send_sticker" = "Send sticker";
"room_action_send_file" = "Send file";
"room_action_reply" = "Reply";
"room_action_report" = "Report room";
"room_action_report_prompt_reason" = "Reason for reporting this room";
"room_replacement_information" = "This room has been replaced and is no longer active.";
"room_replacement_link" = "The conversation continues here.";
"room_predecessor_information" = "This room is a continuation of another conversation.";
Expand Down
8 changes: 8 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5207,6 +5207,14 @@ public class VectorL10n: NSObject {
public static var roomActionReply: String {
return VectorL10n.tr("Vector", "room_action_reply")
}
/// Report room
public static var roomActionReport: String {
return VectorL10n.tr("Vector", "room_action_report")
}
/// Reason for reporting this room
public static var roomActionReportPromptReason: String {
return VectorL10n.tr("Vector", "room_action_report_prompt_reason")
}
/// Send file
public static var roomActionSendFile: String {
return VectorL10n.tr("Vector", "room_action_send_file")
Expand Down
3 changes: 3 additions & 0 deletions Riot/Modules/Room/RoomInfo/RoomInfoCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ extension RoomInfoCoordinator: RoomInfoListCoordinatorDelegate {
self.delegate?.roomInfoCoordinatorDidLeaveRoom(self)
}

func roomInfoListCoordinatorDidRequestReportRoom(_ coordinator: RoomInfoListCoordinatorType) {
self.delegate?.roomInfoCoordinatorDidRequestReportRoom(self)
}
}

extension RoomInfoCoordinator: RoomParticipantsViewControllerDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import MatrixSDK
func roomInfoCoordinatorBridgePresenterDelegateDidLeaveRoom(_ coordinatorBridgePresenter: RoomInfoCoordinatorBridgePresenter)
func roomInfoCoordinatorBridgePresenter(_ coordinatorBridgePresenter: RoomInfoCoordinatorBridgePresenter, didReplaceRoomWithReplacementId roomId: String)
func roomInfoCoordinatorBridgePresenter(_ coordinator: RoomInfoCoordinatorBridgePresenter, viewEventInTimeline event: MXEvent)
func roomInfoCoordinatorBridgePresenterDidRequestReportRoom(_ coordinatorBridgePresenter: RoomInfoCoordinatorBridgePresenter)
}

/// RoomInfoCoordinatorBridgePresenter enables to start RoomInfoCoordinator from a view controller.
Expand Down Expand Up @@ -131,9 +132,14 @@ extension RoomInfoCoordinatorBridgePresenter: RoomInfoCoordinatorDelegate {
func roomInfoCoordinator(_ coordinator: RoomInfoCoordinatorType, didReplaceRoomWithReplacementId roomId: String) {
self.delegate?.roomInfoCoordinatorBridgePresenter(self, didReplaceRoomWithReplacementId: roomId)
}

func roomInfoCoordinator(_ coordinator: RoomInfoCoordinatorType, viewEventInTimeline event: MXEvent) {
self.delegate?.roomInfoCoordinatorBridgePresenter(self, viewEventInTimeline: event)
}

func roomInfoCoordinatorDidRequestReportRoom(_ coordinator: RoomInfoCoordinatorType) {
self.delegate?.roomInfoCoordinatorBridgePresenterDidRequestReportRoom(self)
}
}

// MARK: - UIAdaptivePresentationControllerDelegate
Expand Down
1 change: 1 addition & 0 deletions Riot/Modules/Room/RoomInfo/RoomInfoCoordinatorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protocol RoomInfoCoordinatorDelegate: AnyObject {
func roomInfoCoordinatorDidLeaveRoom(_ coordinator: RoomInfoCoordinatorType)
func roomInfoCoordinator(_ coordinator: RoomInfoCoordinatorType, didReplaceRoomWithReplacementId roomId: String)
func roomInfoCoordinator(_ coordinator: RoomInfoCoordinatorType, viewEventInTimeline event: MXEvent)
func roomInfoCoordinatorDidRequestReportRoom(_ coordinator: RoomInfoCoordinatorType)
}

/// `RoomInfoCoordinatorType` is a protocol describing a Coordinator that handle keybackup setup navigation flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ extension RoomInfoListCoordinator: RoomInfoListViewModelCoordinatorDelegate {
self.delegate?.roomInfoListCoordinatorDidLeaveRoom(self)
}

func roomInfoListViewModelDidRequestReportRoom(_ viewModel: RoomInfoListViewModelType) {
self.delegate?.roomInfoListCoordinatorDidRequestReportRoom(self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protocol RoomInfoListCoordinatorDelegate: AnyObject {
func roomInfoListCoordinator(_ coordinator: RoomInfoListCoordinatorType, wantsToNavigateTo target: RoomInfoListTarget)
func roomInfoListCoordinatorDidCancel(_ coordinator: RoomInfoListCoordinatorType)
func roomInfoListCoordinatorDidLeaveRoom(_ coordinator: RoomInfoListCoordinatorType)
func roomInfoListCoordinatorDidRequestReportRoom(_ coordinator: RoomInfoListCoordinatorType)
}

/// `RoomInfoListCoordinatorType` is a protocol describing a Coordinator that handle key backup setup passphrase navigation flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ enum RoomInfoListViewAction {
case navigate(target: RoomInfoListTarget)
case leave
case cancel
case report
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,16 @@ final class RoomInfoListViewController: UIViewController {
rows: [rowLeave],
footer: nil)

let rowReport = Row(type: .destructive, icon: Asset.Images.error.image, text: VectorL10n.roomEventActionReport, accessoryType: .disclosureIndicator) {
self.viewModel.process(viewAction: .report)
}
let sectionReport = Section(header: nil,
rows: [rowReport],
footer: nil)

tmpSections.append(sectionSettings)
tmpSections.append(sectionLeave)
tmpSections.append(sectionReport)

sections = tmpSections
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
self.leave()
case .cancel:
self.coordinatorDelegate?.roomInfoListViewModelDidCancel(self)
case .report:
self.coordinatorDelegate?.roomInfoListViewModelDidRequestReportRoom(self)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protocol RoomInfoListViewModelCoordinatorDelegate: AnyObject {
func roomInfoListViewModelDidCancel(_ viewModel: RoomInfoListViewModelType)
func roomInfoListViewModelDidLeaveRoom(_ viewModel: RoomInfoListViewModelType)
func roomInfoListViewModel(_ viewModel: RoomInfoListViewModelType, wantsToNavigateTo target: RoomInfoListTarget)
func roomInfoListViewModelDidRequestReportRoom(_ viewModel: RoomInfoListViewModelType)
}

/// Protocol describing the view model used by `RoomInfoListViewController`
Expand Down
53 changes: 53 additions & 0 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5372,6 +5372,50 @@ - (IBAction)onButtonPressed:(id)sender
}
}

- (void)handleReportRoom
{
// Prompt user to enter a description of the problem content.
UIAlertController *reportReasonAlert = [UIAlertController alertControllerWithTitle:[VectorL10n roomActionReportPromptReason]
message:nil
preferredStyle:UIAlertControllerStyleAlert];

[reportReasonAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = NO;
textField.placeholder = nil;
textField.keyboardType = UIKeyboardTypeDefault;
}];

MXWeakify(self);
[reportReasonAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n ok] style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
MXStrongifyAndReturnIfNil(self);

NSString *text = [self->currentAlert textFields].firstObject.text;
self->currentAlert = nil;

[self startActivityIndicator];

[self.roomDataSource.mxSession.matrixRestClient reportRoom:self.roomDataSource.roomId reason:text success:^{
MXStrongifyAndReturnIfNil(self);
[self stopActivityIndicator];
} failure:^(NSError *error) {
MXStrongifyAndReturnIfNil(self);
[self stopActivityIndicator];

MXLogDebug(@"[RoomVC] Report room (%@) failed", self.roomDataSource.roomId);
//Alert user
[self showError:error];
}];
}]];

[reportReasonAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
}]];

[self presentViewController:reportReasonAlert animated:YES completion:nil];
self->currentAlert = reportReasonAlert;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down Expand Up @@ -5617,6 +5661,10 @@ - (void)roomTitleView:(RoomTitleView*)titleView recognizeTapGesture:(UITapGestur
{
[self presentDeclineOptionsFromView:tappedView];
}
else if (tappedView == previewHeader.reportButton)
{
[self handleReportRoom];
}
}

- (void)presentDeclineOptionsFromView:(UIView *)view
Expand Down Expand Up @@ -7984,6 +8032,11 @@ - (void)roomInfoCoordinatorBridgePresenter:(RoomInfoCoordinatorBridgePresenter *
[self reloadRoomWihtEventId:event.eventId threadId:event.threadId forceUpdateRoomMarker:NO];
}

- (void)roomInfoCoordinatorBridgePresenterDidRequestReportRoom:(RoomInfoCoordinatorBridgePresenter *)coordinatorBridgePresenter
{
[self handleReportRoom];
}

-(void)reloadRoomWihtEventId:(NSString *)eventId
threadId:(NSString *)threadId
forceUpdateRoomMarker:(BOOL)forceUpdateRoomMarker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@property (weak, nonatomic) IBOutlet UIView *buttonsContainer;
@property (weak, nonatomic) IBOutlet UIButton *leftButton;
@property (weak, nonatomic) IBOutlet UIButton *rightButton;
@property (weak, nonatomic) IBOutlet UIButton *reportButton;
@property (weak, nonatomic) IBOutlet UILabel *subNoticeLabel;
@property (weak, nonatomic) IBOutlet UIView *bottomBorderView;

Expand Down
12 changes: 12 additions & 0 deletions Riot/Modules/Room/Views/Title/Preview/PreviewRoomTitleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ - (void)awakeFromNib
[self.rightButton setTitle:[VectorL10n join] forState:UIControlStateNormal];
[self.rightButton setTitle:[VectorL10n join] forState:UIControlStateHighlighted];

[self.reportButton setTitle:[VectorL10n roomActionReport] forState:UIControlStateNormal];
[self.reportButton setTitle:[VectorL10n roomActionReport] forState:UIControlStateHighlighted];

tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reportTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.rightButton addGestureRecognizer:tap];
self.rightButton.userInteractionEnabled = YES;

tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reportTapGesture:)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[self.reportButton addGestureRecognizer:tap];
self.reportButton.userInteractionEnabled = YES;
}

-(void)customizeViewRendering
Expand Down Expand Up @@ -86,6 +96,8 @@ -(void)customizeViewRendering
[self.rightButton.layer setCornerRadius:5];
self.rightButton.clipsToBounds = YES;
self.rightButton.backgroundColor = ThemeService.shared.theme.tintColor;

[self.reportButton setTitleColor:ThemeService.shared.theme.warningColor forState:UIControlStateNormal];
}

- (void)refreshDisplay
Expand Down
Loading

0 comments on commit 09f75af

Please sign in to comment.