import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:freezed_annotation/freezed_annotation.dart"; import "package:nexus/models/content/membership.dart"; part "profile_response.freezed.dart"; part "profile_response.g.dart"; @Freezed(toJson: false, fromJson: false) @JsonSerializable() class const ProfileResponse({ @JsonKey(fromJson: Profile.fromJson) required final Profile profile, required final Bio? bio, }) with _$ProfileResponse { Map toJson() => _$ProfileResponseToJson(this); factory ProfileResponse.fromJson(Map json) => _$ProfileResponseFromJson(json); } @Freezed(toJson: false, fromJson: false) @JsonSerializable() class const Bio({required final String html, final String? editSource}) with _$Bio { Map toJson() => _$BioToJson(this); factory Bio.fromJson(Map json) => _$BioFromJson(json); } @Freezed(toJson: false, fromJson: false) @JsonSerializable() class const Profile({ final String? id, final String? parseError, final Uri? avatarUrl, @JsonKey(name: "displayname", fromJson: MembershipContent.displaynameFromJson) final String? displayName, @JsonKey(readValue: Profile.readTimezone, name: "m.tz") final String? timezone, @JsonKey(readValue: Profile.readPronouns, name: "m.pronouns") final IList pronouns = const IList.empty(), }) with _$Profile { Map toJson() => _$ProfileToJson(this); static Object? readPronouns(Map map, String key) => map[key] ?? map["io.fsky.nyx.pronouns"]; static Object? readTimezone(Map map, String key) => map[key] ?? map["us.cloke.msc4175.tz"]; factory Profile.fromJson(Map json) => _$ProfileFromJson(json); factory Profile.fromJsonWithCatch(Map json) { try { return Profile.fromJson(json); } catch (error) { return _Profile(parseError: error.toString()); } } } @Freezed(toJson: false, fromJson: false) @JsonSerializable() class const Pronoun({ required final String language, required final String summary, }) with _$Pronoun { Map toJson() => _$PronounToJson(this); factory Pronoun.fromJson(Map json) => _$PronounFromJson(json); }