Subject: [PATCH] Add support for multiple gravatar-like services

From: Philip K <[email-masked]>
Date: Sat, 7 Mar 2020 01:11:41 +0100

Specifically, the non-proprietary services libravatar (now default)
and unicornify have been added. The behaviour is customised via the
new variable `gravatar-service'.
---
 lisp/image/gravatar.el            | 19 +++++++++++++++----
 test/lisp/image/gravatar-tests.el |  1 +
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lisp/image/gravatar.el b/lisp/image/gravatar.el
index b8542bc3c3..c1ae0cefe3 100644
--- a/lisp/image/gravatar.el
+++ b/lisp/image/gravatar.el
@@ -118,9 +118,16 @@ gravatar-force-default
   :version "27.1"
   :group 'gravatar)
 
-(defconst gravatar-base-url
-  "https://www.gravatar.com/avatar"
-  "Base URL for getting gravatars.")
+(defcustom gravatar-service 'libravatar
+  "Symbol denoting gravatar-like service to use."
+  :type '(choice (const libravatar)
+                 (const gravatar)
+                 (const unicornify))
+  :version "27.1"
+  :link '(url-link "https://www.libravatar.org/")
+  :link '(url-link "https://unicornify.pictures/")
+  :link '(url-link "https://gravatar.com/")
+  :group 'gravatar)
 
 (defun gravatar-hash (mail-address)
   "Return the Gravatar hash for MAIL-ADDRESS."
@@ -142,7 +149,11 @@ gravatar-build-url
   "Return the URL of a gravatar for MAIL-ADDRESS."
   ;; https://gravatar.com/site/implement/images/
   (format "%s/%s?%s"
-          gravatar-base-url
+          (cond ((eq gravatar-service 'gravatar)
+                 "https://www.gravatar.com/avatar")
+                ((eq gravatar-service 'unicornify)
+                 "https://unicornify.pictures/avatar/")
+                (t "https://seccdn.libravatar.org/avatar"))
           (gravatar-hash mail-address)
           (gravatar--query-string)))
 
diff --git a/test/lisp/image/gravatar-tests.el b/test/lisp/image/gravatar-tests.el
index e66b5c6803..31a28293fa 100644
--- a/test/lisp/image/gravatar-tests.el
+++ b/test/lisp/image/gravatar-tests.el
@@ -65,6 +65,7 @@ gravatar-build-url
   "Test `gravatar-build-url'."
   (let ((gravatar-default-image nil)
         (gravatar-force-default nil)
+        (gravatar-service 'gravatar)
         (gravatar-size nil))
     (should (equal (gravatar-build-url "foo") "\
 https://www.gravatar.com/avatar/acbd18db4cc2f85cedef654fccc4a4d8?r=g"))))
-- 
2.20.1