class FriendicaEntry { final Map originalJson; final int id; final String text; final int commentCount; final List images; FriendicaEntry( {required this.originalJson, required this.text, required this.id, required this.commentCount, required this.images}); FriendicaEntry.fromJson(Map 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 json) { final readCount = json['friendica_comments'] ?? 0; final count = readCount is int ? readCount : int.tryParse(readCount) ?? 0; return count; } static List _imagesFromJson(Map json) { final List 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 json) : postId = json['postId'] ?? '', localFilename = json['localFilename'] ?? '', url = json['url'] ?? ''; Map toJson() => { 'postId': postId, 'localFilename': localFilename, 'url': url, }; }