Change default comments sorting

Comments were sorted by descending creation date. Now they are sorted by
descending confidence and descending creation date.
This commit is contained in:
2018-11-26 19:48:12 +01:00
parent 07821c7f97
commit 411a6f75c5

View File

@@ -145,12 +145,21 @@ def comments_for_node(node_id):
def render_comments_for_node(node_id: str, *, can_post_comments: bool): def render_comments_for_node(node_id: str, *, can_post_comments: bool):
"""Render the list of comments for a node.""" """Render the list of comments for a node.
Comments are first sorted by confidence, see:
https://redditblog.com/2009/10/15/reddits-new-comment-sorting-system/
and then by creation date.
"""
# TODO(fsiddi) Implement confidence calculation on node rating in Pillar core.
# Currently this feature is being developed in the Dillo extension.
api = system_util.pillar_api() api = system_util.pillar_api()
# Query for all children, i.e. comments on the node. # Query for all children, i.e. comments on the node.
comments = Node.all({ comments = Node.all({
'where': {'node_type': 'comment', 'parent': node_id}, 'where': {'node_type': 'comment', 'parent': node_id},
'sort': [('properties.confidence', -1), ('_created', -1)],
}, api=api) }, api=api)
def enrich(some_comment): def enrich(some_comment):
@@ -171,6 +180,7 @@ def render_comments_for_node(node_id: str, *, can_post_comments: bool):
# Query for all grandchildren, i.e. replies to comments on the node. # Query for all grandchildren, i.e. replies to comments on the node.
comment['_replies'] = Node.all({ comment['_replies'] = Node.all({
'where': {'node_type': 'comment', 'parent': comment['_id']}, 'where': {'node_type': 'comment', 'parent': comment['_id']},
'sort': [('properties.confidence', -1), ('_created', -1)],
}, api=api) }, api=api)
enrich(comment) enrich(comment)