BotProfile.parse constructor

BotProfile.parse(
  1. Object? source, {
  2. ProfileExtra? extra,
})

Implementation

factory BotProfile.parse(Object? source, {ProfileExtra? extra}) {
  if (source is BotProfile) return source;
  if (source is! Map) return const BotProfile.empty();

  final k = BotProfileKeys.i;
  final rawAge = source[k.age];
  final rawGender = source[k.gender];

  final ex = source[k.extra];

  return BotProfile(
    id: _str(source[k.id]),
    name: _str(source[k.name]),
    photo: _strOrNull(source[k.photo]),
    age: rawAge is num && rawAge > 0 ? rawAge.toInt() : 0,
    gender: _genderTypes.contains(rawGender) ? rawGender as String : '',
    country: _str(source[k.country]),
    continent: _str(source[k.continent]),
    speakingStyle: _str(source[k.speakingStyle]),
    languages: _strList(source[k.languages]),
    interests: _strList(source[k.interests]),
    personalityTraits: _strList(source[k.personalityTraits]),
    favoriteTopics: _strList(source[k.favoriteTopics]),
    extra: extra ?? (ex is Map ? ex.parse() : {}),
  );
}