Compare commits
1 commit
310384f0e9
...
75adf443f2
| Author | SHA1 | Date | |
|---|---|---|---|
|
75adf443f2 |
4 changed files with 18 additions and 30 deletions
|
|
@ -231,10 +231,10 @@ class ClientController extends AsyncNotifier<int> {
|
||||||
Future<Paginate> paginate(PaginateRequest request) async =>
|
Future<Paginate> paginate(PaginateRequest request) async =>
|
||||||
Paginate.fromJson(await _sendCommand("paginate", request.toJson()));
|
Paginate.fromJson(await _sendCommand("paginate", request.toJson()));
|
||||||
|
|
||||||
Future<Profile> getProfile(String userId) async {
|
Future<Profile> getProfile(String userId) async => Profile.fromJsonWithCatch({
|
||||||
final json = await _sendCommand("get_profile", {"user_id": userId});
|
...(await _sendCommand("get_profile", {"user_id": userId})),
|
||||||
return Profile.fromJsonWithCatch({...json, "id": userId});
|
"id": userId,
|
||||||
}
|
});
|
||||||
|
|
||||||
Future<void> reportEvent(ReportRequest request) =>
|
Future<void> reportEvent(ReportRequest request) =>
|
||||||
_sendCommand("report_event", request.toJson());
|
_sendCommand("report_event", request.toJson());
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ class ProfileController extends AsyncNotifier<Profile> {
|
||||||
return client.getProfile(userId);
|
return client.getProfile(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final provider = AsyncNotifierProvider.family
|
static final provider =
|
||||||
.autoDispose<ProfileController, Profile, String>(ProfileController.new);
|
AsyncNotifierProvider.family<ProfileController, Profile, String>(
|
||||||
|
ProfileController.new,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,8 @@ part "membership.g.dart";
|
||||||
@freezed
|
@freezed
|
||||||
abstract class MembershipContent extends Content with _$MembershipContent {
|
abstract class MembershipContent extends Content with _$MembershipContent {
|
||||||
MembershipContent._();
|
MembershipContent._();
|
||||||
|
|
||||||
static String? displaynameFromJson(String? displayName) =>
|
|
||||||
displayName?.isEmpty == true ? null : displayName;
|
|
||||||
|
|
||||||
factory MembershipContent({
|
factory MembershipContent({
|
||||||
@JsonKey(
|
@JsonKey(name: "displayname") required String? displayName,
|
||||||
name: "displayname",
|
|
||||||
fromJson: MembershipContent.displaynameFromJson,
|
|
||||||
)
|
|
||||||
required String? displayName,
|
|
||||||
@JsonKey(name: "membership") required MembershipStatus status,
|
@JsonKey(name: "membership") required MembershipStatus status,
|
||||||
Uri? avatarUrl,
|
Uri? avatarUrl,
|
||||||
String? reason,
|
String? reason,
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,26 @@
|
||||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:freezed_annotation/freezed_annotation.dart";
|
import "package:freezed_annotation/freezed_annotation.dart";
|
||||||
import "package:nexus/models/content/membership.dart";
|
|
||||||
part "profile.freezed.dart";
|
part "profile.freezed.dart";
|
||||||
part "profile.g.dart";
|
part "profile.g.dart";
|
||||||
|
|
||||||
@freezed
|
Object? readPronouns(Map<dynamic, dynamic> map, _) =>
|
||||||
abstract class Profile with _$Profile {
|
|
||||||
static Object? readPronouns(Map<dynamic, dynamic> map, _) =>
|
|
||||||
map["m.pronouns"] ?? map["io.fsky.nyx.pronouns"];
|
map["m.pronouns"] ?? map["io.fsky.nyx.pronouns"];
|
||||||
|
|
||||||
static Object? readTimezone(Map<dynamic, dynamic> map, _) =>
|
Object? readTimezone(Map<dynamic, dynamic> map, _) =>
|
||||||
map["m.tz"] ?? map["us.cloke.msc4175.tz"];
|
map["m.tz"] ?? map["us.cloke.msc4175.tz"];
|
||||||
|
|
||||||
|
@freezed
|
||||||
|
abstract class Profile with _$Profile {
|
||||||
const factory Profile({
|
const factory Profile({
|
||||||
required String id,
|
required String id,
|
||||||
String? parseError,
|
String? parseError,
|
||||||
Uri? avatarUrl,
|
Uri? avatarUrl,
|
||||||
|
@JsonKey(name: "displayname") String? displayName,
|
||||||
|
|
||||||
@JsonKey(
|
@JsonKey(readValue: readTimezone, name: "m.tz") String? timezone,
|
||||||
name: "displayname",
|
|
||||||
fromJson: MembershipContent.displaynameFromJson,
|
|
||||||
)
|
|
||||||
String? displayName,
|
|
||||||
|
|
||||||
@JsonKey(readValue: Profile.readTimezone, name: "m.tz") String? timezone,
|
|
||||||
|
|
||||||
@Default(IList.empty())
|
@Default(IList.empty())
|
||||||
@JsonKey(readValue: Profile.readPronouns, name: "io.fsky.nyx.pronouns")
|
@JsonKey(readValue: readPronouns, name: "io.fsky.nyx.pronouns")
|
||||||
IList<Pronoun> pronouns,
|
IList<Pronoun> pronouns,
|
||||||
}) = _Profile;
|
}) = _Profile;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue