redd icon indicating copy to clipboard operation
redd copied to clipboard

Simplify the process of dealing with MoreComments objects.

Open avinashbot opened this issue 8 years ago • 1 comments

The Problem

When iterating through comments in a submission, users have to deal with a MoreComments, an object that represents comments that need to be expanded manually. Expanding them is also a pain because the object returns a flat listing of comments, forcing me to manually reconstruct the hierarchy locally.

The Solution

A custom CommentListing type that expands MoreComments as you iterate through it and caches the resulting data.

Architecture

Initialization

  1. A CommentListing is initialized by the Submission to represent the comments.
  2. Every subsequent comment also initializes the CommentListing with a reference to the main Submission.

Expanding

  1. If it hasn't been done before, a method is called on the Submission to traverse the comment tree and store references to all subcomments by their id. All unexpanded MoreComments are also stored separately.
  2. The MoreComments object uses this to check where to push expanded comments to.
  3. This also helps users fetch all comments in a submission.

avinashbot avatar Oct 04 '17 21:10 avinashbot

This feature would be extremely useful. How are you currently constructing the hierarchy when expanding MoreComments?

Brotakuu avatar Mar 15 '18 15:03 Brotakuu