mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2024-12-18 12:24:28 -05:00
daemon: Add initial room sending support.
Note: Sending a message for now works only if the other clients have started Olm sessions for us already.
This commit is contained in:
parent
a5930e449c
commit
7ee128f185
@ -282,6 +282,37 @@ class ProxyDaemon:
|
|||||||
text=json.dumps(json_response)
|
text=json.dumps(json_response)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def send_message(self, request):
|
||||||
|
access_token = self.get_access_token(request)
|
||||||
|
|
||||||
|
if not access_token:
|
||||||
|
return self._missing_token
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = self.client_sessions[access_token]
|
||||||
|
except KeyError:
|
||||||
|
return self._uknown_token
|
||||||
|
|
||||||
|
msgtype = request.match_info["event_type"]
|
||||||
|
room_id = request.match_info["room_id"]
|
||||||
|
txnid = request.match_info["txnid"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
content = await request.json()
|
||||||
|
except JSONDecodeError:
|
||||||
|
return self._not_json
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = await client.room_send(room_id, msgtype, content, txnid)
|
||||||
|
except GroupEncryptionError:
|
||||||
|
await client.share_group_session(room_id)
|
||||||
|
response = await client.room_send(room_id, msgtype, content, txnid)
|
||||||
|
|
||||||
|
return web.Response(
|
||||||
|
status=response.transport_response.status,
|
||||||
|
text=await response.transport_response.text()
|
||||||
|
)
|
||||||
|
|
||||||
async def shutdown(self, app):
|
async def shutdown(self, app):
|
||||||
"""Shut the daemon down closing all the client sessions it has.
|
"""Shut the daemon down closing all the client sessions it has.
|
||||||
|
|
||||||
@ -303,8 +334,12 @@ async def init():
|
|||||||
app.add_routes([
|
app.add_routes([
|
||||||
web.post("/_matrix/client/r0/login", proxy.login),
|
web.post("/_matrix/client/r0/login", proxy.login),
|
||||||
web.get("/_matrix/client/r0/sync", proxy.sync),
|
web.get("/_matrix/client/r0/sync", proxy.sync),
|
||||||
|
web.put(
|
||||||
|
r"/_matrix/client/r0/rooms/{room_id}/send/{event_type}/{txnid}",
|
||||||
|
proxy.send_message
|
||||||
|
),
|
||||||
])
|
])
|
||||||
app.router.add_route('*', "/" + '{proxyPath:.*}', proxy.router)
|
app.router.add_route("*", "/" + "{proxyPath:.*}", proxy.router)
|
||||||
app.on_shutdown.append(proxy.shutdown)
|
app.on_shutdown.append(proxy.shutdown)
|
||||||
return proxy, app
|
return proxy, app
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user