Subject: bug#70871: [PATCH v2 2/2] web: Show avatars from Libravatar.

From: [email-masked]
Date: Sat, 2 Nov 2024 16:34:50 +0100

From: Noé Lopez <[email-masked]>

* configure.ac: New dependency.
* mumi/web/view/html.scm: Use Libavatar images as avatars.
---
 configure.ac           |  5 +++++
 mumi/web/view/html.scm | 11 ++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5981682..ff754b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,11 @@ if test "x$have_kolam" != "xyes"; then
   AC_MSG_ERROR([Guile kolam is missing; please install it.])
 fi
 
+GUILE_MODULE_AVAILABLE([have_avatar], [(avatar url)])
+if test "x$have_avatar" != "xyes"; then
+  AC_MSG_ERROR([Guile avatar is missing; please install it.])
+fi
+
 guilemoduledir="${datarootdir}/guile/site/${GUILE_EFFECTIVE_VERSION}"
 AC_SUBST([guilemoduledir])
 AC_SUBST([GUILE_EFFECTIVE_VERSION])
diff --git a/mumi/web/view/html.scm b/mumi/web/view/html.scm
index 661f248..a037a74 100644
--- a/mumi/web/view/html.scm
+++ b/mumi/web/view/html.scm
@@ -19,6 +19,7 @@
 ;;; <http://www.gnu.org/licenses/>.
 
 (define-module (mumi web view html)
+  #:use-module (avatar url)
   #:use-module (email email)
   #:use-module (mumi config)
   #:use-module (mumi debbugs)
@@ -427,12 +428,16 @@ failed to process associated messages.")
 (define* (avatar sender
 		 #:optional
 		 (participants (list (sender-email sender))))
-  `(div (@ (class "avatar")
+  `(img (@ (class "avatar")
            (style ,(string-append
 		    "background-color:"
 		    (avatar-color (sender-email sender)
-				  participants))))
-	,(string-upcase (string-take (sender-name sender) 1))))
+				  participants)))
+	   (src ,(libravatar-url (sender-email sender)
+				 #:default "404"
+				 #:height 48))
+	   (alt ,(string-upcase (string-take (sender-name sender) 1)))
+	   (aria-hidden "true"))))
 
 (define* (issue-page bug #:key flash-message plain?)
   "Render the conversation for the given BUG."
-- 
2.46.0