mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-01-08 14:18:08 -05:00
pantalaimon: Prevent the sending of messages if the client didn't sync
Pantalaimon depends on the room state to be present to decide correctly if a message should be encrypted or now. The room state is fetched from the server every time we restart, this means that failure to fetch room states from the server would hinder us from doing the correct decision. This patch prevents a downgrade to sending unencrypted messages if we're unable to sync at least once with the server.
This commit is contained in:
parent
3dcaad8a9f
commit
340dbf2eb6
@ -410,6 +410,10 @@ class PanClient(AsyncClient):
|
||||
except (asyncio.CancelledError, KeyboardInterrupt):
|
||||
return
|
||||
|
||||
@property
|
||||
def has_been_synced(self) -> bool:
|
||||
self.last_sync_token is not None
|
||||
|
||||
async def sync_tasks(self, response):
|
||||
if self.index:
|
||||
await self.index.commit_events()
|
||||
@ -540,7 +544,6 @@ class PanClient(AsyncClient):
|
||||
timeout = 30000
|
||||
sync_filter = {"room": {"state": {"lazy_load_members": True}}}
|
||||
next_batch = self.pan_store.load_token(self.server_name, self.user_id)
|
||||
self.last_sync_token = next_batch
|
||||
|
||||
# We don't store any room state so initial sync needs to be with the
|
||||
# full_state parameter. Subsequent ones are normal.
|
||||
|
@ -902,7 +902,22 @@ class ProxyDaemon:
|
||||
room = client.rooms[room_id]
|
||||
encrypt = room.encrypted
|
||||
except KeyError:
|
||||
return await self.forward_to_web(request, token=client.access_token)
|
||||
if client.has_been_synced:
|
||||
return await self.forward_to_web(request, token=client.access_token)
|
||||
else:
|
||||
logger.error(
|
||||
"The internal Pantalaimon client did not manage "
|
||||
"to sync with the server."
|
||||
)
|
||||
return web.json_response(
|
||||
{
|
||||
"errcode": "M_UNKNOWN",
|
||||
"error": "The pantalaimon client did not manage to sync with "
|
||||
"the server",
|
||||
},
|
||||
headers=CORS_HEADERS,
|
||||
status=500,
|
||||
)
|
||||
|
||||
# Don't encrypt reactions for now - they are weird and clients
|
||||
# need to support them like this.
|
||||
|
Loading…
Reference in New Issue
Block a user