kopia lustrzana https://github.com/snarfed/bridgy-fed
ATProto.send_chat: handle 400 from getConvoForMembers, sendMessage
for #1024, #966, etcpull/1241/head
rodzic
c8d6ba510f
commit
848313dfd4
19
atproto.py
19
atproto.py
|
@ -864,10 +864,17 @@ class ATProto(User, Protocol):
|
|||
'User-Agent': USER_AGENT,
|
||||
'Authorization': f'Bearer {token}',
|
||||
})
|
||||
convo = client.chat.bsky.convo.getConvoForMembers(members=[to_did])
|
||||
output = client.chat.bsky.convo.sendMessage({
|
||||
'convoId': convo['convo']['id'],
|
||||
'message': msg,
|
||||
})
|
||||
logger.info(f'Sent chat message from {from_user.handle} to {self.handle} {to_did}: {json_dumps(output)}')
|
||||
|
||||
try:
|
||||
convo = client.chat.bsky.convo.getConvoForMembers(members=[to_did])
|
||||
sent = client.chat.bsky.convo.sendMessage({
|
||||
'convoId': convo['convo']['id'],
|
||||
'message': msg,
|
||||
})
|
||||
except RequestException as e:
|
||||
# getConvoForMembers returns eg 400 if the recipient has disabled chat
|
||||
util.interpret_http_exception(e)
|
||||
return False
|
||||
|
||||
logger.info(f'Sent chat message from {from_user.handle} to {self.handle} {to_did}: {json_dumps(sent)}')
|
||||
return True
|
||||
|
|
|
@ -1790,6 +1790,24 @@ Sed tortor neque, aliquet quis posuere aliquam […]
|
|||
'Authorization': ANY,
|
||||
})
|
||||
|
||||
# getConvoForMembers
|
||||
@patch('requests.get', return_value=requests_response({
|
||||
'error': 'InvalidRequest',
|
||||
'message': 'recipient has disabled incoming messages',
|
||||
}, status=400))
|
||||
def test_send_chat_recipient_disabled(self, mock_get):
|
||||
user = self.make_user_and_repo()
|
||||
alice = ATProto(id='did:plc:alice')
|
||||
|
||||
self.assertFalse(alice.send_chat({
|
||||
'$type': 'chat.bsky.convo.defs#messageInput',
|
||||
'text': 'hello world',
|
||||
}, from_user=user))
|
||||
|
||||
mock_get.assert_any_call(
|
||||
'https://chat.service.local/xrpc/chat.bsky.convo.getConvoForMembers?members=did%3Aplc%3Aalice',
|
||||
json=None, data=None, headers=ANY)
|
||||
|
||||
def test_datastore_client_get_record_datastore_object(self):
|
||||
self.make_user_and_repo()
|
||||
post = {
|
||||
|
|
Ładowanie…
Reference in New Issue