This commit is contained in:
@ -6,6 +6,7 @@ class MediaItem {
|
||||
final String dest;
|
||||
final int mode;
|
||||
final List<Tag> tags;
|
||||
final List<Favorite>? favorites;
|
||||
|
||||
MediaItem({
|
||||
required this.id,
|
||||
@ -15,8 +16,31 @@ class MediaItem {
|
||||
required this.dest,
|
||||
required this.mode,
|
||||
required this.tags,
|
||||
required this.favorites,
|
||||
});
|
||||
|
||||
MediaItem copyWith({
|
||||
int? id,
|
||||
String? mime,
|
||||
int? size,
|
||||
int? stamp,
|
||||
String? dest,
|
||||
int? mode,
|
||||
List<Tag>? tags,
|
||||
List<Favorite>? favorites,
|
||||
}) {
|
||||
return MediaItem(
|
||||
id: id ?? this.id,
|
||||
mime: mime ?? this.mime,
|
||||
size: size ?? this.size,
|
||||
stamp: stamp ?? this.stamp,
|
||||
dest: dest ?? this.dest,
|
||||
mode: mode ?? this.mode,
|
||||
tags: tags ?? this.tags,
|
||||
favorites: favorites ?? this.favorites,
|
||||
);
|
||||
}
|
||||
|
||||
factory MediaItem.fromJson(Map<String, dynamic> json) {
|
||||
List<Tag> parsedTags = [];
|
||||
if (json['tags'] is List) {
|
||||
@ -27,6 +51,18 @@ class MediaItem {
|
||||
parsedTags = [];
|
||||
}
|
||||
|
||||
List<Favorite> parsedFavorites = [];
|
||||
if (json['favorites'] is List) {
|
||||
parsedFavorites = (json['favorites'] as List<dynamic>)
|
||||
.map(
|
||||
(favoritesJson) =>
|
||||
Favorite.fromJson(favoritesJson as Map<String, dynamic>),
|
||||
)
|
||||
.toList();
|
||||
} else {
|
||||
parsedFavorites = [];
|
||||
}
|
||||
|
||||
return MediaItem(
|
||||
id: json['id'],
|
||||
mime: json['mime'],
|
||||
@ -35,6 +71,7 @@ class MediaItem {
|
||||
dest: json['dest'],
|
||||
mode: json['mode'],
|
||||
tags: parsedTags,
|
||||
favorites: parsedFavorites,
|
||||
);
|
||||
}
|
||||
|
||||
@ -59,3 +96,21 @@ class Tag {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Favorite {
|
||||
final int userId;
|
||||
final String user;
|
||||
final int avatar;
|
||||
|
||||
Favorite({required this.userId, required this.user, required this.avatar});
|
||||
|
||||
factory Favorite.fromJson(Map<String, dynamic> json) {
|
||||
return Favorite(
|
||||
userId: json['user_id'],
|
||||
user: json['user'],
|
||||
avatar: json['avatar'],
|
||||
);
|
||||
}
|
||||
|
||||
String get avatarUrl => 'https://f0ck.me/t/$avatar.webp';
|
||||
}
|
||||
|
Reference in New Issue
Block a user