/
attachment.dart
60 lines (47 loc) 路 1.33 KB
/
attachment.dart
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
import 'package:json_annotation/json_annotation.dart';
import 'package:mastodon/mock/properties.dart';
part 'attachment.g.dart';
/// https://docs.joinmastodon.org/api/entities/#attachment
@JsonSerializable(
nullable: false,
createToJson: false,
fieldRename: FieldRename.snake,
)
class Attachment {
final String id;
final AttachmentType type;
final Uri url;
@JsonKey(nullable: true)
final Uri remoteUrl;
final Uri previewUrl;
@JsonKey(nullable: true)
final Uri textUrl;
@JsonKey(nullable: true)
final dynamic meta;
@JsonKey(nullable: true)
final String description;
Attachment({
this.id,
this.type,
this.url,
this.remoteUrl,
this.previewUrl,
this.textUrl,
this.meta,
this.description,
});
/// TODO: mock appropriate urls to match the attachment type
Attachment.mock()
: id = MockProperties.string,
type = AttachmentType.unknown,
url = MockProperties.headerUri,
remoteUrl = MockProperties.headerUri,
previewUrl = MockProperties.headerUri,
textUrl = MockProperties.uri,
meta = null,
description = MockProperties.comment;
factory Attachment.fromJson(Map<String, dynamic> json) =>
_$AttachmentFromJson(json);
}
/// https://docs.joinmastodon.org/api/entities/#type
enum AttachmentType { unknown, image, gifv, video }