mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can update comments content
This commit is contained in:
		@@ -9,12 +9,13 @@ import 'package:flutter/material.dart';
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
enum _CommentAction { DELETE }
 | 
			
		||||
enum _CommentAction { DELETE, UPDATE }
 | 
			
		||||
 | 
			
		||||
class CommentTile extends StatelessWidget {
 | 
			
		||||
  final Comment comment;
 | 
			
		||||
  final User user;
 | 
			
		||||
  final void Function(Comment) onUpdateLike;
 | 
			
		||||
  final void Function(Comment) onUpdateComment;
 | 
			
		||||
  final void Function(Comment) onDeleteComment;
 | 
			
		||||
 | 
			
		||||
  const CommentTile({
 | 
			
		||||
@@ -22,10 +23,13 @@ class CommentTile extends StatelessWidget {
 | 
			
		||||
    @required this.comment,
 | 
			
		||||
    @required this.user,
 | 
			
		||||
    @required this.onUpdateLike,
 | 
			
		||||
    @required this.onUpdateComment,
 | 
			
		||||
    @required this.onDeleteComment,
 | 
			
		||||
  })  : assert(comment != null),
 | 
			
		||||
        assert(user != null),
 | 
			
		||||
        assert(onUpdateLike != null),
 | 
			
		||||
        assert(onUpdateComment != null),
 | 
			
		||||
        assert(onDeleteComment != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@@ -46,11 +50,19 @@ class CommentTile extends StatelessWidget {
 | 
			
		||||
      ),
 | 
			
		||||
      onSelected: _selectedMenuOption,
 | 
			
		||||
      itemBuilder: (c) => [
 | 
			
		||||
            // Update comment content
 | 
			
		||||
            PopupMenuItem(
 | 
			
		||||
              enabled: comment.isOwner,
 | 
			
		||||
              child: Text("Delete"),
 | 
			
		||||
              child: Text(tr("Update")),
 | 
			
		||||
              value: _CommentAction.UPDATE,
 | 
			
		||||
            ),
 | 
			
		||||
 | 
			
		||||
            // Delete comment
 | 
			
		||||
            PopupMenuItem(
 | 
			
		||||
              enabled: comment.isOwner,
 | 
			
		||||
              child: Text(tr("Delete")),
 | 
			
		||||
              value: _CommentAction.DELETE,
 | 
			
		||||
            )
 | 
			
		||||
            ),
 | 
			
		||||
          ],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
@@ -128,6 +140,11 @@ class CommentTile extends StatelessWidget {
 | 
			
		||||
  /// A menu option has been selected
 | 
			
		||||
  void _selectedMenuOption(_CommentAction value) {
 | 
			
		||||
    switch (value) {
 | 
			
		||||
      // Update comment content
 | 
			
		||||
      case _CommentAction.UPDATE:
 | 
			
		||||
        onUpdateComment(comment);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      // Delete comment
 | 
			
		||||
      case _CommentAction.DELETE:
 | 
			
		||||
        onDeleteComment(comment);
 | 
			
		||||
 
 | 
			
		||||
@@ -195,6 +195,7 @@ class _PostTileState extends State<PostTile> {
 | 
			
		||||
            comment: widget.post.comments[num],
 | 
			
		||||
            user: widget.usersInfo.getUser(widget.post.comments[num].userID),
 | 
			
		||||
            onUpdateLike: _updateCommentLike,
 | 
			
		||||
            onUpdateComment: _updateCommentContent,
 | 
			
		||||
            onDeleteComment: _deleteComment,
 | 
			
		||||
          ),
 | 
			
		||||
    );
 | 
			
		||||
@@ -366,6 +367,24 @@ class _PostTileState extends State<PostTile> {
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Update comment content
 | 
			
		||||
  Future<void> _updateCommentContent(Comment comment) async {
 | 
			
		||||
    final newContent = await askUserString(
 | 
			
		||||
      context: context,
 | 
			
		||||
      title: tr("Update comment content"),
 | 
			
		||||
      message: tr("New content:"),
 | 
			
		||||
      defaultValue: comment.content,
 | 
			
		||||
      hint: tr("New content..."),
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (!(await _commentsHelper.updateContent(comment.id, newContent)))
 | 
			
		||||
      return showSimpleSnack(context, tr("Could not update comment content!"));
 | 
			
		||||
 | 
			
		||||
    setState(() {
 | 
			
		||||
      comment.content = newContent;
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Process the deletion of a user
 | 
			
		||||
  Future<void> _deleteComment(Comment comment) async {
 | 
			
		||||
    if (!await showConfirmDialog(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user