createComment method

Future<void> createComment(
  1. String postId, {
  2. String? parentCommentId,
})

Implementation

Future<void> createComment(String postId, {String? parentCommentId}) async {
  final token = await CommunityStorage.getAuthToken();
  if (token == null) {
    Get.snackbar('Error', CommunityMessages.loginRequiredComment);
    return;
  }

  if (_contentController.text.isEmpty) {
    Get.snackbar('Error', CommunityMessages.commentEmpty);
    return;
  }

  try {
    isLoading.value = true;
    requireSmartLinksNativeBridge();
    final result = await SmartLinksNativeApi.createComment(
      postId: postId,
      content: _contentController.text,
      authToken: token,
      parentId: parentCommentId,
    );
    if (result != null) {
      Get.snackbar('Success', CommunityMessages.commentAdded);
      _contentController.clear();
      await fetchComments(postId);
    } else {
      Get.snackbar('Error', CommunityMessages.commentCreateFailed);
    }
  } catch (e) {
    Get.snackbar(
      'Error',
      '${CommunityMessages.commentCreateFailed}: ${e.toString()}',
    );
  } finally {
    isLoading.value = false;
  }
}