mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2024-10-01 03:35:38 -04:00
Merge branch 'prevent-downgrade-on-failed-sync'
This commit is contained in:
commit
c6b021ed11
@ -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.
|
||||
|
@ -897,12 +897,36 @@ class ProxyDaemon:
|
||||
|
||||
room_id = request.match_info["room_id"]
|
||||
|
||||
# The room is not in the joined rooms list, just forward it.
|
||||
try:
|
||||
room = client.rooms[room_id]
|
||||
encrypt = room.encrypted
|
||||
except KeyError:
|
||||
return await self.forward_to_web(request, token=client.access_token)
|
||||
# The room is not in the joined rooms list, either the pan client
|
||||
# didn't manage to sync the state or we're not joined, in either
|
||||
# case send an error response.
|
||||
if client.has_been_synced:
|
||||
return web.json_response(
|
||||
{
|
||||
"errcode": "M_FORBIDDEN",
|
||||
"error": "You do not have permission to send the event."
|
||||
},
|
||||
headers=CORS_HEADERS,
|
||||
status=403,
|
||||
)
|
||||
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.
|
||||
@ -927,7 +951,9 @@ class ProxyDaemon:
|
||||
try:
|
||||
content["url"] = await self._decrypt_uri(content["url"], client)
|
||||
if "info" in content and "thumbnail_url" in content["info"]:
|
||||
content["info"]["thumbnail_url"] = await self._decrypt_uri(content["info"]["thumbnail_url"], client)
|
||||
content["info"]["thumbnail_url"] = await self._decrypt_uri(
|
||||
content["info"]["thumbnail_url"], client
|
||||
)
|
||||
return await self.forward_to_web(
|
||||
request, data=json.dumps(content), token=client.access_token
|
||||
)
|
||||
@ -947,7 +973,9 @@ class ProxyDaemon:
|
||||
content_msgtype in ["m.image", "m.video", "m.audio", "m.file"]
|
||||
or msgtype == "m.room.avatar"
|
||||
):
|
||||
upload_info, media_info = self._get_upload_and_media_info(content["url"])
|
||||
upload_info, media_info = self._get_upload_and_media_info(
|
||||
content["url"]
|
||||
)
|
||||
if not upload_info or not media_info:
|
||||
response = await client.room_send(
|
||||
room_id, msgtype, content, txnid, ignore_unverified
|
||||
@ -1265,7 +1293,9 @@ class ProxyDaemon:
|
||||
return self._not_json
|
||||
|
||||
try:
|
||||
content["avatar_url"] = await self._decrypt_uri(content["avatar_url"], client)
|
||||
content["avatar_url"] = await self._decrypt_uri(
|
||||
content["avatar_url"], client
|
||||
)
|
||||
return await self.forward_to_web(
|
||||
request, data=json.dumps(content), token=client.access_token
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user