From 20b19d0a4ae16fae33e0282762781b6a6317512c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 18 Mar 2022 18:45:58 +0100 Subject: [PATCH] Can report post --- lib/models/post.dart | 3 +++ lib/ui/tiles/post_tile.dart | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/models/post.dart b/lib/models/post.dart index 19dde81..11c0fb9 100644 --- a/lib/models/post.dart +++ b/lib/models/post.dart @@ -6,6 +6,7 @@ import 'package:comunic/lists/comments_list.dart'; import 'package:comunic/models/displayed_content.dart'; import 'package:comunic/models/like_element.dart'; import 'package:comunic/models/survey.dart'; +import 'package:comunic/utils/account_utils.dart' as account; /// Single post information /// @@ -76,6 +77,8 @@ class Post implements LikeElement { access == UserAccessLevels.FULL || access == UserAccessLevels.INTERMEDIATE; + bool get isOwner => userID == account.userID(); + @override LikesType get likeType => LikesType.POST; } diff --git a/lib/ui/tiles/post_tile.dart b/lib/ui/tiles/post_tile.dart index fcffc93..3bcfb1e 100644 --- a/lib/ui/tiles/post_tile.dart +++ b/lib/ui/tiles/post_tile.dart @@ -2,15 +2,19 @@ import 'dart:math'; import 'package:comunic/enums/post_kind.dart'; import 'package:comunic/enums/post_visibility_level.dart'; +import 'package:comunic/enums/report_target_type.dart'; import 'package:comunic/helpers/comments_helper.dart'; import 'package:comunic/helpers/posts_helper.dart'; +import 'package:comunic/helpers/server_config_helper.dart'; import 'package:comunic/lists/groups_list.dart'; import 'package:comunic/lists/users_list.dart'; import 'package:comunic/models/comment.dart'; import 'package:comunic/models/new_comment.dart'; import 'package:comunic/models/post.dart'; +import 'package:comunic/models/report_target.dart'; import 'package:comunic/models/user.dart'; import 'package:comunic/ui/dialogs/post_visibility_picker_dialog.dart'; +import 'package:comunic/ui/dialogs/report_dialog.dart'; import 'package:comunic/ui/tiles/comment_tile.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart'; import 'package:comunic/ui/widgets/countdown_widget.dart'; @@ -41,7 +45,7 @@ const TextStyle _userNameStyle = TextStyle( fontSize: 16.0); /// Post actions -enum _PostActions { DELETE, UPDATE_CONTENT } +enum _PostActions { DELETE, UPDATE_CONTENT, REPORT } class PostTile extends StatefulWidget { final Post post; @@ -152,7 +156,14 @@ class _PostTileState extends State { value: _PostActions.DELETE, enabled: widget.post.canDelete, ), - ], + ]..addAll(srvConfig!.isReportingEnabled && !widget.post.isOwner + ? [ + PopupMenuItem( + child: Text(tr("Report abuse")!), + value: _PostActions.REPORT, + ) + ] + : []), onSelected: _selectedPostMenuAction, ) ], @@ -561,6 +572,11 @@ class _PostTileState extends State { case _PostActions.DELETE: confirmDelete(); break; + + // Report content + case _PostActions.REPORT: + reportContent(); + break; } } @@ -620,4 +636,9 @@ class _PostTileState extends State { widget.onDeletedPost(widget.post); } + + /// Report post + void reportContent() async => await showReportDialog( + ctx: context, + target: ReportTarget(ReportTargetType.Post, widget.post.id)); }