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,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)

View File

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