;;; Copyright © 2019 - 2023 Jakob L. Kreuze ;;; ;;; This program is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU General Public License as ;;; published by the Free Software Foundation; either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see ;;; . (define-module (jakob dynamic capabilities common) #:use-module (jakob dynamic util) #:use-module (json) #:use-module (srfi srfi-19) #:export (json->internal-comment internal-comment->json make-internal-comment internal-comment? internal-comment-id internal-comment-name internal-comment-subject internal-comment-email internal-comment-comment internal-comment-url internal-comment-publish-time internal-comment-reactions internal-comment-replies internal-comment-originating-network sort-comments)) (define-json-mapping make-internal-comment internal-comment? json->internal-comment <=> internal-comment->json (id internal-comment-id) (name internal-comment-name) (subject internal-comment-subject) (email internal-comment-email) (comment internal-comment-comment) (url internal-comment-url) (publish-time internal-comment-publish-time "publish-time" (lambda (x) (string->date x "~Y~m~d ~H~M~S.~N")) (lambda (x) (date->string x "~Y-~m-~d ~H:~M:~S.~N"))) (reactions internal-comment-reactions) (replies internal-comment-replies "replies" (lambda (x) (map (lambda (comment) (call-with-input-string (scm->json-string comment) json->internal-comment)) (vector->list x))) (lambda (x) (list->vector (map (lambda (y) (json-string->scm (internal-comment->json y))) x)))) (originating-network internal-comment-originating-network)) (define (sort-comments comments) "Sort COMMENTS, a list of `' chronologically" (sort comments (lambda (c1 c2) (date