From 5b25e670f3195d9ee845127502f662c259425867 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Wed, 31 May 2023 16:26:41 -0500 Subject: [PATCH] Add last-message to room list items --- spidercat.scm | 32 +++++++++++++++++++++++++++----- templates/room-list-item.html | 3 ++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/spidercat.scm b/spidercat.scm index bdab927..6970775 100644 --- a/spidercat.scm +++ b/spidercat.scm @@ -54,14 +54,36 @@ string-append "" (map (lambda (room) - (html-from-template - "templates/room-list-item.html" - `(("ROOM_TITLE" . ,(html-encode-string room)) - ("ROOM_ID" . ,(uri:uri-encode-string room)) - ("LAST_MESSAGE" . "nekonata: Lorem ipso facto…")))) + (room-list-item-html irc-dir room)) (chatdir:channels irc-dir))))))) +(define (room-list-item-html irc-dir room) + (let* ([messages (channel-messages-sorted irc-dir room)] + [last-message (if (null? messages) + #f (last messages))] + [message-text (if last-message + (car last-message) "")] + [message-sender (if last-message + (alist-ref 'user.chat.sender + (cdr last-message)) + "")] + [message-time + (if last-message + (date->string (alist-ref 'user.chat.date + (cdr last-message)) + "[~H:~M:~S]") + "")]) + (html-from-template + "templates/room-list-item.html" + `(("ROOM_TITLE" . ,(html-encode-string room)) + ("ROOM_ID" . ,(uri:uri-encode-string room)) + ("LAST_MSG" . ,message-text) + ("LAST_TIME" . ,message-time) + ("LAST_MSG_SENDER" . ,message-sender))))) + + + ;; “Send” a message to the given chatdir root, simply by creating a file. ;; That was easy! (define (send-message irc-dir channel message) diff --git a/templates/room-list-item.html b/templates/room-list-item.html index a777d24..923f7b5 100644 --- a/templates/room-list-item.html +++ b/templates/room-list-item.html @@ -1,6 +1,7 @@
  • {{ROOM_TITLE}}
    - {{LAST_MESSAGE}} + {{LAST_MSG_SENDER}} {{LAST_TIME}}
    + {{LAST_MSG}}