toJson method

Map<String, dynamic> toJson()
override

Implementation

Map<String, dynamic> toJson() {
  User? userObj = sender;
  late Map receiverMap;
  if (receiverType == CometChatReceiverType.group) {
    Group grp = receiver as Group;
    receiverMap = grp.toJson();
  } else {
    User usr = receiver as User;
    receiverMap = usr.toJson();
  }

  final map = <String, dynamic>{};
  map['metadata'] = metadata;
  if (receiver != null) {
    map['receiver'] = receiverMap;
  }
  map['editedBy'] = editedBy;
  map['conversationId'] = conversationId;
  map['sentAt'] = sentAt == null ? 0 : sentAt?.millisecondsSinceEpoch;
  map['receiverUid'] = receiverUid;
  map['type'] = type;
  map['readAt'] = readAt == null ? 0 : readAt?.millisecondsSinceEpoch;
  map['deletedBy'] = deletedBy;
  map['deliveredAt'] =
      deliveredAt == null ? 0 : deliveredAt?.millisecondsSinceEpoch;
  map['muid'] = muid;
  map['deletedAt'] =
      deletedAt == null ? 0 : deletedAt?.millisecondsSinceEpoch;
  map['replyCount'] = replyCount;
  if (sender != null) {
    map['sender'] = userObj!.toJson();
  }
  map['receiverType'] = receiverType;
  map['editedAt'] = editedAt == null ? 0 : editedAt?.millisecondsSinceEpoch;
  map['parentMessageId'] = parentMessageId;
  map['readByMeAt'] =
      readByMeAt == null ? 0 : readByMeAt?.millisecondsSinceEpoch;
  map['id'] = id;
  map['category'] = category;
  map['deliveredToMeAt'] =
      deliveredToMeAt == null ? 0 : deliveredToMeAt?.millisecondsSinceEpoch;
  map['updatedAt'] =
      updatedAt == null ? 0 : updatedAt?.millisecondsSinceEpoch;
  map['text'] = text;
  map['tags'] = tags;
  return map;
}