From 2ed8ba2d0fe829e96d20995f982b88d0ff018a15 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Mon, 19 Aug 2024 21:43:35 -0700 Subject: [PATCH] DM to request bridging: send acknowledgment DM to requester for #966 --- dms.py | 12 ++++++------ models.py | 5 +++-- tests/test_dms.py | 10 ++++++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/dms.py b/dms.py index 9de3c1f..c259fd7 100644 --- a/dms.py +++ b/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"""\

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. See the docs for more information.

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.

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 diff --git a/models.py b/models.py index c522f75..8e64d1a 100644 --- a/models.py +++ b/models.py @@ -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`? diff --git a/tests/test_dms.py b/tests/test_dms.py index 564e708..8bc0556 100644 --- a/tests/test_dms.py +++ b/tests/test_dms.py @@ -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')],