summaryrefslogtreecommitdiff
path: root/jakob/dynamic/capabilities/common.scm
diff options
context:
space:
mode:
Diffstat (limited to 'jakob/dynamic/capabilities/common.scm')
-rw-r--r--jakob/dynamic/capabilities/common.scm68
1 files changed, 68 insertions, 0 deletions
diff --git a/jakob/dynamic/capabilities/common.scm b/jakob/dynamic/capabilities/common.scm
new file mode 100644
index 0000000..2bca1a2
--- /dev/null
+++ b/jakob/dynamic/capabilities/common.scm
@@ -0,0 +1,68 @@
+;;; Copyright © 2019 - 2023 Jakob L. Kreuze <zerodaysfordays@sdf.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+
+(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 <internal-comment>
+ 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 `<internal-comment>' chronologically"
+ (sort comments (lambda (c1 c2)
+ (date<? (internal-comment-publish-time c1)
+ (internal-comment-publish-time c2)))))