Archived
1
0
Disbranĉigi 0

Add last-message to room list items

This commit is contained in:
Jaidyn Ann 2023-05-31 16:26:41 -05:00
parent 2ad331ed04
commit 5b25e670f3
2 changed files with 29 additions and 6 deletions

View File

@ -54,12 +54,34 @@
string-append string-append
"" ""
(map (lambda (room) (map (lambda (room)
(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 (html-from-template
"templates/room-list-item.html" "templates/room-list-item.html"
`(("ROOM_TITLE" . ,(html-encode-string room)) `(("ROOM_TITLE" . ,(html-encode-string room))
("ROOM_ID" . ,(uri:uri-encode-string room)) ("ROOM_ID" . ,(uri:uri-encode-string room))
("LAST_MESSAGE" . "nekonata: Lorem ipso facto…")))) ("LAST_MSG" . ,message-text)
(chatdir:channels irc-dir))))))) ("LAST_TIME" . ,message-time)
("LAST_MSG_SENDER" . ,message-sender)))))
;; “Send” a message to the given chatdir root, simply by creating a file. ;; “Send” a message to the given chatdir root, simply by creating a file.

View File

@ -1,6 +1,7 @@
<a href="/room/{{ROOM_ID}}/"> <a href="/room/{{ROOM_ID}}/">
<li id="{{ROOM_ID}}"> <li id="{{ROOM_ID}}">
<b>{{ROOM_TITLE}}</b><br /> <b>{{ROOM_TITLE}}</b><br />
{{LAST_MESSAGE}} {{LAST_MSG_SENDER}} <i>{{LAST_TIME}}</i><br />
<i>{{LAST_MSG}}</i>
</li> </li>
</a> </a>