Call.fromMap constructor

Call.fromMap(
  1. dynamic map, {
  2. AppEntity? receiver,
})

Implementation

factory Call.fromMap(dynamic map, {AppEntity? receiver}) {
  if (map == null) throw ArgumentError('The type of mediamessage map is null');

  final appEntity = (map['receiver'] == null)
      ? receiver
      : (map['receiverType'] == 'user')
          ? User.fromMap(map['receiver'])
          : Group.fromMap(map['receiver']);

  final conversationId = map['conversationId'].isEmpty
      ? map['receiverType'] == 'user'
          ? '${map['sender']['uid']}_user_${(appEntity as User).uid}'
          : 'group_${map['receiver']['guid']}'
      : map['conversationId'];

  final callReceiver = (map['callReceiver'] == null)
      ? receiver
      : (map['callReceiver']['guid'] == null ||
              map['callReceiver']['guid'] == 'null')
          ? User.fromMap(map['callReceiver'])
          : Group.fromMap(map['callReceiver']);

  final callInitiator = (map['callInitiator'] == null)
      ? receiver
      : (map['callInitiator']['guid'] == null ||
              map['callInitiator']['guid'] == 'null')
          ? User.fromMap(map['callInitiator'])
          : Group.fromMap(map['callInitiator']);

  return Call(
    sessionId: map['sessionId'],
    callStatus: map['callStatus'],
    action: map['action'],
    callReceiver: callReceiver,
    callInitiator: callInitiator,
    initiatedAt: map['initiatedAt'] == 0 || map['initiatedAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['initiatedAt'] * 1000),
    joinedAt: map['joinedAt'] == 0 || map['joinedAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['joinedAt'] * 1000),
    id: map['id'],
    muid: map['muid'],
    sender: map['sender'] == null ? null : User.fromMap(map['sender']),
    receiver: appEntity,
    receiverUid: map['receiverUid'],
    type: map['type'],
    receiverType: map['receiverType'],
    category: map['category'],
    sentAt: map['sentAt'] == 0 || map['sentAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['sentAt'] * 1000),
    deliveredAt: map['deliveredAt'] == 0 || map['deliveredAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['deliveredAt'] * 1000),
    readAt: map['readAt'] == 0 || map['readAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['readAt'] * 1000),
    metadata: Map<String, dynamic>.from(json.decode(map['metadata'] ?? '{}')),
    readByMeAt: map['readByMeAt'] == 0 || map['readByMeAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['readByMeAt'] * 1000),
    deliveredToMeAt: map['deliveredToMeAt'] == 0 ||
            map['deliveredToMeAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['deliveredToMeAt'] * 1000),
    deletedAt: map['deletedAt'] == 0 || map['deletedAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['deletedAt'] * 1000),
    editedAt: map['editedAt'] == 0 || map['editedAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['editedAt'] * 1000),
    deletedBy: map['deletedBy'],
    editedBy: map['editedBy'],
    updatedAt: map['updatedAt'] == 0 || map['updatedAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] * 1000),
    conversationId: conversationId,
    parentMessageId: map['parentMessageId'],
    replyCount: map['replyCount'],
  );
}