add profile editor

Fixes #12
This commit is contained in:
Henry Hiles 2026-10-22 21:20:13 -04:00
commit 8fbfcde9c5
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -31,24 +31,46 @@ class const Bio({required final String html, final String? editSource})
class const Profile({
final String? id,
final String? parseError,
final Uri? avatarUrl,
@JsonKey(name: Profile.avatarUrlKey) final Uri? avatarUrl,
@JsonKey(name: "displayname", fromJson: MembershipContent.displaynameFromJson)
@JsonKey(
name: Profile.displayNameKey,
fromJson: MembershipContent.displaynameFromJson,
)
final String? displayName,
@JsonKey(readValue: Profile.readTimezone, name: "m.tz")
@JsonKey(readValue: Profile.readTimezone, name: Profile.timezoneKey)
final String? timezone,
@JsonKey(readValue: Profile.readPronouns, name: "m.pronouns")
@JsonKey(readValue: Profile.readPronouns, name: Profile.pronounsKey)
final IList<Pronoun> pronouns = const .empty(),
}) with _$Profile {
static const avatarUrlKey = "avatar_url";
static const displayNameKey = "displayname";
static const timezoneKey = "m.tz";
static const unstableTimezoneKey = "us.cloke.msc4175.tz";
static const pronounsKey = "m.pronouns";
static const unstablePronounsKey = "io.fsky.nyx.pronouns";
Map<String, Object?> toJson() => _$ProfileToJson(this);
Profile withPronouns(String language, Iterable<String> summaries) => copyWith(
pronouns: pronouns
.where((pronoun) => pronoun.language != language)
.toIList()
.addAll(
summaries.map(
(summary) => Pronoun(language: language, summary: summary),
),
),
);
static Object? readPronouns(Map<dynamic, dynamic> map, String key) =>
map[key] ?? map["io.fsky.nyx.pronouns"];
/* until stable, commented out: map[key] ?? */ map[Profile
.unstablePronounsKey];
static Object? readTimezone(Map<dynamic, dynamic> map, String key) =>
map[key] ?? map["us.cloke.msc4175.tz"];
map[key] ?? map[Profile.unstableTimezoneKey];
factory Profile.fromJson(Map<String, dynamic> json) =>
_$ProfileFromJson(json);