Action.fromMap constructor

Action.fromMap(
  1. dynamic map
)

Implementation

factory Action.fromMap(dynamic map) {
  if (map == null) throw ArgumentError('The type of action map is null');

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


  AppEntity? getAppEntity(dynamic  map){
    AppEntity? returningEntity;
    if(map==null) return null;
    if(map['uid']!=null){
      returningEntity = User.fromMap(map);
    }else if(map['guid']!=null){
      returningEntity = Group.fromMap(map);
    }else if(map['id']!=null){
      return(BaseMessage.fromMap(map));
    }
    return returningEntity;
  }


  Action message = Action(
      message: map['message'] ?? '',
      rawData: map['rawData'] ?? '{}',
      action: map['action'].toString(),
      oldScope: map['oldScope'].toString(),
      newScope: map['newScope'].toString(),
      id: map['id'],
      muid: map['muid'],
      sender: User.fromMap(map['sender']),
      receiver: appEntity,
      receiverUid: map['receiverUid'],
      type: map['type'],
      receiverType: map['receiverType'],
      category: map['category'],
      sentAt: DateTime.fromMillisecondsSinceEpoch(map['sentAt'] * 1000),
      deliveredAt: DateTime.fromMillisecondsSinceEpoch(map['deliveredAt'] * 1000),
      readAt: DateTime.fromMillisecondsSinceEpoch(map['readAt'] * 1000),
      metadata: Map<String, dynamic>.from(json.decode(map['metadata'] ?? '{}')),
      readByMeAt: DateTime.fromMillisecondsSinceEpoch(map['readByMeAt'] * 1000),
      deliveredToMeAt: DateTime.fromMillisecondsSinceEpoch(map['deliveredToMeAt'] * 1000),
      deletedAt: DateTime.fromMillisecondsSinceEpoch(map['deletedAt'] * 1000),
      editedAt: DateTime.fromMillisecondsSinceEpoch(map['editedAt'] * 1000),
      deletedBy: map['deletedBy'],
      editedBy: map['editedBy'],
      updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt'] * 1000),
      conversationId: map['conversationId'],
      parentMessageId: map['parentMessageId'],
      replyCount: map['replyCount'],
      actionBy: getAppEntity(map['actionBy']),
      actionOn :getAppEntity(map['actionOn']),
      actionFor :getAppEntity(map['actionFor']),
  );
  message._mentionedUsers= map[MessageConstants.mentionedUsers]?.map<User>((e) => User.fromMap(e)).toList() ?? [];
  message._hasMentionedMe=map[MessageConstants.hasMentionedMe] ?? false;
  return message;
}