CustomMessage.fromMap constructor
CustomMessage.fromMap(
- dynamic map, {
- AppEntity? receiver,
Implementation
factory CustomMessage.fromMap(dynamic map, {AppEntity? receiver}) {
if (map == null)
throw ArgumentError('The type of custom message 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'];
return CustomMessage(
subType: map['subType'] ?? '',
customData:
Map<String, dynamic>.from(json.decode(map['customData'] ?? '{}')),
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'],
tags: List<String>.from(map['tags'] ?? []),
);
}