mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Fix issue: when creating a comment on a list of posts where user never appeared before
This commit is contained in:
		@@ -4,6 +4,7 @@ import 'package:comunic/enums/post_kind.dart';
 | 
			
		||||
import 'package:comunic/enums/post_visibility_level.dart';
 | 
			
		||||
import 'package:comunic/helpers/comments_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/posts_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/users_helper.dart';
 | 
			
		||||
import 'package:comunic/lists/groups_list.dart';
 | 
			
		||||
import 'package:comunic/lists/users_list.dart';
 | 
			
		||||
import 'package:comunic/models/comment.dart';
 | 
			
		||||
@@ -472,31 +473,40 @@ class _PostTileState extends State<PostTile> {
 | 
			
		||||
 | 
			
		||||
  /// Submit comment entered by the user
 | 
			
		||||
  Future<void> _submitComment() async {
 | 
			
		||||
    _sendingComment = true;
 | 
			
		||||
    try {
 | 
			
		||||
      _sendingComment = true;
 | 
			
		||||
 | 
			
		||||
    final commentID = await _commentsHelper.createComment(NewComment(
 | 
			
		||||
      postID: widget.post.id,
 | 
			
		||||
      content: _commentController.text,
 | 
			
		||||
      image: _commentImage,
 | 
			
		||||
    ));
 | 
			
		||||
      final commentID = await _commentsHelper.createComment(NewComment(
 | 
			
		||||
        postID: widget.post.id,
 | 
			
		||||
        content: _commentController.text,
 | 
			
		||||
        image: _commentImage,
 | 
			
		||||
      ));
 | 
			
		||||
 | 
			
		||||
    _sendingComment = false;
 | 
			
		||||
      _sendingComment = false;
 | 
			
		||||
 | 
			
		||||
    if (commentID < 1)
 | 
			
		||||
      return showSimpleSnack(context, tr("Could not create comment!"));
 | 
			
		||||
      if (commentID < 1) throw new Exception("Comment ID is inferior to 1!");
 | 
			
		||||
 | 
			
		||||
    clearCommentForm();
 | 
			
		||||
      clearCommentForm();
 | 
			
		||||
 | 
			
		||||
    // Get and show new comment
 | 
			
		||||
    final newComment = await _commentsHelper.getSingle(commentID);
 | 
			
		||||
      // Get and show new comment
 | 
			
		||||
      final newComment = await _commentsHelper.getSingle(commentID);
 | 
			
		||||
 | 
			
		||||
    if (newComment == null)
 | 
			
		||||
      return showSimpleSnack(
 | 
			
		||||
          context, tr("Could not retrieve created comment!"));
 | 
			
		||||
      if (newComment == null)
 | 
			
		||||
        return showSimpleSnack(
 | 
			
		||||
            context, tr("Could not retrieve created comment!"));
 | 
			
		||||
 | 
			
		||||
    setState(() {
 | 
			
		||||
      widget.post.comments.add(newComment);
 | 
			
		||||
    });
 | 
			
		||||
      // Get information about the user who created the comment (if required)
 | 
			
		||||
      if (!widget.usersInfo.hasUser(newComment.userID))
 | 
			
		||||
        widget.usersInfo
 | 
			
		||||
            .add(await UsersHelper().getSingleWithThrow(newComment.userID));
 | 
			
		||||
 | 
			
		||||
      setState(() {
 | 
			
		||||
        widget.post.comments.add(newComment);
 | 
			
		||||
      });
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      print(e);
 | 
			
		||||
      showSimpleSnack(context, tr("Could not create comment!"));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Update comment content
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user