From 21c7a4d6942ec38a34cbcc336a5d2e7a72141b39 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Wed, 31 May 2023 01:31:52 -0500 Subject: [PATCH] User-lists for rooms --- spidercat.scm | 45 ++++++++++++++++++++++++++---- templates/room-user-list-item.html | 1 + templates/room-user-list.html | 16 +++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 templates/room-user-list-item.html create mode 100644 templates/room-user-list.html diff --git a/spidercat.scm b/spidercat.scm index e5929ab..0943dce 100644 --- a/spidercat.scm +++ b/spidercat.scm @@ -16,8 +16,8 @@ ;; (import scheme - (chicken io) (chicken sort) (chicken string) (chicken irregex) - (chicken pretty-print) + (chicken file) (chicken io) (chicken sort) (chicken string) + (chicken irregex) (chicken pretty-print) srfi-1 srfi-19 (prefix chatdir chatdir:) (prefix intarweb intarweb:) @@ -94,6 +94,30 @@ (alist-ref 'user.chat.date (cdr b)))))) +(define (channel-online-users irc-dir channel) + (directory + (string-append irc-dir "/" channel "/.users/online/"))) + + +(define (room-users-html irc-dir channel) + (html-from-template + "templates/room-user-list.html" + `(("ROOM_TITLE" . ,(uri:uri-decode-string channel)) + ("LIST_ITEMS" + . ,(reduce-right + string-append "" + (map (lambda (user) + (room-users-item-html irc-dir channel user)) + (channel-online-users + irc-dir + (uri:uri-decode-string channel)))))))) + + +(define (room-users-item-html irc-dir channel user) + (html-from-template + "templates/room-user-list-item.html" + `(("USER_NAME" . ,user)))) + ;; Generate the HTML listing a room's chat messages. (define (room-chat-html irc-dir channel) @@ -143,9 +167,20 @@ (define (http-get-room-dir irc-dir #!optional request path) - (let ([channel (third path)]) - (spiffy:send-response status: 'ok - body: (room-chat-html irc-dir channel)))) + (let* ([channel (third path)] + [channel? (member channel (chatdir:channels irc-dir))] + [sub-path (if (eq? (length path) 4) + (fourth path) #f)]) + (cond + [(not channel?) + (spiffy:send-response code: 404 + body: "