hardened API decoding against server fields the models did not expect
The Talk room list crashed for a new account because the server omits
lastMessage for rooms without a visible message and the model required it.
Beyond that single field, a review of the Talk models against the OpenAPI
spec of the installed version (23.0.8) found the same crash class in several
places: closed enums over open server values (inCall bitmask, rich-object
types, actor and message types), a deleted parent sent as {id, deleted},
and the autocomplete status arriving as an object.
- json_serializable `checked: true`: decode errors now name class and field
- lists (rooms, messages, participants, autocomplete) decode per entry;
a malformed entry is skipped and reported via ClientErrorReporter
- unknownEnumValue fallbacks for all response enums of Talk and breakers
- lastMessage nullable; inCall as bitmask; deleted parent placeholder;
autocomplete status object/string; fixed shareWithDisplayNameUnique key
- GetRoomParams no longer sends null query parameters
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HrepDTL4qDe35TuS29sLW3
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../api_response.dart';
|
||||
import '../../../json_lenient.dart';
|
||||
|
||||
part 'get_participants_response.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetParticipantsResponse extends ApiResponse {
|
||||
@JsonKey(fromJson: _participantsFromJson)
|
||||
Set<GetParticipantsResponseObject> data;
|
||||
|
||||
GetParticipantsResponse(this.data);
|
||||
@@ -15,15 +17,25 @@ class GetParticipantsResponse extends ApiResponse {
|
||||
Map<String, dynamic> toJson() => _$GetParticipantsResponseToJson(this);
|
||||
}
|
||||
|
||||
Set<GetParticipantsResponseObject> _participantsFromJson(Object? raw) =>
|
||||
decodeSetLenient(
|
||||
raw,
|
||||
GetParticipantsResponseObject.fromJson,
|
||||
what: 'participant',
|
||||
);
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetParticipantsResponseObject {
|
||||
int attendeeId;
|
||||
String actorType;
|
||||
String actorId;
|
||||
String displayName;
|
||||
@JsonKey(unknownEnumValue: GetParticipantsResponseObjectParticipantType.user)
|
||||
GetParticipantsResponseObjectParticipantType participantType;
|
||||
int lastPing;
|
||||
GetParticipantsResponseObjectParticipantsInCallFlags inCall;
|
||||
|
||||
/// Bitmask: 1 = in call, 2 = with audio, 4 = with video, 8 = via phone.
|
||||
int inCall;
|
||||
int permissions;
|
||||
int attendeePermissions;
|
||||
String? sessionId;
|
||||
@@ -54,6 +66,11 @@ class GetParticipantsResponseObject {
|
||||
factory GetParticipantsResponseObject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetParticipantsResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetParticipantsResponseObjectToJson(this);
|
||||
|
||||
bool get isInCall => inCall & 1 != 0;
|
||||
bool get inCallWithAudio => inCall & 2 != 0;
|
||||
bool get inCallWithVideo => inCall & 4 != 0;
|
||||
bool get inCallViaPhone => inCall & 8 != 0;
|
||||
}
|
||||
|
||||
enum GetParticipantsResponseObjectParticipantType {
|
||||
@@ -73,16 +90,3 @@ enum GetParticipantsResponseObjectParticipantType {
|
||||
const GetParticipantsResponseObjectParticipantType(this.prettyName);
|
||||
final String prettyName;
|
||||
}
|
||||
|
||||
enum GetParticipantsResponseObjectParticipantsInCallFlags {
|
||||
@JsonValue(0)
|
||||
disconnected,
|
||||
@JsonValue(1)
|
||||
inCall,
|
||||
@JsonValue(2)
|
||||
providesAudio,
|
||||
@JsonValue(3)
|
||||
providesVideo,
|
||||
@JsonValue(4)
|
||||
usesSipDialIn,
|
||||
}
|
||||
|
||||
@@ -8,19 +8,18 @@ part of 'get_participants_response.dart';
|
||||
|
||||
GetParticipantsResponse _$GetParticipantsResponseFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
GetParticipantsResponse(
|
||||
(json['data'] as List<dynamic>)
|
||||
.map(
|
||||
(e) => GetParticipantsResponseObject.fromJson(
|
||||
e as Map<String, dynamic>,
|
||||
),
|
||||
)
|
||||
.toSet(),
|
||||
)
|
||||
..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
);
|
||||
) => $checkedCreate('GetParticipantsResponse', json, ($checkedConvert) {
|
||||
final val = GetParticipantsResponse(
|
||||
$checkedConvert('data', (v) => _participantsFromJson(v)),
|
||||
);
|
||||
$checkedConvert(
|
||||
'headers',
|
||||
(v) => val.headers = (v as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
),
|
||||
);
|
||||
return val;
|
||||
});
|
||||
|
||||
Map<String, dynamic> _$GetParticipantsResponseToJson(
|
||||
GetParticipantsResponse instance,
|
||||
@@ -31,29 +30,36 @@ Map<String, dynamic> _$GetParticipantsResponseToJson(
|
||||
|
||||
GetParticipantsResponseObject _$GetParticipantsResponseObjectFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => GetParticipantsResponseObject(
|
||||
(json['attendeeId'] as num).toInt(),
|
||||
json['actorType'] as String,
|
||||
json['actorId'] as String,
|
||||
json['displayName'] as String,
|
||||
$enumDecode(
|
||||
_$GetParticipantsResponseObjectParticipantTypeEnumMap,
|
||||
json['participantType'],
|
||||
),
|
||||
(json['lastPing'] as num).toInt(),
|
||||
$enumDecode(
|
||||
_$GetParticipantsResponseObjectParticipantsInCallFlagsEnumMap,
|
||||
json['inCall'],
|
||||
),
|
||||
(json['permissions'] as num).toInt(),
|
||||
(json['attendeePermissions'] as num).toInt(),
|
||||
json['sessionId'] as String?,
|
||||
(json['sessionIds'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
json['status'] as String?,
|
||||
json['statusIcon'] as String?,
|
||||
json['statusMessage'] as String?,
|
||||
json['roomToken'] as String?,
|
||||
);
|
||||
) => $checkedCreate('GetParticipantsResponseObject', json, ($checkedConvert) {
|
||||
final val = GetParticipantsResponseObject(
|
||||
$checkedConvert('attendeeId', (v) => (v as num).toInt()),
|
||||
$checkedConvert('actorType', (v) => v as String),
|
||||
$checkedConvert('actorId', (v) => v as String),
|
||||
$checkedConvert('displayName', (v) => v as String),
|
||||
$checkedConvert(
|
||||
'participantType',
|
||||
(v) => $enumDecode(
|
||||
_$GetParticipantsResponseObjectParticipantTypeEnumMap,
|
||||
v,
|
||||
unknownValue: GetParticipantsResponseObjectParticipantType.user,
|
||||
),
|
||||
),
|
||||
$checkedConvert('lastPing', (v) => (v as num).toInt()),
|
||||
$checkedConvert('inCall', (v) => (v as num).toInt()),
|
||||
$checkedConvert('permissions', (v) => (v as num).toInt()),
|
||||
$checkedConvert('attendeePermissions', (v) => (v as num).toInt()),
|
||||
$checkedConvert('sessionId', (v) => v as String?),
|
||||
$checkedConvert(
|
||||
'sessionIds',
|
||||
(v) => (v as List<dynamic>).map((e) => e as String).toList(),
|
||||
),
|
||||
$checkedConvert('status', (v) => v as String?),
|
||||
$checkedConvert('statusIcon', (v) => v as String?),
|
||||
$checkedConvert('statusMessage', (v) => v as String?),
|
||||
$checkedConvert('roomToken', (v) => v as String?),
|
||||
);
|
||||
return val;
|
||||
});
|
||||
|
||||
Map<String, dynamic> _$GetParticipantsResponseObjectToJson(
|
||||
GetParticipantsResponseObject instance,
|
||||
@@ -66,9 +72,7 @@ Map<String, dynamic> _$GetParticipantsResponseObjectToJson(
|
||||
_$GetParticipantsResponseObjectParticipantTypeEnumMap[instance
|
||||
.participantType]!,
|
||||
'lastPing': instance.lastPing,
|
||||
'inCall':
|
||||
_$GetParticipantsResponseObjectParticipantsInCallFlagsEnumMap[instance
|
||||
.inCall]!,
|
||||
'inCall': instance.inCall,
|
||||
'permissions': instance.permissions,
|
||||
'attendeePermissions': instance.attendeePermissions,
|
||||
'sessionId': instance.sessionId,
|
||||
@@ -87,11 +91,3 @@ const _$GetParticipantsResponseObjectParticipantTypeEnumMap = {
|
||||
GetParticipantsResponseObjectParticipantType.userFollowingPublicLink: 5,
|
||||
GetParticipantsResponseObjectParticipantType.guestWithModeratorPermissions: 6,
|
||||
};
|
||||
|
||||
const _$GetParticipantsResponseObjectParticipantsInCallFlagsEnumMap = {
|
||||
GetParticipantsResponseObjectParticipantsInCallFlags.disconnected: 0,
|
||||
GetParticipantsResponseObjectParticipantsInCallFlags.inCall: 1,
|
||||
GetParticipantsResponseObjectParticipantsInCallFlags.providesAudio: 2,
|
||||
GetParticipantsResponseObjectParticipantsInCallFlags.providesVideo: 3,
|
||||
GetParticipantsResponseObjectParticipantsInCallFlags.usesSipDialIn: 4,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user