kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
c9b356f101
commit
2ed8ba2d0f
12
dms.py
12
dms.py
|
@ -108,12 +108,12 @@ def receive(*, from_user, obj):
|
|||
|
||||
# request a user
|
||||
elif to_proto.owns_handle(content) is not False:
|
||||
def error_reply(text, type=None):
|
||||
def reply(text, type=None):
|
||||
maybe_send(from_proto=to_proto, to_user=from_user, text=text, type=type)
|
||||
return 'OK', 200
|
||||
|
||||
if not from_user.is_enabled(to_proto):
|
||||
return error_reply(f'Please bridge your account to {to_proto.PHRASE} by following this account before requesting another user.')
|
||||
return reply(f'Please bridge your account to {to_proto.PHRASE} by following this account before requesting another user.')
|
||||
|
||||
if to_id := to_proto.handle_to_id(content):
|
||||
handle = content
|
||||
|
@ -122,22 +122,22 @@ def receive(*, from_user, obj):
|
|||
|
||||
if not to_user.obj:
|
||||
# doesn't exist
|
||||
return error_reply(f"Couldn't find {to_proto.PHRASE} user {handle}")
|
||||
return reply(f"Couldn't find {to_proto.PHRASE} user {handle}")
|
||||
|
||||
elif to_user.is_enabled(from_proto):
|
||||
# already bridged
|
||||
return error_reply(f'{to_user.user_link(handle=True, maybe_internal_link=False)} is already bridged into {from_proto.PHRASE}.')
|
||||
return reply(f'{to_user.user_link(handle=True, maybe_internal_link=False)} is already bridged into {from_proto.PHRASE}.')
|
||||
|
||||
elif (models.DM(protocol=from_proto.LABEL, type='request_bridging')
|
||||
in to_user.sent_dms):
|
||||
# already requested
|
||||
return error_reply(f'That user is already bridged into {from_proto.PHRASE}: {to_user.user_link(handle=True, maybe_internal_link=False)}')
|
||||
return reply(f"We've already sent {to_user.user_link(handle=True, maybe_internal_link=False)} a DM. Fingers crossed!")
|
||||
|
||||
maybe_send(from_proto=from_proto, to_user=to_user,
|
||||
type='request_bridging', text=f"""\
|
||||
<p>Hi! {obj.actor_link(image=False)} ({from_user.handle_as(to_proto)}) is using Bridgy Fed to bridge their account on {from_proto.PHRASE} into {to_proto.PHRASE} here, and they'd like to follow you. To let {from_proto.PHRASE} users see and interact with you, follow this account. <a href="https://fed.brid.gy/docs">See the docs</a> for more information.
|
||||
<p>If you do nothing, your account won't be bridged, and users on {from_proto.PHRASE} won't be able to see or interact with you.
|
||||
<p>Bridgy Fed will only send you this message once.""")
|
||||
return 'OK', 200
|
||||
return reply(f"Got it! We'll send {to_user.user_link(handle=True, maybe_internal_link=False)} a DM. Fingers crossed!")
|
||||
|
||||
return "Couldn't understand DM: foo bar", 304
|
||||
|
|
|
@ -716,8 +716,9 @@ Welcome to Bridgy Fed! Your account will soon be bridged to {to_proto.PHRASE} at
|
|||
def user_link(self, handle=False, maybe_internal_link=True):
|
||||
"""Returns a pretty link to the user with name and profile picture.
|
||||
|
||||
If they're opted in, links to their Bridgy Fed user page. Otherwise,
|
||||
links to their external account.
|
||||
Links to their Bridgy Fed user page if they're opted in and
|
||||
``maybe_internal_link`` is True. Otherwise, links to their external
|
||||
account.
|
||||
|
||||
TODO: unify with :meth:`Object.actor_link`?
|
||||
|
||||
|
|
|
@ -147,7 +147,10 @@ class DmsTest(TestCase):
|
|||
|
||||
obj = Object(our_as1=DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB)
|
||||
self.assertEqual(('OK', 200), receive(from_user=alice, obj=obj))
|
||||
self.assertEqual([], ExplicitEnableFake.sent)
|
||||
self.assertEqual(
|
||||
[('https://other.brid.gy/#?-dm-eefake:alice-2022-01-02T03:04:05+00:00',
|
||||
'eefake:alice:target')],
|
||||
ExplicitEnableFake.sent)
|
||||
self.assertEqual(
|
||||
[('https://eefake.brid.gy/#request_bridging-dm-other:bob-2022-01-02T03:04:05+00:00',
|
||||
'other:bob:target')],
|
||||
|
@ -162,7 +165,10 @@ class DmsTest(TestCase):
|
|||
|
||||
obj = Object(our_as1=DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB)
|
||||
self.assertEqual(('OK', 200), receive(from_user=alice, obj=obj))
|
||||
self.assertEqual([], ExplicitEnableFake.sent)
|
||||
self.assertEqual(
|
||||
[('https://other.brid.gy/#?-dm-eefake:alice-2022-01-02T03:04:05+00:00',
|
||||
'eefake:alice:target')],
|
||||
ExplicitEnableFake.sent)
|
||||
self.assertEqual(
|
||||
[('https://eefake.brid.gy/#request_bridging-dm-other:bob-2022-01-02T03:04:05+00:00',
|
||||
'other:bob:target')],
|
||||
|
|
Ładowanie…
Reference in New Issue