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

[JES] Testing some more updates. Hopefully have get_discussion in condenser...

[JES] Testing some more updates. Hopefully have get_discussion in condenser using the new blacklists
parent 0752a18b
No related branches found
No related tags found
No related merge requests found
......@@ -65,24 +65,9 @@ class Mutes:
self.fetched = perf()
@classmethod
async def all(cls, observer=None, context=None):
async def all(cls):
"""Return the set of all muted accounts from singleton instance."""
if not observer:
return cls.instance().accounts
if not context:
return cls.instance().accounts
valid_account(observer)
db = context['db']
sql = GET_BLACKLISTED_ACCOUNTS_SQL
sql_result = await db.query_all(sql, observer=observer)
names = set()
for row in sql_result:
names.add(row['name'])
return names
return cls.instance().accounts
@classmethod
async def get_blacklists_for_observer(cls, observer=None, context=None):
......@@ -102,31 +87,12 @@ class Mutes:
return blacklisted_users
@classmethod
async def lists(cls, name, rep, observer=None, context=None):
async def lists(cls, name, rep):
"""Return blacklists the account belongs to."""
return[]
assert name
inst = cls.instance()
if observer and context:
blacklists_for_user = []
valid_account(observer)
db = context['db']
sql = GET_BLACKLISTED_ACCOUNTS_SQL
sql_result = await db.query_all(sql, observer=observer)
for row in sql_result:
if row['name'] == name:
blacklists_for_user.append(row['source'])
if int(rep) < 1:
blacklists_for_user.append('reputation-0')
if int(rep) == 1:
blacklists_for_user.append('reputation-1')
return blacklists_for_user
# update hourly
if perf() - inst.fetched > 3600:
inst.load()
......
......@@ -94,7 +94,7 @@ async def call(context, api, method, params):
# Content primitives
elif method == 'get_content':
return await get_content(context, *_strict_list(params, 2))
return await get_content(context, *_strict_list(params, 3, 2))
elif method == 'get_content_replies':
return await get_content_replies(context, *_strict_list(params, 2))
......
......@@ -111,7 +111,7 @@ async def get_account_reputations(context, account_lower_bound: str = None, limi
# Content Primitives
@return_error_info
async def get_content(context, author: str, permlink: str):
async def get_content(context, author: str, permlink: str, observer=None):
"""Get a single post object."""
db = context['db']
valid_account(author)
......@@ -123,7 +123,11 @@ async def get_content(context, author: str, permlink: str):
result = await db.query_all(sql, author=author, permlink=permlink)
result = dict(result[0])
post = _condenser_post_object(result, 0)
post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all())
if not observer:
post['active_votes'] = _mute_votes(post['active_votes'], Mutes.all())
else:
blacklists_for_user = Mutes.get_blacklists_for_observer(observer, context)
post['active_votes'] = _mute_votes(post['active_votes'], blacklists_for_user.keys())
assert post, 'post was not found in cache'
return 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