Remove flutter chat #26
4 changed files with 23 additions and 10 deletions
fix error handling in models
commit
14ec487bbe
|
|
@ -230,7 +230,7 @@ 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.fromJson({
|
||||
Future<Profile> getProfile(String userId) async => Profile.fromJsonWithCatch({
|
||||
...(await _sendCommand("get_profile", {"user_id": userId})),
|
||||
"id": userId,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import "package:collection/collection.dart";
|
||||
import "package:nexus/models/content/avatar.dart";
|
||||
import "package:nexus/models/content/canonical_alias.dart";
|
||||
import "package:nexus/models/content/create.dart";
|
||||
|
|
@ -15,16 +14,21 @@ import "package:nexus/models/content/server_acl.dart";
|
|||
import "package:nexus/models/content/topic.dart";
|
||||
|
||||
class Content {
|
||||
Content();
|
||||
final String? parseError;
|
||||
Content({this.parseError});
|
||||
|
||||
factory Content.fromJson(Map<String, dynamic> json) => Content();
|
||||
Map<String, dynamic> toJson() => {};
|
||||
|
||||
static Content fromEventJson(Map<String, dynamic> eventJson, String type) =>
|
||||
(EventType.values
|
||||
.firstWhereOrNull((eventType) => eventType.type == type)
|
||||
?.contentFromJson ??
|
||||
Content.fromJson)(eventJson);
|
||||
static Content fromEventJson(Map<String, dynamic> eventJson, String type) {
|
||||
try {
|
||||
return EventType.values
|
||||
.firstWhere((eventType) => eventType.type == type)
|
||||
.contentFromJson(eventJson);
|
||||
} catch (error) {
|
||||
return Content(parseError: error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ part "event.g.dart";
|
|||
|
||||
Profile? pmpFromJson(Map<String, dynamic>? json) {
|
||||
final pmp = json?["content"]?["com.beeper.per_message_profile"];
|
||||
return pmp == null ? null : Profile.fromJson(pmp);
|
||||
return pmp == null ? null : Profile.fromJsonWithCatch(pmp);
|
||||
}
|
||||
|
||||
@freezed
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ Object? readTimezone(Map<dynamic, dynamic> map, _) =>
|
|||
abstract class Profile with _$Profile {
|
||||
const factory Profile({
|
||||
required String id,
|
||||
String? parseError,
|
||||
Uri? avatarUrl,
|
||||
@JsonKey(name: "displayname") String? displayName,
|
||||
|
||||
|
|
@ -23,8 +24,16 @@ abstract class Profile with _$Profile {
|
|||
IList<Pronoun> pronouns,
|
||||
}) = _Profile;
|
||||
|
||||
factory Profile.fromJson(Map<String, Object?> json) =>
|
||||
factory Profile.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProfileFromJson(json);
|
||||
|
||||
factory Profile.fromJsonWithCatch(Map<String, dynamic> json) {
|
||||
try {
|
||||
return Profile.fromJson(json);
|
||||
} catch (error) {
|
||||
return Profile(id: json["id"], parseError: error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue