1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-21 20:39:22 +00:00

Can report post

This commit is contained in:
Pierre HUBERT 2022-03-18 18:45:58 +01:00
parent ec16984b8a
commit 20b19d0a4a
2 changed files with 26 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import 'package:comunic/lists/comments_list.dart';
import 'package:comunic/models/displayed_content.dart'; import 'package:comunic/models/displayed_content.dart';
import 'package:comunic/models/like_element.dart'; import 'package:comunic/models/like_element.dart';
import 'package:comunic/models/survey.dart'; import 'package:comunic/models/survey.dart';
import 'package:comunic/utils/account_utils.dart' as account;
/// Single post information /// Single post information
/// ///
@ -76,6 +77,8 @@ class Post implements LikeElement {
access == UserAccessLevels.FULL || access == UserAccessLevels.FULL ||
access == UserAccessLevels.INTERMEDIATE; access == UserAccessLevels.INTERMEDIATE;
bool get isOwner => userID == account.userID();
@override @override
LikesType get likeType => LikesType.POST; LikesType get likeType => LikesType.POST;
} }

View File

@ -2,15 +2,19 @@ import 'dart:math';
import 'package:comunic/enums/post_kind.dart'; import 'package:comunic/enums/post_kind.dart';
import 'package:comunic/enums/post_visibility_level.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/comments_helper.dart';
import 'package:comunic/helpers/posts_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/groups_list.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/comment.dart'; import 'package:comunic/models/comment.dart';
import 'package:comunic/models/new_comment.dart'; import 'package:comunic/models/new_comment.dart';
import 'package:comunic/models/post.dart'; import 'package:comunic/models/post.dart';
import 'package:comunic/models/report_target.dart';
import 'package:comunic/models/user.dart'; import 'package:comunic/models/user.dart';
import 'package:comunic/ui/dialogs/post_visibility_picker_dialog.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/tiles/comment_tile.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/countdown_widget.dart'; import 'package:comunic/ui/widgets/countdown_widget.dart';
@ -41,7 +45,7 @@ const TextStyle _userNameStyle = TextStyle(
fontSize: 16.0); fontSize: 16.0);
/// Post actions /// Post actions
enum _PostActions { DELETE, UPDATE_CONTENT } enum _PostActions { DELETE, UPDATE_CONTENT, REPORT }
class PostTile extends StatefulWidget { class PostTile extends StatefulWidget {
final Post post; final Post post;
@ -152,7 +156,14 @@ class _PostTileState extends State<PostTile> {
value: _PostActions.DELETE, value: _PostActions.DELETE,
enabled: widget.post.canDelete, enabled: widget.post.canDelete,
), ),
], ]..addAll(srvConfig!.isReportingEnabled && !widget.post.isOwner
? [
PopupMenuItem(
child: Text(tr("Report abuse")!),
value: _PostActions.REPORT,
)
]
: []),
onSelected: _selectedPostMenuAction, onSelected: _selectedPostMenuAction,
) )
], ],
@ -561,6 +572,11 @@ class _PostTileState extends State<PostTile> {
case _PostActions.DELETE: case _PostActions.DELETE:
confirmDelete(); confirmDelete();
break; break;
// Report content
case _PostActions.REPORT:
reportContent();
break;
} }
} }
@ -620,4 +636,9 @@ class _PostTileState extends State<PostTile> {
widget.onDeletedPost(widget.post); widget.onDeletedPost(widget.post);
} }
/// Report post
void reportContent() async => await showReportDialog(
ctx: context,
target: ReportTarget(ReportTargetType.Post, widget.post.id));
} }