This commit is contained in:
17
lib/models/feed.dart
Normal file
17
lib/models/feed.dart
Normal file
@ -0,0 +1,17 @@
|
||||
import 'package:f0ckapp/models/item.dart';
|
||||
|
||||
class Feed {
|
||||
final bool atEnd;
|
||||
final bool atStart;
|
||||
final List<MediaItem> items;
|
||||
|
||||
Feed({required this.atEnd, required this.atStart, required this.items});
|
||||
|
||||
factory Feed.fromJson(Map<String, dynamic> json) {
|
||||
return Feed(
|
||||
atEnd: json['atEnd'] ?? false,
|
||||
atStart: json['atStart'] ?? false,
|
||||
items: (json['items'] as List).map((e) => MediaItem.fromJson(e)).toList(),
|
||||
);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ class MediaItem {
|
||||
final int stamp;
|
||||
final String dest;
|
||||
final int mode;
|
||||
final List<Tag> tags;
|
||||
final List<Tag>? tags;
|
||||
final List<Favorite>? favorites;
|
||||
|
||||
MediaItem({
|
||||
@ -15,10 +15,15 @@ class MediaItem {
|
||||
required this.stamp,
|
||||
required this.dest,
|
||||
required this.mode,
|
||||
required this.tags,
|
||||
required this.favorites,
|
||||
this.tags = const [],
|
||||
this.favorites = const [],
|
||||
});
|
||||
|
||||
String get thumbnailUrl => 'https://f0ck.me/t/$id.webp';
|
||||
String get mediaUrl => 'https://f0ck.me/b/$dest';
|
||||
String get coverUrl => 'https://f0ck.me/ca/$id.webp';
|
||||
String get postUrl => 'https://f0ck.me/$id';
|
||||
|
||||
MediaItem copyWith({
|
||||
int? id,
|
||||
String? mime,
|
||||
@ -42,27 +47,6 @@ class MediaItem {
|
||||
}
|
||||
|
||||
factory MediaItem.fromJson(Map<String, dynamic> json) {
|
||||
List<Tag> parsedTags = [];
|
||||
if (json['tags'] is List) {
|
||||
parsedTags = (json['tags'] as List<dynamic>)
|
||||
.map((tagJson) => Tag.fromJson(tagJson as Map<String, dynamic>))
|
||||
.toList();
|
||||
} else {
|
||||
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'],
|
||||
@ -70,15 +54,18 @@ class MediaItem {
|
||||
stamp: json['stamp'],
|
||||
dest: json['dest'],
|
||||
mode: json['mode'],
|
||||
tags: parsedTags,
|
||||
favorites: parsedFavorites,
|
||||
tags:
|
||||
(json['tags'] as List<dynamic>?)
|
||||
?.map((e) => Tag.fromJson(e))
|
||||
.toList() ??
|
||||
[],
|
||||
favorites:
|
||||
(json['favorites'] as List<dynamic>?)
|
||||
?.map((e) => Favorite.fromJson(e))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
String get thumbnailUrl => 'https://f0ck.me/t/$id.webp';
|
||||
String get mediaUrl => 'https://f0ck.me/b/$dest';
|
||||
String get coverUrl => 'https://f0ck.me/ca/$id.webp';
|
||||
String get postUrl => 'https://f0ck.me/$id';
|
||||
}
|
||||
|
||||
class Tag {
|
||||
@ -99,15 +86,19 @@ class Tag {
|
||||
|
||||
class Favorite {
|
||||
final int userId;
|
||||
final String user;
|
||||
final String username;
|
||||
final int avatar;
|
||||
|
||||
Favorite({required this.userId, required this.user, required this.avatar});
|
||||
Favorite({
|
||||
required this.userId,
|
||||
required this.username,
|
||||
required this.avatar,
|
||||
});
|
||||
|
||||
factory Favorite.fromJson(Map<String, dynamic> json) {
|
||||
return Favorite(
|
||||
userId: json['user_id'],
|
||||
user: json['user'],
|
||||
username: json['user'],
|
||||
avatar: json['avatar'],
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user