Fix: (ement-room--format-m.image) Handle missing URLs

Not sure why this can happen, but occasionally it does (maybe only
while debugging or when other bugs cause incomplete event insertion).
This commit is contained in:
Adam Porter 2022-03-25 21:10:20 -05:00
parent 9d1baf6670
commit 44580a8a25

View file

@ -3132,12 +3132,13 @@ show it in the buffer."
((cl-struct ement-room local) ement-room)
((map buffer) local)
;; TODO: Thumbnail support.
((map url info ;; (thumbnail_url thumbnail-url)
((map ('url mxc) info ;; ('thumbnail_url thumbnail-url)
) content)
((map thumbnail_info) info)
((map ('h _thumbnail-height) ('w _thumbnail-width)) thumbnail_info)
((map image) event-local)
(url (ement--mxc-to-url url ement-session))
(url (when mxc
(ement--mxc-to-url mxc ement-session)))
;; (thumbnail-url (ement--mxc-to-url thumbnail-url ement-session))
)
(if (and ement-room-images image)
@ -3177,12 +3178,12 @@ show it in the buffer."
;; Image not downloaded: insert URL as button, and download if enabled.
(prog1
(with-temp-buffer
(insert-text-button url
(insert-text-button (or url "[no URL for image]")
'face 'link
'follow-link t)
(buffer-string))
(when ement-room-images
;; Images enabled: download it.
(when (and ement-room-images url)
;; Images enabled and URL present: download it.
(plz 'get url :as 'binary
:then (apply-partially #'ement-room--m.image-callback event ement-room)
:noquery t))))))