ChatMessageModel.fromJson constructor
ChatMessageModel.fromJson(
- Map<String, dynamic> json
)
Implementation
factory ChatMessageModel.fromJson(Map<String, dynamic> json) => ChatMessageModel(
chatUserJid: json["chatUserJid"] ?? "",
contactType: json["contactType"] == "unknown"
? "unknown_contact"
: json["contactType"] == "live"
? "live_contact"
: json["contactType"] == "local"
? "local_contact"
: json["contactType"] == "deleted"
? "deleted_contact"
: json["contactType"] ?? "",
isItCarbonMessage: Platform.isAndroid ? json["isItCarbonMessage"] ?? false : json["isCarbonMessage"] ?? false,
isItSavedContact: Platform.isAndroid ? json["isItSavedContact"] ?? false : json["isSavedContact"] ?? false,
isMessageDeleted: json["isMessageDeleted"],
isMessageRecalled: json["isMessageRecalled"],
isMessageSentByMe: json["isMessageSentByMe"],
isMessageStarred: json["isMessageStarred"],
isSelected: json["isSelected"] ?? false,
isThisAReplyMessage: Platform.isAndroid ? json["isThisAReplyMessage"] : json["isReplyMessage"],
messageChatType: json["messageChatType"] == "singleChat" ? "chat" : json["messageChatType"].toLowerCase(),
messageCustomField: json["messageCustomField"] ?? {},
messageId: json["messageId"],
messageSentTime: json["messageSentTime"].toInt(),
messageStatus: Platform.isAndroid
? json["messageStatus"]["status"]
: json["messageStatus"] == 2 //acknowledge
? "A"
: json["messageStatus"] == 3 //delivered
? "D"
: json["messageStatus"] == 4 //seen
? "S"
: json["messageStatus"] == 5 //received
? "R"
: "N", //0 notAcknowledged in iOS
messageTextContent: json["messageTextContent"].toString(),
messageType: json["messageType"].toString().toUpperCase() == "FILE"
? "DOCUMENT"
: json["messageType"].toString().toUpperCase(),
replyParentChatMessage: json["replyParentChatMessage"] == null
? null
: ReplyParentChatMessage.fromJson(json["replyParentChatMessage"]),
senderNickName: json["senderNickName"],
senderUserJid: json["senderUserJid"],
senderUserName: json["senderUserName"],
contactChatMessage:
json["contactChatMessage"] == null ? null : ContactChatMessage.fromJson(json["contactChatMessage"]),
mediaChatMessage: json["mediaChatMessage"] == null ? null : MediaChatMessage.fromJson(json["mediaChatMessage"]),
locationChatMessage:
json["locationChatMessage"] == null ? null : LocationChatMessage.fromJson(json["locationChatMessage"]),
);