blob: 4f6d3d99517a2a59fa8f2bf87d4565355761343a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
(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
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)))))
(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)))))
|