2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/models/account.dart';
|
|
|
|
import 'package:solian/models/realm.dart';
|
|
|
|
|
|
|
|
class Post {
|
|
|
|
int id;
|
|
|
|
DateTime createdAt;
|
|
|
|
DateTime updatedAt;
|
|
|
|
DateTime? deletedAt;
|
|
|
|
String alias;
|
|
|
|
String content;
|
|
|
|
dynamic tags;
|
|
|
|
dynamic categories;
|
|
|
|
dynamic reactions;
|
|
|
|
List<Post>? replies;
|
2024-05-20 15:11:26 +00:00
|
|
|
List<int>? attachments;
|
2024-05-18 10:17:16 +00:00
|
|
|
int? replyId;
|
|
|
|
int? repostId;
|
|
|
|
int? realmId;
|
|
|
|
Post? replyTo;
|
|
|
|
Post? repostTo;
|
|
|
|
Realm? realm;
|
|
|
|
DateTime? publishedAt;
|
|
|
|
int authorId;
|
|
|
|
Account author;
|
|
|
|
int replyCount;
|
|
|
|
int reactionCount;
|
2024-05-19 12:30:50 +00:00
|
|
|
Map<String, int> reactionList;
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
Post({
|
|
|
|
required this.id,
|
|
|
|
required this.createdAt,
|
|
|
|
required this.updatedAt,
|
|
|
|
required this.deletedAt,
|
|
|
|
required this.alias,
|
|
|
|
required this.content,
|
|
|
|
required this.tags,
|
|
|
|
required this.categories,
|
|
|
|
required this.reactions,
|
|
|
|
required this.replies,
|
|
|
|
required this.attachments,
|
|
|
|
required this.replyId,
|
|
|
|
required this.repostId,
|
|
|
|
required this.realmId,
|
|
|
|
required this.replyTo,
|
|
|
|
required this.repostTo,
|
|
|
|
required this.realm,
|
|
|
|
required this.publishedAt,
|
|
|
|
required this.authorId,
|
|
|
|
required this.author,
|
|
|
|
required this.replyCount,
|
|
|
|
required this.reactionCount,
|
|
|
|
required this.reactionList,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory Post.fromJson(Map<String, dynamic> json) => Post(
|
2024-05-19 12:30:50 +00:00
|
|
|
id: json["id"],
|
|
|
|
createdAt: DateTime.parse(json["created_at"]),
|
|
|
|
updatedAt: DateTime.parse(json["updated_at"]),
|
2024-05-21 16:05:03 +00:00
|
|
|
deletedAt: json["deleted_at"] != null
|
|
|
|
? DateTime.parse(json['deleted_at'])
|
|
|
|
: null,
|
2024-05-19 12:30:50 +00:00
|
|
|
alias: json["alias"],
|
|
|
|
content: json["content"],
|
|
|
|
tags: json["tags"],
|
|
|
|
categories: json["categories"],
|
|
|
|
reactions: json["reactions"],
|
|
|
|
replies: json["replies"],
|
2024-05-21 16:05:03 +00:00
|
|
|
attachments: json["attachments"] != null
|
|
|
|
? List<int>.from(json["attachments"])
|
|
|
|
: null,
|
2024-05-19 12:30:50 +00:00
|
|
|
replyId: json["reply_id"],
|
|
|
|
repostId: json["repost_id"],
|
|
|
|
realmId: json["realm_id"],
|
2024-05-21 16:05:03 +00:00
|
|
|
replyTo:
|
|
|
|
json["reply_to"] != null ? Post.fromJson(json["reply_to"]) : null,
|
|
|
|
repostTo:
|
|
|
|
json["repost_to"] != null ? Post.fromJson(json["repost_to"]) : null,
|
2024-06-22 17:52:05 +00:00
|
|
|
realm: json["realm"] != null ? Realm.fromJson(json["realm"]) : null,
|
|
|
|
publishedAt: json["published_at"] != null ? DateTime.parse(json["published_at"]) : null,
|
2024-05-19 12:30:50 +00:00
|
|
|
authorId: json["author_id"],
|
|
|
|
author: Account.fromJson(json["author"]),
|
|
|
|
replyCount: json["reply_count"],
|
|
|
|
reactionCount: json["reaction_count"],
|
|
|
|
reactionList: json["reaction_list"] != null
|
|
|
|
? json["reaction_list"]
|
2024-05-21 16:05:03 +00:00
|
|
|
.map((key, value) => MapEntry(
|
|
|
|
key,
|
|
|
|
int.tryParse(value.toString()) ??
|
|
|
|
(value is double ? value.toInt() : null)))
|
2024-05-19 12:30:50 +00:00
|
|
|
.cast<String, int>()
|
|
|
|
: {},
|
|
|
|
);
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
2024-05-19 12:30:50 +00:00
|
|
|
"id": id,
|
|
|
|
"created_at": createdAt.toIso8601String(),
|
|
|
|
"updated_at": updatedAt.toIso8601String(),
|
|
|
|
"deleted_at": deletedAt,
|
|
|
|
"alias": alias,
|
|
|
|
"content": content,
|
|
|
|
"tags": tags,
|
|
|
|
"categories": categories,
|
|
|
|
"reactions": reactions,
|
|
|
|
"replies": replies,
|
|
|
|
"attachments": attachments,
|
|
|
|
"reply_id": replyId,
|
|
|
|
"repost_id": repostId,
|
|
|
|
"realm_id": realmId,
|
|
|
|
"reply_to": replyTo?.toJson(),
|
2024-05-21 16:05:03 +00:00
|
|
|
"repost_to": repostTo?.toJson(),
|
2024-06-22 17:52:05 +00:00
|
|
|
"realm": realm?.toJson(),
|
|
|
|
"published_at": publishedAt?.toIso8601String(),
|
2024-05-19 12:30:50 +00:00
|
|
|
"author_id": authorId,
|
|
|
|
"author": author.toJson(),
|
|
|
|
"reply_count": replyCount,
|
|
|
|
"reaction_count": reactionCount,
|
|
|
|
"reaction_list": reactionList,
|
|
|
|
};
|
|
|
|
}
|