kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
ff57074651
commit
a232cd457e
5
dms.py
5
dms.py
|
@ -107,6 +107,10 @@ def receive(*, from_user, obj):
|
|||
return 'OK', 200
|
||||
|
||||
elif to_proto.owns_handle(content) is not False:
|
||||
if not from_user.is_enabled(to_proto):
|
||||
maybe_send(from_proto=to_proto, to_user=from_user, text=f'Please bridge your account to {to_proto.PHRASE} by following this account before requesting another user.')
|
||||
return 'OK', 200
|
||||
|
||||
if to_id := to_proto.handle_to_id(content):
|
||||
if to_user := to_proto.get_or_create(to_id):
|
||||
maybe_send(from_proto=from_user, to_user=to_user,
|
||||
|
@ -116,3 +120,4 @@ def receive(*, from_user, obj):
|
|||
<p>Bridgy Fed will only send you this message once.""")
|
||||
return 'OK', 200
|
||||
|
||||
return "Couldn't understand DM: foo bar", 304
|
||||
|
|
|
@ -5,6 +5,14 @@ from web import Web
|
|||
|
||||
from .testutil import ExplicitEnableFake, Fake, OtherFake, TestCase
|
||||
|
||||
DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB = {
|
||||
'objectType': 'note',
|
||||
'id': 'eefake:dm',
|
||||
'actor': 'eefake:alice',
|
||||
'to': ['other.brid.gy'],
|
||||
'content': ' other:handle:bob ',
|
||||
}
|
||||
|
||||
|
||||
class DmsTest(TestCase):
|
||||
def test_maybe_send(self):
|
||||
|
@ -56,7 +64,19 @@ class DmsTest(TestCase):
|
|||
self.assertEqual([], OtherFake.sent)
|
||||
self.assertEqual([], user.sent_dms)
|
||||
|
||||
# def test_receive_unknown_text(self):
|
||||
def test_receive_unknown_text(self):
|
||||
self.make_user(id='other.brid.gy', cls=Web)
|
||||
alice = self.make_user('eefake:alice', cls=ExplicitEnableFake,
|
||||
enabled_protocols=['other'], obj_id='eefake:alice')
|
||||
|
||||
obj = Object(our_as1={
|
||||
**DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB,
|
||||
'content': 'foo bar',
|
||||
})
|
||||
self.assertEqual(("Couldn't understand DM: foo bar", 304),
|
||||
receive(from_user=alice, obj=obj))
|
||||
self.assertEqual([], OtherFake.sent)
|
||||
self.assertEqual([], Fake.sent)
|
||||
|
||||
def test_receive_no_yes_sets_enabled_protocols(self):
|
||||
alice = self.make_user('fake:alice', cls=Fake, obj_id='fake:alice')
|
||||
|
@ -115,31 +135,46 @@ class DmsTest(TestCase):
|
|||
Fake.sent)
|
||||
|
||||
def test_receive_handle_sends_request_dm(self):
|
||||
self.make_user(id='other.brid.gy', cls=Web)
|
||||
self.make_user(id='eefake.brid.gy', cls=Web)
|
||||
alice = self.make_user(id='eefake:alice', cls=ExplicitEnableFake,
|
||||
enabled_protocols=['other'], obj_as1={'x': 'y'})
|
||||
bob = self.make_user(id='other:bob', cls=OtherFake, obj_as1={'x': 'y'})
|
||||
|
||||
dm = Object(our_as1={
|
||||
'objectType': 'note',
|
||||
'id': 'eefake:dm',
|
||||
'actor': 'eefake:alice',
|
||||
'to': ['other.brid.gy'],
|
||||
'content': ' other:handle:bob ',
|
||||
})
|
||||
self.assertEqual(('OK', 200), receive(from_user=alice, obj=dm))
|
||||
obj = Object(our_as1=DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB)
|
||||
self.assertEqual(('OK', 200), receive(from_user=alice, obj=obj))
|
||||
self.assertEqual(
|
||||
[('https://eefake.brid.gy/#request_bridging-dm-other:bob-2022-01-02T03:04:05+00:00',
|
||||
'other:bob:target')],
|
||||
OtherFake.sent)
|
||||
|
||||
# def test_receive_handle_from_user_not_bridged(self):
|
||||
def test_receive_handle_from_user_not_bridged(self):
|
||||
self.make_user(id='other.brid.gy', cls=Web)
|
||||
# Alice isn't bridged into OtherFake
|
||||
alice = self.make_user(id='eefake:alice', cls=ExplicitEnableFake,
|
||||
enabled_protocols=['fake'], obj_as1={'x': 'y'})
|
||||
self.make_user(id='other:bob', cls=OtherFake, obj_as1={'x': 'y'})
|
||||
|
||||
obj = Object(our_as1=DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB)
|
||||
self.assertEqual(('OK', 200), receive(from_user=alice, obj=obj))
|
||||
self.assertEqual([], OtherFake.sent)
|
||||
self.assertEqual([], Fake.sent)
|
||||
|
||||
# def test_receive_handle_already_bridged(self):
|
||||
|
||||
# def test_receive_handle_already_requested(self):
|
||||
|
||||
def test_receive_handle_wrong_protocol(self):
|
||||
self.make_user(id='other.brid.gy', cls=Web)
|
||||
|
||||
obj = Object(our_as1={
|
||||
**DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB,
|
||||
'content': 'fake:eve',
|
||||
})
|
||||
self.assertEqual(("Couldn't understand DM: foo bar", 304),
|
||||
receive(from_user=Fake(id='fake:user'), obj=obj))
|
||||
self.assertEqual([], OtherFake.sent)
|
||||
self.assertEqual([], Fake.sent)
|
||||
|
||||
# def test_receive_handle_fetch_user(self):
|
||||
|
||||
# def test_receive_handle_wrong_protocol(self):
|
||||
|
||||
# def test_receive_handle_user_doesnt_exist(self):
|
||||
|
|
Ładowanie…
Reference in New Issue