From 1b3c76ee2f2e0212b23a3e3b182d5d6726d34fcb Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 10 Jul 2022 16:04:37 +0200 Subject: [PATCH] Working webmentions --- app/boxes.py | 16 ++++++++++++++++ app/outgoing_activities.py | 4 ++-- app/templates/utils.html | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/boxes.py b/app/boxes.py index 706558c..dde094d 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -34,6 +34,7 @@ from app.outgoing_activities import new_outgoing_activity from app.source import markdownify from app.uploads import upload_to_attachment from app.utils import opengraph +from app.utils import webmentions AnyboxObject = models.InboxObject | models.OutboxObject @@ -372,6 +373,21 @@ async def send_create( for rcp in recipients: await new_outgoing_activity(db_session, rcp, outbox_object.id) + # If the note is public, check if we need to send any webmentions + if visibility == ap.VisibilityEnum.PUBLIC: + possible_targets = opengraph._urls_from_note(note) + logger.info(f"webmentions possible targert {possible_targets}") + for target in possible_targets: + webmention_endpoint = await webmentions.discover_webmention_endpoint(target) + logger.info(f"{target=} {webmention_endpoint=}") + if webmention_endpoint: + await new_outgoing_activity( + db_session, + webmention_endpoint, + outbox_object_id=outbox_object.id, + webmention_target=target, + ) + return note_id diff --git a/app/outgoing_activities.py b/app/outgoing_activities.py index 4a84345..27bd29d 100644 --- a/app/outgoing_activities.py +++ b/app/outgoing_activities.py @@ -104,7 +104,7 @@ def _send_actor_update_if_needed(db_session: Session) -> None: for rcp in { follower.actor.shared_inbox_url or follower.actor.inbox_url for follower in followers - } + { + } | { row.recipient for row in db_session.execute( select(func.distinct(models.OutgoingActivity.recipient).label("recipient")) @@ -124,7 +124,7 @@ def _send_actor_update_if_needed(db_session: Session) -> None: async def new_outgoing_activity( db_session: AsyncSession, recipient: str, - outbox_object_id: int | None, + outbox_object_id: int | None = None, inbox_object_id: int | None = None, webmention_target: str | None = None, ) -> models.OutgoingActivity: diff --git a/app/templates/utils.html b/app/templates/utils.html index afee9b7..b940126 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -157,7 +157,7 @@
- +
{{ actor.display_name | clean_html(actor) | safe }}