Fix loading m.image events in encrypted rooms

Fix bug introduced in 11fb32:

When loading an encrypted thumbnail, QML lacks the decryption dict for
half a second at first.

When calling python like this, python calls the wrong matrix API
for fetching the encrypted thumbnail, and the added retry code
would be forever stuck.

The retry code has been moved to QML, and now works for all HImage.
This commit is contained in:
miruka
2020-07-19 14:49:41 -04:00
parent 26a4d76fc2
commit f1055ce5b9
5 changed files with 34 additions and 24 deletions

View File

@@ -12,7 +12,6 @@ from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, Optional
from urllib.parse import urlparse
from .errors import MatrixError
from PIL import Image as PILImage
@@ -134,20 +133,8 @@ class Media:
async def create(self) -> Path:
"""Download and cache the media file to disk."""
retries = 0
while True:
try:
async with CONCURRENT_DOWNLOADS_LIMIT:
data = await self._get_remote_data()
except MatrixError as err:
if err.http_code != 404 and err.http_code < 500:
raise
else:
break
await asyncio.sleep(min(30, 0.2 * (2 ** (min(1000, retries) - 1))))
retries += 1
async with CONCURRENT_DOWNLOADS_LIMIT:
data = await self._get_remote_data()
self.local_path.parent.mkdir(parents=True, exist_ok=True)