From d381bb3fec73cc27235ef5411c76f65eb600d721 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Mon, 15 Aug 2022 10:50:13 +0200 Subject: [PATCH] Improve actor-level blocking --- app/boxes.py | 50 +++++++++++++++++++++++++++----------------------- app/main.py | 2 ++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/boxes.py b/app/boxes.py index 666c275..d38f8c4 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -1219,10 +1219,11 @@ async def _handle_read_activity( wrapped_object_actor = await fetch_actor( db_session, ap.get_actor_id(wrapped_object) ) - ro = RemoteObject(wrapped_object, actor=wrapped_object_actor) + if not wrapped_object_actor.is_blocked: + ro = RemoteObject(wrapped_object, actor=wrapped_object_actor) - # Then process it likes it's coming from a forwarded activity - await _process_note_object(db_session, read_activity, wrapped_object_actor, ro) + # Then process it likes it's coming from a forwarded activity + await _process_note_object(db_session, read_activity, wrapped_object_actor, ro) async def _process_note_object( @@ -1666,26 +1667,29 @@ async def save_to_inbox( announced_actor = await fetch_actor( db_session, ap.get_actor_id(announced_raw_object) ) - announced_object = RemoteObject(announced_raw_object, announced_actor) - announced_inbox_object = models.InboxObject( - server=urlparse(announced_object.ap_id).hostname, - actor_id=announced_actor.id, - ap_actor_id=announced_actor.ap_id, - ap_type=announced_object.ap_type, - ap_id=announced_object.ap_id, - ap_context=announced_object.ap_context, - ap_published_at=announced_object.ap_published_at, - ap_object=announced_object.ap_object, - visibility=announced_object.visibility, - og_meta=await opengraph.og_meta_from_note( - db_session, announced_object - ), - is_hidden_from_stream=True, - ) - db_session.add(announced_inbox_object) - await db_session.flush() - inbox_object.relates_to_inbox_object_id = announced_inbox_object.id - inbox_object.is_hidden_from_stream = not is_from_following + if not announced_actor.is_blocked: + announced_object = RemoteObject( + announced_raw_object, announced_actor + ) + announced_inbox_object = models.InboxObject( + server=urlparse(announced_object.ap_id).hostname, + actor_id=announced_actor.id, + ap_actor_id=announced_actor.ap_id, + ap_type=announced_object.ap_type, + ap_id=announced_object.ap_id, + ap_context=announced_object.ap_context, + ap_published_at=announced_object.ap_published_at, + ap_object=announced_object.ap_object, + visibility=announced_object.visibility, + og_meta=await opengraph.og_meta_from_note( + db_session, announced_object + ), + is_hidden_from_stream=True, + ) + db_session.add(announced_inbox_object) + await db_session.flush() + inbox_object.relates_to_inbox_object_id = announced_inbox_object.id + inbox_object.is_hidden_from_stream = not is_from_following elif activity_ro.ap_type in ["Like", "Announce"]: if not relates_to_outbox_object: diff --git a/app/main.py b/app/main.py index 7c91578..92a8ed3 100644 --- a/app/main.py +++ b/app/main.py @@ -76,6 +76,8 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac # TODO(ts): # # Next: +# - support Move +# - support actor delete # - allow to share old notes # - allow to interact with object not in anybox (i.e. like from a lookup) # - only show 10 most recent threads in DMs