From 31e8c2e1e05f52781f3369996be6456b7e868f2e Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Sun, 5 Jul 2026 06:23:41 +0200 Subject: [PATCH] fix(plex): coerce PlexHomeUser fields against account-API drift Same clients.plex.tv surface that broke in #1488: /home/users powers first sign-in and profile setup, so a drifted scalar shape would kill the whole fetch. Coerce strings, bools, and ints tolerantly instead of hard-casting. --- lib/models/plex/plex_home_user.dart | 29 ++++++++++++++++++--------- lib/models/plex/plex_home_user.g.dart | 26 ++++++++++++------------ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/lib/models/plex/plex_home_user.dart b/lib/models/plex/plex_home_user.dart index 00fa5e69..89d7cc14 100644 --- a/lib/models/plex/plex_home_user.dart +++ b/lib/models/plex/plex_home_user.dart @@ -1,30 +1,39 @@ import 'package:json_annotation/json_annotation.dart'; +import '../../utils/json_utils.dart'; + part 'plex_home_user.g.dart'; +/// Parsed from the clients.plex.tv `/api/v2/home/users` account API — the +/// same drift-prone surface as PlexUserProfile (#1488), so scalar fields +/// coerce tolerantly instead of hard-casting. @JsonSerializable() class PlexHomeUser { - @JsonKey(defaultValue: 0) + @JsonKey(fromJson: _intOr0) final int id; - @JsonKey(defaultValue: '') + @JsonKey(readValue: readStringField, defaultValue: '') final String uuid; - @JsonKey(defaultValue: 'Unknown') + @JsonKey(readValue: readStringField, defaultValue: 'Unknown') final String title; + @JsonKey(readValue: readStringField) final String? username; + @JsonKey(readValue: readStringField) final String? email; + @JsonKey(readValue: readStringField) final String? friendlyName; - @JsonKey(defaultValue: '') + @JsonKey(readValue: readStringField, defaultValue: '') final String thumb; - @JsonKey(defaultValue: false) + @JsonKey(fromJson: flexibleBool) final bool hasPassword; - @JsonKey(defaultValue: false) + @JsonKey(fromJson: flexibleBool) final bool restricted; + @JsonKey(fromJson: flexibleInt) final int? updatedAt; - @JsonKey(defaultValue: false) + @JsonKey(fromJson: flexibleBool) final bool admin; - @JsonKey(defaultValue: false) + @JsonKey(fromJson: flexibleBool) final bool guest; - @JsonKey(defaultValue: false) + @JsonKey(fromJson: flexibleBool) final bool protected; PlexHomeUser({ @@ -54,3 +63,5 @@ class PlexHomeUser { bool get isGuestUser => guest; bool get requiresPassword => protected; } + +int _intOr0(Object? v) => flexibleInt(v) ?? 0; diff --git a/lib/models/plex/plex_home_user.g.dart b/lib/models/plex/plex_home_user.g.dart index 56d5e7d6..94a011ac 100644 --- a/lib/models/plex/plex_home_user.g.dart +++ b/lib/models/plex/plex_home_user.g.dart @@ -7,19 +7,19 @@ part of 'plex_home_user.dart'; // ************************************************************************** PlexHomeUser _$PlexHomeUserFromJson(Map json) => PlexHomeUser( - id: (json['id'] as num?)?.toInt() ?? 0, - uuid: json['uuid'] as String? ?? '', - title: json['title'] as String? ?? 'Unknown', - username: json['username'] as String?, - email: json['email'] as String?, - friendlyName: json['friendlyName'] as String?, - thumb: json['thumb'] as String? ?? '', - hasPassword: json['hasPassword'] as bool? ?? false, - restricted: json['restricted'] as bool? ?? false, - updatedAt: (json['updatedAt'] as num?)?.toInt(), - admin: json['admin'] as bool? ?? false, - guest: json['guest'] as bool? ?? false, - protected: json['protected'] as bool? ?? false, + id: _intOr0(json['id']), + uuid: readStringField(json, 'uuid') as String? ?? '', + title: readStringField(json, 'title') as String? ?? 'Unknown', + username: readStringField(json, 'username') as String?, + email: readStringField(json, 'email') as String?, + friendlyName: readStringField(json, 'friendlyName') as String?, + thumb: readStringField(json, 'thumb') as String? ?? '', + hasPassword: flexibleBool(json['hasPassword']), + restricted: flexibleBool(json['restricted']), + updatedAt: flexibleInt(json['updatedAt']), + admin: flexibleBool(json['admin']), + guest: flexibleBool(json['guest']), + protected: flexibleBool(json['protected']), ); Map _$PlexHomeUserToJson(PlexHomeUser instance) =>