Skip to content

Commit

Permalink
Make comments an option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Deuchnord committed Jan 26, 2023
1 parent 3dbadef commit e18a72d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions config.dist.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions f2ap/activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion f2ap/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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}:
Expand Down

0 comments on commit e18a72d

Please sign in to comment.