feat: Implement reporting of events

This commit is contained in:
Christian Pauly 2021-02-01 21:26:02 +01:00
parent 3f08890ce9
commit d553685dea
2 changed files with 125 additions and 8 deletions

View File

@ -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",

View File

@ -305,6 +305,47 @@ class _ChatState extends State<Chat> {
setState(() => selectedEvents.clear());
}
void reportEventAction(BuildContext context) async {
final event = selectedEvents.single;
final score = await showConfirmationDialog<int>(
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,14 +608,42 @@ class _ChatState extends State<Chat> {
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)
IconButton(
icon: Icon(Icons.delete_outlined),
onPressed: () => redactEventsAction(context),
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',
),
],
),
]
: <Widget>[