import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:freezed_annotation/freezed_annotation.dart"; part "profile.freezed.dart"; part "profile.g.dart"; Object? readPronouns(Map map, _) => map["m.pronouns"] ?? map["io.fsky.nyx.pronouns"]; Object? readTimezone(Map map, _) => map["m.tz"] ?? map["us.cloke.msc4175.tz"]; @freezed abstract class Profile with _$Profile { const factory Profile({ required String id, String? parseError, Uri? avatarUrl, @JsonKey(name: "displayname") String? displayName, @JsonKey(readValue: readTimezone, name: "m.tz") String? timezone, @Default(IList.empty()) @JsonKey(readValue: readPronouns, name: "io.fsky.nyx.pronouns") IList pronouns, }) = _Profile; factory Profile.fromJson(Map json) => _$ProfileFromJson(json); factory Profile.fromJsonWithCatch(Map json) { try { return Profile.fromJson(json); } catch (error) { return Profile(id: json["id"], parseError: error.toString()); } } } @freezed abstract class Pronoun with _$Pronoun { const factory Pronoun({required String language, required String summary}) = _Pronoun; factory Pronoun.fromJson(Map json) => _$PronounFromJson(json); }