Re-enable filtering

Gah, I forgot brutaldon had client side filters
This commit is contained in:
Cy 2020-06-01 19:17:30 +00:00 committed by Cy
parent f2f8e7a0c8
commit 72c6ba5d85
No known key found for this signature in database
GPG Key ID: F66D599380F88521
2 changed files with 38 additions and 10 deletions

View File

@ -1,13 +1,38 @@
from pprint import pprint
def maketree(mastodon, root, descendants):
class filtered_toot:
class account:
acct = "(filtered)"
display_name = "(filtered)"
emojis = ()
avatar_static = 'about:blank'
created_at = None
spoiler_text = None
content = ""
poll = None
card = None
media_attachments = None
sensitive = False
id = None
replies_count = -1
visibility = 'filtered'
favourited = False
in_reply_to_id = None
def maketree(mastodon, oktoot, root, descendants):
# Apply filters later...
# descendants = [toot for toot in descendants if oktoot(toot)]
lookup = dict((descendant.id, descendant) for descendant in descendants)
lookup[root.id] = root
replies = {}
roots = set([root.id])
def lookup_or_fetch(id):
if not id in lookup:
lookup[id] = mastodon.status(id)
toot = mastodon.status(id)
if not oktoot(toot):
# just a placeholder so it doesn't mess up the UI
return filtered_toot
return lookup[id]
def getreps(id):
if id in replies:
@ -65,8 +90,8 @@ def unmaketree(tree):
yield from unmaketree(children)
yield OUT
def build(mastodon, root, descendants):
tree, leftover = maketree(mastodon, root, descendants)
def build(mastodon, oktoot, root, descendants):
tree, leftover = maketree(mastodon, oktoot, root, descendants)
yield IN
yield from unmaketree(tree)
yield OUT

View File

@ -688,20 +688,23 @@ def thread(request, id):
notifications = _notes_count(account, mastodon)
filters = get_filters(mastodon, context="thread")
# # Apply filters
# descendants = [
# x for x in context.descendants if not toot_matches_filters(x, filters)
# ]
if account.preferences.tree_threads:
toots = tuple(threadtree.build(mastodon, root, context.descendants))
def oktoot(toot):
return not toot_matches_filters(toot, filters)
toots = tuple(threadtree.build(mastodon, oktoot,
root, context.descendants))
def vars(defaults):
defaults['toots'] = toots
defaults['IN'] = threadtree.IN
defaults['OUT'] = threadtree.OUT
return defaults
else:
# Apply filters
descendants = [
x for x in context.descendants if not toot_matches_filters(x, filters)
]
def vars(defaults):
defaults['descendants'] = context.descendants
defaults['descendants'] = descendants
defaults['root'] = toot
return defaults
return render(