]> git.eshelyaron.com Git - emacs.git/commitdiff
Make gravatar-build-url respect dynamically bound variables again
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 31 Jul 2020 02:19:03 +0000 (04:19 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 31 Jul 2020 02:19:03 +0000 (04:19 +0200)
* 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.

lisp/image/gravatar.el
test/lisp/image/gravatar-tests.el

index ff612d2e9f33fc86d029960d8d3c0a20f85e20ee..d1091e57cb561d89c20734ea721e86dd6976a506 100644 (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."
index e66b5c6803d8e87b64dd8ff03103cf98f157cf42..43c3024721e739265f6e05018cfe3e1ea0f1d3ad 100644 (file)
   "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