parent method

Future<UserContent> parent()

Return the parent of the comment.

The returned parent will be an instance of either Comment or Submission.

Implementation

Future<UserContent> parent() async {
  if (_submission is! Submission) {
    _submission = await _submission!.populate();
  }
  final initializedSubmission = _submission as Submission;
  if (parentId == initializedSubmission.fullname) {
    return submission;
  }

  // Check if the comment already exists.
  CommentRef? parent = getCommentByIdInternal(_submission!, parentId);
  if (parent == null) {
    parent = CommentRef.withID(reddit, parentId.split('_')[1]);
    parent._submission = _submission;
  }
  return parent;
}