Adds hide comment query & function

This commit is contained in:
Oleg Silkin 2019-08-03 23:34:00 -04:00
parent 87150d9470
commit 3c9e9d13c9
2 changed files with 39 additions and 3 deletions

View file

@ -170,6 +170,15 @@ def delete_comment_by_id(conn: sqlite3.Connection, comment_id: str):
return bool(curs.rowcount)
def hide_comment_by_id(conn: sqlite3.Connection, comment_id: str):
with conn:
curs = conn.execute("""
UPDATE OR IGNORE COMMENT SET IsHidden = TRUE
WHERE CommentId = ?
""", (comment_id,))
return bool(curs.rowcount)
def insert_channel(conn: sqlite3.Connection, channel_name: str, channel_id: str):
with conn:
conn.execute(

View file

@ -4,11 +4,13 @@ import sqlite3
from asyncio import coroutine
from database.queries import delete_comment_by_id
from src.server.misc import is_authentic_delete_signal
from src.server.misc import is_authentic_delete_signal, request_lbrynet, validate_signature_from_claim
from database.queries import get_comment_or_none
from database.queries import insert_comment
from database.queries import insert_channel
from database.queries import get_channel_id_from_comment_id
from database.queries import hide_comment_by_id
from src.server.misc import channel_matches_pattern_or_error
logger = logging.getLogger(__name__)
@ -47,5 +49,30 @@ async def delete_comment_if_authorized(app, comment_id, **kwargs):
return {'deleted': await job.wait()}
async def write_comment(app, comment):
return await coroutine(create_comment_or_error)(app['writer'], **comment)
async def write_comment(app, params):
return await coroutine(create_comment_or_error)(app['writer'], **params)
async def hide_comment(app, comment_id):
return await coroutine(hide_comment_by_id)(app['writer'], comment_id)
# comment_ids: [
# {
# "comment_id": id,
# "signing_ts": signing_ts,
# "signature": signature
# },
# ...
# ]
async def hide_comment_if_authorized(app, comment_id, signing_ts, signature):
channel = get_channel_id_from_comment_id(app['reader'], comment_id)
claim = await request_lbrynet(app, 'claim_search', claim_id=channel['channel_id'])
claim = claim['items'][0]
if not validate_signature_from_claim(claim, signature, signing_ts, comment_id):
raise ValueError('Invalid Signature')
job = await app['comment_scheduler'].spawn(hide_comment(app, comment_id))
return {
'hidden': await job.wait()
}