2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/models/account.dart';
|
2024-07-07 04:33:54 +00:00
|
|
|
import 'package:solian/models/feed.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/models/realm.dart';
|
|
|
|
|
|
|
|
class Post {
|
|
|
|
int id;
|
|
|
|
DateTime createdAt;
|
|
|
|
DateTime updatedAt;
|
2024-07-30 06:49:26 +00:00
|
|
|
DateTime? editedAt;
|
2024-05-18 10:17:16 +00:00
|
|
|
DateTime? deletedAt;
|
2024-08-17 10:44:20 +00:00
|
|
|
String? alias;
|
|
|
|
String? areaAlias;
|
2024-07-23 10:09:41 +00:00
|
|
|
dynamic body;
|
2024-07-07 04:33:54 +00:00
|
|
|
List<Tag>? tags;
|
|
|
|
List<Category>? categories;
|
2024-05-18 10:17:16 +00:00
|
|
|
List<Post>? replies;
|
2024-07-30 08:44:04 +00:00
|
|
|
String type;
|
2024-05-18 10:17:16 +00:00
|
|
|
int? replyId;
|
|
|
|
int? repostId;
|
|
|
|
int? realmId;
|
|
|
|
Post? replyTo;
|
|
|
|
Post? repostTo;
|
|
|
|
Realm? realm;
|
|
|
|
DateTime? publishedAt;
|
2024-08-01 07:49:42 +00:00
|
|
|
DateTime? publishedUntil;
|
2024-07-26 10:23:51 +00:00
|
|
|
DateTime? pinnedAt;
|
2024-07-09 13:23:38 +00:00
|
|
|
bool? isDraft;
|
2024-05-18 10:17:16 +00:00
|
|
|
int authorId;
|
|
|
|
Account author;
|
2024-07-16 11:46:53 +00:00
|
|
|
PostMetric? metric;
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
Post({
|
|
|
|
required this.id,
|
|
|
|
required this.createdAt,
|
|
|
|
required this.updatedAt,
|
2024-07-30 06:49:26 +00:00
|
|
|
required this.editedAt,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.deletedAt,
|
2024-08-17 10:44:20 +00:00
|
|
|
required this.alias,
|
|
|
|
required this.areaAlias,
|
2024-07-30 08:44:04 +00:00
|
|
|
required this.type,
|
2024-07-23 10:09:41 +00:00
|
|
|
required this.body,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.tags,
|
|
|
|
required this.categories,
|
|
|
|
required this.replies,
|
|
|
|
required this.replyId,
|
|
|
|
required this.repostId,
|
|
|
|
required this.realmId,
|
|
|
|
required this.replyTo,
|
|
|
|
required this.repostTo,
|
|
|
|
required this.realm,
|
|
|
|
required this.publishedAt,
|
2024-08-01 07:49:42 +00:00
|
|
|
required this.publishedUntil,
|
2024-07-26 10:23:51 +00:00
|
|
|
required this.pinnedAt,
|
2024-07-09 13:23:38 +00:00
|
|
|
required this.isDraft,
|
2024-05-18 10:17:16 +00:00
|
|
|
required this.authorId,
|
|
|
|
required this.author,
|
2024-07-16 11:46:53 +00:00
|
|
|
required this.metric,
|
2024-05-18 10:17:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
factory Post.fromJson(Map<String, dynamic> json) => Post(
|
2024-06-23 10:51:49 +00:00
|
|
|
id: json['id'],
|
|
|
|
createdAt: DateTime.parse(json['created_at']),
|
|
|
|
updatedAt: DateTime.parse(json['updated_at']),
|
|
|
|
deletedAt: json['deleted_at'] != null
|
2024-05-21 16:05:03 +00:00
|
|
|
? DateTime.parse(json['deleted_at'])
|
|
|
|
: null,
|
2024-08-17 10:44:20 +00:00
|
|
|
alias: json['alias'],
|
|
|
|
areaAlias: json['area_alias'],
|
2024-07-30 08:44:04 +00:00
|
|
|
type: json['type'],
|
2024-07-23 10:09:41 +00:00
|
|
|
body: json['body'],
|
2024-07-07 04:33:54 +00:00
|
|
|
tags: json['tags']?.map((x) => Tag.fromJson(x)).toList().cast<Tag>(),
|
|
|
|
categories: json['categories']
|
|
|
|
?.map((x) => Category.fromJson(x))
|
|
|
|
.toList()
|
|
|
|
.cast<Category>(),
|
2024-06-23 10:51:49 +00:00
|
|
|
replies: json['replies'],
|
|
|
|
replyId: json['reply_id'],
|
|
|
|
repostId: json['repost_id'],
|
|
|
|
realmId: json['realm_id'],
|
2024-05-21 16:05:03 +00:00
|
|
|
replyTo:
|
2024-06-23 10:51:49 +00:00
|
|
|
json['reply_to'] != null ? Post.fromJson(json['reply_to']) : null,
|
2024-05-21 16:05:03 +00:00
|
|
|
repostTo:
|
2024-06-23 10:51:49 +00:00
|
|
|
json['repost_to'] != null ? Post.fromJson(json['repost_to']) : null,
|
|
|
|
realm: json['realm'] != null ? Realm.fromJson(json['realm']) : null,
|
2024-07-30 06:49:26 +00:00
|
|
|
editedAt: json['edited_at'] != null
|
|
|
|
? DateTime.parse(json['edited_at'])
|
|
|
|
: null,
|
2024-07-07 04:33:54 +00:00
|
|
|
publishedAt: json['published_at'] != null
|
|
|
|
? DateTime.parse(json['published_at'])
|
|
|
|
: null,
|
2024-08-01 07:49:42 +00:00
|
|
|
publishedUntil: json['published_until'] != null
|
|
|
|
? DateTime.parse(json['published_until'])
|
|
|
|
: null,
|
2024-07-26 10:23:51 +00:00
|
|
|
pinnedAt: json['pinned_at'] != null
|
|
|
|
? DateTime.parse(json['pinned_at'])
|
|
|
|
: null,
|
2024-07-09 13:23:38 +00:00
|
|
|
isDraft: json['is_draft'],
|
2024-06-23 10:51:49 +00:00
|
|
|
authorId: json['author_id'],
|
|
|
|
author: Account.fromJson(json['author']),
|
2024-07-16 11:46:53 +00:00
|
|
|
metric:
|
|
|
|
json['metric'] != null ? PostMetric.fromJson(json['metric']) : null,
|
2024-05-19 12:30:50 +00:00
|
|
|
);
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
2024-06-23 10:51:49 +00:00
|
|
|
'id': id,
|
|
|
|
'created_at': createdAt.toIso8601String(),
|
|
|
|
'updated_at': updatedAt.toIso8601String(),
|
2024-07-30 06:49:26 +00:00
|
|
|
'edited_at': editedAt?.toIso8601String(),
|
|
|
|
'deleted_at': deletedAt?.toIso8601String(),
|
2024-08-17 10:44:20 +00:00
|
|
|
'alias': alias,
|
|
|
|
'area_alias': areaAlias,
|
2024-07-30 08:44:04 +00:00
|
|
|
'type': type,
|
2024-07-23 10:09:41 +00:00
|
|
|
'body': body,
|
2024-06-23 10:51:49 +00:00
|
|
|
'tags': tags,
|
|
|
|
'categories': categories,
|
|
|
|
'replies': replies,
|
|
|
|
'reply_id': replyId,
|
|
|
|
'repost_id': repostId,
|
|
|
|
'realm_id': realmId,
|
|
|
|
'reply_to': replyTo?.toJson(),
|
|
|
|
'repost_to': repostTo?.toJson(),
|
|
|
|
'realm': realm?.toJson(),
|
|
|
|
'published_at': publishedAt?.toIso8601String(),
|
2024-08-01 07:49:42 +00:00
|
|
|
'published_until': publishedUntil?.toIso8601String(),
|
2024-07-26 10:23:51 +00:00
|
|
|
'pinned_at': pinnedAt?.toIso8601String(),
|
2024-07-09 13:23:38 +00:00
|
|
|
'is_draft': isDraft,
|
2024-06-23 10:51:49 +00:00
|
|
|
'author_id': authorId,
|
|
|
|
'author': author.toJson(),
|
2024-07-16 11:46:53 +00:00
|
|
|
'metric': metric?.toJson(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class PostMetric {
|
|
|
|
int reactionCount;
|
|
|
|
Map<String, int> reactionList;
|
|
|
|
int replyCount;
|
|
|
|
|
|
|
|
PostMetric({
|
|
|
|
required this.reactionCount,
|
|
|
|
required this.reactionList,
|
|
|
|
required this.replyCount,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory PostMetric.fromJson(Map<String, dynamic> json) => PostMetric(
|
|
|
|
reactionCount: json['reaction_count'],
|
|
|
|
replyCount: json['reply_count'],
|
|
|
|
reactionList: json['reaction_list'] != null
|
|
|
|
? json['reaction_list']
|
|
|
|
.map((key, value) => MapEntry(
|
|
|
|
key,
|
|
|
|
int.tryParse(value.toString()) ??
|
|
|
|
(value is double ? value.toInt() : null)))
|
|
|
|
.cast<String, int>()
|
|
|
|
: {},
|
|
|
|
);
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() => {
|
2024-06-23 10:51:49 +00:00
|
|
|
'reaction_count': reactionCount,
|
2024-07-16 11:46:53 +00:00
|
|
|
'reply_count': replyCount,
|
2024-06-23 10:51:49 +00:00
|
|
|
'reaction_list': reactionList,
|
2024-05-19 12:30:50 +00:00
|
|
|
};
|
|
|
|
}
|