User.from constructor

User.from(
  1. dynamic payload
)

Implementation

factory User.from(dynamic payload) {
  final List<UserFlagContract> publicFlags = [];
  if (payload['public_flags'] != null) {
    for (int element in UserFlag.values) {
      if ((payload['public_flags'] & element) == element) {
        publicFlags.add(UserFlag.find(element));
      }
    }
  }

  final List<UserFlagContract> flags = [];
  if (payload['flags'] != null) {
    for (int element in UserFlag.values) {
      if ((payload['flags'] & element) == element) {
        flags.add(UserFlag.find(element));
      }
    }
  }

  return User(
    payload['id'],
    payload['username'],
    payload['global_name'],
    payload['discriminator'],
    payload['bot'] == true,
    payload['system'] == true,
    publicFlags,
    flags,
    UserDecoration(
      payload['discriminator'],
      payload['avatar'] != null ? ImageFormater(payload['avatar'], 'avatars/${payload['id']}') : null,
      payload['avatar_decoration'] != null ? ImageFormater(payload['avatar'], 'avatars/${payload['id']}') : null,
    ),
    payload['locale'] ?? 'en-GB',
    payload['premium_type'] != null
      ? PremiumType.values.firstWhere((element) => element.value == payload['premium_type'])
      : PremiumType.none
  );
}