summaryrefslogtreecommitdiffstats
path: root/entities/src/instance.rs
blob: 16d34d6709958c110e0fdb4fd8cf10f3b6233d5f (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
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
//! Module containing everything related to an instance.
use isolang::Language;
use serde::{Deserialize, Serialize};
use time::{serde::iso8601, OffsetDateTime};
use url::Url;

use crate::{account::Account, admin, conversion, RuleId};

/// Represents the software instance of Mastodon running on this domain.
///
/// See also [the API documentation](https://docs.joinmastodon.org/entities/Instance/)
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Instance {
    /// The domain name of the instance.
    pub domain: String,
    /// The title of the website.
    pub title: String,
    /// The version of Mastodon installed on the instance.
    pub version: String,
    /// The URL for the source code of the software running on this instance, in keeping with AGPL license requirements.
    pub source_url: String,
    /// A short, plain-text description defined by the admin.
    pub description: String,
    /// Usage data for this instance.
    pub usage: Usage,
    /// An image used to represent this instance.
    pub thumbnail: Thumbnail,
    /// Primary languages of the website and its staff.
    pub languages: Vec<Language>,
    /// Configured values and limits for this website.
    pub configuration: Configuration,
    /// Information about registering for this website.
    pub registrations: Registrations,
    /// Hints related to contacting a representative of the website.
    pub contact: Contact,
    /// An itemized list of rules for this website.
    pub rules: Vec<Rule>,
}

/// Usage data for this instance.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Usage {
    /// Usage data related to users on this instance.
    pub users: Users,
}

#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Users {
    pub active_month: i64,
}

/// An image used to represent this instance.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Thumbnail {
    /// The URL for the thumbnail image.
    pub url: String,
    /// A hash computed by [the BlurHash algorithm](https://github.com/woltapp/blurhash),
    /// for generating colorful preview thumbnails when media has not been
    /// downloaded yet.
    pub blurhash: String,
    /// Links to scaled resolution images, for high DPI screens.
    pub versions: ThumbnailVersions,
}

/// Links to scaled resolution images, for high DPI screens.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ThumbnailVersions {
    /// The URL for the thumbnail image at 1x resolution.
    #[serde(rename = "@1x")]
    pub at_1x: Url,
    /// The URL for the thumbnail image at 2x resolution.
    #[serde(rename = "@2x")]
    pub at_2x: Url,
}

/// Hints related to contacting a representative of the website.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Contact {
    /// An email address that can be messaged regarding inquiries or issues.
    pub email: String,
    /// An account that can be contacted natively over the network regarding inquiries or issues.
    pub account: Account,
}

/// Information about registering for this website.
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Registrations {
    /// Whether registrations are enabled.
    pub enabled: bool,
    /// Whether registrations require moderator approval.
    pub approval_required: bool,
    /// A custom, HTML-formatted message to be shown when registrations are closed.
    pub message: Option<String>,
}
/// Represents a rule that server users should follow.
///
/// See also [the API documentation](https://docs.joinmastodon.org/entities/Rule/)
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Rule {
    /// An identifier for the rule.
    pub id: RuleId,
    /// The rule to be followed.
    pub text: String,
}

/// Represents a domain that is blocked by the instance.
///
/// See also [the API documentation](https://docs.joinmastodon.org/entities/DomainBlock/)
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct DomainBlock {
    /// The domain which is blocked. This may be obfuscated or partially censored.
    pub domain: String,
    /// The SHA256 hash digest of the domain string.
    pub digest: String,
    /// The level to which the domain is blocked.
    pub severity: admin::domain::BlockSeverity,
    /// Admin's public comment, an optional reason for the domain block.
    pub comment: Option<String>,
}

