From d4aaf610917f61f2a0b4029de6f8f9a36d7069f7 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 8 Dec 2024 00:53:22 +0800 Subject: [PATCH] :sparkles: Report post --- assets/translations/en.json | 7 ++- assets/translations/zh.json | 7 ++- lib/widgets/post/post_item.dart | 88 +++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 629680b..6cbf2a2 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -387,5 +387,10 @@ "articleWrittenAt": "Written at {}", "articleEditedAt": "Edited at {}", "attachmentSaved": "Saved to album", - "openInAlbum": "Open in album" + "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.", + "submit": "Submit" } diff --git a/assets/translations/zh.json b/assets/translations/zh.json index 736317d..c4d63cd 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -387,5 +387,10 @@ "articleWrittenAt": "发表于 {}", "articleEditedAt": "编辑于 {}", "attachmentSaved": "已保存到相册", - "openInAlbum": "在相册中打开" + "openInAlbum": "在相册中打开", + "postAbuseReport": "检举帖子", + "postAbuseReportDescription": "检举不符合我们用户协议以及社区准则的帖子,来帮助我们更好的维护 Solar Network 上的内容。请在下面描述该帖子如何违反我么的相关规定。请勿填写任何敏感信息。我们将会在 24 小时内处理您的检举。", + "postAbuseReportReason": "检举原因", + "postAbuseReportSubmitted": "检举已提交,感谢你的贡献。", + "submit": "提交" } diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 9615896..c71637d 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -569,6 +569,18 @@ class _PostContentHeader extends StatelessWidget { Text('report').tr(), ], ), + onTap: () { + showDialog( + context: context, + builder: (context) => _PostAbuseReportDialog( + data: data, + ), + ).then((value) { + if (value == true && context.mounted) { + context.showSnackbar('postAbuseReportSubmitted'.tr()); + } + }); + }, ), ], ), @@ -724,3 +736,79 @@ class _PostTruncatedHint extends StatelessWidget { ).opacity(0.75); } } + +class _PostAbuseReportDialog extends StatefulWidget { + final SnPost data; + + const _PostAbuseReportDialog({super.key, required this.data}); + + @override + State<_PostAbuseReportDialog> createState() => _PostAbuseReportDialogState(); +} + +class _PostAbuseReportDialogState extends State<_PostAbuseReportDialog> { + bool _isBusy = false; + + final _reasonController = TextEditingController(); + + @override + 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': 'post:${widget.data.id}', + '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('postAbuseReport'.tr()), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('postAbuseReportDescription'.tr()), + const Gap(12), + TextField( + controller: _reasonController, + maxLength: null, + decoration: InputDecoration( + border: const UnderlineInputBorder(), + labelText: 'postAbuseReportReason'.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(), + ), + ], + ); + } +}