mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Can report comment
This commit is contained in:
		@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import 'package:comunic/helpers/server_config_helper.dart';
 | 
				
			||||||
import 'package:comunic/models/comment.dart';
 | 
					import 'package:comunic/models/comment.dart';
 | 
				
			||||||
import 'package:comunic/models/user.dart';
 | 
					import 'package:comunic/models/user.dart';
 | 
				
			||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
					import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
				
			||||||
@@ -13,13 +14,14 @@ import 'package:flutter/material.dart';
 | 
				
			|||||||
///
 | 
					///
 | 
				
			||||||
/// @author Pierre HUBERT
 | 
					/// @author Pierre HUBERT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum _CommentAction { DELETE, UPDATE }
 | 
					enum _CommentAction { DELETE, UPDATE, REPORT }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CommentTile extends StatelessWidget {
 | 
					class CommentTile extends StatelessWidget {
 | 
				
			||||||
  final Comment comment;
 | 
					  final Comment comment;
 | 
				
			||||||
  final User user;
 | 
					  final User user;
 | 
				
			||||||
  final void Function(Comment) onUpdateComment;
 | 
					  final void Function(Comment) onUpdateComment;
 | 
				
			||||||
  final void Function(Comment) onDeleteComment;
 | 
					  final void Function(Comment) onDeleteComment;
 | 
				
			||||||
 | 
					  final void Function(Comment) onReportComment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const CommentTile({
 | 
					  const CommentTile({
 | 
				
			||||||
    Key? key,
 | 
					    Key? key,
 | 
				
			||||||
@@ -27,6 +29,7 @@ class CommentTile extends StatelessWidget {
 | 
				
			|||||||
    required this.user,
 | 
					    required this.user,
 | 
				
			||||||
    required this.onUpdateComment,
 | 
					    required this.onUpdateComment,
 | 
				
			||||||
    required this.onDeleteComment,
 | 
					    required this.onDeleteComment,
 | 
				
			||||||
 | 
					    required this.onReportComment,
 | 
				
			||||||
  }) : super(key: key);
 | 
					  }) : super(key: key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
@@ -37,34 +40,13 @@ class CommentTile extends StatelessWidget {
 | 
				
			|||||||
        user.displayName,
 | 
					        user.displayName,
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
      subtitle: _buildCommentContent(),
 | 
					      subtitle: _buildCommentContent(),
 | 
				
			||||||
      trailing: Text(
 | 
					      trailing: _buildTrailing(),
 | 
				
			||||||
        diffTimeFromNowToStr(comment.timeSent)!,
 | 
					 | 
				
			||||||
        style: TextStyle(fontSize: 10.0),
 | 
					 | 
				
			||||||
      ),
 | 
					 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Widget _buildAccountImageWidget() {
 | 
					  Widget _buildAccountImageWidget() {
 | 
				
			||||||
    return PopupMenuButton<_CommentAction>(
 | 
					    return AccountImageWidget(
 | 
				
			||||||
      child: AccountImageWidget(
 | 
					 | 
				
			||||||
      user: user,
 | 
					      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,
 | 
					 | 
				
			||||||
        ),
 | 
					 | 
				
			||||||
      ],
 | 
					 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -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
 | 
					  /// A menu option has been selected
 | 
				
			||||||
  void _selectedMenuOption(_CommentAction value) {
 | 
					  void _selectedMenuOption(_CommentAction value) {
 | 
				
			||||||
    switch (value) {
 | 
					    switch (value) {
 | 
				
			||||||
@@ -113,6 +138,11 @@ class CommentTile extends StatelessWidget {
 | 
				
			|||||||
      case _CommentAction.DELETE:
 | 
					      case _CommentAction.DELETE:
 | 
				
			||||||
        onDeleteComment(comment);
 | 
					        onDeleteComment(comment);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Report comment
 | 
				
			||||||
 | 
					      case _CommentAction.REPORT:
 | 
				
			||||||
 | 
					        onReportComment(comment);
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -367,6 +367,7 @@ class _PostTileState extends State<PostTile> {
 | 
				
			|||||||
          user: widget.usersInfo.getUser(comment.userID),
 | 
					          user: widget.usersInfo.getUser(comment.userID),
 | 
				
			||||||
          onUpdateComment: _updateCommentContent,
 | 
					          onUpdateComment: _updateCommentContent,
 | 
				
			||||||
          onDeleteComment: _deleteComment,
 | 
					          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
 | 
					  /// Method called each time the user has selected an option
 | 
				
			||||||
  void _selectedPostMenuAction(_PostActions value) {
 | 
					  void _selectedPostMenuAction(_PostActions value) {
 | 
				
			||||||
    switch (value) {
 | 
					    switch (value) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user