/// Weekly activity on an instance
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Activity {
    /// UNIX Timestamp at midnight at the first day of the week.
    pub week: String,
    /// The number of Statuses created since the week began (cast from an integer)
    #[serde(with = "conversion::string_to::u64")]
    pub statuses: u64,
    /// The number of user logins since the week began (cast from an integer)
    #[serde(with = "conversion::string_to::u64")]
    pub logins: u64,
    /// The number of user registrations since the week began (cast from an integer)
    #[serde(with = "conversion::string_to::u64")]
    pub registrations: u64,
}

/// Configured values and limits for this website.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Configuration {
    /// URLs of interest for clients apps.
    pub urls: configuration::Urls,
    /// Limits related to accounts.
    pub accounts: v1::configuration::Accounts,
    /// Limits related to authoring statuses.
    pub statuses: v1::configuration::Statuses,
    /// Hints for which attachments will be accepted.
    pub media_attachments: v1::configuration::MediaAttachments,
    /// Hints for which attachments will be accepted.
    pub polls: v1::configuration::Polls,
    /// Hints related to translation.
    pub translation: configuration::Translation,
}

/// Represents an extended description for the instance, to be shown on its about page.
///
/// See also [the API documentation](https://docs.joinmastodon.org/entities/ExtendedDescription/)
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct ExtendedDescription {
    /// A timestamp of when the extended description was last updated.
    #[serde(with = "iso8601")]
    pub updated_at: OffsetDateTime,
    /// The rendered HTML content of the extended description.
    pub content: String,
}

pub mod configuration {
    use serde::{Deserialize, Serialize};
    use url::Url;

    /// Url configurations
    #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
    pub struct Urls {
        /// Url for streaming API, typically a `wss://` url.
        pub streaming: Url,
    }

    /// Hints related to translation.
    #[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq, Eq)]
    pub struct Translation {
        /// Whether the Translations API is available on this instance.
        pub enabled: bool,
    }
}

pub mod v1 {
    use isolang::Language;
    use url::Url;

    use super::*;

    /// Obsolete type, see [`super::Instance`]. Represents the software instance
    /// of Mastodon running on this domain.
    ///
    /// See also [the API documentation](https://docs.joinmastodon.org/entities/V1_Instance/)
    #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
    pub struct Instance {
        /// URI of the current instance
        pub uri: String,
        /// The instance's title.
        pub title: String,
        /// A description for the instance.
        pub description: String,
        /// A short, plain-text description defined by the admin.
        pub short_description: String,
        /// An email address which can be used to contact the
        /// instance administrator.
        pub email: String,
        /// The Mastodon version used by instance.
        pub version: String,
        /// Urls to the streaming api.
        pub urls: Option<Urls>,
        /// Stats about the instance.
        pub stats: Option<Stats>,
        /// Thumbnail of the server image.
        pub thumbnail: Option<Url>,
        /// List of languages used on the server.
        pub languages: Option<Vec<Language>>,
        /// Whether registrations are enabled.
        pub registrations: bool,
        /// Whether registrations require moderator approval.
        pub approval_required: bool,
        /// A user that can be contacted, as an alternative to email.
        pub contact_account: Account,
        /// An itemized list of rules for this website.  
        pub rules: Vec<Rule>,
        /// Configured values and limits for this website.
        pub configuration: Configuration,
    }

    /// Statistics about the Mastodon instance.
    #[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
    pub struct Stats {
        /// Total users on this instance.
        pub user_count: u64,
        /// Total statuses on this instance.
        pub status_count: u64,
        /// Total domains discovered by this instance.
        pub domain_count: u64,
    }

    #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
    pub struct Configuration {
        /// Limits related to accounts.
        pub accounts: Option<configuration::Accounts>,
        /// Limits related to authoring statuses.
        pub statuses: configuration::Statuses,
        /// Hints for which attachments will be accepted.
        pub media_attachments: configuration::MediaAttachments,
    }

    /// Url configurations
    #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
    pub struct Urls {
        /// Url for streaming API, typically a `wss://` url.
        pub streaming_api: Url,
    }

    pub mod configuration {
        use serde::{Deserialize