Skip to content

Commit

Permalink
Fix: (-defevent "m.room.avatar") Warn for unreadable images
Browse files Browse the repository at this point in the history
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 <#147>.

Fixes #147.  Thanks to @jgarte for reporting.
  • Loading branch information
alphapapa committed May 14, 2023
1 parent 5be1e07 commit 6bd1091
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 16 additions & 10 deletions ement.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down

0 comments on commit 6bd1091

Please sign in to comment.