Skip to content

Commit

Permalink
User.enable_protocol: fill in real welcome DM message
Browse files Browse the repository at this point in the history
for #1024, #966, etc
  • Loading branch information
snarfed committed Aug 9, 2024
1 parent 9257715 commit 07b8a3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
10 changes: 8 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,17 @@ def enable():
if to_proto.LABEL in ids.COPIES_PROTOCOLS and not user.get_copy(to_proto):
to_proto.create_for(user)

enable()
return user

self_with_copy = enable()
add(self.enabled_protocols, to_proto.LABEL)

if added:
to_proto.bot_dm(to_user=self, text='hello world')
handle = self.handle_as(to_proto)
if url := to_proto.bridged_web_url_for(self_with_copy):
handle = f'<a href="{url}">{handle}</a>'
to_proto.bot_dm(to_user=self, text=f"""\
Welcome to Bridgy Fed! Your account will soon be bridged to {to_proto.PHRASE} at {handle}. <a href="https://fed.brid.gy/docs">See the docs</a> and <a href="https://{common.PRIMARY_DOMAIN}{self.user_page_path()}">your user page</a> for more information. To disable this and delete your bridged profile, block this account.""")

msg = f'Enabled {to_proto.LABEL} for {self.key.id()} : {self.user_page_path()}'
logger.info(msg)
Expand Down
24 changes: 20 additions & 4 deletions tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,13 @@ def test_activitypub_follow_bsky_bot_user_enables_protocol(self, mock_get, mock_
# bot user DM
args, kwargs = mock_post.call_args_list[1]
self.assert_equals(('http://inst/inbox',), args)
message = '<p>Welcome to Bridgy Fed! Your account will soon be bridged to Bluesky at <a href="https://bsky.app/profile/alice.inst.ap.brid.gy">alice.inst.ap.brid.gy</a>. <a href="https://fed.brid.gy/docs">See the docs</a> and <a href="https://fed.brid.gy/ap/@alice@inst">your user page</a> for more information. To disable this and delete your bridged profile, block this account.</p>'
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',
'actor': 'https://bsky.brid.gy/bsky.brid.gy',
'content': '<p>hello world</p>',
'contentMap': {'en': '<p>hello world</p>'},
'content': message,
'contentMap': {'en': message},
'content_is_html': True,
'to': ['https://inst/alice'],
}, json_loads(kwargs['data']), ignore=['to', '@context'])
Expand Down Expand Up @@ -518,9 +519,24 @@ def test_atproto_follow_ap_bot_user_enables_protocol(self, mock_get, mock_post):
'convoId': 'convo123',
'message': {
'$type': 'chat.bsky.convo.defs#messageInput',
'text': 'hello world',
'text': 'Welcome to Bridgy Fed! Your account will soon be bridged to the fediverse at @[email protected]. See the docs and your user page for more information. To disable this and delete your bridged profile, block this account.',
'facets': [{
'$type': 'app.bsky.richtext.facet',
'index': {'byteStart': 102, 'byteEnd': 114},
'features': [{
'$type': 'app.bsky.richtext.facet#link',
'uri': 'https://fed.brid.gy/docs',
}],
}, {
'$type': 'app.bsky.richtext.facet',
'index': {'byteStart': 119, 'byteEnd': 133},
'features': [{
'$type': 'app.bsky.richtext.facet#link',
'uri': 'https://fed.brid.gy/bsky/alice.com',
}],
}],
'createdAt': '2022-01-02T03:04:05.000Z',
'bridgyOriginalText': 'hello world',
'bridgyOriginalText': 'Welcome to Bridgy Fed! Your account will soon be bridged to the fediverse at @[email protected]. <a href="https://fed.brid.gy/docs">See the docs</a> and <a href="https://fed.brid.gy/bsky/alice.com">your user page</a> for more information. To disable this and delete your bridged profile, block this account.',
'bridgyOriginalUrl': 'https://ap.brid.gy/#welcome-dm-did:plc:alice-2022-01-02T03:04:05+00:00',
},
}, data=None, headers=headers)
Expand Down

0 comments on commit 07b8a3d

Please sign in to comment.