From d553685dea9f7c69c6fde40da95e0b212f208421 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 1 Feb 2021 21:26:02 +0100 Subject: [PATCH] feat: Implement reporting of events --- lib/l10n/intl_en.arb | 48 +++++++++++++++++++++++++ lib/views/chat.dart | 85 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 8 deletions(-) diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index d31a112a..4f70bec2 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1332,6 +1332,54 @@ "username": {} } }, + + + "howOffensiveIsThisContent": "How offensive is this content?", + "@howOffensiveIsThisContent": { + "type": "text", + "placeholders": {} + }, + "extremeOffensive": "Extreme offensive", + "@extremeOffensive": { + "type": "text", + "placeholders": {} + }, + "offensive": "Offensive", + "@offensive": { + "type": "text", + "placeholders": {} + }, + "inoffensive": "Inoffensive", + "@inoffensive": { + "type": "text", + "placeholders": {} + }, + "whyDoYouWantToReportThis": "Why do you want to report this?", + "@whyDoYouWantToReportThis": { + "type": "text", + "placeholders": {} + }, + "reason": "Reason", + "@reason": { + "type": "text", + "placeholders": {} + }, + "contentHasBeenReported": "The content has been reported to the server admins", + "@contentHasBeenReported": { + "type": "text", + "placeholders": {} + }, + "redactMessage": "Redact message", + "@redactMessage": { + "type": "text", + "placeholders": {} + }, + "reportMessage": "Report message", + "@reportMessage": { + "type": "text", + "placeholders": {} + }, + "searchForAChat": "Search for a chat", "@searchForAChat": { "type": "text", diff --git a/lib/views/chat.dart b/lib/views/chat.dart index 4cd41939..829d67bd 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -305,6 +305,47 @@ class _ChatState extends State { setState(() => selectedEvents.clear()); } + void reportEventAction(BuildContext context) async { + final event = selectedEvents.single; + final score = await showConfirmationDialog( + context: context, + title: L10n.of(context).howOffensiveIsThisContent, + 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( + context: context, + title: L10n.of(context).whyDoYouWantToReportThis, + 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.reportEvent( + event.roomId, + event.eventId, + reason.single, + score, + ), + ); + if (result.error != null) return; + setState(() => selectedEvents.clear()); + await FlushbarHelper.createSuccess( + message: L10n.of(context).contentHasBeenReported) + .show(context); + } + void redactEventsAction(BuildContext context) async { var confirmed = await showOkCancelAlertDialog( context: context, @@ -567,15 +608,43 @@ class _ChatState extends State { inputFocus.requestFocus(); }, ), - IconButton( - icon: Icon(Icons.content_copy_outlined), - onPressed: () => copyEventsAction(context), + PopupMenuButton( + onSelected: (selected) { + switch (selected) { + case 'copy': + copyEventsAction(context); + break; + case 'redact': + redactEventsAction(context); + break; + case 'report': + reportEventAction(context); + break; + } + }, + itemBuilder: (_) => [ + PopupMenuItem( + child: Text(L10n.of(context).copy), + value: 'copy', + ), + if (canRedactSelectedEvents) + PopupMenuItem( + child: Text( + L10n.of(context).redactMessage, + style: TextStyle(color: Colors.orange), + ), + value: 'redact', + ), + if (selectedEvents.length == 1) + PopupMenuItem( + child: Text( + L10n.of(context).reportMessage, + style: TextStyle(color: Colors.red), + ), + value: 'report', + ), + ], ), - if (canRedactSelectedEvents) - IconButton( - icon: Icon(Icons.delete_outlined), - onPressed: () => redactEventsAction(context), - ), ] : [ IconButton(