deleteReply method

Future<void> deleteReply(
  1. String parentId,
  2. String replyId
)

Deletes a reply from a parent comment.

Removes the reply from the parent comment's replies list and deletes it from the server. Also updates the parent comment's Comment.replyCount.

parentId is the ID of the parent comment. replyId is the ID of the reply to delete.

If the parent comment is not found, this method does nothing.

Implementation

Future<void> deleteReply(String parentId, String replyId) async {
  await controller.deleteComment(replyId);

  final parentIndex = _comments.indexWhere((c) => c.id == parentId);
  if (parentIndex == -1) return;

  final updatedReplies = _comments[parentIndex]
      .replies
      .where((r) => r.id != replyId)
      .toList();

  _comments[parentIndex] = _comments[parentIndex].copyWith(
      replies: updatedReplies,
      replyCount: updatedReplies.length
  );
  notifyListeners();
}