support blocking content

This commit is contained in:
Victor Shyba 2020-11-05 22:04:46 -03:00 committed by Lex Berezhny
parent 90e7821283
commit d3ec200e46
4 changed files with 15 additions and 6 deletions

View file

@ -288,7 +288,7 @@ def update_claim_filters(blocking_channel_hashes, filtering_channel_hashes, p: P
def select_reposts(channel_hashes, filter_type=0):
return select(
Claim.c.reposted_claim_hash, filter_type, Claim.c.channel_hash).where(
(Claim.c.channel_hash.in_(filtering_channel_hashes)) & (Claim.c.reposted_claim_hash.isnot(None)))
(Claim.c.channel_hash.in_(channel_hashes)) & (Claim.c.reposted_claim_hash.isnot(None)))
p.ctx.execute(ClaimFilter.delete())
# order matters: first we insert the blocked ones. Then the filtered ones.

View file

@ -18,6 +18,7 @@ log = logging.getLogger(__name__)
def resolve_claims(**constraints):
censor = context().get_resolve_censor()
rows = context().fetchall(select_claims(**constraints))
rows = censor.apply(rows, level=2)
return rows_to_txos(rows), censor

View file

@ -32,11 +32,11 @@ class Censor:
self.censored = {}
self.total = 0
def apply(self, rows):
return [row for row in rows if not self.censor(row)]
def apply(self, rows, level=1):
return [row for row in rows if not self.censor(row, level)]
def censor(self, row) -> bool:
was_censored = row['censor_type'] > 0
def censor(self, row, level=1) -> bool:
was_censored = row['censor_type'] >= level
if was_censored:
censoring_channel_hash = row['censor_owner_hash']
self.censored.setdefault(censoring_channel_hash, 0)

View file

@ -12,7 +12,7 @@ from lbry.crypto.base58 import Base58
from lbry.schema.claim import Claim, Stream, Channel
from lbry.schema.result import Outputs
from lbry.schema.support import Support
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError, ResolveCensoredError
from lbry.blockchain.lbrycrd import Lbrycrd
from lbry.blockchain.sync import BlockchainSync
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
@ -1405,6 +1405,14 @@ class TestClaimtrieSync(SyncingBlockchainTestCase):
results = await self.db.search_claims(channel="@some_channel")
self.assertEqual(len(results.rows), 0)
self.assertEqual(results.censor.censored.get(moderator_chan.claim_hash), 3) # good, bad and repost
# direct resolves are still possible
result = await self.db.resolve([bad_content.permanent_url])
self.assertEqual(bad_content.claim_id, result[bad_content.permanent_url].claim_id)
# blocklist, now applied to resolve as well
self.sync.blocking_channel_hashes.add(moderator_chan.claim_hash)
await self.generate(1)
result = await self.db.resolve([bad_content.permanent_url])
self.assertIsInstance(result[bad_content.permanent_url], ResolveCensoredError)
@skip