forked from LBRYCommunity/lbry-sdk
hide_comments
now returns lists for both hidden
and visible
comments
This commit is contained in:
parent
149d343201
commit
006494b1fa
2 changed files with 25 additions and 13 deletions
|
@ -5154,10 +5154,11 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--comment_ids=<comment_ids> : (str, list) one or more comment_id to hide.
|
--comment_ids=<comment_ids> : (str, list) one or more comment_id to hide.
|
||||||
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
|
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
|
||||||
|
|
||||||
Returns:
|
Returns: lists containing the ids comments that are hidden and visible.
|
||||||
(dict) keyed by comment_id, containing success info
|
|
||||||
'<comment_id>': {
|
{
|
||||||
"hidden": (bool) flag indicating if comment_id was hidden
|
"hidden": (list) IDs of hidden comments.
|
||||||
|
"visible": (list) IDs of visible comments.
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||||
|
@ -5165,9 +5166,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
if isinstance(comment_ids, str):
|
if isinstance(comment_ids, str):
|
||||||
comment_ids = [comment_ids]
|
comment_ids = [comment_ids]
|
||||||
|
|
||||||
comments = await comment_client.jsonrpc_post(
|
comments = await comment_client.jsonrpc_post(self.conf.comment_server, 'get_comments_by_id', comment_ids=comment_ids)
|
||||||
self.conf.comment_server, 'get_comments_by_id', comment_ids=comment_ids
|
comments = comments['items']
|
||||||
)
|
|
||||||
claim_ids = {comment['claim_id'] for comment in comments}
|
claim_ids = {comment['claim_id'] for comment in comments}
|
||||||
claims = {cid: await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id=cid) for cid in claim_ids}
|
claims = {cid: await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id=cid) for cid in claim_ids}
|
||||||
pieces = []
|
pieces = []
|
||||||
|
|
|
@ -106,11 +106,16 @@ class MockedCommentServer:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def hide_comments(self, pieces: list):
|
def hide_comments(self, pieces: list):
|
||||||
comments_hidden = []
|
hidden = []
|
||||||
for p in pieces:
|
for p in pieces:
|
||||||
if self.hide_comment(**p):
|
if self.hide_comment(**p):
|
||||||
comments_hidden.append(p['comment_id'])
|
hidden.append(p['comment_id'])
|
||||||
return {'hidden': comments_hidden}
|
|
||||||
|
comment_ids = {c['comment_id'] for c in pieces}
|
||||||
|
return {
|
||||||
|
'hidden': hidden,
|
||||||
|
'visible': list(comment_ids - set(hidden))
|
||||||
|
}
|
||||||
|
|
||||||
def get_claim_comments(self, claim_id, page=1, page_size=50,**kwargs):
|
def get_claim_comments(self, claim_id, page=1, page_size=50,**kwargs):
|
||||||
comments = list(filter(lambda c: c['claim_id'] == claim_id, self.comments))
|
comments = list(filter(lambda c: c['claim_id'] == claim_id, self.comments))
|
||||||
|
@ -138,12 +143,19 @@ class MockedCommentServer:
|
||||||
def get_comment_channel_by_id(self, comment_id: int, **kwargs):
|
def get_comment_channel_by_id(self, comment_id: int, **kwargs):
|
||||||
comment = self.comments[self.get_comment_id(comment_id)]
|
comment = self.comments[self.get_comment_id(comment_id)]
|
||||||
return {
|
return {
|
||||||
'channel_id': comment.get('channel_id'),
|
'channel_id': comment['channel_id'],
|
||||||
'channel_name': comment.get('channel_name')
|
'channel_name': comment['channel_name'],
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_comments_by_id(self, comment_ids: list):
|
def get_comments_by_id(self, comment_ids: list):
|
||||||
return [self.comments[self.get_comment_id(cid)] for cid in comment_ids]
|
comments = [self.comments[self.get_comment_id(cid)] for cid in comment_ids]
|
||||||
|
return {
|
||||||
|
'page': 1,
|
||||||
|
'page_size': len(comment_ids),
|
||||||
|
'total_pages': 1,
|
||||||
|
'items': comments,
|
||||||
|
'has_hidden_comments': bool({c for c in comments if c['is_hidden']})
|
||||||
|
}
|
||||||
|
|
||||||
methods = {
|
methods = {
|
||||||
'get_claim_comments': get_claim_comments,
|
'get_claim_comments': get_claim_comments,
|
||||||
|
|
Loading…
Reference in a new issue