replyTo method

Future<void> replyTo(
  1. String entityId,
  2. String parentId,
  3. String content
)

Adds a reply to a comment.

Creates a new reply to the specified parent comment and adds it to that comment's replies list.

entityId is the identifier of the entity. parentId is the ID of the comment being replied to. content is the text content of the reply.

If the reply creation fails or the parent comment is not found, this method does nothing.

Implementation

Future<void> replyTo(String entityId, String parentId, String content) async {
  final Comment? comment = await controller.postReply(entityId, parentId, content);
  if (comment == null) return;
  final index = _comments.indexWhere((c) => c.id == parentId);
  if (index != -1) {
    final updatedReplies = [..._comments[index].replies, comment];
    _comments[index] = _comments[index].copyWith(replies: updatedReplies);
    notifyListeners();
  }
}