From b96e67ceea9202d16999456e77c22fbb6b4f29c7 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 3 Feb 2022 06:53:14 +0100 Subject: [PATCH] feat: Add button to report offensive users to server admins --- assets/l10n/intl_en.arb | 3 +- .../user_bottom_sheet/user_bottom_sheet.dart | 44 +++++++++++++++++++ .../user_bottom_sheet_view.dart | 7 +++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 40f0d56a..2b024355 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2708,5 +2708,6 @@ "iUnderstand": "I understand", "@iUnderstand": {}, "dismiss": "Dismiss", - "markAsRead": "Mark as read" + "markAsRead": "Mark as read", + "reportUser": "Report user" } diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart index 84bdd966..4316b62b 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart @@ -39,6 +39,50 @@ class UserBottomSheetController extends State { ) == OkCancelResult.ok); switch (action) { + case 'report': + final event = widget.user; + final score = await showConfirmationDialog( + context: context, + title: L10n.of(context)!.reportUser, + message: L10n.of(context)!.howOffensiveIsThisContent, + cancelLabel: L10n.of(context)!.cancel, + okLabel: L10n.of(context)!.ok, + actions: [ + AlertDialogAction( + key: -100, + label: L10n.of(context)!.extremeOffensive, + ), + AlertDialogAction( + key: -50, + label: L10n.of(context)!.offensive, + ), + AlertDialogAction( + key: 0, + label: L10n.of(context)!.inoffensive, + ), + ]); + if (score == null) return; + final reason = await showTextInputDialog( + useRootNavigator: false, + context: context, + title: L10n.of(context)!.whyDoYouWantToReportThis, + okLabel: L10n.of(context)!.ok, + cancelLabel: L10n.of(context)!.cancel, + textFields: [DialogTextField(hintText: L10n.of(context)!.reason)]); + if (reason == null || reason.single.isEmpty) return; + final result = await showFutureLoadingDialog( + context: context, + future: () => Matrix.of(context).client.reportContent( + event.roomId!, + event.eventId, + reason: reason.single, + score: score, + ), + ); + if (result.error != null) return; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(L10n.of(context)!.contentHasBeenReported))); + break; case 'mention': Navigator.of(context, rootNavigator: false).pop(); widget.onMention!(); diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart index 4c163432..3af87d05 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart @@ -102,6 +102,13 @@ class UserBottomSheetView extends StatelessWidget { Icons.block, ), ), + PopupMenuItem( + value: 'report', + child: _TextWithIcon( + L10n.of(context)!.reportUser, + Icons.shield_outlined, + ), + ), ], onSelected: controller.participantAction, ),