Conversation.fromMap constructor
Conversation.fromMap(
- dynamic map
Creates a new Conversation instance from a map.
Implementation
factory Conversation.fromMap(dynamic map) {
if (map == null) {
throw ArgumentError('The type of conversation map is null');
}
final appEntity = (map['conversationType'] == 'user')
? User.fromMap(map['conversationWith'])
: Group.fromMap(map['conversationWith']);
return Conversation(
conversationId: map['conversationId'],
conversationType: map['conversationType'],
conversationWith: appEntity,
lastMessage: map['lastMessage'] == null || map['lastMessage'].isEmpty
? null
: BaseMessage.fromMap(map['lastMessage']),
updatedAt: map['updatedAt'] == 0 || map['updatedAt'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] * 1000),
unreadMessageCount: map['unreadMessageCount'] ?? 0,
tags: List<String>.from(map['tags'] ?? []),
unreadMentionsCount: map['unreadMentionsCount'] ?? 0,
// Parsed defensively: the server sends these as **Strings**, and the
// implicit `dynamic` -> `int?` downcast throws a TypeError on one —
// taking the whole conversation parse down with it. Measured on iOS
// (read-coverage conformance report, §6) and reproduced here.
lastReadMessageId: _asInt(map['lastReadMessageId']),
latestMessageId: _asInt(map['latestMessageId']),
pinnedAt: map['pinnedAt'] == 0 || map['pinnedAt'] == null
? null
: DateTime.fromMillisecondsSinceEpoch(map['pinnedAt'] * 1000),
pinnedBy: map['pinnedBy'],
);
}