From efddaf50f22e62cae81e33b4121d006434133aa1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 8 Dec 2024 01:01:20 +0800 Subject: [PATCH] :sparkles: Abuse report --- assets/translations/en.json | 8 ++- assets/translations/zh.json | 8 ++- lib/screens/account.dart | 104 ++++++++++++++++++++++++++++++++ lib/widgets/post/post_item.dart | 4 +- 4 files changed, 118 insertions(+), 6 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 6cbf2a2..03d9859 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -390,7 +390,11 @@ "openInAlbum": "Open in album", "postAbuseReport": "Report Post", "postAbuseReportDescription": "Report posts that violate our user agreement and community guidelines to help us improve the content on Solar Network. Please describe how this post violates the relevant rules. Do not include any sensitive information. We will process your report within 24 hours.", - "postAbuseReportReason": "Reason", - "postAbuseReportSubmitted": "Report submitted, thank you for your contribution.", + "abuseReport": "Abuse Report", + "abuseReportDescription": "Report any resources that violate our user agreement and community guidelines to help us improve the content on Solar Network. Please describe the location of the resource (provide resource ID as best as possible) and how this violates the relevant rules. Do not include any sensitive information. We will process your report within 24 hours.", + "abuseReportActionDescription": "Report abuse usage behavior.", + "abuseReportResource": "Resource Location / ID", + "abuseReportReason": "Reason", + "abuseReportSubmitted": "Report submitted, thank you for your contribution.", "submit": "Submit" } diff --git a/assets/translations/zh.json b/assets/translations/zh.json index c4d63cd..daaa85b 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -390,7 +390,11 @@ "openInAlbum": "在相册中打开", "postAbuseReport": "检举帖子", "postAbuseReportDescription": "检举不符合我们用户协议以及社区准则的帖子,来帮助我们更好的维护 Solar Network 上的内容。请在下面描述该帖子如何违反我么的相关规定。请勿填写任何敏感信息。我们将会在 24 小时内处理您的检举。", - "postAbuseReportReason": "检举原因", - "postAbuseReportSubmitted": "检举已提交,感谢你的贡献。", + "abuseReport": "检举", + "abuseReportDescription": "检举不符合我们用户协议以及社区准则的任何资源,来帮助我们更好的维护 Solar Network 上的内容。请在下面描述资源的位置(提供资源 ID 为佳)以及如何违反我么的相关规定。请勿填写任何敏感信息。我们将会在 24 小时内处理您的检举。", + "abuseReportActionDescription": "检举不合规行为。", + "abuseReportResource": "资源位置 / ID", + "abuseReportReason": "检举原因", + "abuseReportSubmitted": "检举已提交,感谢你的贡献。", "submit": "提交" } diff --git a/lib/screens/account.dart b/lib/screens/account.dart index 963261a..e7560b9 100644 --- a/lib/screens/account.dart +++ b/lib/screens/account.dart @@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart'; import 'package:material_symbols_icons/symbols.dart'; import 'package:provider/provider.dart'; import 'package:styled_widget/styled_widget.dart'; +import 'package:surface/providers/sn_network.dart'; import 'package:surface/providers/userinfo.dart'; import 'package:surface/widgets/account/account_image.dart'; import 'package:surface/widgets/app_bar_leading.dart'; @@ -104,6 +105,23 @@ class _AuthorizedAccountScreen extends StatelessWidget { GoRouter.of(context).pushNamed('accountPublishers'); }, ), + ListTile( + title: Text('abuseReport').tr(), + subtitle: Text('abuseReportActionDescription').tr(), + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + leading: const Icon(Symbols.flag), + trailing: const Icon(Symbols.chevron_right), + onTap: () { + showDialog( + context: context, + builder: (context) => _AbuseReportDialog(), + ).then((value) { + if (value == true && context.mounted) { + context.showSnackbar('abuseReportSubmitted'.tr()); + } + }); + }, + ), ListTile( title: Text('accountLogout').tr(), subtitle: Text('accountLogoutSubtitle').tr(), @@ -183,3 +201,89 @@ class _UnauthorizedAccountScreen extends StatelessWidget { ); } } + +class _AbuseReportDialog extends StatefulWidget { + const _AbuseReportDialog({super.key}); + + @override + State<_AbuseReportDialog> createState() => _AbuseReportDialogState(); +} + +class _AbuseReportDialogState extends State<_AbuseReportDialog> { + bool _isBusy = false; + + final _resourceController = TextEditingController(); + final _reasonController = TextEditingController(); + + @override + dispose() { + _resourceController.dispose(); + _reasonController.dispose(); + super.dispose(); + } + + Future _performAction() async { + setState(() => _isBusy = true); + try { + final sn = context.read(); + await sn.client.request( + '/cgi/id/reports/abuse', + data: { + 'resource': _resourceController.text, + 'reason': _reasonController.text, + }, + ); + if (!mounted) return; + Navigator.pop(context, true); + } catch (err) { + if (!mounted) return; + context.showErrorDialog(err); + } finally { + setState(() => _isBusy = false); + } + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text('abuseReport'.tr()), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('abuseReportDescription'.tr()), + const Gap(12), + TextField( + controller: _resourceController, + maxLength: null, + decoration: InputDecoration( + border: const UnderlineInputBorder(), + labelText: 'abuseReportResource'.tr(), + ), + onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(), + ), + const Gap(4), + TextField( + controller: _reasonController, + maxLength: null, + decoration: InputDecoration( + border: const UnderlineInputBorder(), + labelText: 'abuseReportReason'.tr(), + ), + onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(), + ), + ], + ), + actions: [ + TextButton( + onPressed: _isBusy ? null : () => Navigator.pop(context), + child: Text('dialogDismiss').tr(), + ), + TextButton( + onPressed: _isBusy ? null : _performAction, + child: Text('submit').tr(), + ), + ], + ); + } +} diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index c71637d..4de41ea 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -577,7 +577,7 @@ class _PostContentHeader extends StatelessWidget { ), ).then((value) { if (value == true && context.mounted) { - context.showSnackbar('postAbuseReportSubmitted'.tr()); + context.showSnackbar('abuseReportSubmitted'.tr()); } }); }, @@ -793,7 +793,7 @@ class _PostAbuseReportDialogState extends State<_PostAbuseReportDialog> { maxLength: null, decoration: InputDecoration( border: const UnderlineInputBorder(), - labelText: 'postAbuseReportReason'.tr(), + labelText: 'abuseReportReason'.tr(), ), onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(), ),