lib/redd/models/submission.rb in redd-0.8.4 vs lib/redd/models/submission.rb in redd-0.8.5
- old
+ new
@@ -30,15 +30,20 @@
def sort_order
@sort_order ||= nil
end
# Set the sort order of the comments and reload if necessary.
- # @param order [:confidence, :top, :controversial, :old, :qa] the sort order
- def sort_order=(order)
- @sort_order = order
- reload if @definitely_fully_loaded
- order
+ # @param new_order [:confidence, :top, :controversial, :old, :qa] the sort order
+ def sort_order=(new_order)
+ # If the comments were loaded in a different sort order, delete them and invalidate this
+ # model.
+ if @attributes.key?(:comments) && @sort_order != new_order
+ @attributes.delete(:comments)
+ @definitely_fully_loaded = false
+ end
+
+ @sort_order = new_order
end
# Get all submissions for the same url.
# @param params [Hash] A list of optional params to send with the request.
# @option params [String] :after return results after the given fullname
@@ -101,9 +106,18 @@
end
# Allow users to comment on the link again.
def unlock
@client.post('/api/unlock', id: get_attribute(:name))
+ end
+
+ # Set the suggested sort order for comments for all users.
+ # @param suggested ['blank', 'confidence', 'top', 'new', 'controversial', 'old', 'random',
+ # 'qa', 'live'] the sort type
+ def set_suggested_sort(suggested) # rubocop:disable Style/AccessorMethodName
+ # Style/AccessorMethodName is disabled because it feels wrong for accessor methods to make
+ # HTTP requests.
+ @client.post('/api/set_suggested_sort', id: get_attribute(:name), sort: suggested)
end
private
def default_loader