From 14a63b81062fd6eae9e89c394e5fb5e4e2a55f5b Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sat, 17 Aug 2024 14:35:57 -0700 Subject: [PATCH] Protocol.maybe_bot_dm bug fix: send a Create activity, not a bare Note for #1205 etc --- protocol.py | 15 +++++++++++---- tests/test_integrations.py | 16 +++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/protocol.py b/protocol.py index 79d67d4d..5f987d56 100644 --- a/protocol.py +++ b/protocol.py @@ -1146,7 +1146,7 @@ class Protocol: Args: to_user (models.User) - text (str) + text (str): message content. May be HTML. type (str): one of DM.TYPES """ dm = DM(protocol=bot_cls.LABEL, type=type) @@ -1165,10 +1165,17 @@ class Protocol: target_uri = to_user.target_for(to_user.obj, shared=False) target = Target(protocol=to_user.LABEL, uri=target_uri) obj_key = Object(id=id, source_protocol='web', undelivered=[target], our_as1={ - 'objectType': 'note', - 'id': id, + 'objectType': 'activity', + 'verb': 'post', + 'id': f'{id}-create', 'actor': bot.key.id(), - 'content': text, + 'object': { + 'objectType': 'note', + 'id': id, + 'author': bot.key.id(), + 'content': text, + 'to': [to_user.key.id()], + }, 'to': [to_user.key.id()], }).put() diff --git a/tests/test_integrations.py b/tests/test_integrations.py index 02dff666..70dd13e9 100644 --- a/tests/test_integrations.py +++ b/tests/test_integrations.py @@ -399,12 +399,18 @@ class IntegrationTests(TestCase): self.assert_equals(('http://inst/inbox',), args) message = '

Welcome to Bridgy Fed! Your account will soon be bridged to Bluesky at alice.inst.ap.brid.gy. See the docs and your user page for more information. To disable this and delete your bridged profile, block this account.

' self.assert_equals({ - 'type': 'Note', - 'id': 'https://bsky.brid.gy/r/https://bsky.brid.gy/#welcome-dm-https://inst/alice-2022-01-02T03:04:05+00:00', + 'type': 'Create', + 'id': 'https://bsky.brid.gy/r/https://bsky.brid.gy/#welcome-dm-https://inst/alice-2022-01-02T03:04:05+00:00-create', 'actor': 'https://bsky.brid.gy/bsky.brid.gy', - 'content': message, - 'contentMap': {'en': message}, - 'content_is_html': True, + 'object': { + 'type': 'Note', + 'id': 'https://bsky.brid.gy/r/https://bsky.brid.gy/#welcome-dm-https://inst/alice-2022-01-02T03:04:05+00:00', + 'attributedTo': 'https://bsky.brid.gy/bsky.brid.gy', + 'content': message, + 'contentMap': {'en': message}, + 'content_is_html': True, + 'to': ['https://inst/alice'], + }, 'to': ['https://inst/alice'], }, json_loads(kwargs['data']), ignore=['to', '@context'])