mapComments method

Future<List<PostCommentContainer>?> mapComments(
  1. String postId,
  2. List<PostCommentModel?>? sourceComments,
  3. String appId,
  4. List<String> blockedMembers,
)

Implementation

Future<List<PostCommentContainer>?> mapComments(
  String postId,
  List<PostCommentModel?>? sourceComments,
  String appId,
  List<String> blockedMembers,
) async {
  if (sourceComments == null) return null;
  if (sourceComments.isEmpty) return null;

  List<PostCommentContainer> comments = [];
  for (int i = 0; i < sourceComments.length; i++) {
    var comment = sourceComments[i];
    if (comment != null) {
      List<PostCommentModel?>? sourceCommentComments =
          await postCommentRepository(appId: appId)!.valuesList(
              orderBy: 'timestamp',
              descending: true,
              eliudQuery: EliudQuery()
                  .withCondition(
                      EliudQueryCondition('postId', isEqualTo: postId))
                  .withCondition(EliudQueryCondition('postCommentId',
                      isEqualTo: comment.documentID)));
      List<PostCommentContainer>? commentComments = await mapComments(
        postId,
        sourceCommentComments,
        appId,
        blockedMembers,
      );

      var likeKey =
          PostHelper.getLikeKey(postId, comment.documentID, memberId);
      var like = await postLikeRepository(appId: appId)!.get(likeKey);

      var postCommentContainer =
          await construct(appId, comment, commentComments, like != null);
      comments.add(postCommentContainer);
    }
  }
  return filterCommentsFromBlockedMembers(comments, blockedMembers);
}