fix: generated new models, fixed reactions
This commit is contained in:
@@ -16,7 +16,7 @@ ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) {
|
||||
: ChannelConfig.fromJson(json['config'] as Map<String, dynamic>),
|
||||
createdBy: json['created_by'] == null
|
||||
? null
|
||||
: User.fromJson(json['created_by'] as Map<String, dynamic>?),
|
||||
: User.fromJson(json['created_by'] as Map<String, dynamic>),
|
||||
frozen: json['frozen'] as bool? ?? false,
|
||||
lastMessageAt: json['last_message_at'] == null
|
||||
? null
|
||||
|
||||
@@ -10,9 +10,9 @@ ChannelState _$ChannelStateFromJson(Map<String, dynamic> json) {
|
||||
return ChannelState(
|
||||
channel: json['channel'] == null
|
||||
? null
|
||||
: ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?),
|
||||
: ChannelModel.fromJson(json['channel'] as Map<String, dynamic>),
|
||||
messages: (json['messages'] as List<dynamic>?)
|
||||
?.map((e) => Message.fromJson(e as Map<String, dynamic>?))
|
||||
?.map((e) => Message.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
members: (json['members'] as List<dynamic>?)
|
||||
@@ -20,12 +20,12 @@ ChannelState _$ChannelStateFromJson(Map<String, dynamic> json) {
|
||||
.toList() ??
|
||||
[],
|
||||
pinnedMessages: (json['pinned_messages'] as List<dynamic>?)
|
||||
?.map((e) => Message.fromJson(e as Map<String, dynamic>?))
|
||||
?.map((e) => Message.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
watcherCount: json['watcher_count'] as int?,
|
||||
watchers: (json['watchers'] as List<dynamic>?)
|
||||
?.map((e) => User.fromJson(e as Map<String, dynamic>?))
|
||||
?.map((e) => User.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
read: (json['read'] as List<dynamic>?)
|
||||
|
||||
@@ -16,22 +16,22 @@ Event _$EventFromJson(Map<String, dynamic> json) {
|
||||
: DateTime.parse(json['created_at'] as String),
|
||||
me: json['me'] == null
|
||||
? null
|
||||
: OwnUser.fromJson(json['me'] as Map<String, dynamic>?),
|
||||
: OwnUser.fromJson(json['me'] as Map<String, dynamic>),
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>?),
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
message: json['message'] == null
|
||||
? null
|
||||
: Message.fromJson(json['message'] as Map<String, dynamic>?),
|
||||
: Message.fromJson(json['message'] as Map<String, dynamic>),
|
||||
totalUnreadCount: json['total_unread_count'] as int?,
|
||||
unreadChannels: json['unread_channels'] as int?,
|
||||
reaction: json['reaction'] == null
|
||||
? null
|
||||
: Reaction.fromJson(json['reaction'] as Map<String, dynamic>?),
|
||||
: Reaction.fromJson(json['reaction'] as Map<String, dynamic>),
|
||||
online: json['online'] as bool?,
|
||||
channel: json['channel'] == null
|
||||
? null
|
||||
: EventChannel.fromJson(json['channel'] as Map<String, dynamic>?),
|
||||
: EventChannel.fromJson(json['channel'] as Map<String, dynamic>),
|
||||
member: json['member'] == null
|
||||
? null
|
||||
: Member.fromJson(json['member'] as Map<String, dynamic>),
|
||||
@@ -84,7 +84,7 @@ EventChannel _$EventChannelFromJson(Map<String, dynamic> json) {
|
||||
config: ChannelConfig.fromJson(json['config'] as Map<String, dynamic>),
|
||||
createdBy: json['created_by'] == null
|
||||
? null
|
||||
: User.fromJson(json['created_by'] as Map<String, dynamic>?),
|
||||
: User.fromJson(json['created_by'] as Map<String, dynamic>),
|
||||
frozen: json['frozen'] as bool? ?? false,
|
||||
lastMessageAt: json['last_message_at'] == null
|
||||
? null
|
||||
|
||||
@@ -10,7 +10,7 @@ Member _$MemberFromJson(Map<String, dynamic> json) {
|
||||
return Member(
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>?),
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
inviteAcceptedAt: json['invite_accepted_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['invite_accepted_at'] as String),
|
||||
|
||||
@@ -15,7 +15,7 @@ Message _$MessageFromJson(Map<String, dynamic> json) {
|
||||
?.map((e) => Attachment.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
mentionedUsers: (json['mentioned_users'] as List<dynamic>?)
|
||||
?.map((e) => User.fromJson(e as Map<String, dynamic>?))
|
||||
?.map((e) => User.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
silent: json['silent'] as bool?,
|
||||
shadowed: json['shadowed'] as bool?,
|
||||
@@ -26,19 +26,19 @@ Message _$MessageFromJson(Map<String, dynamic> json) {
|
||||
(k, e) => MapEntry(k, e as int),
|
||||
),
|
||||
latestReactions: (json['latest_reactions'] as List<dynamic>?)
|
||||
?.map((e) => Reaction.fromJson(e as Map<String, dynamic>?))
|
||||
?.map((e) => Reaction.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
ownReactions: (json['own_reactions'] as List<dynamic>?)
|
||||
?.map((e) => Reaction.fromJson(e as Map<String, dynamic>?))
|
||||
?.map((e) => Reaction.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
parentId: json['parent_id'] as String?,
|
||||
quotedMessage: json['quoted_message'] == null
|
||||
? null
|
||||
: Message.fromJson(json['quoted_message'] as Map<String, dynamic>?),
|
||||
: Message.fromJson(json['quoted_message'] as Map<String, dynamic>),
|
||||
quotedMessageId: json['quoted_message_id'] as String?,
|
||||
replyCount: json['reply_count'] as int?,
|
||||
threadParticipants: (json['thread_participants'] as List<dynamic>?)
|
||||
?.map((e) => User.fromJson(e as Map<String, dynamic>?))
|
||||
?.map((e) => User.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
showInChannel: json['show_in_channel'] as bool?,
|
||||
command: json['command'] as String?,
|
||||
@@ -50,7 +50,7 @@ Message _$MessageFromJson(Map<String, dynamic> json) {
|
||||
: DateTime.parse(json['updated_at'] as String),
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>?),
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
pinned: json['pinned'] as bool?,
|
||||
pinnedAt: json['pinned_at'] == null
|
||||
? null
|
||||
@@ -60,7 +60,7 @@ Message _$MessageFromJson(Map<String, dynamic> json) {
|
||||
: DateTime.parse(json['pin_expires'] as String),
|
||||
pinnedBy: json['pinned_by'] == null
|
||||
? null
|
||||
: User.fromJson(json['pinned_by'] as Map<String, dynamic>?),
|
||||
: User.fromJson(json['pinned_by'] as Map<String, dynamic>),
|
||||
extraData: json['extra_data'] as Map<String, dynamic>?,
|
||||
deletedAt: json['deleted_at'] == null
|
||||
? null
|
||||
|
||||
@@ -10,10 +10,10 @@ Mute _$MuteFromJson(Map<String, dynamic> json) {
|
||||
return Mute(
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>?),
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
channel: json['channel'] == null
|
||||
? null
|
||||
: ChannelModel.fromJson(json['channel'] as Map<String, dynamic>?),
|
||||
: ChannelModel.fromJson(json['channel'] as Map<String, dynamic>),
|
||||
createdAt: json['created_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['created_at'] as String),
|
||||
|
||||
@@ -10,13 +10,14 @@ class Reaction {
|
||||
/// Constructor used for json serialization
|
||||
Reaction({
|
||||
this.messageId,
|
||||
required this.createdAt,
|
||||
required this.type,
|
||||
DateTime? createdAt,
|
||||
this.type = '',
|
||||
required this.user,
|
||||
String? userId,
|
||||
required this.score,
|
||||
this.score = 0,
|
||||
this.extraData,
|
||||
}) : userId = userId ?? user.id;
|
||||
}) : userId = userId ?? user.id,
|
||||
createdAt = createdAt ?? DateTime.now();
|
||||
|
||||
/// Create a new instance from a json
|
||||
factory Reaction.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -40,6 +41,7 @@ class Reaction {
|
||||
final User user;
|
||||
|
||||
/// The score of the reaction (ie. number of reactions sent)
|
||||
@JsonKey(defaultValue: 0)
|
||||
final int score;
|
||||
|
||||
/// The userId that sent the reaction
|
||||
|
||||
@@ -9,11 +9,13 @@ part of 'reaction.dart';
|
||||
Reaction _$ReactionFromJson(Map<String, dynamic> json) {
|
||||
return Reaction(
|
||||
messageId: json['message_id'] as String?,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
createdAt: json['created_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['created_at'] as String),
|
||||
type: json['type'] as String,
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>?),
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
userId: json['user_id'] as String?,
|
||||
score: json['score'] as int,
|
||||
score: json['score'] as int? ?? 0,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>?,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ part of 'read.dart';
|
||||
Read _$ReadFromJson(Map<String, dynamic> json) {
|
||||
return Read(
|
||||
lastRead: DateTime.parse(json['last_read'] as String),
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>?),
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
unreadMessages: json['unread_messages'] as int? ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user