Conversation.fromMap constructor

Conversation.fromMap(
  1. 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'],
    tags: List<String>.from(
      map['tags'] ?? [],
    ),
    unreadMentionsCount: map['unreadMentionsCount'],
    lastReadMessageId: map['lastReadMessageId'],
  );
}