toJson method

Map<String, dynamic> toJson()
override

Generates a map representing the CustomMessage.

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['customData'] = customData;
  map['tags'] = tags;
  map['unreadRepliesCount'] = unreadRepliesCount;
  map['mentionedUsers'] = mentionedUsers.map((e) => e.toJson()).toList();
  map['hasMentionedMe'] = hasMentionedMe;
  map['reactions'] = reactions.map((e) => e.toJson()).toList();
  map['text'] = conversationText;
  map['updateConversation'] = updateConversation;
  map['sendNotification'] = sendNotification;
  return map;
}