summaryrefslogtreecommitdiff
path: root/toot/statuses.scm
blob: 48e73caf0962eaa3d8c55ea78dc9d8f2b142783c (about) (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
;;; Toot --- Mastodon client.
;;; Copyright © 2020 Masaya Tojo <masaya@tojo.tokyo>
;;;
;;; This file is part of Toot.
;;;
;;; Toot 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.
;;;
;;; Toot 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 Toot.  If not, see <http://www.gnu.org/licenses/>.

(define-module (toot statuses)
  #:use-module (toot emojis)
  #:use-module (toot accounts)
  #:use-module (toot attachments)
  #:use-module (srfi srfi-9)
  #:use-module (srfi srfi-9 gnu)
  #:use-module (ice-9 format)
  #:use-module (srfi srfi-19)
  #:use-module (toot utils)
  #:export (status-from-json
            status?
            status-public?
            status-sensitive?
            status-id
            status-account
            status-reblog
            status-visibility
            status-spoiler-text
            status-content
            status-emojis
            status-media-attachments
            status-in-reply-to-id
            status-in-reply-to-account-id
            status-creation-time))

(define-record-type <status>
  (status-from-json json)
  status?
  (json status-json))

(set-record-type-printer! <status>
  (lambda (status port)
    (format port
            "#<status id: ~s ...>"
            (status-id status))))

(define (status-public? status)
  (eq? 'public (status-visibility status)))

(define (status-sensitive? status)
  (assoc-ref (status-json status) "sensitive"))

(define (status-id status)
  (assoc-ref (status-json status) "id"))

(define (status-account status)
  (account-from-json (assoc-ref (status-json status) "account")))

(define (status-reblog status)
  (let ((reblog/json (assoc-ref (status-json status) "reblog")))
    (if (eq? reblog/json 'null)
        #f
        (status-from-json reblog/json))))

(define (status-visibility status)
  (string->symbol (assoc-ref (status-json status) "visibility")))

(define (status-spoiler-text status)
  (let ((s (assoc-ref (status-json status) "spoiler_text")))
    (if (zero? (string-length s))
        #f
        s)))

(define (status-content status)
  (assoc-ref (status-json status) "content"))

(define (status-emojis status)
  (map emoji-from-json
       (vector->list (assoc-ref (status-json status) "emojis"))))

(define (status-media-attachments status)
  (let ((v (assoc-ref (status-json status) "media_attachments")))
    (map attachment-from-json (vector->list v))))

(define (status-in-reply-to-id status)
  (let ((id (assoc-ref (status-json status) "in_reply_to_id")))
    (if (eq? 'null id)
        #f
        id)))

(define (status-in-reply-to-account-id status)
  (let ((id (assoc-ref (status-json status) "in_reply_to_account_id")))
    (if (eq? 'null id)
        #f
        id)))

(define (status-creation-time status)
  (created-at->creation-time (assoc-ref (status-json status)
                                        "created_at")))