diff --git a/brutaldon/threadtree.py b/brutaldon/threadtree.py index a9cc416..a5a4dd3 100644 --- a/brutaldon/threadtree.py +++ b/brutaldon/threadtree.py @@ -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 diff --git a/brutaldon/views.py b/brutaldon/views.py index 6b39080..b702092 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -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(