Remove flutter chat #26

Manually merged
Henry-Hiles merged 108 commits from remove-flutter-chat into main 2026-05-22 15:26:28 -04:00
4 changed files with 23 additions and 10 deletions
Showing only changes of commit 14ec487bbe - Show all commits

fix error handling in models

Henry Hiles 2026-05-18 10:12:53 -04:00
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -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,
});

View file

@ -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 {

View file

@ -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

View file

@ -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