-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathobjects.lisp
985 lines (859 loc) · 35.8 KB
/
objects.lisp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
(in-package #:org.shirakumo.tooter)
(defclass entity ()
())
(defgeneric decode-entity (type data))
(defmethod decode-entity ((type symbol) data)
(decode-entity (allocate-instance (find-class type)) data))
(defmethod decode-entity ((type symbol) (data list))
(loop for entry in data
collect (decode-entity type entry)))
(defmacro define-entity (name &body slots)
(let ((*print-case* (readtable-case *readtable*))
(data (gensym "DATA"))
(value (gensym "VALUE")))
`(progn
(defclass ,name (entity)
,(loop for (slot . options) in slots
collect `(,slot :initarg ,(intern (string slot) "KEYWORD")
:initform ,(if (getf options :nullable)
NIL
`(error ,(format NIL "~a required for a ~a." slot name)))
:accessor ,slot)))
(defmethod decode-entity ((,name ,name) ,data)
,@(loop for (slot . options) in slots
for field = (getf options :field #1='#.(make-symbol "no value"))
collect `(let ((,value ,(cond ((null field) data)
((eq field #1#) `(getj ,data ,(translate-key slot)))
(T `(getj ,data ,field)))))
(setf (slot-value ,name ',slot)
(when ,value
(funcall ,(or (getf options :translate-with)
'#'identity)
,value)))))
,name)
(defun ,(intern (format NIL "~a-~a" 'decode name)) (,data)
(decode-entity ',name ,data)))))
(define-entity field
(name)
(value)
(verified-at :field "verified_at" :translate-with #'convert-timestamp :nullable T))
(defmethod print-object ((field field) stream)
(print-unreadable-object (field stream :type T)
(format stream "~a -> ~a verified-at ~a" (name field) (value field) (verified-at field))))
(define-entity account
(id)
(username)
(account-name :field "acct")
(display-name)
(locked)
(emojis :translate-with #'decode-emoji)
(discoverable)
(created-at :translate-with #'convert-timestamp)
(followers-count)
(following-count)
(statuses-count)
(note)
(url)
(avatar)
(avatar-static)
(header)
(header-static)
(moved :nullable T :translate-with #'decode-account)
(fields :nullable T :translate-with #'decode-field)
(bot :nullable T)
(source :nullable T :translate-with #'decode-source))
(defmethod print-object ((account account) stream)
(print-unreadable-object (account stream :type T)
(format stream "~a #~a" (account-name account) (id account))))
(define-entity activity
(week :translate-with #'convert-timestamp)
(statuses)
(logins)
(registrations))
(defmethod print-object ((activity activity) stream)
(print-unreadable-object (activity stream :type T)
(format stream
"week ~a statuses ~a logins ~a registrations ~a"
(week activity)
(statuses activity)
(logins activity)
(registrations activity))))
(define-entity announcement-account
(id)
(username)
(account-name :field "acct")
(url))
(defmethod print-object ((announcement-account announcement-account) stream)
(print-unreadable-object (announcement-account stream :type T)
(format stream
"#~a username: ~a account-name: ~a url: ~a"
(id announcement-account)
(username announcement-account)
(account-name announcement-account)
(url announcement-account))))
(define-entity announcement-status
(id)
(url))
(defmethod print-object ((announcement-status announcement-status) stream)
(print-unreadable-object (announcement-status stream :type T)
(format stream
"#~a url: ~a"
(id announcement-status)
(url announcement-status))))
(define-entity announcement
(id)
(content)
(starts-at :translate-with #'convert-timestamp :nullable t)
(ends-at :translate-with #'convert-timestamp :nullable t)
(published)
(all-day)
(published-at :translate-with #'convert-timestamp)
(updated-at :translate-with #'convert-timestamp)
(readp :field "read")
(mentions :translate-with #'decode-announcement-account)
(statuses :translate-with #'decode-announcement-status)
(tags :translate-with #'decode-tag)
(emojis :translate-with #'decode-emoji)
(reactions :translate-with #'decode-reaction))
(defmethod print-object ((announcement announcement) stream)
(print-unreadable-object (announcement stream :type T)
(format stream
"#~a already read? ~a content: ~a"
(id announcement)
(readp announcement)
(content announcement))))
(define-entity application
(name)
(website :nullable T)
(scopes)
(redirect-uris :field "redirect_uris"))
(defmethod print-object ((application application) stream)
(print-unreadable-object (application stream :type T)
(format stream "~a ~@[website: ~a~]" (name application) (website application))))
(define-entity credential-application
(name)
(website :nullable T)
(scopes)
(redirect-uris :field "redirect_uris")
(client-id :field "client_id")
(client-secret :field "client_secret")
(client-secret-expires-at :field "client_secret_expires_at")) ; always 0, according to docs
(define-entity attachment
(id)
(kind :field "type" :translate-with #'to-keyword)
(url)
(preview-url)
(remote-url :nullable T)
(text-url :nullable T)
(metadata :field NIL :nullable T :translate-with #'%decode-metadata)
(description :nullable T)
(blurhash :nullable T))
(defmethod print-object ((attachment attachment) stream)
(print-unreadable-object (attachment stream :type T)
(format stream "~a #~a" (kind attachment) (id attachment))))
(defvar *translator*)
(defun %decode-metadata (data)
(let ((metadata (getj data "meta")))
(when metadata
(let ((focus (getj metadata "focus")))
(when focus
(setf (gethash "focus" metadata) (cons (getj focus "x") (getj focus "y"))))
(ecase (to-keyword (getj data "type"))
(:image
(let ((*translator* (lambda (data) (decode-entity 'image-metadata data))))
(decode-entity 'metadata metadata)))
((:video :gifv)
(let ((*translator* (lambda (data) (decode-entity 'video-metadata data))))
(decode-entity 'metadata metadata)))
(:audio
(let ((*translator* (lambda (data) (decode-entity 'audio-metadata data))))
(decode-entity 'metadata metadata)))
(:unknown NIL))))))
(define-entity metadata
(small :nullable T :translate-with *translator*)
(original :nullable T :translate-with *translator*)
(focus :nullable T))
(define-entity image-metadata
(width :nullable T)
(height :nullable T)
(size :nullable T)
(aspect :nullable T))
(defmethod print-object ((image-metadata image-metadata) stream)
(print-unreadable-object (image-metadata stream :type T)
(format stream "~ax~a" (width image-metadata) (height image-metadata))))
(define-entity video-metadata
(width :nullable T)
(height :nullable T)
(frame-rate :nullable T)
(duration :nullable T)
(bitrate :nullable T))
(defmethod print-object ((video-metadata video-metadata) stream)
(print-unreadable-object (video-metadata stream :type T)
(format stream "~ax~a~@[@~afps~]~@[ ~as~]" (width video-metadata) (height video-metadata)
(frame-rate video-metadata) (duration video-metadata))))
(define-entity audio-metadata
(audio-length :field "length" :nullable T)
(duration :nullable T)
(audio-encode :field "audio_encode" :nullable T)
(audio-bitrate :field "audio_bitrate" :nullable T)
(audio-channels :field "audio_channels" :nullable T))
(defmethod print-object ((audio-metadata audio-metadata) stream)
(print-unreadable-object (audio-metadata stream :type T)
(format stream "length ~a encode ~a" (audio-length audio-metadata) (audio-encode audio-metadata))))
(define-entity card
(url)
(title)
(description)
(kind :field "type" :translate-with #'to-keyword)
(author-name :nullable T)
(author-url :nullable T)
(provider-name :nullable T)
(provider-url :nullable T)
(html :nullable T)
(width :nullable T)
(height :nullable T)
(image :nullable T)
(embed-url :field "embed_url" :nullable T))
(defmethod print-object ((card card) stream)
(print-unreadable-object (card stream :type T)
(format stream "~a ~a" (kind card) (title card))))
(define-entity context
(ancestors :translate-with #'decode-status)
(descendants :translate-with #'decode-status))
(define-entity emoji
(shortcode)
(url)
(static-url)
(visible-in-picker :field "visible_in_picker")
(category :nullable T))
(defmethod print-object ((emoji emoji) stream)
(print-unreadable-object (emoji stream :type T)
(format stream "~a" (shortcode emoji))))
(defun translate-languages (languages)
(mapcar #'to-keyword languages))
;; according to documentation the fields of this entity are numbers
;; (and integer, given the description)
(define-entity instance-stats
(user-count :field "user_count")
(status-count :field "status_count")
(domain-count :field "domain_count"))
(defmethod print-object ((instance-stats instance-stats) stream)
(print-unreadable-object (instance-stats stream :type T)
(format stream "user count ~a status count ~a domain count ~a"
(user-count instance-stats)
(status-count instance-stats)
(domain-count instance-stats))))
(defun %decode-configuration (data)
(let ((accounts (gethash "accounts" data))
(statuses (gethash "statuses" data))
(media-attachments (gethash "media_attachments" data))
(polls (gethash "polls" data))
(translation (gethash "translation" data))
(urls (gethash "urls" data))
(vapid (gethash "vapid" data)))
(append
(when accounts
(list :accounts (list :max-featured-tags (gethash "max_featured_tags" accounts)
:max-pinned-status (gethash "max_pinned-status" accounts))))
(when statuses
(list :statuses (list :max-characters (gethash "max_characters" statuses)
:max-media-attachments (gethash "max_media_attachments" statuses)
:characters-reserved-per-url
(gethash "characters_reserved_per_url" statuses))))
(when media-attachments
(list :media-attachments (list :supported-mime-types
(gethash "supported_mime_types" media-attachments)
:image-size-limit
(gethash "image_size_limit" media-attachments)
:image-matrix-limit
(gethash "image_matrix_limit" media-attachments)
:video-size-limit
(gethash "video_size_limit" media-attachments)
:video-frame-rate-limit
(gethash "video_frame_rate_limit" media-attachments)
:video-matrix-limit
(gethash "video_matrix_limit" media-attachments))))
(when polls
(list :polls (list :max-options (gethash "max-options" polls)
:max-characters-per-option
(gethash "max_characters_per_option" polls)
:min-expiration (gethash "min_expiration" polls)
:max-expiration (gethash "max_expiration" polls))))
(when translation
(list :translation (list :enabled (gethash "enabled" translation))))
(when urls
(list :urls (list :streaming (gethash "streaming" urls)
:status (gethash "status" urls)))) ; undocumented, 2024-10-12
(when vapid
(list :vapid (list :public-key (gethash "public_key" vapid)))))))
(defun %decode-registrations (data)
(let ((registrations data))
(when (hash-table-p registrations)
(list :enabled (gethash "enabled" registrations)
:approval-required (gethash "approval_required" registrations)
:message (gethash "message" registrations)))))
(defun %decode-api-versions (data)
(let ((api-versions data))
(when (hash-table-p api-versions)
(list :api-versions (list :mastodon
(gethash "mastodon" api-versions))))))
(defun %decode-contact (data)
(let ((contact data))
(when (hash-table-p contact)
(list :email (gethash "email" contact)
:account (and (gethash "account" contact)
(decode-account (gethash "account" contact)))))))
(define-entity instance-rule
(id)
(text)
(hint))
(defmethod print-object ((instance-rule instance-rule) stream)
(print-unreadable-object (instance-rule stream :type T)
(format stream
"rule #~a text ~s hint ~s"
(id instance-rule)
(text instance-rule)
(hint instance-rule))))
(defun %decode-usage (data)
(when (hash-table-p data)
(let ((users (gethash "users" data)))
(when (hash-table-p users)
(list :active-month (gethash "active_month" users))))))
(defun %decode-thumbnail (data)
(when (hash-table-p data)
(let* ((thumbnail data)
(versions (gethash "versions" thumbnail)))
(list :thumbnail
(append (list :url (gethash "url" thumbnail)
:blurhash (gethash "blurhash" thumbnail))
(when (hash-table-p versions)
(list :@1x (gethash "@1x" versions)
:@2x (gethash "@2x" versions))))))))
(defun %decode-instance-icon-size (data)
(let ((multiplication-symbol-pos (position #\x data :test #'char-equal)))
(if multiplication-symbol-pos
(list (subseq data 0 multiplication-symbol-pos)
(subseq data (1+ multiplication-symbol-pos)))
data)))
(define-entity instance-icon
(icon-src :field "src")
(icon-size :field "size" :translate-with #'%decode-instance-icon-size))
(defmethod print-object ((instance-icon instance-icon) stream)
(print-unreadable-object (instance-icon stream :type T)
(format t "url ~a size ~a" (icon-src instance-icon) (icon-size instance-icon))))
(define-entity instance
(domain)
(title)
(version)
(source-url :field "source_url")
(description)
(usage :translate-with #'%decode-usage)
(thumbnail :nullable T :translate-with #'%decode-thumbnail)
(icon :translate-with #'decode-instance-icon)
(languages :translate-with #'translate-languages)
(configuration :translate-with #'%decode-configuration)
(registrations :translate-with #'%decode-registrations)
(api-versions :field "api_versions" :translate-with #'%decode-api-versions)
(contact :translate-with #'%decode-contact)
(rules :translate-with #'decode-instance-rule))
(defmethod print-object ((instance instance) stream)
(print-unreadable-object (instance stream :type T)
(format stream
"~s ~a configuration ~a"
(title instance)
(domain instance)
(configuration instance))))
(define-entity user-list
(id)
(title))
(defmethod print-object ((user-list user-list) stream)
(print-unreadable-object (user-list stream :type T)
(format stream "~s #~a" (title user-list) (id user-list))))
(define-entity marker
(last-read-id :field "last_read_id")
(updated-at :field "updated_at" :translate-with #'convert-timestamp)
(version))
(defmethod print-object ((marker marker) stream)
(print-unreadable-object (marker stream :type T)
(format stream "last read id ~a uptdated at ~a"
(last-read-id marker) (updated-at marker))))
(define-entity mention
(url)
(username)
(account-name :field "acct")
(id))
(defmethod print-object ((mention mention) stream)
(print-unreadable-object (mention stream :type T)
(format stream "~a #~a" (account-name mention) (id mention))))
(define-entity notification
(id)
(kind :field "type" :translate-with #'to-keyword)
(group-id :field "group_id")
(created-at :translate-with #'convert-timestamp)
(account :translate-with #'decode-account)
(status :translate-with #'decode-status :nullable T)
(report :translate-with #'decode-report :nullable T)
(relationship-severance-event :field "relationship_severance_event"
:translate-with #'decode-relationship-severance-event
:nullable t)
(moderation-warning :field "moderation_warning"
:translate-with #'decode-account-warning
:nullable t))
(defmethod print-object ((notification notification) stream)
(print-unreadable-object (notification stream :type T)
(format stream
"~a ~a #~a ~@[report: ~a~] ~@[moderation warning: ~a~]"
(kind notification)
(account-name (account notification))
(id notification)
(report notification)
(moderation-warning notification))))
(define-entity poll-option
(title)
(votes-count :field "votes_count"))
(defmethod print-object ((poll-option poll-option) stream)
(print-unreadable-object (poll-option stream :type T)
(format stream "title ~a count ~a" (title poll-option) (votes-count poll-option))))
(define-entity poll
(id)
(expires-at :field "expires_at" :translate-with #'convert-timestamp)
(expired)
(multiple)
(voters-count :field "voters_count")
(votes-count :field "votes_count")
(voted)
(own-votes :field "own_votes")
(options :translate-with #'decode-poll-option)
(emojis :translate-with #'decode-emoji))
(defmethod print-object ((poll poll) stream)
(print-unreadable-object (poll stream :type T)
(format stream
"#~a voted? ~a voters count ~a votes count ~a"
(id poll)
(voted poll)
(voters-count poll)
(votes-count poll))))
(define-entity preferences
(posting-default-visibility :field "posting:default:visibility" :translate-with #'to-keyword)
(posting-default-sensitive :field "posting:default:sensitive")
(posting-default-language :field "posting:default:language" :translate-with #'to-keyword :nullable T)
(reading-expand-media :field "reading:expand:media" :translate-with #'to-keyword)
(reading-expand-spoilers :field "reading:expand:spoilers"))
(defmethod print-object ((preferences preferences) stream)
(print-unreadable-object (preferences stream :type T)
(format stream
"posting default visibility ~a posting default sensitive ~a posting default language ~a reading expand media ~a reading expand spoilers ~a"
(posting-default-visibility preferences)
(posting-default-sensitive preferences)
(posting-default-language preferences)
(reading-expand-media preferences)
(reading-expand-spoilers preferences))))
(define-entity push-subscription-alerts
(alert-follow)
(alert-favourite)
(alert-mention)
(alert-reblog)
(alert-poll))
(defmethod print-object ((push-subscription-alerts push-subscription-alerts) stream)
(print-unreadable-object (push-subscription-alerts stream :type T)
(format stream
"when follow? ~a when favourite ~a when mention? ~a when reblog? ~a when poll? ~a"
(alert-follow push-subscription-alerts)
(alert-favourite push-subscription-alerts)
(alert-mention push-subscription-alerts)
(alert-reblog push-subscription-alerts)
(alert-poll push-subscription-alerts))))
(define-entity push-subscription
(id)
(endpoint)
(server-key)
(alerts :nullable T :translate-with #'decode-push-subscription-alerts))
(defmethod print-object ((push-subscription push-subscription) stream)
(print-unreadable-object (push-subscription stream :type T)
(format stream "~a #~a" (endpoint push-subscription) (id push-subscription))))
(define-entity reaction
(name)
(reaction-count :field "count")
(me :nullable T)
(url :nullable T)
(static-url :nullable T))
(defmethod print-object ((reaction reaction) stream)
(print-unreadable-object (reaction stream :type T)
(format stream
"me? ~a name: ~a count: ~a url: ~a static_url ~a"
(me reaction)
(name reaction)
(reaction-count reaction)
(url reaction)
(static-url reaction))))
(define-entity relationship
(id)
(following)
(requested)
(endorsed)
(followed-by :field "followed_by")
(muting)
(muting-notifications)
(showing-reblogs :field "showing_reblogs")
(blocking)
(domain-blocking)
(blocked-by :field "blocked_by"))
(defmethod print-object ((relationship relationship) stream)
(print-unreadable-object (relationship stream :type T)
(format stream "#~a" (id relationship))))
(define-entity report
(id)
(action-taken)
(action-taken-at :field "action_taken_at" :translate-with #'convert-timestamp)
(report-category :field "category" :translate-with #'to-keyword)
(comment)
(forwarded)
(created-at :field "created_at" :translate-with #'convert-timestamp)
(status-ids :field "status_ids" :nullable T)
(rule-ids :field "rule_ids" :nullable T)
(target-account :field "target_account" :translate-with #'decode-account))
(defmethod print-object ((report report) stream)
(print-unreadable-object (report stream :type T)
(format stream
"#~a action taken? ~a category: ~a comment ~a"
(id report)
(action-taken report)
(category report)
(comment report))))
(define-entity results
(results-accounts :field "accounts" :translate-with #'decode-account)
(results-statuses :field "statuses" :translate-with #'decode-status)
(results-tags :field "hashtags" :translate-with #'decode-tag))
(defmethod print-object ((results results) stream)
(print-unreadable-object (results stream :type T)
(format stream
"account ~a statuses ~a hashtags ~a"
(results-accounts results)
(results-statuses results)
(results-tags results))))
(define-entity status-params
(text)
(in-reply-to-id :field "in_rein_reply_to_id" :nullable T)
(media-ids :field "media_ids" :nullable T)
(sensitive :nullable T)
(spoiler-text :field "spoiler_text" :nullable T)
(visibility :translate-with #'to-keyword)
(scheduled-at :field "scheduled_at" :nullable T :translate-with #'convert-timestamp)
(application-id :field "application_id"))
;; TODO check official documentation because currently is WIP 2020-08-25
(define-entity scheduled-status
(id)
(scheduled-at :field "scheduled_at" :translate-with #'convert-timestamp)
(params :translate-with #'decode-status-params))
(defmethod print-object ((scheduled-status scheduled-status) stream)
(print-unreadable-object (scheduled-status stream :type T)
(format stream "~a@~a" (id scheduled-status) (scheduled-at scheduled-status))))
(define-entity status-tag
(name)
(url))
(defmethod print-object ((status-tag status-tag) stream)
(print-unreadable-object (status-tag stream :type T)
(format stream "name ~a url ~a" (name status-tag) (url status-tag))))
(define-entity status
(id)
(uri)
(url :nullable T)
(account :translate-with #'decode-account)
(in-reply-to-id :nullable T)
(in-reply-to-account-id :nullable T)
(parent :field "reblog" :nullable T :translate-with #'decode-status)
(content)
(created-at :translate-with #'convert-timestamp)
(emojis :translate-with #'decode-emoji)
(reblogs-count)
(favourites-count)
(replies-count :field "replies_count" :translate-with #'ensure-integer)
(reblogged :nullable T)
(favourited :nullable T)
(muted :nullable T)
(sensitive)
(spoiler-text)
(visibility :translate-with #'to-keyword)
(media-attachments :translate-with #'decode-attachment)
(mentions :translate-with #'decode-mention)
(tags :translate-with #'decode-status-tag)
(application :translate-with #'decode-application :nullable T)
(language :nullable T :translate-with #'to-keyword)
(pinned :nullable T)
(poll :nullable T :translate-with #'decode-poll)
(preview-card :field "card" :nullable T :translate-with #'decode-card)
(bookmarked)
(filtered :nullable T :translate-with #'decode-filter-results))
(defmethod print-object ((status status) stream)
(print-unreadable-object (status stream :type T)
(format stream "~a #~a" (account-name (account status)) (id status))))
(defmethod describe-object ((status status) stream)
(format stream "~s~%~%" status)
(present status stream))
(defmethod present ((status status) (stream stream))
(let ((account (account status))
(width (or *print-right-margin* 80)))
(multiple-value-bind (ss mm hh d m y) (decode-universal-time (created-at status) 0)
(format stream
"~v<~a @~a ~;~d.~d.~d ~d:~2,'0d:~2,'0d~>
~a
~v<~d♺ ~d❤~>"
width
(display-name account)
(account-name account)
y m d hh mm ss
(line-wrap (plain-format-html (content status))
:prefix "| " :width width)
width
(reblogs-count status)
(favourites-count status)))))
(define-entity source
(note)
(fields :translate-with #'decode-field)
(privacy :translate-with #'to-keyword)
(sensitive)
(language :translate-with #'to-keyword)
(follow-requests-count :fields "follow_requests_count" :translate-with #'ensure-integer))
(defmethod print-object ((source source) stream)
(print-unreadable-object (source stream :type T)
(format stream "~a" (note source))))
(define-entity tag
(name)
(url)
(history :translate-with #'decode-tag-history :nullable T)
(following))
(defmethod print-object ((tag tag) stream)
(print-unreadable-object (tag stream :type T)
(format stream "~a following? ~a" (name tag) (following tag))))
(define-entity tag-history
(day :translate-with (lambda (a) (convert-timestamp (parse-integer a))))
(use-count :field "uses")
(account-count :field "accounts"))
(defmethod print-object ((tag-history tag-history) stream)
(print-unreadable-object (tag-history stream :type T)
(format stream
"day: ~a use-count: ~a account-count: ~a"
(day tag-history)
(use-count tag-history)
(account-count tag-history))))
(define-entity conversation
(id)
(accounts :translate-with #'decode-account)
(unread)
(last-status :field "last_status" :translate-with #'decode-status))
(defmethod print-object ((conversation conversation) stream)
(print-unreadable-object (conversation stream :type T)
(format stream
"~a unread? ~a ~a ~a"
(id conversation)
(unread conversation)
(accounts conversation)
(last-status conversation))))
(define-entity featured-tag
(id)
(name)
(statuses-count :field "statuses_count" :translate-with #'ensure-integer)
(last-status-at :field "last_status_at" :translate-with #'convert-timestamp))
(defmethod print-object ((featured-tag featured-tag) stream)
(print-unreadable-object (featured-tag stream :type T)
(format stream
"~a name ~a count ~a last status at ~a"
(id featured-tag)
(name featured-tag)
(statuses-count featured-tag)
(last-status-at featured-tag))))
(define-entity filter
(id)
(title)
(filter-context)
(expires-at :field "expires_at" :translate-with #'convert-timestamp)
(filter-action :field "filter_action" :translate-with #'to-keyword)
(keywords :translate-with #'decode-filter-keyword)
(statuses :translate-with #'decode-filter-status))
(defmethod print-object ((filter filter) stream)
(print-unreadable-object (filter stream :type T)
(format stream
"~a title ~a context ~a expires at ~a actions ~a keywords ~a statuses ~a"
(id filter)
(title filter)
(filter-context filter)
(expires-at filter)
(filter-action filter)
(keywords filter)
(statuses filter))))
(define-entity filter-results
(query-filter :translate-with #'decode-filter)
(keyword-matches :field "keyword_matches" :nullable T)
(status-matches :field "status_matches" :nullable T))
(defmethod print-object ((filter-results filter-results) stream)
(print-unreadable-object (filter-results stream :type T)
(format stream
"filter: ~a matched keywords: ~a matched status: ~a"
(query-filter filter-results)
(keyword-matches filter-results)
(status-matches filter-results))))
(define-entity filter-keyword
(id)
(status-id)
(whole-word :field "whole_word"))
(defmethod print-object ((filter-keyword filter-keyword) stream)
(print-unreadable-object (filter-keyword stream :type T)
(format stream
"id: ~a status-id: ~a whole word? ~a"
(id filter-keyword)
(status-id filter-keyword)
(whole-word filter-keyword))))
(define-entity filter-status
(id)
(status-id))
(defmethod print-object ((filter-status filter-status) stream)
(print-unreadable-object (filter-status stream :type T)
(format stream
"id: ~a status-id: ~a"
(id filter-status)
(status-id filter-status))))
(define-entity identity-proof
(provider)
(provider-username :field "provider_username")
(profile-url :field "profile_url")
(proof-url :field "proof_url")
(updated-at :field "updated_at" :translate-with #'convert-timestamp))
(defmethod print-object ((identity-proof identity-proof) stream)
(print-unreadable-object (identity-proof stream :type T)
(format stream
"provider ~a provider username ~a profile url ~a proof url ~a updated at ~a"
(provider identity-proof)
(provider-username identity-proof)
(profile-url identity-proof)
(proof-url identity-proof)
(updated-at identity-proof))))
(define-entity token
(access-token :field "access_token")
(token-type :field "token_type")
(scope)
(created-at :field "created_at" :translate-with #'convert-timestamp))
(defmethod print-object ((token token) stream)
(print-unreadable-object (token stream :type T)
(format stream
"access token ~a type ~a scope ~a created at ~a"
(access-token token)
(token-type token)
(scope token)
(created-at token))))
(define-entity relationship-severance-event
(id)
(kind :field "type" :translate-with #'to-keyword)
(purged)
(target-name :field "target_name")
(relationships-count :field "relationships_count" :nullable t)
(created-at :field "created_at" :translate-with #'convert-timestamp))
(defmethod print-object ((relationship-severance-event relationship-severance-event) stream)
(print-unreadable-object (relationship-severance-event stream :type T)
(format stream
"~a type ~a ~@[count ~a~]"
(id relationship-severance-event)
(kind relationship-severance-event)
(relationships-count relationship-severance-event))))
(define-entity account-warning
(id)
(action :translate-with #'to-keyword)
(text)
(status-ids :field "status_ids")
(target-account :field "target_account" :translate-with #'decode-account)
(appeal :nullable t :translate-with #'decode-appeal)
(created-at :field "created_at" :translate-with #'convert-timestamp))
(defmethod print-object ((account-warning account-warning) stream)
(print-unreadable-object (account-warning stream :type T)
(format stream
"~a action ~a text ~a"
(id account-warning)
(action account-warning)
(text account-warning))))
(define-entity appeal
(text)
(state))
(defmethod print-object ((appeal appeal) stream)
(print-unreadable-object (appeal stream :type T)
(format stream
"text: ~a state: ~a"
(text appeal)
(state appeal))))
(define-entity partial-account-with-avatar
(id)
(account-name :field "acct")
(url)
(avatar)
(avatar-static)
(locked)
(display-name)
(bot))
(define-entity notification-group
(group-key :field "group_key")
(notifications-count :field "notifications_count")
(kind :field "type")
(most-recent-notification-id :field "most_recent_notification_id")
(page-min-id :field "page_min_id" :nullable t)
(page-max-id :field "page_max_id" :nullable t)
(latest-page-notification-at :field "latest_page_notification_at" :nullable t)
(sample-account-ids :field "sample_account_ids")
(status-id :field "status_id" :nullable t)
(report :translate-with #'decode-report :nullable t)
(relationship-severance-event :field "event"
:translate-with #'decode-relationship-severance-event
:nullable t)
(moderation-warning :field "moderation_warning" :nullable t))
(define-entity grouped-notifications-results
(accounts :translate-with #'decode-account)
(partial-accounts :field "partial_accounts"
:translate-with #'decode-partial-account-with-avatar
:nullable t)
(statuses :translate-with #'decode-status)
(notification-groups :field "notification-groups"
:translate-with #'decode-notification-group))
(defmethod print-object ((grouped-notifications-results grouped-notifications-results) stream)
(print-unreadable-object (grouped-notifications-results stream :type T)
(format stream
"accounts: ~a ~@[partial accounts: ~a~] statuses: ~a group: ~a"
(accounts grouped-notifications-results)
(partial-accounts grouped-notifications-results)
(statuses grouped-notifications-results)
(notification-groups grouped-notifications-results))))
(defun %decode-notification-policy-summary (summary-data)
(when (hash-table-p summary-data)
(list :pending-requests-count (gethash "pending_requests_count" summary-data)
:pending-notifications-count (gethash "pending_notifications_count" summary-data))))
(define-entity notification-policy
(for-not-following :field "for_not_following" :translate-with #'to-keyword)
(for-not-followers :field "for_not_followers" :translate-with #'to-keyword)
(for-new-accounts :field "for_new_accounts" :translate-with #'to-keyword)
(for-private-mentions :field "for_private_mentions" :translate-with #'to-keyword)
(for-limited-accounts :field "for_limited_accounts" :translate-with #'to-keyword)
(summary :translate-with #'%decode-notification-policy-summary))
(defmethod print-object ((notification-policy notification-policy) stream)
(print-unreadable-object (notification-policy stream :type T)
(format stream
"for-not-following ~a for-not-followers ~a for-new-accounts ~a for-private-mentions ~a for-limited-accounts ~a"
(for-not-following notification-policy)
(for-not-followers notification-policy)
(for-new-accounts notification-policy)
(for-private-mentions notification-policy)
(for-limited-accounts notification-policy))))
(define-entity notification-request
(id)
(created-at :field "created_at" :translate-with #'convert-timestamp)
(updated-at :field "update_at" :translate-with #'convert-timestamp)
(account :translate-with #'decode-account)
(notifications-count :field "notifications_count")
(last-status :field "last_status" :translate-with #'decode-status :nullable t))
(defmethod print-object ((notification-request notification-request) stream)
(print-unreadable-object (notification-request stream :type T)
(format stream
"#~a created at: ~a updated at: ~a account ~a count ~a"
(id notification-request)
(created-at notification-request)
(updated-at notification-request)
(account notification-request)
(notifications-count notification-request))))
(defun %decode-check-notification-requests-merged (request)
(when (hash-table-p request)
(gethash "merged" request)))