From 6bd1091757bce5feedb337d01b88ab0aa3bc6124 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Fri, 12 May 2023 20:47:50 -0500 Subject: [PATCH] Fix: (-defevent "m.room.avatar") Warn for unreadable images If Emacs can't load a room's avatar image, `create-image' returns nil. This can happen if, e.g. the image is corrupt or an unreadable format (such as an ICO file). See . Fixes #147. Thanks to @jgarte for reporting. --- README.org | 1 + ement.el | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.org b/README.org index 6032ef11..c20f85d7 100644 --- a/README.org +++ b/README.org @@ -311,6 +311,7 @@ Note that, while ~matrix-client~ remains usable, and probably will for some time *Fixes* + Recognition of certain MXID or displayname forms in outgoing messages when linkifying (aka "pilling") them. ++ Unreadable room avatar images no longer cause errors. (Fixes [[https://github.com/alphapapa/ement.el/issues/147][#147]]. Thanks to [[https://github.com/jgarte][@jgarte]] for reporting.) ** 0.8.3 diff --git a/ement.el b/ement.el index 0c5eded2..32ade698 100644 --- a/ement.el +++ b/ement.el @@ -874,16 +874,22 @@ and `session' to the session. Adds function to :ascent 'center :max-width ement-room-avatar-max-width :max-height ement-room-avatar-max-height))) - (when (fboundp 'imagemagick-types) - ;; Only do this when ImageMagick is supported. - ;; FIXME: When requiring Emacs 27+, remove this (I guess?). - (setf (image-property image :type) 'imagemagick)) - ;; We set the room-avatar slot to a propertized string that - ;; displays as the image. This seems the most convenient thing to - ;; do. We also unset the cached room-list-avatar so it can be - ;; remade. - (setf (ement-room-avatar room) (propertize " " 'display image) - (alist-get 'room-list-avatar (ement-room-local room)) nil)))))) + (if (not image) + (progn + (display-warning 'ement (format "Room avatar seems unreadable: ROOM-ID:%S AVATAR-URL:%S" + (ement-room-id room) (ement--mxc-to-url url session))) + (setf (ement-room-avatar room) nil + (alist-get 'room-list-avatar (ement-room-local room)) nil)) + (when (fboundp 'imagemagick-types) + ;; Only do this when ImageMagick is supported. + ;; FIXME: When requiring Emacs 27+, remove this (I guess?). + (setf (image-property image :type) 'imagemagick)) + ;; We set the room-avatar slot to a propertized string that + ;; displays as the image. This seems the most convenient thing to + ;; do. We also unset the cached room-list-avatar so it can be + ;; remade. + (setf (ement-room-avatar room) (propertize " " 'display image) + (alist-get 'room-list-avatar (ement-room-local room)) nil))))))) ;; Unset avatar. (setf (ement-room-avatar room) nil (alist-get 'room-list-avatar (ement-room-local room)) nil))))