aboutsummaryrefslogtreecommitdiff
path: root/lib/activitypub/types.ml
blob: e4a56e9bb81909a95d02b678a6b13b1aa13aac79 (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
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
type yojson = Yojson.Safe.t
let pp_yojson fmt vl = Yojson.Safe.pretty_print fmt vl
let equal_yojson l r = Yojson.Safe.equal l r

(** * Collections *)
type 'a ordered_collection_page = {
  id: string;
  prev: string option;
  next: string option;
  is_ordered: bool;
  items: 'a list;
  part_of: string option;
  total_items: int option;
} [@@deriving show, eq]


type 'a ordered_collection = {
  id: string option;
  total_items: int;
  contents: [
    | `Items of (bool * 'a list)
    | `First of 'a ordered_collection_page
  ]
} [@@deriving show, eq]

(** * Events *)
type 'a create = {
  id: string;
  actor: string;
  published: Ptime.t option;
  to_: string list;
  cc: string list;
  direct_message: bool;
  obj: 'a;
  raw: yojson;
} [@@deriving show, eq]


type 'a announce = {
  id: string;
  actor: string;
  published: Ptime.t option;
  to_: string list;
  cc: string list;
  obj: 'a;
  raw: yojson;
} [@@deriving show, eq]


type 'a accept = {
  id: string;
  actor: string;
  published: Ptime.t option;
  obj: 'a;
  raw: yojson;
} [@@deriving show, eq]

type 'a undo = {
  id: string;
  actor: string;
  published: Ptime.t option;
  obj: 'a;
  raw: yojson;
} [@@deriving show, eq]

type 'a delete = {
  id: string;
  actor: string;
  published: Ptime.t option;
  obj: 'a;
  raw: yojson;
}
[@@deriving show, eq]

type 'a event = [
    `Create of 'a create
  | `Announce of 'a announce
  | `Accept of 'a accept
  | `Undo of 'a undo
  | `Delete of 'a delete
] [@@deriving show, eq]


(** * Objects *)
type public_key = {
  id: string;
  owner: string;
  pem: string;
} [@@deriving show, eq]

type person = {
  id: string;
  name: string option;
  url: string option;

  preferred_username: string option;

  inbox: string;
  outbox: string;

  summary: string option;

  public_key: public_key;

  manually_approves_followers: bool;

  discoverable: bool;
  followers: string option;
  following: string option;
  icon: string option;
  raw: yojson;
}  [@@deriving show, eq]

type follow = {
  id: string;
  actor: string;
  cc: string list;
  to_: string list;
  object_: string;
  state: [`Pending | `Cancelled ] option;
  raw: yojson;
} [@@deriving show, eq]

type tag = {
  ty: [`Mention | `Hashtag ];
  href: string;
  name: string;
} [@@deriving show, eq]

type attachment = {
  media_type: string option;
  name: string option;
  type_: string option;
  url: string;
} [@@deriving show, eq]

type note = {
  id: string;
  actor: string;
  attachment: attachment list;
  to_: string list;
  in_reply_to: string option;
  cc: string list;
  content: string;
  sensitive: bool;
  source: string option;
  summary: string option;
  published: Ptime.t option;
  tags: [ `Raw of yojson | `Value of tag ] list;
  raw: yojson;
} [@@deriving show, eq]

type block = {
  id: string;
  obj: string;
  published: Ptime.t option;
  actor: string;
  raw: yojson;
} [@@deriving show, eq]

type like = {
  id: string;
  actor: string;
  published: Ptime.t option;
  obj: string;
  raw: yojson;
}
[@@deriving show, eq]


type core_obj = [
    `Person of person
  | `Follow of follow
  | `Note of note
  | `Block of block
  | `Like of like
  | `Link of string
] [@@deriving show, eq]

type core_event = core_obj event
[@@deriving show, eq]

type obj = [ core_obj | core_event ]
[@@deriving show, eq]

module Webfinger = struct

  type ty = [ `Html | `Json | `ActivityJson | `ActivityJsonLd ]
  [@@deriving show, eq]

  type link =
    | Self of ty * string
    | ProfilePage of ty * string
    | OStatusSubscribe of string
  [@@deriving show, eq]

  type query_result = {
    subject: string;
    aliases: string list;
    links: link list;
  }
  [@@deriving show, eq]

  let self_link query =
    query.links
    |> List.find_map (function
        | Self ((`ActivityJson | `ActivityJsonLd | `Json), url) -> Some (Uri.of_string url)
        | _ -> None)

end

module Nodeinfo = struct

  type software = {
    name: string;
    version: string;
  }
  [@@deriving show, eq]

  type usage_users = {
    total: int;
    active_month: int;
    active_half_year: int;
  }
  [@@deriving show, eq]

  type usage = {
    local_posts: int;
    users: usage_users;
  }
  [@@deriving show, eq]

  type t = {
    software: software;
    protocols: string list;
    inbound_services: string list;
    outbound_services: string list;
    usage: usage;
    open_registrations: bool;
    metadata: yojson option;
    raw: yojson;
  }
  [@@deriving show, eq]

end