From 54f7c966ba411a1a1d3c6f0179f2c3f22bf884e7 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 21 May 2023 10:04:17 -0500 Subject: [PATCH] Functions for listing channels/users/metadata --- chatdir.scm | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/chatdir.scm b/chatdir.scm index 3bc7de9..2784082 100644 --- a/chatdir.scm +++ b/chatdir.scm @@ -114,6 +114,12 @@ (create-directory user-path #t)]))) +;; Return a list of all users of a channel of given state. +;; (Lists files in /$channel/.users/$state/). +(define (channel-users root channel #!optional (state "online")) + (directory (subpath root channel ".users" state))) + + ;; Sets a file in the user's directory to given value. ;; Sets /.users/$user/$key to $value. (define (user-file-set! root username key value #!optional (xattr-alist '())) @@ -237,7 +243,6 @@ xattr-alist))) - (define (directory-file-get directory key) (read-file-to-string (subpath directory key))) @@ -271,6 +276,16 @@ (directory-file-get* (subpath root channel ".meta") key)) +;; Return a list of all metadata key (files in /$channel/.meta/). +(define (channel-metadata root channel) + (directory (subpath root channel ".meta"))) + + +;; Lists all currently-joined channels. +(define (channels root) + (directory root)) + + ;; Return a file path with the given parameters as elements of the path ;; E.g., "/etc/", "/systemd/user" "mom" => "/etc/systemd/user/mom" (define (subpath . children) @@ -319,6 +334,11 @@ contents attrs))) +;; List all messages of the given channel. +(define (channel-messages root channel) + (directory (subpath root channel))) + + ;; Initialization for the input loop (define (input-loop-init root-dir callbacks-alist) (let ([join-callback (alist-ref 'join-channel callbacks-alist)])