diff --git a/config.dist.toml b/config.dist.toml index b43d128..83128f4 100644 --- a/config.dist.toml +++ b/config.dist.toml @@ -64,3 +64,9 @@ tag_format = "camelCase" # A list of groups you want to send the message to, additionally to the followers. # This is required to get the messages discoverable by some social applications like Lemmy. groups = [] + +# Enable this to enable the comments feature. +# When disabled (default behavior): +# - the comments are silently rejected (social applications still receive an Accepted response to prevent them sending the responses again and again) +# - the API and JS widget are not available +accept_responses = false diff --git a/f2ap/activitypub.py b/f2ap/activitypub.py index c8b6b90..8d6e1a3 100644 --- a/f2ap/activitypub.py +++ b/f2ap/activitypub.py @@ -156,7 +156,7 @@ def handle_inbox( check_message_signature(config, actor, headers, inbox) - return actor, handle_inbox_message(db, inbox, on_following_accepted) + return actor, handle_inbox_message(db, inbox, on_following_accepted, config.message.accept_responses) def get_actor_from_inbox(db: Database, inbox: dict) -> dict: @@ -201,7 +201,7 @@ def check_message_signature( def handle_inbox_message( - db: Database, inbox: dict, on_following_accepted: Callable + db: Database, inbox: dict, on_following_accepted: Callable, accept_responses: bool ) -> Optional[dict]: if ( inbox.get("type") == "Accept" @@ -219,7 +219,7 @@ def handle_inbox_message( db.delete_follower(inbox.get("actor")) return - if inbox.get("type") == "Create" and inbox.get("object", {}).get("type") == "Note": + if accept_responses and inbox.get("type") == "Create" and inbox.get("object", {}).get("type") == "Note": # Save comments to a note note = inbox.get("object") in_reply_to = note.get("inReplyTo") @@ -251,6 +251,7 @@ def handle_inbox_message( return # Tombstone might be a Note, try to delete it. + # Note: this is always done, even when accept_responses is False, just in case it has been disabled lately. db.delete_comment(o.get("id")) return diff --git a/f2ap/config.py b/f2ap/config.py index 9052a27..5fb8966 100644 --- a/f2ap/config.py +++ b/f2ap/config.py @@ -133,7 +133,7 @@ def followers_link(self) -> str: class Message: def __init__( - self, format: str, tag_format: str = "camelCase", groups: [str] = None + self, format: str, tag_format: str = "camelCase", groups: [str] = None, accept_responses: bool = False ): valid_tag_formats = self.get_tags_formatters().keys() @@ -147,6 +147,7 @@ def __init__( self.tag_format = tag_format self.groups = groups if groups is not None else [] + self.accept_responses = accept_responses @staticmethod def get_tags_formatters() -> {str: Callable}: