From 46f3f156947fc0f4108bc5a1493b9c6a0a28498a Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 9 Mar 2020 12:06:58 -0400 Subject: [PATCH] Fix cached thumbnails extensions --- TODO.md | 4 +++- src/backend/matrix_client.py | 2 ++ src/backend/models/items.py | 1 + src/backend/nio_callbacks.py | 1 + src/gui/Pages/Chat/Timeline/EventImage.qml | 2 +- src/gui/Pages/Chat/Timeline/EventMediaLoader.qml | 13 +++++++++++++ 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index 836486ca..229abcb3 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,7 @@ ## Before release -- Downloaded media filenames +- Fix highlighted account/room in MainPane - "exception during sync" aren't caught - nio ClientTimeout - Name @@ -153,6 +153,8 @@ ## Backend +- Have a `Thubmnail.from_existing_file()` to be called after generating and + and uploading a thumbnail, like the equivalent `Media.from_existing_file()` - Saving the room settings - Refetch profile after manual profile change, don't wait for a room event diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index e0a06c17..2bb6c285 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -553,6 +553,8 @@ class MatrixClient(nio.AsyncClient): content["info"].get("thumbnail_info", {}).get("w", 0), thumbnail_height = content["info"].get("thumbnail_info", {}).get("h", 0), + thumbnail_mime = + content["info"].get("thumbnail_info", {}).get("mimetype", ""), ) await self._send_message(room_id, content) diff --git a/src/backend/models/items.py b/src/backend/models/items.py index 2be336a3..b5ecb34a 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -197,6 +197,7 @@ class Event(ModelItem): media_crypt_dict: Dict[str, Any] = field(default_factory=dict) thumbnail_url: str = "" + thumbnail_mime: str = "" thumbnail_width: int = 0 thumbnail_height: int = 0 thumbnail_crypt_dict: Dict[str, Any] = field(default_factory=dict) diff --git a/src/backend/nio_callbacks.py b/src/backend/nio_callbacks.py index 5a2e9c86..9a31039d 100644 --- a/src/backend/nio_callbacks.py +++ b/src/backend/nio_callbacks.py @@ -140,6 +140,7 @@ class NioCallbacks: thumbnail_width = thumb_info.get("w") or 0, thumbnail_height = thumb_info.get("h") or 0, + thumbnail_mime = thumb_info.get("mimetype") or "", thumbnail_crypt_dict = thumb_crypt_dict, ) diff --git a/src/gui/Pages/Chat/Timeline/EventImage.qml b/src/gui/Pages/Chat/Timeline/EventImage.qml index 588708dd..b220d49a 100644 --- a/src/gui/Pages/Chat/Timeline/EventImage.qml +++ b/src/gui/Pages/Chat/Timeline/EventImage.qml @@ -9,7 +9,7 @@ HMxcImage { height: fitSize.height horizontalAlignment: Image.AlignLeft - title: loader.title + title: thumbnail ? loader.thumbnailTitle : loader.title animated: loader.singleMediaInfo.media_mime === "image/gif" || utils.urlExtension(loader.mediaUrl).toLowerCase() === "gif" thumbnail: ! animated && loader.thumbnailMxc diff --git a/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml b/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml index bfaf3498..7df1ca04 100644 --- a/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml +++ b/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml @@ -31,6 +31,19 @@ HLoader { readonly property string title: singleMediaInfo.media_title || utils.urlFileName(mediaUrl) + readonly property string thumbnailTitle: + singleMediaInfo.media_title.replace( + /\.[^\.]+$/, + singleMediaInfo.thumbnail_mime === "image/jpeg" ? ".jpg" : + singleMediaInfo.thumbnail_mime === "image/png" ? ".png" : + singleMediaInfo.thumbnail_mime === "image/gif" ? ".gif" : + singleMediaInfo.thumbnail_mime === "image/tiff" ? ".tiff" : + singleMediaInfo.thumbnail_mime === "image/svg+xml" ? ".svg" : + singleMediaInfo.thumbnail_mime === "image/webp" ? ".webp" : + singleMediaInfo.thumbnail_mime === "image/bmp" ? ".bmp" : + ".thumbnail" + ) || utils.urlFileName(mediaUrl) + readonly property var imageExtensions: [ "bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm", "tiff", "webp", "svg",