mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Q&A sort type: add special collapsing rules
In the Q&A sort type, we now collapse everything except: * top-level posts * OP posts * the comments preceding OP posts to help readers find OP interactions.
This commit is contained in:
@@ -354,6 +354,9 @@ num_comments = 100
|
||||
# max number of comments to show at once
|
||||
max_comments = 500
|
||||
max_comments_gold = 2500
|
||||
# max number of parents to walk up the tree while uncollapsing replies in Q&A
|
||||
# sort mode
|
||||
max_comment_parent_walk = 20
|
||||
# how deep do we go into the top listing when fetching /random
|
||||
num_serendipity = 250
|
||||
# number of subscriptions a user needs to have before the "my subreddits"
|
||||
|
||||
@@ -169,6 +169,7 @@ class Globals(object):
|
||||
'num_comments',
|
||||
'max_comments',
|
||||
'max_comments_gold',
|
||||
'max_comment_parent_walk',
|
||||
'max_sr_images',
|
||||
'num_serendipity',
|
||||
'sr_dropdown_threshold',
|
||||
|
||||
@@ -883,17 +883,82 @@ class CommentBuilder(Builder):
|
||||
wrapped_by_id = {comment._id: comment for comment in wrapped}
|
||||
final = []
|
||||
|
||||
# We have some special collapsing rules for the Q&A sort type.
|
||||
# However, we want to show everything when we're building a specific
|
||||
# set of children (like from "load more" links).
|
||||
qa_sort_hiding = (self.sort.col == '_qa') and not self.children
|
||||
if qa_sort_hiding:
|
||||
special_responder_ids = self.link.responder_ids
|
||||
else:
|
||||
special_responder_ids = ()
|
||||
|
||||
max_relation_walks = g.max_comment_parent_walk
|
||||
for comment in wrapped:
|
||||
# skip deleted comments with no children
|
||||
if (comment.deleted and not cid_tree.has_key(comment._id)
|
||||
and not self.show_deleted):
|
||||
comment.hidden_completely = True
|
||||
continue
|
||||
|
||||
comment.num_children = num_children[comment._id]
|
||||
comment.edits_visible = self.edits_visible
|
||||
|
||||
# In the Q&A sort type, we want to collapse all comments other than
|
||||
# those that are:
|
||||
#
|
||||
# 1. Top-level comments,
|
||||
# 2. Responses from the OP(s),
|
||||
# 3. Responded to by the OP(s) (dealt with below), or
|
||||
# 4. Otherwise normally prevented from collapse (eg distinguished
|
||||
# comments).
|
||||
if (qa_sort_hiding and
|
||||
depth[comment._id] != 0 and # (1)
|
||||
comment.author_id not in special_responder_ids and # (2)
|
||||
not comment.prevent_collapse): # (4)
|
||||
comment.hidden = True
|
||||
|
||||
if comment.collapsed and comment._id in dont_collapse:
|
||||
comment.collapsed = False
|
||||
comment.hidden = False
|
||||
|
||||
parent = wrapped_by_id.get(comment.parent_id)
|
||||
if parent:
|
||||
if (qa_sort_hiding and
|
||||
comment.author_id in special_responder_ids):
|
||||
# Un-collapse parents as necessary. It's a lot easier to
|
||||
# do this here, upwards, than to check through all the
|
||||
# children when we were iterating at the parent.
|
||||
ancestor = parent
|
||||
counter = 0
|
||||
while (ancestor and
|
||||
not getattr(ancestor, 'walked', False) and
|
||||
counter < max_relation_walks):
|
||||
ancestor.hidden = False
|
||||
# In case we haven't processed this comment yet.
|
||||
ancestor.prevent_collapse = True
|
||||
# This allows us to short-circuit when the rest of the
|
||||
# tree has already been uncollapsed.
|
||||
ancestor.walked = True
|
||||
|
||||
ancestor = wrapped_by_id.get(ancestor.parent_id)
|
||||
counter += 1
|
||||
|
||||
# One more time through to actually add things to the final list. We
|
||||
# couldn't do that the first time because in the Q&A sort we don't know
|
||||
# if a comment should be visible until after we've processed all its
|
||||
# children.
|
||||
for comment in wrapped:
|
||||
if getattr(comment, 'hidden_completely', False):
|
||||
# Don't add it to the tree, don't put it in "load more", don't
|
||||
# acknowledge its existence at all.
|
||||
continue
|
||||
|
||||
if getattr(comment, 'hidden', False):
|
||||
# Remove it from the list of visible comments so it'll
|
||||
# automatically be a candidate for the "load more" links.
|
||||
del wrapped_by_id[comment._id]
|
||||
# And don't add it to the tree.
|
||||
continue
|
||||
|
||||
# add the comment as a child of its parent or to the top level of
|
||||
# the tree if it has no parent
|
||||
|
||||
@@ -1263,12 +1263,12 @@ class Comment(Thing, Printable):
|
||||
|
||||
item.collapsed = False
|
||||
distinguished = item.distinguished and item.distinguished != "no"
|
||||
prevent_collapse = profilepage or user_is_admin or distinguished
|
||||
item.prevent_collapse = profilepage or user_is_admin or distinguished
|
||||
|
||||
if (item.deleted and item.subreddit.collapse_deleted_comments and
|
||||
not prevent_collapse):
|
||||
not item.prevent_collapse):
|
||||
item.collapsed = True
|
||||
elif item.score < min_score and not prevent_collapse:
|
||||
elif item.score < min_score and not item.prevent_collapse:
|
||||
item.collapsed = True
|
||||
item.collapsed_reason = _("comment score below threshold")
|
||||
elif user_is_loggedin and item.author_id in c.user.enemies:
|
||||
|
||||
@@ -90,7 +90,7 @@ ${parent.midcol(cls = cls)}
|
||||
<em>${_("[deleted]")}</em> 
|
||||
%endif
|
||||
|
||||
%if thing.collapsed and show:
|
||||
%if thing.collapsed and show and hasattr(thing, "collapsed_reason"):
|
||||
<span class="collapsed-reason">${thing.collapsed_reason}</span>
|
||||
%endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user