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

From: Robert Pluim <[email-masked]>
Date: Mon, 09 Mar 2020 11:39:18 +0100

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

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

    Philip> diff --git a/lisp/image/gravatar.el b/lisp/image/gravatar.el
    Philip> index b8542bc3c3..c1ae0cefe3 100644
    Philip> --- a/lisp/image/gravatar.el
    Philip> +++ b/lisp/image/gravatar.el
    Philip> @@ -118,9 +118,16 @@ gravatar-force-default
    Philip>    :version "27.1"
    Philip>    :group 'gravatar)
 
    Philip> -(defconst gravatar-base-url
    Philip> -  "https://www.gravatar.com/avatar"
    Philip> -  "Base URL for getting gravatars.")
    Philip> +(defcustom gravatar-service 'libravatar
    Philip> +  "Symbol denoting gravatar-like service to use."
    Philip> +  :type '(choice (const libravatar)
    Philip> +                 (const gravatar)
    Philip> +                 (const unicornify))
    Philip> +  :version "27.1"
    Philip> +  :link '(url-link "https://www.libravatar.org/")
    Philip> +  :link '(url-link "https://unicornify.pictures/")
    Philip> +  :link '(url-link "https://gravatar.com/")
    Philip> +  :group 'gravatar)

If you make this an alist then your cond below becomes just
'alist-get', and you have the URLS in just one place.

    Philip>  (defun gravatar-hash (mail-address)
    Philip>    "Return the Gravatar hash for MAIL-ADDRESS."
    Philip> @@ -142,7 +149,11 @@ gravatar-build-url
    Philip>    "Return the URL of a gravatar for MAIL-ADDRESS."
    Philip>    ;; https://gravatar.com/site/implement/images/
    Philip>    (format "%s/%s?%s"
    Philip> -          gravatar-base-url
    Philip> +          (cond ((eq gravatar-service 'gravatar)
    Philip> +                 "https://www.gravatar.com/avatar")
    Philip> +                ((eq gravatar-service 'unicornify)
    Philip> +                 "https://unicornify.pictures/avatar/")
    Philip> +                (t "https://seccdn.libravatar.org/avatar"))
    Philip>            (gravatar-hash mail-address)
    Philip>            (gravatar--query-string)))

This is changing the default from gravatar->libravatar, won't that
break stuff?

Robert