aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-media.el
diff options
context:
space:
mode:
authormousebot <mousebot@riseup.net>2021-10-09 15:18:41 +0200
committermousebot <mousebot@riseup.net>2021-10-09 15:18:41 +0200
commit0034797ed285eff9ca85448b21a39fa27f40a3ce (patch)
treed060768081f4198b22b69cf917f3df54e0933d77 /lisp/mastodon-media.el
parent0129bcf466a4913bdda095b977cd06560c406a30 (diff)
handle caching of images
we now store images ourselves for caching rather than relying on url-automatic-caching.
Diffstat (limited to 'lisp/mastodon-media.el')
-rw-r--r--lisp/mastodon-media.el12
1 files changed, 8 insertions, 4 deletions
diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el
index 8ef9c44..8aadf0a 100644
--- a/lisp/mastodon-media.el
+++ b/lisp/mastodon-media.el
@@ -130,7 +130,7 @@ fKRJkmVZjAQwh78A6vCRWJE8K+8AAAAASUVORK5CYII=")
"The PNG data for a generic 200x200 'broken image' view.")
(defun mastodon-media--process-image-response
- (status-plist marker image-options region-length)
+ (status-plist marker image-options region-length url)
"Callback function processing the url retrieve response for URL.
STATUS-PLIST is the usual plist of status events as per `url-retrieve'.
@@ -151,6 +151,8 @@ REGION-LENGTH is the length of the region that should be replaced with the image
(when image-options 'imagemagick)
nil) ; inbuilt scaling in 27.1
t image-options))))
+ (unless (url-is-cached url) ; cache image if not already cached
+ (url-store-in-cache url-buffer))
(with-current-buffer (marker-buffer marker)
;; Save narrowing in our buffer
(let ((inhibit-read-only t))
@@ -190,14 +192,16 @@ REGION-LENGTH is the range from start to propertize."
;; catch any errors in url-retrieve so as to not abort
;; whatever called us
(if (url-is-cached url)
+ ;; if image url is cached, decompress and use it
(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))
+ (mastodon-media--process-image-response nil marker image-options region-length url))
+ ;; else fetch as usual and process-image-response will cache it
(url-retrieve url
#'mastodon-media--process-image-response
- (list marker image-options region-length)))
+ (list marker image-options region-length url)))
(error (with-current-buffer buffer
;; TODO: Consider adding retries
(put-text-property marker
@@ -205,7 +209,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.