Compare commits

..

2 commits

Author SHA1 Message Date
310384f0e9
Don't reverse the CustomScrollView
Helps with scrolling jank, fixes #29
2026-05-31 21:46:59 -04:00
eb87cbc17b
more elegantly handle empty displaynames 2026-05-31 21:46:29 -04:00
4 changed files with 30 additions and 18 deletions

View file

@ -231,10 +231,10 @@ class ClientController extends AsyncNotifier<int> {
Future<Paginate> paginate(PaginateRequest request) async =>
Paginate.fromJson(await _sendCommand("paginate", request.toJson()));
Future<Profile> getProfile(String userId) async => Profile.fromJsonWithCatch({
...(await _sendCommand("get_profile", {"user_id": userId})),
"id": userId,
});
Future<Profile> getProfile(String userId) async {
final json = await _sendCommand("get_profile", {"user_id": userId});
return Profile.fromJsonWithCatch({...json, "id": userId});
}
Future<void> reportEvent(ReportRequest request) =>
_sendCommand("report_event", request.toJson());

View file

@ -12,8 +12,6 @@ class ProfileController extends AsyncNotifier<Profile> {
return client.getProfile(userId);
}
static final provider =
AsyncNotifierProvider.family<ProfileController, Profile, String>(
ProfileController.new,
);
static final provider = AsyncNotifierProvider.family
.autoDispose<ProfileController, Profile, String>(ProfileController.new);
}

View file

@ -7,8 +7,16 @@ part "membership.g.dart";
@freezed
abstract class MembershipContent extends Content with _$MembershipContent {
MembershipContent._();
static String? displaynameFromJson(String? displayName) =>
displayName?.isEmpty == true ? null : displayName;
factory MembershipContent({
@JsonKey(name: "displayname") required String? displayName,
@JsonKey(
name: "displayname",
fromJson: MembershipContent.displaynameFromJson,
)
required String? displayName,
@JsonKey(name: "membership") required MembershipStatus status,
Uri? avatarUrl,
String? reason,

View file

@ -1,26 +1,32 @@
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.freezed.dart";
part "profile.g.dart";
Object? readPronouns(Map<dynamic, dynamic> map, _) =>
map["m.pronouns"] ?? map["io.fsky.nyx.pronouns"];
Object? readTimezone(Map<dynamic, dynamic> map, _) =>
map["m.tz"] ?? map["us.cloke.msc4175.tz"];
@freezed
abstract class Profile with _$Profile {
static Object? readPronouns(Map<dynamic, dynamic> map, _) =>
map["m.pronouns"] ?? map["io.fsky.nyx.pronouns"];
static Object? readTimezone(Map<dynamic, dynamic> map, _) =>
map["m.tz"] ?? map["us.cloke.msc4175.tz"];
const factory Profile({
required String id,
String? parseError,
Uri? avatarUrl,
@JsonKey(name: "displayname") String? displayName,
@JsonKey(readValue: readTimezone, name: "m.tz") String? timezone,
@JsonKey(
name: "displayname",
fromJson: MembershipContent.displaynameFromJson,
)
String? displayName,
@JsonKey(readValue: Profile.readTimezone, name: "m.tz") String? timezone,
@Default(IList.empty())
@JsonKey(readValue: readPronouns, name: "io.fsky.nyx.pronouns")
@JsonKey(readValue: Profile.readPronouns, name: "io.fsky.nyx.pronouns")
IList<Pronoun> pronouns,
}) = _Profile;