toJson method
Implementation
Map<String, dynamic> toJson({bool includeNullValues = true}) {
final data = <String, dynamic>{
'id': id,
'message': message,
'createdAt': createdAt.toIso8601String(),
'sentBy': sentBy,
'status': _status.value.name,
'message_type': messageType.name,
};
if (includeNullValues) {
data[_replyMessage] = replyMessage.toJson();
data[_reaction] = reaction.toJson();
data[_voiceMessageDuration] = voiceMessageDuration?.inMicroseconds;
data[_updateAt] = updateAt?.toIso8601String();
data[_update] = update;
} else {
if (!replyMessage.isEmpty) data[_replyMessage] = replyMessage.toJson();
if (!reaction.isEmpty) data[_reaction] = reaction.toJson();
if (voiceMessageDuration case final duration?) {
data[_voiceMessageDuration] = duration.inMicroseconds;
}
if (updateAt case final updateAt?) {
data[_updateAt] = updateAt.toIso8601String();
}
if (update?.isNotEmpty ?? false) data[_update] = update;
}
return data;
}