mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-01-09 06:37:55 -05:00
daemon: Simplify the room send logic.
This commit is contained in:
parent
bfd7144b4f
commit
2151f55337
@ -14,7 +14,7 @@ from aiohttp.client_exceptions import (ContentTypeError,
|
|||||||
ClientConnectionError)
|
ClientConnectionError)
|
||||||
from multidict import CIMultiDict
|
from multidict import CIMultiDict
|
||||||
from nio import (EncryptionError, GroupEncryptionError, LoginResponse,
|
from nio import (EncryptionError, GroupEncryptionError, LoginResponse,
|
||||||
MembersSyncError)
|
SendRetryError)
|
||||||
|
|
||||||
from pantalaimon.client import PanClient
|
from pantalaimon.client import PanClient
|
||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
@ -31,10 +31,6 @@ from pantalaimon.thread_messages import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SendError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class ProxyDaemon:
|
class ProxyDaemon:
|
||||||
name = attr.ib()
|
name = attr.ib()
|
||||||
@ -620,24 +616,6 @@ class ProxyDaemon:
|
|||||||
body=await response.read()
|
body=await response.read()
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _send_message(self, client, room_id, msgtype, content, txnid):
|
|
||||||
"""Send a room message, fetch room members and share group sessions."""
|
|
||||||
retries = 5
|
|
||||||
|
|
||||||
for i in range(retries):
|
|
||||||
try:
|
|
||||||
return await client.room_send(room_id, msgtype, content, txnid)
|
|
||||||
except GroupEncryptionError:
|
|
||||||
await client.share_group_session(room_id)
|
|
||||||
except MembersSyncError:
|
|
||||||
await client.joined_members(room_id)
|
|
||||||
|
|
||||||
if client.should_query_keys:
|
|
||||||
keys_query_response = await client.keys_query()
|
|
||||||
await client.keys_query_cb(keys_query_response)
|
|
||||||
|
|
||||||
raise SendError("Service Unavailable")
|
|
||||||
|
|
||||||
async def send_message(self, request):
|
async def send_message(self, request):
|
||||||
access_token = self.get_access_token(request)
|
access_token = self.get_access_token(request)
|
||||||
|
|
||||||
@ -672,11 +650,10 @@ class ProxyDaemon:
|
|||||||
return self._not_json
|
return self._not_json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await self._send_message(client, room_id, msgtype,
|
response = await client.room_send(room_id, msgtype, content, txnid)
|
||||||
content, txnid)
|
|
||||||
except ClientConnectionError as e:
|
except ClientConnectionError as e:
|
||||||
return web.Response(status=500, text=str(e))
|
return web.Response(status=500, text=str(e))
|
||||||
except SendError as e:
|
except SendRetryError as e:
|
||||||
return web.Response(status=503, text=str(e))
|
return web.Response(status=503, text=str(e))
|
||||||
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
|
Loading…
Reference in New Issue
Block a user