mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-24 13:59:22 +00:00
Can report comment
This commit is contained in:
parent
20b19d0a4a
commit
e80232931e
@ -1,3 +1,4 @@
|
||||
import 'package:comunic/helpers/server_config_helper.dart';
|
||||
import 'package:comunic/models/comment.dart';
|
||||
import 'package:comunic/models/user.dart';
|
||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||
@ -13,13 +14,14 @@ import 'package:flutter/material.dart';
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
enum _CommentAction { DELETE, UPDATE }
|
||||
enum _CommentAction { DELETE, UPDATE, REPORT }
|
||||
|
||||
class CommentTile extends StatelessWidget {
|
||||
final Comment comment;
|
||||
final User user;
|
||||
final void Function(Comment) onUpdateComment;
|
||||
final void Function(Comment) onDeleteComment;
|
||||
final void Function(Comment) onReportComment;
|
||||
|
||||
const CommentTile({
|
||||
Key? key,
|
||||
@ -27,6 +29,7 @@ class CommentTile extends StatelessWidget {
|
||||
required this.user,
|
||||
required this.onUpdateComment,
|
||||
required this.onDeleteComment,
|
||||
required this.onReportComment,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -37,34 +40,13 @@ class CommentTile extends StatelessWidget {
|
||||
user.displayName,
|
||||
),
|
||||
subtitle: _buildCommentContent(),
|
||||
trailing: Text(
|
||||
diffTimeFromNowToStr(comment.timeSent)!,
|
||||
style: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
trailing: _buildTrailing(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAccountImageWidget() {
|
||||
return PopupMenuButton<_CommentAction>(
|
||||
child: AccountImageWidget(
|
||||
user: user,
|
||||
),
|
||||
onSelected: _selectedMenuOption,
|
||||
itemBuilder: (c) => [
|
||||
// Update comment content
|
||||
PopupMenuItem(
|
||||
enabled: comment.isOwner,
|
||||
child: Text(tr("Update")!),
|
||||
value: _CommentAction.UPDATE,
|
||||
),
|
||||
|
||||
// Delete comment
|
||||
PopupMenuItem(
|
||||
enabled: comment.isOwner,
|
||||
child: Text(tr("Delete")!),
|
||||
value: _CommentAction.DELETE,
|
||||
),
|
||||
],
|
||||
return AccountImageWidget(
|
||||
user: user,
|
||||
);
|
||||
}
|
||||
|
||||
@ -101,6 +83,49 @@ class CommentTile extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTrailing() {
|
||||
return IntrinsicWidth(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
diffTimeFromNowToStr(comment.timeSent)!,
|
||||
style: TextStyle(fontSize: 10.0),
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
PopupMenuButton<_CommentAction>(
|
||||
padding: EdgeInsets.all(0),
|
||||
child: InkWell(
|
||||
child: Icon(Icons.adaptive.more, size: 20),
|
||||
),
|
||||
onSelected: _selectedMenuOption,
|
||||
itemBuilder: (c) => [
|
||||
// Update comment content
|
||||
PopupMenuItem(
|
||||
enabled: comment.isOwner,
|
||||
child: Text(tr("Update")!),
|
||||
value: _CommentAction.UPDATE,
|
||||
),
|
||||
|
||||
// Delete comment
|
||||
PopupMenuItem(
|
||||
enabled: comment.isOwner,
|
||||
child: Text(tr("Delete")!),
|
||||
value: _CommentAction.DELETE,
|
||||
),
|
||||
]..addAll(srvConfig!.isReportingEnabled && !comment.isOwner
|
||||
? [
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Report Abuse")!),
|
||||
value: _CommentAction.REPORT,
|
||||
)
|
||||
]
|
||||
: []),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// A menu option has been selected
|
||||
void _selectedMenuOption(_CommentAction value) {
|
||||
switch (value) {
|
||||
@ -113,6 +138,11 @@ class CommentTile extends StatelessWidget {
|
||||
case _CommentAction.DELETE:
|
||||
onDeleteComment(comment);
|
||||
break;
|
||||
|
||||
// Report comment
|
||||
case _CommentAction.REPORT:
|
||||
onReportComment(comment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -367,6 +367,7 @@ class _PostTileState extends State<PostTile> {
|
||||
user: widget.usersInfo.getUser(comment.userID),
|
||||
onUpdateComment: _updateCommentContent,
|
||||
onDeleteComment: _deleteComment,
|
||||
onReportComment: _reportComment,
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -560,6 +561,10 @@ class _PostTileState extends State<PostTile> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Process a report request
|
||||
void _reportComment(Comment comment) => showReportDialog(
|
||||
ctx: context, target: ReportTarget(ReportTargetType.Comment, comment.id));
|
||||
|
||||
/// Method called each time the user has selected an option
|
||||
void _selectedPostMenuAction(_PostActions value) {
|
||||
switch (value) {
|
||||
|
Loading…
Reference in New Issue
Block a user