mirror of
https://gitlab.com/mysocialportal/fediverse-archiving-tools.git
synced 2024-10-18 08:53:31 +00:00
68 lines
1.8 KiB
Dart
68 lines
1.8 KiB
Dart
class FriendicaEntry {
|
|
final Map<String, dynamic> originalJson;
|
|
final int id;
|
|
final String text;
|
|
final int commentCount;
|
|
final List<String> images;
|
|
|
|
FriendicaEntry(
|
|
{required this.originalJson,
|
|
required this.text,
|
|
required this.id,
|
|
required this.commentCount,
|
|
required this.images});
|
|
|
|
FriendicaEntry.fromJson(Map<String, dynamic> json)
|
|
: originalJson = json,
|
|
id = json['id'] ?? -1,
|
|
text = json['text'] ?? '',
|
|
commentCount = _commentCountFromJson(json),
|
|
images = _imagesFromJson(json);
|
|
|
|
@override
|
|
String toString() {
|
|
return '''
|
|
FriendicaPost{
|
|
id: $id,
|
|
text: $text,
|
|
commentCount: $commentCount,
|
|
images: $images,
|
|
}
|
|
''';
|
|
}
|
|
|
|
static int _commentCountFromJson(Map<String, dynamic> json) {
|
|
final readCount = json['friendica_comments'] ?? 0;
|
|
final count = readCount is int ? readCount : int.tryParse(readCount) ?? 0;
|
|
return count;
|
|
}
|
|
|
|
static List<String> _imagesFromJson(Map<String, dynamic> json) {
|
|
final List<dynamic> attachments = json['attachments'] ?? [];
|
|
return attachments
|
|
.where((a) => a['mimetype']?.startsWith('image') ?? false)
|
|
.map((a) => a['url']?.toString() ?? '')
|
|
.where((urlString) => urlString.isNotEmpty)
|
|
.toList();
|
|
}
|
|
}
|
|
|
|
class ImageEntry {
|
|
final String postId;
|
|
final String localFilename;
|
|
final String url;
|
|
|
|
ImageEntry(
|
|
{required this.postId, required this.localFilename, required this.url});
|
|
|
|
ImageEntry.fromJson(Map<String, dynamic> json)
|
|
: postId = json['postId'] ?? '',
|
|
localFilename = json['localFilename'] ?? '',
|
|
url = json['url'] ?? '';
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'postId': postId,
|
|
'localFilename': localFilename,
|
|
'url': url,
|
|
};
|
|
}
|