Subject: bug#70871: [PATCH v2 1/2] web: Extract user avatars to function.

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

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

* mumi/web/view/html.scm (avatar): New function.
---
 mumi/web/view/html.scm | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/mumi/web/view/html.scm b/mumi/web/view/html.scm
index fa19ab4..661f248 100644
--- a/mumi/web/view/html.scm
+++ b/mumi/web/view/html.scm
@@ -424,6 +424,16 @@ failed to process associated messages.")
   "Encode PARTS and join them together into an absolute URI path."
   (string-append "/" (encode-and-join-uri-path parts)))
 
+(define* (avatar sender
+		 #:optional
+		 (participants (list (sender-email sender))))
+  `(div (@ (class "avatar")
+           (style ,(string-append
+		    "background-color:"
+		    (avatar-color (sender-email sender)
+				  participants))))
+	,(string-upcase (string-take (sender-name sender) 1))))
+
 (define* (issue-page bug #:key flash-message plain?)
   "Render the conversation for the given BUG."
   (define id (bug-num bug))
@@ -450,12 +460,7 @@ failed to process associated messages.")
          ,(map (match-lambda
                  ((message-number message)
                   `(li
-                    (div
-                     (@ (class "avatar")
-                        (style ,(string-append "background-color:"
-                                               (avatar-color (sender-email message)
-                                                             (map extract-email parties)))))
-                     ,(string-upcase (string-take (sender-name message) 1)))
+		    ,(avatar message (map extract-email parties))
                     (span (@ (class "date"))
                           (a (@ (href ,(string-append "#" (number->string
                                                            message-number))))
@@ -638,23 +643,13 @@ currently disabled."))
              (id ,(number->string message-number))))
        (a (@ (class "message-anchor")
              (id ,(format #false "msgid-~a" (msgid-hash (message-id message))))))
-       (div
-        (@ (class "avatar")
-           (style ,(string-append "background-color:"
-                                  (avatar-color (sender-email message)
-                                                (map extract-email parties)))))
-        ,(string-upcase (string-take (sender-name message) 1)))
+       ,(avatar message (map extract-email parties))
        (article
         (@ (class "message"))
         (header
          (div
           (@ (class "from"))
-          (div
-           (@ (class "avatar")
-              (style ,(string-append "background-color:"
-                                     (avatar-color (sender-email message)
-                                                   (map extract-email parties)))))
-           ,(string-upcase (string-take (sender-name message) 1)))
+	  ,(avatar message (map extract-email parties))
           (span (@ (class "address")) ,(sender-name message))
           " wrote "
           (span (@ (class "date"))
-- 
2.46.0