aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormousebot <mousebot@riseup.net>2021-10-09 13:22:04 +0200
committermousebot <mousebot@riseup.net>2021-10-09 13:22:04 +0200
commit0129bcf466a4913bdda095b977cd06560c406a30 (patch)
treead9e47a2e2bc563ede833ddf0dba084ce609e3dc /lisp
parent5b64479e34546cea01b600cf5a9fc8c47e2e4a4e (diff)
handle cached images
when we fetch images, check if they are cached, and if so use the cached version. for now, images aren't cached explicitly, but this should work if the user has `url-automatic-caching' enabled.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-media.el14
1 files changed, 10 insertions, 4 deletions
diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el
index b58eab6..8ef9c44 100644
--- a/lisp/mastodon-media.el
+++ b/lisp/mastodon-media.el
@@ -189,9 +189,15 @@ REGION-LENGTH is the range from start to propertize."
(condition-case nil
;; catch any errors in url-retrieve so as to not abort
;; whatever called us
- (url-retrieve url
- #'mastodon-media--process-image-response
- (list marker image-options region-length))
+ (if (url-is-cached url)
+ (with-current-buffer (url-fetch-from-cache url)
+ (set-buffer-multibyte nil)
+ (goto-char (point-min))
+ (zlib-decompress-region (goto-char (search-forward "\n\n")) (point-max))
+ (mastodon-media--process-image-response nil marker image-options region-length))
+ (url-retrieve url
+ #'mastodon-media--process-image-response
+ (list marker image-options region-length)))
(error (with-current-buffer buffer
;; TODO: Consider adding retries
(put-text-property marker
@@ -199,7 +205,7 @@ REGION-LENGTH is the range from start to propertize."
'media-state
'loading-failed)
:loading-failed))))))
-
+H
(defun mastodon-media--select-next-media-line (end-pos)
"Find coordinates of the next media to load before END-POS.