refresh method

  1. @override
Future<void> refresh()
override

Requests updated information from the Reddit API and updates the current object properties.

Implementation

@override
Future<void> refresh() async {
  if ((_submission == null) || (_submission is SubmissionRef)) {
    _submission = await submission.populate();
  }
  final path = submission.infoPath + '_/' + _id;
  final params = {
    'context': '100',
  };
  // TODO(bkonyi): clean-up this so it's objectified in a nicer way?
  final commentList = (await reddit.get(path, params: params))[1]['listing'];
  final queue = Queue.from(commentList);
  var comment;
  while (queue.isNotEmpty && ((comment == null) || (comment._id != _id))) {
    comment = queue.removeFirst();
    if ((comment is CommentRef) && (comment.replies != null)) {
      queue.addAll(comment.replies!.toList());
    }
  }
  if ((comment == null) || comment._id != _id) {
    throw DRAWClientError('Could not find comment with id $_id');
  }

  // Update the backing state of this comment object.
  setData(this, comment.data);

  _replies = comment.replies;

  // Ensure all the sub-comments are pointing to the same submission as this.
  setSubmissionInternal(this, submission);
}