chore(llc): json annotation changes
Signed-off-by: xsahil03x <xdsahil@gmail.com>
This commit is contained in:
@@ -135,7 +135,6 @@ class Attachment extends Equatable {
|
||||
late final UploadState uploadState;
|
||||
|
||||
/// Map of custom channel extraData
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, Object?> extraData;
|
||||
|
||||
/// The attachment ID.
|
||||
|
||||
@@ -122,7 +122,6 @@ class ChannelModel {
|
||||
}
|
||||
|
||||
/// Map of custom channel extraData
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, Object?> extraData;
|
||||
|
||||
/// The team the channel belongs to
|
||||
|
||||
@@ -131,7 +131,7 @@ class Message extends Equatable {
|
||||
final String? parentId;
|
||||
|
||||
/// A quoted reply message.
|
||||
@JsonKey(toJson: Serializer.readOnly)
|
||||
@JsonKey(includeToJson: false)
|
||||
final Message? quotedMessage;
|
||||
|
||||
final String? _quotedMessageId;
|
||||
@@ -185,7 +185,7 @@ class Message extends Equatable {
|
||||
final bool pinned;
|
||||
|
||||
/// Reserved field indicating when the message was pinned.
|
||||
@JsonKey(toJson: Serializer.readOnly)
|
||||
@JsonKey(includeToJson: false)
|
||||
final DateTime? pinnedAt;
|
||||
|
||||
/// Reserved field indicating when the message will expire.
|
||||
@@ -194,11 +194,10 @@ class Message extends Equatable {
|
||||
final DateTime? pinExpires;
|
||||
|
||||
/// Reserved field indicating who pinned the message.
|
||||
@JsonKey(toJson: Serializer.readOnly)
|
||||
@JsonKey(includeToJson: false)
|
||||
final User? pinnedBy;
|
||||
|
||||
/// Message custom extraData.
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, Object?> extraData;
|
||||
|
||||
/// True if the message is a system info.
|
||||
@@ -211,7 +210,7 @@ class Message extends Equatable {
|
||||
bool get isEphemeral => type == 'ephemeral';
|
||||
|
||||
/// A Map of translations.
|
||||
@JsonKey(includeIfNull: false)
|
||||
@JsonKey(includeToJson: false)
|
||||
final Map<String, String>? i18n;
|
||||
|
||||
/// Known top level fields.
|
||||
|
||||
@@ -71,30 +71,16 @@ Message _$MessageFromJson(Map<String, dynamic> json) => Message(
|
||||
),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$MessageToJson(Message instance) {
|
||||
final val = <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'text': instance.text,
|
||||
'attachments': instance.attachments.map((e) => e.toJson()).toList(),
|
||||
'mentioned_users': User.toIds(instance.mentionedUsers),
|
||||
'parent_id': instance.parentId,
|
||||
'quoted_message': readonly(instance.quotedMessage),
|
||||
'quoted_message_id': instance.quotedMessageId,
|
||||
'show_in_channel': instance.showInChannel,
|
||||
'silent': instance.silent,
|
||||
'pinned': instance.pinned,
|
||||
'pinned_at': readonly(instance.pinnedAt),
|
||||
'pin_expires': instance.pinExpires?.toIso8601String(),
|
||||
'pinned_by': readonly(instance.pinnedBy),
|
||||
'extra_data': instance.extraData,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('i18n', instance.i18n);
|
||||
return val;
|
||||
}
|
||||
Map<String, dynamic> _$MessageToJson(Message instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'text': instance.text,
|
||||
'attachments': instance.attachments.map((e) => e.toJson()).toList(),
|
||||
'mentioned_users': User.toIds(instance.mentionedUsers),
|
||||
'parent_id': instance.parentId,
|
||||
'quoted_message_id': instance.quotedMessageId,
|
||||
'show_in_channel': instance.showInChannel,
|
||||
'silent': instance.silent,
|
||||
'pinned': instance.pinned,
|
||||
'pin_expires': instance.pinExpires?.toIso8601String(),
|
||||
'extra_data': instance.extraData,
|
||||
};
|
||||
|
||||
@@ -48,7 +48,6 @@ class Reaction {
|
||||
final String? userId;
|
||||
|
||||
/// Reaction custom extraData
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, Object?> extraData;
|
||||
|
||||
/// Map of custom user extraData
|
||||
|
||||
@@ -131,7 +131,6 @@ class User extends Equatable {
|
||||
final String? language;
|
||||
|
||||
/// Map of custom user extraData.
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, Object?> extraData;
|
||||
|
||||
/// List of users to list of userIds.
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
/// Used to avoid to serialize properties to json
|
||||
// ignore: prefer_void_to_null
|
||||
Null readonly(_) => null;
|
||||
|
||||
/// Helper class for serialization to and from json
|
||||
class Serializer {
|
||||
/// Used to avoid to serialize properties to json
|
||||
static const Function readOnly = readonly;
|
||||
|
||||
/// Takes unknown json keys and puts them in the `extra_data` key
|
||||
static Map<String, dynamic> moveToExtraDataFromRoot(
|
||||
Map<String, dynamic> json,
|
||||
|
||||
Reference in New Issue
Block a user