From 9c451f485a030adc2ebd34140139e2bf9b8d2141 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 7 Sep 2024 15:36:06 +0800 Subject: [PATCH] :art: Refactored all models with json annotation to make code cleaner --- lib/models/account.dart | 73 +++------------- lib/models/account.g.dart | 72 +++++++++++++++ lib/models/account_status.dart | 49 +++-------- lib/models/account_status.g.dart | 59 +++++++++++++ lib/models/attachment.dart | 65 +++----------- lib/models/attachment.g.dart | 72 +++++++++++++++ lib/models/call.dart | 31 ++----- lib/models/call.g.dart | 37 ++++++++ lib/models/channel.dart | 67 +++----------- lib/models/channel.g.dart | 74 ++++++++++++++++ lib/models/event.dart | 106 +++-------------------- lib/models/event.g.dart | 64 ++++++++++++++ lib/models/feed.dart | 83 ------------------ lib/models/keypair.dart | 32 ------- lib/models/link.dart | 40 ++------- lib/models/link.g.dart | 41 +++++++++ lib/models/notification.dart | 38 ++------ lib/models/notification.g.dart | 38 ++++++++ lib/models/packet.dart | 24 ++--- lib/models/packet.g.dart | 23 +++++ lib/models/pagination.dart | 12 +-- lib/models/pagination.g.dart | 19 ++++ lib/models/post.dart | 100 +++------------------ lib/models/post.g.dart | 103 ++++++++++++++++++++++ lib/models/post_categories.dart | 54 ++++++++++++ lib/models/post_categories.g.dart | 51 +++++++++++ lib/models/realm.dart | 58 +++---------- lib/models/realm.g.dart | 60 +++++++++++++ lib/models/relations.dart | 29 ++----- lib/models/relations.g.dart | 34 ++++++++ lib/models/stickers.dart | 71 +++------------ lib/models/stickers.g.dart | 73 ++++++++++++++++ lib/screens/dashboard.dart | 1 - lib/widgets/chat/chat_message_input.dart | 2 +- lib/widgets/posts/post_tags.dart | 2 +- 35 files changed, 1015 insertions(+), 742 deletions(-) create mode 100644 lib/models/account.g.dart create mode 100644 lib/models/account_status.g.dart create mode 100644 lib/models/attachment.g.dart create mode 100644 lib/models/call.g.dart create mode 100644 lib/models/channel.g.dart create mode 100644 lib/models/event.g.dart delete mode 100644 lib/models/feed.dart delete mode 100644 lib/models/keypair.dart create mode 100644 lib/models/link.g.dart create mode 100644 lib/models/notification.g.dart create mode 100644 lib/models/packet.g.dart create mode 100644 lib/models/pagination.g.dart create mode 100644 lib/models/post.g.dart create mode 100644 lib/models/post_categories.dart create mode 100644 lib/models/post_categories.g.dart create mode 100644 lib/models/realm.g.dart create mode 100644 lib/models/relations.g.dart create mode 100644 lib/models/stickers.g.dart diff --git a/lib/models/account.dart b/lib/models/account.dart index e28c9a6..54c6281 100644 --- a/lib/models/account.dart +++ b/lib/models/account.dart @@ -1,3 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'account.g.dart'; + +@JsonSerializable() class Account { int id; DateTime createdAt; @@ -31,50 +36,13 @@ class Account { this.externalId, }); - factory Account.fromJson(Map json) => Account( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - confirmedAt: json['confirmed_at'] != null - ? DateTime.parse(json['confirmed_at']) - : null, - suspendedAt: json['suspended_at'] != null - ? DateTime.parse(json['suspended_at']) - : null, - name: json['name'], - nick: json['nick'], - avatar: json['avatar'], - banner: json['banner'], - description: json['description'], - emailAddress: json['email_address'], - badges: json['badges'] - ?.map((e) => AccountBadge.fromJson(e)) - .toList() - .cast(), - externalId: json['external_id'], - ); + factory Account.fromJson(Map json) => + _$AccountFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'confirmed_at': confirmedAt?.toIso8601String(), - 'suspended_at': suspendedAt?.toIso8601String(), - 'name': name, - 'nick': nick, - 'avatar': avatar, - 'banner': banner, - 'description': description, - 'email_address': emailAddress, - 'badges': badges?.map((e) => e.toJson()).toList(), - 'external_id': externalId, - }; + Map toJson() => _$AccountToJson(this); } +@JsonSerializable() class AccountBadge { int id; DateTime createdAt; @@ -94,25 +62,8 @@ class AccountBadge { required this.type, }); - factory AccountBadge.fromJson(Map json) => AccountBadge( - id: json['id'], - accountId: json['account_id'], - updatedAt: DateTime.parse(json['updated_at']), - createdAt: DateTime.parse(json['created_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - metadata: json['metadata'], - type: json['type'], - ); + factory AccountBadge.fromJson(Map json) => + _$AccountBadgeFromJson(json); - Map toJson() => { - 'id': id, - 'account_id': accountId, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'metadata': metadata, - 'type': type, - }; + Map toJson() => _$AccountBadgeToJson(this); } diff --git a/lib/models/account.g.dart b/lib/models/account.g.dart new file mode 100644 index 0000000..703928b --- /dev/null +++ b/lib/models/account.g.dart @@ -0,0 +1,72 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'account.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Account _$AccountFromJson(Map json) => Account( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + confirmedAt: json['confirmed_at'] == null + ? null + : DateTime.parse(json['confirmed_at'] as String), + suspendedAt: json['suspended_at'] == null + ? null + : DateTime.parse(json['suspended_at'] as String), + name: json['name'] as String, + nick: json['nick'] as String, + avatar: json['avatar'], + banner: json['banner'], + description: json['description'] as String, + badges: (json['badges'] as List?) + ?.map((e) => AccountBadge.fromJson(e as Map)) + .toList(), + emailAddress: json['email_address'] as String?, + externalId: (json['external_id'] as num?)?.toInt(), + ); + +Map _$AccountToJson(Account instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'confirmed_at': instance.confirmedAt?.toIso8601String(), + 'suspended_at': instance.suspendedAt?.toIso8601String(), + 'name': instance.name, + 'nick': instance.nick, + 'avatar': instance.avatar, + 'banner': instance.banner, + 'description': instance.description, + 'badges': instance.badges?.map((e) => e.toJson()).toList(), + 'email_address': instance.emailAddress, + 'external_id': instance.externalId, + }; + +AccountBadge _$AccountBadgeFromJson(Map json) => AccountBadge( + id: (json['id'] as num).toInt(), + accountId: (json['account_id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + metadata: json['metadata'] as Map?, + type: json['type'] as String, + ); + +Map _$AccountBadgeToJson(AccountBadge instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'metadata': instance.metadata, + 'type': instance.type, + 'account_id': instance.accountId, + }; diff --git a/lib/models/account_status.dart b/lib/models/account_status.dart index 38a6747..40ce724 100644 --- a/lib/models/account_status.dart +++ b/lib/models/account_status.dart @@ -1,3 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'account_status.g.dart'; + +@JsonSerializable() class AccountStatus { bool isDisturbable; bool isOnline; @@ -11,21 +16,13 @@ class AccountStatus { required this.status, }); - factory AccountStatus.fromJson(Map json) => AccountStatus( - isDisturbable: json['is_disturbable'], - isOnline: json['is_online'], - lastSeenAt: json['last_seen_at'] != null ? DateTime.parse(json['last_seen_at']) : null, - status: json['status'] != null ? Status.fromJson(json['status']) : null, - ); + factory AccountStatus.fromJson(Map json) => + _$AccountStatusFromJson(json); - Map toJson() => { - 'is_disturbable': isDisturbable, - 'is_online': isOnline, - 'last_seen_at': lastSeenAt?.toIso8601String(), - 'status': status?.toJson(), - }; + Map toJson() => _$AccountStatusToJson(this); } +@JsonSerializable() class Status { int id; DateTime createdAt; @@ -53,31 +50,7 @@ class Status { required this.accountId, }); - factory Status.fromJson(Map json) => Status( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null ? DateTime.parse(json['deleted_at']) : null, - type: json['type'], - label: json['label'], - attitude: json['attitude'], - isNoDisturb: json['is_no_disturb'], - isInvisible: json['is_invisible'], - clearAt: json['clear_at'] != null ? DateTime.parse(json['clear_at']) : null, - accountId: json['account_id'], - ); + factory Status.fromJson(Map json) => _$StatusFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'type': type, - 'label': label, - 'attitude': attitude, - 'is_no_disturb': isNoDisturb, - 'is_invisible': isInvisible, - 'clear_at': clearAt?.toIso8601String(), - 'account_id': accountId, - }; + Map toJson() => _$StatusToJson(this); } diff --git a/lib/models/account_status.g.dart b/lib/models/account_status.g.dart new file mode 100644 index 0000000..6189fd0 --- /dev/null +++ b/lib/models/account_status.g.dart @@ -0,0 +1,59 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'account_status.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AccountStatus _$AccountStatusFromJson(Map json) => + AccountStatus( + isDisturbable: json['is_disturbable'] as bool, + isOnline: json['is_online'] as bool, + lastSeenAt: json['last_seen_at'] == null + ? null + : DateTime.parse(json['last_seen_at'] as String), + status: json['status'] == null + ? null + : Status.fromJson(json['status'] as Map), + ); + +Map _$AccountStatusToJson(AccountStatus instance) => + { + 'is_disturbable': instance.isDisturbable, + 'is_online': instance.isOnline, + 'last_seen_at': instance.lastSeenAt?.toIso8601String(), + 'status': instance.status?.toJson(), + }; + +Status _$StatusFromJson(Map json) => Status( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + type: json['type'] as String, + label: json['label'] as String, + attitude: (json['attitude'] as num).toInt(), + isNoDisturb: json['is_no_disturb'] as bool, + isInvisible: json['is_invisible'] as bool, + clearAt: json['clear_at'] == null + ? null + : DateTime.parse(json['clear_at'] as String), + accountId: (json['account_id'] as num).toInt(), + ); + +Map _$StatusToJson(Status instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'type': instance.type, + 'label': instance.label, + 'attitude': instance.attitude, + 'is_no_disturb': instance.isNoDisturb, + 'is_invisible': instance.isInvisible, + 'clear_at': instance.clearAt?.toIso8601String(), + 'account_id': instance.accountId, + }; diff --git a/lib/models/attachment.dart b/lib/models/attachment.dart index bd95afb..90e9f9f 100644 --- a/lib/models/attachment.dart +++ b/lib/models/attachment.dart @@ -1,5 +1,9 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:solian/models/account.dart'; +part 'attachment.g.dart'; + +@JsonSerializable() class AttachmentPlaceholder { int chunkCount; int chunkSize; @@ -12,19 +16,12 @@ class AttachmentPlaceholder { }); factory AttachmentPlaceholder.fromJson(Map json) => - AttachmentPlaceholder( - chunkCount: json['chunk_count'], - chunkSize: json['chunk_size'], - meta: Attachment.fromJson(json['meta']), - ); + _$AttachmentPlaceholderFromJson(json); - Map toJson() => { - 'chunk_count': chunkCount, - 'chunk_size': chunkSize, - 'meta': meta.toJson(), - }; + Map toJson() => _$AttachmentPlaceholderToJson(this); } +@JsonSerializable() class Attachment { int id; DateTime createdAt; @@ -68,50 +65,8 @@ class Attachment { required this.accountId, }); - factory Attachment.fromJson(Map json) => Attachment( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - rid: json['rid'], - uuid: json['uuid'], - size: json['size'], - name: json['name'], - alt: json['alt'], - mimetype: json['mimetype'], - hash: json['hash'], - destination: json['destination'], - isAnalyzed: json['is_analyzed'], - isUploaded: json['is_uploaded'], - metadata: json['metadata'], - fileChunks: json['file_chunks'], - isMature: json['is_mature'], - account: - json['account'] != null ? Account.fromJson(json['account']) : null, - accountId: json['account_id'], - ); + factory Attachment.fromJson(Map json) => + _$AttachmentFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'rid': rid, - 'uuid': uuid, - 'size': size, - 'name': name, - 'alt': alt, - 'mimetype': mimetype, - 'hash': hash, - 'destination': destination, - 'is_analyzed': isAnalyzed, - 'is_uploaded': isUploaded, - 'metadata': metadata, - 'file_chunks': fileChunks, - 'is_mature': isMature, - 'account': account?.toJson(), - 'account_id': accountId, - }; + Map toJson() => _$AttachmentToJson(this); } diff --git a/lib/models/attachment.g.dart b/lib/models/attachment.g.dart new file mode 100644 index 0000000..5628ca5 --- /dev/null +++ b/lib/models/attachment.g.dart @@ -0,0 +1,72 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'attachment.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +AttachmentPlaceholder _$AttachmentPlaceholderFromJson( + Map json) => + AttachmentPlaceholder( + chunkCount: (json['chunk_count'] as num).toInt(), + chunkSize: (json['chunk_size'] as num).toInt(), + meta: Attachment.fromJson(json['meta'] as Map), + ); + +Map _$AttachmentPlaceholderToJson( + AttachmentPlaceholder instance) => + { + 'chunk_count': instance.chunkCount, + 'chunk_size': instance.chunkSize, + 'meta': instance.meta.toJson(), + }; + +Attachment _$AttachmentFromJson(Map json) => Attachment( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + rid: json['rid'] as String, + uuid: json['uuid'] as String, + size: (json['size'] as num).toInt(), + name: json['name'] as String, + alt: json['alt'] as String, + mimetype: json['mimetype'] as String, + hash: json['hash'] as String, + destination: (json['destination'] as num).toInt(), + isAnalyzed: json['is_analyzed'] as bool, + isUploaded: json['is_uploaded'] as bool, + metadata: json['metadata'] as Map?, + fileChunks: json['file_chunks'] as Map?, + isMature: json['is_mature'] as bool, + account: json['account'] == null + ? null + : Account.fromJson(json['account'] as Map), + accountId: (json['account_id'] as num?)?.toInt(), + ); + +Map _$AttachmentToJson(Attachment instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'rid': instance.rid, + 'uuid': instance.uuid, + 'size': instance.size, + 'name': instance.name, + 'alt': instance.alt, + 'mimetype': instance.mimetype, + 'hash': instance.hash, + 'destination': instance.destination, + 'is_analyzed': instance.isAnalyzed, + 'is_uploaded': instance.isUploaded, + 'metadata': instance.metadata, + 'file_chunks': instance.fileChunks, + 'is_mature': instance.isMature, + 'account': instance.account?.toJson(), + 'account_id': instance.accountId, + }; diff --git a/lib/models/call.dart b/lib/models/call.dart index b93325a..4e23c3a 100644 --- a/lib/models/call.dart +++ b/lib/models/call.dart @@ -1,6 +1,10 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:livekit_client/livekit_client.dart'; import 'package:solian/models/channel.dart'; +part 'call.g.dart'; + +@JsonSerializable() class Call { int id; DateTime createdAt; @@ -26,32 +30,9 @@ class Call { required this.channel, }); - factory Call.fromJson(Map json) => Call( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'], - endedAt: - json['ended_at'] != null ? DateTime.parse(json['ended_at']) : null, - externalId: json['external_id'], - founderId: json['founder_id'], - channelId: json['channel_id'], - participants: json['participants'] ?? List.empty(), - channel: Channel.fromJson(json['channel']), - ); + factory Call.fromJson(Map json) => _$CallFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'ended_at': endedAt?.toIso8601String(), - 'external_id': externalId, - 'founder_id': founderId, - 'channel_id': channelId, - 'participants': participants, - 'channel': channel.toJson(), - }; + Map toJson() => _$CallToJson(this); } enum ParticipantStatsType { diff --git a/lib/models/call.g.dart b/lib/models/call.g.dart new file mode 100644 index 0000000..918cbbd --- /dev/null +++ b/lib/models/call.g.dart @@ -0,0 +1,37 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'call.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Call _$CallFromJson(Map json) => Call( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + endedAt: json['ended_at'] == null + ? null + : DateTime.parse(json['ended_at'] as String), + externalId: json['external_id'] as String, + founderId: (json['founder_id'] as num).toInt(), + channelId: (json['channel_id'] as num).toInt(), + participants: json['participants'] as List, + channel: Channel.fromJson(json['channel'] as Map), + ); + +Map _$CallToJson(Call instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'ended_at': instance.endedAt?.toIso8601String(), + 'external_id': instance.externalId, + 'founder_id': instance.founderId, + 'channel_id': instance.channelId, + 'participants': instance.participants, + 'channel': instance.channel.toJson(), + }; diff --git a/lib/models/channel.dart b/lib/models/channel.dart index abea23c..e5b3748 100644 --- a/lib/models/channel.dart +++ b/lib/models/channel.dart @@ -1,6 +1,10 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:solian/models/account.dart'; import 'package:solian/models/realm.dart'; +part 'channel.g.dart'; + +@JsonSerializable() class Channel { int id; DateTime createdAt; @@ -17,6 +21,7 @@ class Channel { int? realmId; bool isEncrypted; + @JsonKey(includeFromJson: false, includeToJson: true) bool isAvailable = false; Channel({ @@ -36,42 +41,10 @@ class Channel { required this.realmId, }); - factory Channel.fromJson(Map json) => Channel( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'], - alias: json['alias'], - name: json['name'], - description: json['description'], - type: json['type'], - members: json['members'] - ?.map((e) => ChannelMember.fromJson(e)) - .toList() - .cast(), - account: Account.fromJson(json['account']), - accountId: json['account_id'], - realm: json['realm'] != null ? Realm.fromJson(json['realm']) : null, - realmId: json['realm_id'], - isEncrypted: json['is_encrypted'], - ); + factory Channel.fromJson(Map json) => + _$ChannelFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'alias': alias, - 'name': name, - 'description': description, - 'type': type, - 'members': members?.map((e) => e.toJson()).toList(), - 'account': account.toJson(), - 'account_id': accountId, - 'realm': realm?.toJson(), - 'realm_id': realmId, - 'is_encrypted': isEncrypted, - }; + Map toJson() => _$ChannelToJson(this); @override bool operator ==(Object other) { @@ -83,6 +56,7 @@ class Channel { int get hashCode => id; } +@JsonSerializable() class ChannelMember { int id; DateTime createdAt; @@ -104,25 +78,8 @@ class ChannelMember { required this.notify, }); - factory ChannelMember.fromJson(Map json) => ChannelMember( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'], - channelId: json['channel_id'], - accountId: json['account_id'], - account: Account.fromJson(json['account']), - notify: json['notify'], - ); + factory ChannelMember.fromJson(Map json) => + _$ChannelMemberFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'channel_id': channelId, - 'account_id': accountId, - 'account': account.toJson(), - 'notify': notify, - }; + Map toJson() => _$ChannelMemberToJson(this); } diff --git a/lib/models/channel.g.dart b/lib/models/channel.g.dart new file mode 100644 index 0000000..8bc0cb4 --- /dev/null +++ b/lib/models/channel.g.dart @@ -0,0 +1,74 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'channel.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Channel _$ChannelFromJson(Map json) => Channel( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + alias: json['alias'] as String, + name: json['name'] as String, + description: json['description'] as String, + type: (json['type'] as num).toInt(), + members: (json['members'] as List?) + ?.map((e) => ChannelMember.fromJson(e as Map)) + .toList(), + account: Account.fromJson(json['account'] as Map), + accountId: (json['account_id'] as num).toInt(), + isEncrypted: json['is_encrypted'] as bool, + realm: json['realm'] == null + ? null + : Realm.fromJson(json['realm'] as Map), + realmId: (json['realm_id'] as num?)?.toInt(), + ); + +Map _$ChannelToJson(Channel instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'alias': instance.alias, + 'name': instance.name, + 'description': instance.description, + 'type': instance.type, + 'members': instance.members?.map((e) => e.toJson()).toList(), + 'account': instance.account.toJson(), + 'account_id': instance.accountId, + 'realm': instance.realm?.toJson(), + 'realm_id': instance.realmId, + 'is_encrypted': instance.isEncrypted, + 'is_available': instance.isAvailable, + }; + +ChannelMember _$ChannelMemberFromJson(Map json) => + ChannelMember( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + channelId: (json['channel_id'] as num).toInt(), + accountId: (json['account_id'] as num).toInt(), + account: Account.fromJson(json['account'] as Map), + notify: (json['notify'] as num).toInt(), + ); + +Map _$ChannelMemberToJson(ChannelMember instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'channel_id': instance.channelId, + 'account_id': instance.accountId, + 'account': instance.account.toJson(), + 'notify': instance.notify, + }; diff --git a/lib/models/event.dart b/lib/models/event.dart index a5ed28b..784565a 100644 --- a/lib/models/event.dart +++ b/lib/models/event.dart @@ -1,6 +1,9 @@ -import 'package:solian/models/account.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:solian/models/channel.dart'; +part 'event.g.dart'; + +@JsonSerializable() class Event { int id; String uuid; @@ -10,10 +13,11 @@ class Event { Map body; String type; Channel? channel; - Sender sender; + ChannelMember sender; int channelId; int senderId; + @JsonKey(includeFromJson: false, includeToJson: true) bool isPending = false; Event({ @@ -30,38 +34,16 @@ class Event { required this.senderId, }); - factory Event.fromJson(Map json) => Event( - id: json['id'], - uuid: json['uuid'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'], - body: json['body'], - type: json['type'], - channel: - json['channel'] != null ? Channel.fromJson(json['channel']) : null, - sender: Sender.fromJson(json['sender']), - channelId: json['channel_id'], - senderId: json['sender_id'], - ); + factory Event.fromJson(Map json) => _$EventFromJson(json); - Map toJson() => { - 'id': id, - 'uuid': uuid, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'body': body, - 'type': type, - 'channel': channel?.toJson(), - 'sender': sender.toJson(), - 'channel_id': channelId, - 'sender_id': senderId, - }; + Map toJson() => _$EventToJson(this); } +@JsonSerializable() class EventMessageBody { + @JsonKey(defaultValue: '') String text; + @JsonKey(defaultValue: 'plain') String algorithm; List? attachments; int? quoteEvent; @@ -78,69 +60,7 @@ class EventMessageBody { }); factory EventMessageBody.fromJson(Map json) => - EventMessageBody( - text: json['text'] ?? '', - algorithm: json['algorithm'] ?? 'plain', - attachments: json['attachments'] != null - ? List.from(json['attachments']?.whereType()) - : null, - quoteEvent: json['quote_event'], - relatedEvent: json['related_event'], - relatedUsers: json['related_users'] != null - ? List.from(json['related_users'].map((x) => x)) - : null, - ); + _$EventMessageBodyFromJson(json); - Map toJson() => { - 'text': text, - 'algorithm': algorithm, - 'attachments': attachments?.cast(), - 'quote_event': quoteEvent, - 'related_event': relatedEvent, - 'related_users': relatedUsers?.cast(), - }; -} - -class Sender { - int id; - DateTime createdAt; - DateTime updatedAt; - DateTime? deletedAt; - Account account; - int channelId; - int accountId; - int notify; - - Sender({ - required this.id, - required this.createdAt, - required this.updatedAt, - this.deletedAt, - required this.account, - required this.channelId, - required this.accountId, - required this.notify, - }); - - factory Sender.fromJson(Map json) => Sender( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'], - account: Account.fromJson(json['account']), - channelId: json['channel_id'], - accountId: json['account_id'], - notify: json['notify'], - ); - - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'account': account.toJson(), - 'channel_id': channelId, - 'account_id': accountId, - 'notify': notify, - }; + Map toJson() => _$EventMessageBodyToJson(this); } diff --git a/lib/models/event.g.dart b/lib/models/event.g.dart new file mode 100644 index 0000000..c88a26c --- /dev/null +++ b/lib/models/event.g.dart @@ -0,0 +1,64 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'event.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Event _$EventFromJson(Map json) => Event( + id: (json['id'] as num).toInt(), + uuid: json['uuid'] as String, + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + body: json['body'] as Map, + type: json['type'] as String, + channel: json['channel'] == null + ? null + : Channel.fromJson(json['channel'] as Map), + sender: ChannelMember.fromJson(json['sender'] as Map), + channelId: (json['channel_id'] as num).toInt(), + senderId: (json['sender_id'] as num).toInt(), + ); + +Map _$EventToJson(Event instance) => { + 'id': instance.id, + 'uuid': instance.uuid, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'body': instance.body, + 'type': instance.type, + 'channel': instance.channel?.toJson(), + 'sender': instance.sender.toJson(), + 'channel_id': instance.channelId, + 'sender_id': instance.senderId, + 'is_pending': instance.isPending, + }; + +EventMessageBody _$EventMessageBodyFromJson(Map json) => + EventMessageBody( + text: json['text'] as String? ?? '', + algorithm: json['algorithm'] as String? ?? 'plain', + attachments: (json['attachments'] as List?) + ?.map((e) => e as String) + .toList(), + quoteEvent: (json['quote_event'] as num?)?.toInt(), + relatedEvent: (json['related_event'] as num?)?.toInt(), + relatedUsers: (json['related_users'] as List?) + ?.map((e) => (e as num).toInt()) + .toList(), + ); + +Map _$EventMessageBodyToJson(EventMessageBody instance) => + { + 'text': instance.text, + 'algorithm': instance.algorithm, + 'attachments': instance.attachments, + 'quote_event': instance.quoteEvent, + 'related_event': instance.relatedEvent, + 'related_users': instance.relatedUsers, + }; diff --git a/lib/models/feed.dart b/lib/models/feed.dart deleted file mode 100644 index 5acc8a1..0000000 --- a/lib/models/feed.dart +++ /dev/null @@ -1,83 +0,0 @@ -class Tag { - int id; - String alias; - String name; - String description; - DateTime createdAt; - DateTime updatedAt; - DateTime? deletedAt; - - Tag({ - required this.id, - required this.alias, - required this.name, - required this.description, - required this.createdAt, - required this.updatedAt, - required this.deletedAt, - }); - - factory Tag.fromJson(Map json) => Tag( - id: json['id'], - alias: json['alias'], - name: json['name'], - description: json['description'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - ); - - Map toJson() => { - 'id': id, - 'alias': alias, - 'description': description, - 'name': name, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - }; -} - -class Category { - int id; - String alias; - String name; - String description; - DateTime createdAt; - DateTime updatedAt; - DateTime? deletedAt; - - Category({ - required this.id, - required this.alias, - required this.name, - required this.description, - required this.createdAt, - required this.updatedAt, - required this.deletedAt, - }); - - factory Category.fromJson(Map json) => Category( - id: json['id'], - alias: json['alias'], - name: json['name'], - description: json['description'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - ); - - Map toJson() => { - 'id': id, - 'alias': alias, - 'description': description, - 'name': name, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - }; -} diff --git a/lib/models/keypair.dart b/lib/models/keypair.dart deleted file mode 100644 index 53fc010..0000000 --- a/lib/models/keypair.dart +++ /dev/null @@ -1,32 +0,0 @@ -class Keypair { - final String id; - final String algorithm; - final String publicKey; - final String? privateKey; - - final bool isOwned; - - Keypair({ - required this.id, - required this.algorithm, - required this.publicKey, - required this.privateKey, - this.isOwned = false, - }); - - factory Keypair.fromJson(Map json) => Keypair( - id: json['id'], - algorithm: json['algorithm'], - publicKey: json['public_key'], - privateKey: json['private_key'], - isOwned: json['is_owned'], - ); - - Map toJson() => { - 'id': id, - 'algorithm': algorithm, - 'public_key': publicKey, - 'private_key': privateKey, - 'is_owned': isOwned, - }; -} diff --git a/lib/models/link.dart b/lib/models/link.dart index e088cfc..ca58c82 100644 --- a/lib/models/link.dart +++ b/lib/models/link.dart @@ -1,3 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'link.g.dart'; + +@JsonSerializable() class LinkMeta { int id; DateTime createdAt; @@ -29,37 +34,8 @@ class LinkMeta { required this.siteName, }); - factory LinkMeta.fromJson(Map json) => LinkMeta( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - entryId: json['entry_id'], - icon: json['icon'], - url: json['url'], - title: json['title'], - image: json['image'], - video: json['video'], - audio: json['audio'], - description: json['description'], - siteName: json['site_name'], - ); + factory LinkMeta.fromJson(Map json) => + _$LinkMetaFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'entry_id': entryId, - 'icon': icon, - 'url': url, - 'title': title, - 'image': image, - 'video': video, - 'audio': audio, - 'description': description, - 'site_name': siteName, - }; + Map toJson() => _$LinkMetaToJson(this); } diff --git a/lib/models/link.g.dart b/lib/models/link.g.dart new file mode 100644 index 0000000..8022e7f --- /dev/null +++ b/lib/models/link.g.dart @@ -0,0 +1,41 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'link.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +LinkMeta _$LinkMetaFromJson(Map json) => LinkMeta( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + entryId: json['entry_id'] as String, + icon: json['icon'] as String?, + url: json['url'] as String, + title: json['title'] as String?, + image: json['image'] as String?, + video: json['video'] as String?, + audio: json['audio'] as String?, + description: json['description'] as String?, + siteName: json['site_name'] as String?, + ); + +Map _$LinkMetaToJson(LinkMeta instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'entry_id': instance.entryId, + 'icon': instance.icon, + 'url': instance.url, + 'title': instance.title, + 'image': instance.image, + 'video': instance.video, + 'audio': instance.audio, + 'description': instance.description, + 'site_name': instance.siteName, + }; diff --git a/lib/models/notification.dart b/lib/models/notification.dart index ad8b528..8e33d21 100755 --- a/lib/models/notification.dart +++ b/lib/models/notification.dart @@ -1,3 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'notification.g.dart'; + +@JsonSerializable() class Notification { int id; DateTime createdAt; @@ -25,35 +30,8 @@ class Notification { required this.accountId, }); - factory Notification.fromJson(Map json) => Notification( - id: json['id'] ?? 0, - createdAt: json['created_at'] == null - ? DateTime.now() - : DateTime.parse(json['created_at']), - updatedAt: json['updated_at'] == null - ? DateTime.now() - : DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'], - title: json['title'], - subtitle: json['subtitle'], - body: json['body'], - avatar: json['avatar'], - picture: json['picture'], - senderId: json['sender_id'], - accountId: json['account_id'], - ); + factory Notification.fromJson(Map json) => + _$NotificationFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'title': title, - 'subtitle': subtitle, - 'body': body, - 'avatar': avatar, - 'picture': picture, - 'sender_id': senderId, - 'account_id': accountId, - }; + Map toJson() => _$NotificationToJson(this); } diff --git a/lib/models/notification.g.dart b/lib/models/notification.g.dart new file mode 100644 index 0000000..f940126 --- /dev/null +++ b/lib/models/notification.g.dart @@ -0,0 +1,38 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'notification.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Notification _$NotificationFromJson(Map json) => Notification( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + title: json['title'] as String, + subtitle: json['subtitle'] as String?, + body: json['body'] as String, + avatar: json['avatar'] as String?, + picture: json['picture'] as String?, + senderId: (json['sender_id'] as num?)?.toInt(), + accountId: (json['account_id'] as num).toInt(), + ); + +Map _$NotificationToJson(Notification instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'title': instance.title, + 'subtitle': instance.subtitle, + 'body': instance.body, + 'avatar': instance.avatar, + 'picture': instance.picture, + 'sender_id': instance.senderId, + 'account_id': instance.accountId, + }; diff --git a/lib/models/packet.dart b/lib/models/packet.dart index dd73c56..90341c5 100644 --- a/lib/models/packet.dart +++ b/lib/models/packet.dart @@ -1,7 +1,16 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'packet.g.dart'; + +@JsonSerializable() class NetworkPackage { + @JsonKey(name: 'w') String method; + @JsonKey(name: 'e') String? endpoint; + @JsonKey(name: 'm') String? message; + @JsonKey(name: 'p') Map? payload; NetworkPackage({ @@ -11,17 +20,8 @@ class NetworkPackage { this.payload, }); - factory NetworkPackage.fromJson(Map json) => NetworkPackage( - method: json['w'], - endpoint: json['e'], - message: json['m'], - payload: json['p'], - ); + factory NetworkPackage.fromJson(Map json) => + _$NetworkPackageFromJson(json); - Map toJson() => { - 'w': method, - 'e': endpoint, - 'm': message, - 'p': payload, - }; + Map toJson() => _$NetworkPackageToJson(this); } diff --git a/lib/models/packet.g.dart b/lib/models/packet.g.dart new file mode 100644 index 0000000..5c8d7ed --- /dev/null +++ b/lib/models/packet.g.dart @@ -0,0 +1,23 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'packet.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +NetworkPackage _$NetworkPackageFromJson(Map json) => + NetworkPackage( + method: json['w'] as String, + endpoint: json['e'] as String?, + message: json['m'] as String?, + payload: json['p'] as Map?, + ); + +Map _$NetworkPackageToJson(NetworkPackage instance) => + { + 'w': instance.method, + 'e': instance.endpoint, + 'm': instance.message, + 'p': instance.payload, + }; diff --git a/lib/models/pagination.dart b/lib/models/pagination.dart index b1107d7..5603758 100755 --- a/lib/models/pagination.dart +++ b/lib/models/pagination.dart @@ -1,3 +1,8 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'pagination.g.dart'; + +@JsonSerializable() class PaginationResult { int count; List? data; @@ -8,10 +13,7 @@ class PaginationResult { }); factory PaginationResult.fromJson(Map json) => - PaginationResult(count: json['count'], data: json['data']); + _$PaginationResultFromJson(json); - Map toJson() => { - 'count': count, - 'data': data, - }; + Map toJson() => _$PaginationResultToJson(this); } diff --git a/lib/models/pagination.g.dart b/lib/models/pagination.g.dart new file mode 100644 index 0000000..f9b499e --- /dev/null +++ b/lib/models/pagination.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pagination.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PaginationResult _$PaginationResultFromJson(Map json) => + PaginationResult( + count: (json['count'] as num).toInt(), + data: json['data'] as List?, + ); + +Map _$PaginationResultToJson(PaginationResult instance) => + { + 'count': instance.count, + 'data': instance.data, + }; diff --git a/lib/models/post.dart b/lib/models/post.dart index 92d271f..ca10ca0 100755 --- a/lib/models/post.dart +++ b/lib/models/post.dart @@ -1,7 +1,11 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:solian/models/account.dart'; -import 'package:solian/models/feed.dart'; +import 'package:solian/models/post_categories.dart'; import 'package:solian/models/realm.dart'; +part 'post.g.dart'; + +@JsonSerializable() class Post { int id; DateTime createdAt; @@ -57,81 +61,15 @@ class Post { required this.metric, }); - factory Post.fromJson(Map json) => Post( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - alias: json['alias'], - areaAlias: json['area_alias'], - type: json['type'], - body: json['body'], - tags: json['tags']?.map((x) => Tag.fromJson(x)).toList().cast(), - categories: json['categories'] - ?.map((x) => Category.fromJson(x)) - .toList() - .cast(), - replies: json['replies'], - replyId: json['reply_id'], - repostId: json['repost_id'], - realmId: json['realm_id'], - replyTo: - json['reply_to'] != null ? Post.fromJson(json['reply_to']) : null, - repostTo: - json['repost_to'] != null ? Post.fromJson(json['repost_to']) : null, - realm: json['realm'] != null ? Realm.fromJson(json['realm']) : null, - editedAt: json['edited_at'] != null - ? DateTime.parse(json['edited_at']) - : null, - publishedAt: json['published_at'] != null - ? DateTime.parse(json['published_at']) - : null, - publishedUntil: json['published_until'] != null - ? DateTime.parse(json['published_until']) - : null, - pinnedAt: json['pinned_at'] != null - ? DateTime.parse(json['pinned_at']) - : null, - isDraft: json['is_draft'], - authorId: json['author_id'], - author: Account.fromJson(json['author']), - metric: - json['metric'] != null ? PostMetric.fromJson(json['metric']) : null, - ); + factory Post.fromJson(Map json) => _$PostFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'edited_at': editedAt?.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'alias': alias, - 'area_alias': areaAlias, - 'type': type, - 'body': body, - '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(), - 'published_until': publishedUntil?.toIso8601String(), - 'pinned_at': pinnedAt?.toIso8601String(), - 'is_draft': isDraft, - 'author_id': authorId, - 'author': author.toJson(), - 'metric': metric?.toJson(), - }; + Map toJson() => _$PostToJson(this); } +@JsonSerializable() class PostMetric { int reactionCount; + @JsonKey(defaultValue: {}) Map reactionList; int replyCount; @@ -141,22 +79,8 @@ class PostMetric { required this.replyCount, }); - factory PostMetric.fromJson(Map 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() - : {}, - ); + factory PostMetric.fromJson(Map json) => + _$PostMetricFromJson(json); - Map toJson() => { - 'reaction_count': reactionCount, - 'reply_count': replyCount, - 'reaction_list': reactionList, - }; + Map toJson() => _$PostMetricToJson(this); } diff --git a/lib/models/post.g.dart b/lib/models/post.g.dart new file mode 100644 index 0000000..7ec5d4e --- /dev/null +++ b/lib/models/post.g.dart @@ -0,0 +1,103 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'post.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Post _$PostFromJson(Map json) => Post( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + editedAt: json['edited_at'] == null + ? null + : DateTime.parse(json['edited_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + alias: json['alias'] as String?, + areaAlias: json['area_alias'] as String?, + type: json['type'] as String, + body: json['body'], + tags: (json['tags'] as List?) + ?.map((e) => Tag.fromJson(e as Map)) + .toList(), + categories: (json['categories'] as List?) + ?.map((e) => Category.fromJson(e as Map)) + .toList(), + replies: (json['replies'] as List?) + ?.map((e) => Post.fromJson(e as Map)) + .toList(), + replyId: (json['reply_id'] as num?)?.toInt(), + repostId: (json['repost_id'] as num?)?.toInt(), + realmId: (json['realm_id'] as num?)?.toInt(), + replyTo: json['reply_to'] == null + ? null + : Post.fromJson(json['reply_to'] as Map), + repostTo: json['repost_to'] == null + ? null + : Post.fromJson(json['repost_to'] as Map), + realm: json['realm'] == null + ? null + : Realm.fromJson(json['realm'] as Map), + publishedAt: json['published_at'] == null + ? null + : DateTime.parse(json['published_at'] as String), + publishedUntil: json['published_until'] == null + ? null + : DateTime.parse(json['published_until'] as String), + pinnedAt: json['pinned_at'] == null + ? null + : DateTime.parse(json['pinned_at'] as String), + isDraft: json['is_draft'] as bool?, + authorId: (json['author_id'] as num).toInt(), + author: Account.fromJson(json['author'] as Map), + metric: json['metric'] == null + ? null + : PostMetric.fromJson(json['metric'] as Map), + ); + +Map _$PostToJson(Post instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'edited_at': instance.editedAt?.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'alias': instance.alias, + 'area_alias': instance.areaAlias, + 'body': instance.body, + 'tags': instance.tags?.map((e) => e.toJson()).toList(), + 'categories': instance.categories?.map((e) => e.toJson()).toList(), + 'replies': instance.replies?.map((e) => e.toJson()).toList(), + 'type': instance.type, + 'reply_id': instance.replyId, + 'repost_id': instance.repostId, + 'realm_id': instance.realmId, + 'reply_to': instance.replyTo?.toJson(), + 'repost_to': instance.repostTo?.toJson(), + 'realm': instance.realm?.toJson(), + 'published_at': instance.publishedAt?.toIso8601String(), + 'published_until': instance.publishedUntil?.toIso8601String(), + 'pinned_at': instance.pinnedAt?.toIso8601String(), + 'is_draft': instance.isDraft, + 'author_id': instance.authorId, + 'author': instance.author.toJson(), + 'metric': instance.metric?.toJson(), + }; + +PostMetric _$PostMetricFromJson(Map json) => PostMetric( + reactionCount: (json['reaction_count'] as num).toInt(), + reactionList: (json['reaction_list'] as Map?)?.map( + (k, e) => MapEntry(k, (e as num).toInt()), + ) ?? + {}, + replyCount: (json['reply_count'] as num).toInt(), + ); + +Map _$PostMetricToJson(PostMetric instance) => + { + 'reaction_count': instance.reactionCount, + 'reaction_list': instance.reactionList, + 'reply_count': instance.replyCount, + }; diff --git a/lib/models/post_categories.dart b/lib/models/post_categories.dart new file mode 100644 index 0000000..6bcf911 --- /dev/null +++ b/lib/models/post_categories.dart @@ -0,0 +1,54 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'post_categories.g.dart'; + +@JsonSerializable() +class Tag { + int id; + String alias; + String name; + String description; + DateTime createdAt; + DateTime updatedAt; + DateTime? deletedAt; + + Tag({ + required this.id, + required this.alias, + required this.name, + required this.description, + required this.createdAt, + required this.updatedAt, + required this.deletedAt, + }); + + factory Tag.fromJson(Map json) => _$TagFromJson(json); + + Map toJson() => _$TagToJson(this); +} + +@JsonSerializable() +class Category { + int id; + String alias; + String name; + String description; + DateTime createdAt; + DateTime updatedAt; + DateTime? deletedAt; + + Category({ + required this.id, + required this.alias, + required this.name, + required this.description, + required this.createdAt, + required this.updatedAt, + required this.deletedAt, + }); + + factory Category.fromJson(Map json) => + _$CategoryFromJson(json); + + Map toJson() => _$CategoryToJson(this); +} diff --git a/lib/models/post_categories.g.dart b/lib/models/post_categories.g.dart new file mode 100644 index 0000000..c2c6c69 --- /dev/null +++ b/lib/models/post_categories.g.dart @@ -0,0 +1,51 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'post_categories.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Tag _$TagFromJson(Map json) => Tag( + id: (json['id'] as num).toInt(), + alias: json['alias'] as String, + name: json['name'] as String, + description: json['description'] as String, + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + ); + +Map _$TagToJson(Tag instance) => { + 'id': instance.id, + 'alias': instance.alias, + 'name': instance.name, + 'description': instance.description, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + }; + +Category _$CategoryFromJson(Map json) => Category( + id: (json['id'] as num).toInt(), + alias: json['alias'] as String, + name: json['name'] as String, + description: json['description'] as String, + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + ); + +Map _$CategoryToJson(Category instance) => { + 'id': instance.id, + 'alias': instance.alias, + 'name': instance.name, + 'description': instance.description, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + }; diff --git a/lib/models/realm.dart b/lib/models/realm.dart index c2ecba7..9fa7f94 100644 --- a/lib/models/realm.dart +++ b/lib/models/realm.dart @@ -1,5 +1,9 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:solian/models/account.dart'; +part 'realm.g.dart'; + +@JsonSerializable() class Realm { int id; DateTime createdAt; @@ -25,33 +29,9 @@ class Realm { this.accountId, }); - factory Realm.fromJson(Map json) => Realm( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - alias: json['alias'], - name: json['name'], - description: json['description'], - isPublic: json['is_public'], - isCommunity: json['is_community'], - accountId: json['account_id'], - ); + factory Realm.fromJson(Map json) => _$RealmFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'alias': alias, - 'name': name, - 'description': description, - 'is_public': isPublic, - 'is_community': isCommunity, - 'account_id': accountId, - }; + Map toJson() => _$RealmToJson(this); @override bool operator ==(Object other) { @@ -65,6 +45,7 @@ class Realm { int get hashCode => id; } +@JsonSerializable() class RealmMember { int id; DateTime createdAt; @@ -86,27 +67,8 @@ class RealmMember { required this.powerLevel, }); - factory RealmMember.fromJson(Map json) => RealmMember( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : null, - realmId: json['realm_id'], - accountId: json['account_id'], - account: Account.fromJson(json['account']), - powerLevel: json['power_level'], - ); + factory RealmMember.fromJson(Map json) => + _$RealmMemberFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'realm_id': realmId, - 'account_id': accountId, - 'account': account.toJson(), - 'power_level': powerLevel, - }; + Map toJson() => _$RealmMemberToJson(this); } diff --git a/lib/models/realm.g.dart b/lib/models/realm.g.dart new file mode 100644 index 0000000..74e25b8 --- /dev/null +++ b/lib/models/realm.g.dart @@ -0,0 +1,60 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'realm.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Realm _$RealmFromJson(Map json) => Realm( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + alias: json['alias'] as String, + name: json['name'] as String, + description: json['description'] as String, + isPublic: json['is_public'] as bool, + isCommunity: json['is_community'] as bool, + accountId: (json['account_id'] as num?)?.toInt(), + ); + +Map _$RealmToJson(Realm instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'alias': instance.alias, + 'name': instance.name, + 'description': instance.description, + 'is_public': instance.isPublic, + 'is_community': instance.isCommunity, + 'account_id': instance.accountId, + }; + +RealmMember _$RealmMemberFromJson(Map json) => RealmMember( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + realmId: (json['realm_id'] as num).toInt(), + accountId: (json['account_id'] as num).toInt(), + account: Account.fromJson(json['account'] as Map), + powerLevel: (json['power_level'] as num).toInt(), + ); + +Map _$RealmMemberToJson(RealmMember instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'realm_id': instance.realmId, + 'account_id': instance.accountId, + 'account': instance.account.toJson(), + 'power_level': instance.powerLevel, + }; diff --git a/lib/models/relations.dart b/lib/models/relations.dart index 5fd9cee..42cdb30 100644 --- a/lib/models/relations.dart +++ b/lib/models/relations.dart @@ -1,5 +1,9 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:solian/models/account.dart'; +part 'relations.g.dart'; + +@JsonSerializable() class Relationship { int id; DateTime createdAt; @@ -23,27 +27,8 @@ class Relationship { required this.status, }); - factory Relationship.fromJson(Map json) => Relationship( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'], - accountId: json['account_id'], - relatedId: json['related_id'], - account: Account.fromJson(json['account']), - related: Account.fromJson(json['related']), - status: json['status'], - ); + factory Relationship.fromJson(Map json) => + _$RelationshipFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt, - 'account_id': accountId, - 'related_id': relatedId, - 'account': account.toJson(), - 'related': related.toJson(), - 'status': status, - }; + Map toJson() => _$RelationshipToJson(this); } diff --git a/lib/models/relations.g.dart b/lib/models/relations.g.dart new file mode 100644 index 0000000..5edc805 --- /dev/null +++ b/lib/models/relations.g.dart @@ -0,0 +1,34 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'relations.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Relationship _$RelationshipFromJson(Map json) => Relationship( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + accountId: (json['account_id'] as num).toInt(), + relatedId: (json['related_id'] as num).toInt(), + account: Account.fromJson(json['account'] as Map), + related: Account.fromJson(json['related'] as Map), + status: (json['status'] as num).toInt(), + ); + +Map _$RelationshipToJson(Relationship instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'account_id': instance.accountId, + 'related_id': instance.relatedId, + 'account': instance.account.toJson(), + 'related': instance.related.toJson(), + 'status': instance.status, + }; diff --git a/lib/models/stickers.dart b/lib/models/stickers.dart index ff26061..e1e1b6b 100644 --- a/lib/models/stickers.dart +++ b/lib/models/stickers.dart @@ -1,7 +1,11 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:solian/models/account.dart'; import 'package:solian/models/attachment.dart'; import 'package:solian/services.dart'; +part 'stickers.g.dart'; + +@JsonSerializable() class Sticker { int id; DateTime createdAt; @@ -39,38 +43,13 @@ class Sticker { '/attachments/${attachment.rid}', ); - factory Sticker.fromJson(Map json) => Sticker( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : json['deleted_at'], - alias: json['alias'], - name: json['name'], - attachmentId: json['attachment_id'], - attachment: Attachment.fromJson(json['attachment']), - packId: json['pack_id'], - pack: json['pack'] != null ? StickerPack.fromJson(json['pack']) : null, - accountId: json['account_id'], - account: Account.fromJson(json['account']), - ); + factory Sticker.fromJson(Map json) => + _$StickerFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'alias': alias, - 'name': name, - 'attachment_id': attachmentId, - 'attachment': attachment.toJson(), - 'pack_id': packId, - 'account_id': accountId, - 'account': account.toJson(), - }; + Map toJson() => _$StickerToJson(this); } +@JsonSerializable() class StickerPack { int id; DateTime createdAt; @@ -96,36 +75,8 @@ class StickerPack { required this.account, }); - factory StickerPack.fromJson(Map json) => StickerPack( - id: json['id'], - createdAt: DateTime.parse(json['created_at']), - updatedAt: DateTime.parse(json['updated_at']), - deletedAt: json['deleted_at'] != null - ? DateTime.parse(json['deleted_at']) - : json['deleted_at'], - prefix: json['prefix'], - name: json['name'], - description: json['description'], - stickers: json['stickers'] == null - ? [] - : List.from( - json['stickers']!.map((x) => Sticker.fromJson(x))), - accountId: json['account_id'], - account: Account.fromJson(json['account']), - ); + factory StickerPack.fromJson(Map json) => + _$StickerPackFromJson(json); - Map toJson() => { - 'id': id, - 'created_at': createdAt.toIso8601String(), - 'updated_at': updatedAt.toIso8601String(), - 'deleted_at': deletedAt?.toIso8601String(), - 'prefix': prefix, - 'name': name, - 'description': description, - 'stickers': stickers == null - ? [] - : List.from(stickers!.map((x) => x.toJson())), - 'account_id': accountId, - 'account': account.toJson(), - }; + Map toJson() => _$StickerPackToJson(this); } diff --git a/lib/models/stickers.g.dart b/lib/models/stickers.g.dart new file mode 100644 index 0000000..de7e654 --- /dev/null +++ b/lib/models/stickers.g.dart @@ -0,0 +1,73 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'stickers.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Sticker _$StickerFromJson(Map json) => Sticker( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + alias: json['alias'] as String, + name: json['name'] as String, + attachmentId: (json['attachment_id'] as num).toInt(), + attachment: + Attachment.fromJson(json['attachment'] as Map), + packId: (json['pack_id'] as num).toInt(), + pack: json['pack'] == null + ? null + : StickerPack.fromJson(json['pack'] as Map), + accountId: (json['account_id'] as num).toInt(), + account: Account.fromJson(json['account'] as Map), + ); + +Map _$StickerToJson(Sticker instance) => { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'alias': instance.alias, + 'name': instance.name, + 'attachment_id': instance.attachmentId, + 'attachment': instance.attachment.toJson(), + 'pack_id': instance.packId, + 'pack': instance.pack?.toJson(), + 'account_id': instance.accountId, + 'account': instance.account.toJson(), + }; + +StickerPack _$StickerPackFromJson(Map json) => StickerPack( + id: (json['id'] as num).toInt(), + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + deletedAt: json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), + prefix: json['prefix'] as String, + name: json['name'] as String, + description: json['description'] as String, + stickers: (json['stickers'] as List?) + ?.map((e) => Sticker.fromJson(e as Map)) + .toList(), + accountId: (json['account_id'] as num).toInt(), + account: Account.fromJson(json['account'] as Map), + ); + +Map _$StickerPackToJson(StickerPack instance) => + { + 'id': instance.id, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + 'prefix': instance.prefix, + 'name': instance.name, + 'description': instance.description, + 'stickers': instance.stickers?.map((e) => e.toJson()).toList(), + 'account_id': instance.accountId, + 'account': instance.account.toJson(), + }; diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index 6e0d7f6..01417d4 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -51,7 +51,6 @@ class _DashboardScreenState extends State { int? _currentPostsCount; Future _pullPosts() async { - print(_lastRead.feedLastReadAt); if (_lastRead.feedLastReadAt == null) return; log('[Dashboard] Pulling posts with pivot: ${_lastRead.feedLastReadAt}'); final resp = await _posts.seeWhatsNew(_lastRead.feedLastReadAt!); diff --git a/lib/widgets/chat/chat_message_input.dart b/lib/widgets/chat/chat_message_input.dart index 12501b4..6d9920b 100644 --- a/lib/widgets/chat/chat_message_input.dart +++ b/lib/widgets/chat/chat_message_input.dart @@ -156,7 +156,7 @@ class _ChatMessageInputState extends State { }; // The local mock data - final sender = Sender( + final sender = ChannelMember( id: 0, createdAt: DateTime.now(), updatedAt: DateTime.now(), diff --git a/lib/widgets/posts/post_tags.dart b/lib/widgets/posts/post_tags.dart index 787fbe1..9d74545 100644 --- a/lib/widgets/posts/post_tags.dart +++ b/lib/widgets/posts/post_tags.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:solian/models/feed.dart'; +import 'package:solian/models/post_categories.dart'; import 'package:solian/router.dart'; class PostTagsList extends StatelessWidget {