Skip to content
Snippets Groups Projects
Commit d36f98c8 authored by Jason Salyers's avatar Jason Salyers
Browse files

[JES] Some bug fixes

parent 40eabedd
No related branches found
No related tags found
No related merge requests found
...@@ -90,7 +90,8 @@ async def get_post(context, author, permlink, observer=None): ...@@ -90,7 +90,8 @@ async def get_post(context, author, permlink, observer=None):
result = await db.query_all(sql, author=author, permlink=permlink) result = await db.query_all(sql, author=author, permlink=permlink)
assert len(result) == 1, 'invalid author/permlink or post not found in cache' assert len(result) == 1, 'invalid author/permlink or post not found in cache'
post = _condenser_post_object(result[0]) post = _condenser_post_object(result[0])
post['blacklists'] = await Mutes.lists(post['author'], result[0]['author_rep'], observer, context) blacklists_for_user = Mutes.get_blacklists_for_observer(observer, context)
post['blacklists'] = await append_statistics_to_post(post, result[0], False, blacklists_for_user)
return post return post
@return_error_info @return_error_info
...@@ -188,7 +189,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', ...@@ -188,7 +189,7 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='',
pinned_result = await db.query_all(pinned_sql, author=start_author, limit=limit, tag=tag, permlink=start_permlink, community_name=tag, observer=observer) pinned_result = await db.query_all(pinned_sql, author=start_author, limit=limit, tag=tag, permlink=start_permlink, community_name=tag, observer=observer)
for row in pinned_result: for row in pinned_result:
post = _condenser_post_object(row) post = _condenser_post_object(row)
post = await append_statistics_to_post(post, row, True, observer, context, blacklists_for_user) post = await append_statistics_to_post(post, row, True, blacklists_for_user)
limit = limit - 1 limit = limit - 1
posts.append(post) posts.append(post)
pinned_post_ids.append(post['post_id']) pinned_post_ids.append(post['post_id'])
...@@ -196,17 +197,16 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='', ...@@ -196,17 +197,16 @@ async def get_ranked_posts(context, sort, start_author='', start_permlink='',
sql_result = await db.query_all(sql, author=start_author, limit=limit, tag=tag, permlink=start_permlink, community_name=tag, observer=observer) sql_result = await db.query_all(sql, author=start_author, limit=limit, tag=tag, permlink=start_permlink, community_name=tag, observer=observer)
for row in sql_result: for row in sql_result:
post = _condenser_post_object(row) post = _condenser_post_object(row)
post = await append_statistics_to_post(post, row, False, observer, context, blacklists_for_user) post = await append_statistics_to_post(post, row, False, blacklists_for_user)
if post['post_id'] in pinned_post_ids: if post['post_id'] in pinned_post_ids:
continue continue
posts.append(post) posts.append(post)
return posts return posts
async def append_statistics_to_post(post, row, is_pinned, observer=None, context=None, async def append_statistics_to_post(post, row, is_pinned, blacklists_for_user=None):
blacklists_for_user=None):
""" apply information such as blacklists and community names/roles to a given post """ """ apply information such as blacklists and community names/roles to a given post """
if not blacklists_for_user: if not blacklists_for_user:
post['blacklists'] = await Mutes.lists(row['author'], row['author_rep'], observer, context) post['blacklists'] = await Mutes.lists(row['author'], row['author_rep'])
else: else:
post['blacklists'] = [] post['blacklists'] = []
if row['author'] in blacklists_for_user: if row['author'] in blacklists_for_user:
...@@ -289,7 +289,7 @@ async def get_account_posts(context, sort, account, start_author='', start_perml ...@@ -289,7 +289,7 @@ async def get_account_posts(context, sort, account, start_author='', start_perml
sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit) sql_result = await db.query_all(sql, account=account, author=start_author, permlink=start_permlink, limit=limit)
for row in sql_result: for row in sql_result:
post = _condenser_post_object(row) post = _condenser_post_object(row)
post = await append_statistics_to_post(post, row, False, observer, context, blacklists_for_user) post = await append_statistics_to_post(post, row, False, blacklists_for_user)
posts.append(post) posts.append(post)
return posts return posts
......
...@@ -54,7 +54,7 @@ async def get_discussion(context, author, permlink, observer=None): ...@@ -54,7 +54,7 @@ async def get_discussion(context, author, permlink, observer=None):
root_id = rows[0]['id'] root_id = rows[0]['id']
all_posts = {} all_posts = {}
root_post = _condenser_post_object(rows[0]) root_post = _condenser_post_object(rows[0])
root_post = await append_statistics_to_post(root_post, rows[0], False, observer, context, blacklists_for_user) root_post = await append_statistics_to_post(root_post, rows[0], False, blacklists_for_user)
root_post['replies'] = [] root_post['replies'] = []
all_posts[root_id] = root_post all_posts[root_id] = root_post
...@@ -64,7 +64,7 @@ async def get_discussion(context, author, permlink, observer=None): ...@@ -64,7 +64,7 @@ async def get_discussion(context, author, permlink, observer=None):
for index in range(1, len(rows)): for index in range(1, len(rows)):
id_to_parent_id_map[rows[index]['id']] = rows[index]['parent_id'] id_to_parent_id_map[rows[index]['id']] = rows[index]['parent_id']
post = _condenser_post_object(rows[index]) post = _condenser_post_object(rows[index])
post = await append_statistics_to_post(post, rows[index], False, observer, context, blacklists_for_user) post = await append_statistics_to_post(post, rows[index], False, blacklists_for_user)
post['replies'] = [] post['replies'] = []
all_posts[post['post_id']] = post all_posts[post['post_id']] = post
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment