ChatLog.fromJson constructor

ChatLog.fromJson(
  1. Map map
)

Implementation

factory ChatLog.fromJson(Map map) {
  bool createdByVisitor = map['createdByVisitor'];
  String displayName = map['displayName'] ?? '';

  final mCreatedTimestamp = map['createdTimestamp'];
  final mLastModifiedTimestamp = map['lastModifiedTimestamp'];

  DateTime createdTimestamp = DateTime.fromMillisecondsSinceEpoch(
      mCreatedTimestamp is double
          ? mCreatedTimestamp.toInt()
          : mCreatedTimestamp);

  DateTime lastModifiedTimestamp = DateTime.fromMillisecondsSinceEpoch(
      mLastModifiedTimestamp is double
          ? mLastModifiedTimestamp.toInt()
          : mLastModifiedTimestamp);

  String nick = map['nick'] ?? '';

  ChatLogDeliveryStatus chatLogDeliveryStatus =
      ChatLogDeliveryStatus.fromJson(map['deliveryStatus']);

  ChatLogType chatLogType = ChatLogType.fromJson(map['type']);

  CHAT_PARTICIPANT chatParticipant = CHAT_PARTICIPANT.SYSTEM;
  String mChatParticipant = map['chatParticipant'];

  switch (mChatParticipant) {
    case 'AGENT':
      chatParticipant = CHAT_PARTICIPANT.AGENT;
      break;
    case 'SYSTEM':
      chatParticipant = CHAT_PARTICIPANT.SYSTEM;
      break;
    case 'TRIGGER':
      chatParticipant = CHAT_PARTICIPANT.TRIGGER;
      break;
    case 'VISITOR':
      chatParticipant = CHAT_PARTICIPANT.VISITOR;
      break;
  }

  return ChatLog(
    createdByVisitor,
    createdTimestamp,
    displayName,
    lastModifiedTimestamp,
    nick,
    chatLogDeliveryStatus,
    chatLogType,
    chatParticipant,
  );
}