MessageReceipt.fromMap constructor

MessageReceipt.fromMap(
  1. dynamic map
)

Creates a new MessageReceipt instance from a map.

Implementation

factory MessageReceipt.fromMap(dynamic map) {
  late int messageId;
  DateTime? deliveredAt;
  DateTime? readAt;
  if (Platform.isAndroid) {
    messageId = map['messageId'] ?? 0;
    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);
  } else if (Platform.isIOS) {
    messageId = int.parse(map['messageId'] ?? '0');
    deliveredAt = map['deliveredAt'] == 0 || map['deliveredAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch(
            (map['deliveredAt'] * 1000).toInt());
    readAt = map['readAt'] == 0 || map['readAt'] == null
        ? null
        : DateTime.fromMillisecondsSinceEpoch((map['readAt'] * 1000).toInt());
  } else {
    messageId = map['messageId'] ?? 0;
  }
  return MessageReceipt(
    messageId: messageId,
    sender: User.fromMap(map['sender']),
    receiverType: map['receivertype'],
    receiptType: map['receiptType'],
    timestamp: map['timestamp'] == 0
        ? DateTime.fromMillisecondsSinceEpoch(0)
        : DateTime.fromMillisecondsSinceEpoch(map['timestamp'] * 1000),
    deliveredAt: deliveredAt,
    readAt: readAt,
    receiverId: map['receiverId'],
  );
}