UserProfile.parse constructor

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

Implementation

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

  final k = UserProfileKeys.i;
  final ex = source[k.extra];

  return UserProfile(
    id: _str(source[k.id]),
    name: _strOrNull(source[k.name]),
    photo: _strOrNull(source[k.photo]),
    platform: _str(source[k.platform]),
    token: _str(source[k.token]),
    room: _strOrNull(source[k.room]),
    newMessageAlerts: _parseBool(source[k.newMessageAlerts]),
    newRoomAlerts: _parseBool(source[k.newRoomAlerts]),
    extra: extra ?? (ex is Map ? ex.parse() : {}),
  );
}