Make gravatar-build-url respect dynamically bound variables again

* lisp/image/gravatar.el (gravatar-build-url): Compute
query-string first, so that dynamically bound values of
`gravatar-rating' (etc.) are respected, instead of computing it
when the callback happens.
This commit is contained in:
Lars Ingebrigtsen 2020-07-31 04:19:03 +02:00
parent 5c63130968
commit 50a12de877
2 changed files with 16 additions and 10 deletions

View file

@ -188,14 +188,15 @@ to track whether you're reading a specific mail."
(defun gravatar-build-url (mail-address callback)
"Find the URL of a gravatar for MAIL-ADDRESS and call CALLBACK with it."
;; https://gravatar.com/site/implement/images/
(funcall (alist-get gravatar-service gravatar-service-alist)
mail-address
(lambda (url)
(funcall callback
(format "%s/%s?%s"
url
(gravatar-hash mail-address)
(gravatar--query-string))))))
(let ((query-string (gravatar--query-string)))
(funcall (alist-get gravatar-service gravatar-service-alist)
mail-address
(lambda (url)
(funcall callback
(format "%s/%s?%s"
url
(gravatar-hash mail-address)
query-string))))))
(defun gravatar-get-data ()
"Return body of current URL buffer, or nil on failure."

View file

@ -65,8 +65,13 @@
"Test `gravatar-build-url'."
(let ((gravatar-default-image nil)
(gravatar-force-default nil)
(gravatar-size nil))
(should (equal (gravatar-build-url "foo") "\
(gravatar-size nil)
(gravatar-service 'gravatar)
url)
(gravatar-build-url "foo" (lambda (u) (setq url u)))
(while (not url)
(sleep-for 0.01))
(should (equal url "\
https://www.gravatar.com/avatar/acbd18db4cc2f85cedef654fccc4a4d8?r=g"))))
;;; gravatar-tests.el ends here