Skip to content

Commit

Permalink
Protocol.check_supported: allow DMs both to and from bot accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Aug 16, 2024
1 parent a185b34 commit ccb7158
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 4 additions & 1 deletion protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,11 @@ def check_supported(cls, obj):
and inner_type not in cls.SUPPORTED_AS1_TYPES)):
error(f"Bridgy Fed for {cls.LABEL} doesn't support {obj.type} {inner_type} yet", status=204)

# DMs are only allowed to/from protocol bot accounts
if recip := as1.recipient_if_dm(obj.as1):
if not cls.SUPPORTS_DMS or recip not in PROTOCOL_DOMAINS:
if (not cls.SUPPORTS_DMS
or (recip not in PROTOCOL_DOMAINS
and as1.get_owner(obj.as1) not in PROTOCOL_DOMAINS)):
error(f"Bridgy Fed doesn't support DMs", status=204)


Expand Down
22 changes: 13 additions & 9 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,15 +759,19 @@ def test_check_supported(self):
Fake.check_supported(Object(our_as1=obj))

# Fake doesn't support DMs, ExplicitEnableFake does
bot_dm = Object(our_as1={
'objectType': 'note',
'actor': 'ap.brid.gy',
'to': ['did:bob'],
'content': 'hello world',
})
ExplicitEnableFake.check_supported(bot_dm)
with self.assertRaises(NoContent):
Fake.check_supported(bot_dm)
for actor, recip in (
('ap.brid.gy', 'did:bob'),
('did:bob', 'ap.brid.gy'),
):
bot_dm = Object(our_as1={
'objectType': 'note',
'actor': actor,
'to': [recip],
'content': 'hello world',
})
ExplicitEnableFake.check_supported(bot_dm)
with self.assertRaises(NoContent):
Fake.check_supported(bot_dm)

dm = Object(our_as1={
'objectType': 'note',
Expand Down

0 comments on commit ccb7158

Please sign in to comment.