lib/redd/models/more_comments.rb in redd-0.8.3 vs lib/redd/models/more_comments.rb in redd-0.8.4
- old
+ new
@@ -8,25 +8,23 @@
class MoreComments < BasicModel
# Expand the object's children into a listing of Comments and MoreComments.
# @param link [Submission] the submission the object belongs to
# @param sort [String] the sort order of the submission
# @return [Listing<Comment, MoreComments>] the expanded children
- def expand(link:, sort: 'best')
- @client.model(
- :get, '/api/morechildren',
- link_id: link.name,
- children: get_attribute(:children).join(','),
- sort: sort
- )
+ def expand(link:, sort: nil)
+ params = { link_id: link.name, children: get_attribute(:children).join(',') }
+ params[:sort] = sort if sort
+ params[:sort] = link.sort_order if link.sort_order
+ @client.model(:get, '/api/morechildren', params)
end
# Keep expanding until all top-level MoreComments are converted to comments.
# @param link [Submission] the object's submission
# @param sort [String] the sort order of the returned comments
# @param lookup [Hash] a hash of comments to add future replies to
# @param depth [Number] the maximum recursion depth
# @return [Array<Comment, MoreComments>] the expanded comments or self if past depth
- def recursive_expand(link:, sort: 'best', lookup: {}, depth: 10)
+ def recursive_expand(link:, sort: nil, lookup: {}, depth: 10)
return [self] if depth == 0
expand(link: link, sort: sort).flat_map do |thing|
if thing.is_a?(MoreComments) && thing.count > 0
# Get an array of expanded comments from the thing.