Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Upcoming

🐞 Fixed

- Fixed failing to parse `null` values in `UpsertPushPreferencesResponse.userPreferences` JSON.

## 9.25.0

- Minor bug fixes and improvements
Expand Down
18 changes: 16 additions & 2 deletions packages/stream_chat/lib/src/core/api/responses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,11 @@ class GetUnreadCountResponse extends _BaseResponse {
/// Model response for [StreamChatClient.setPushPreferences] api call
@JsonSerializable(createToJson: false)
class UpsertPushPreferencesResponse extends _BaseResponse {
/// Mapping of user IDs to their push preferences
@JsonKey(defaultValue: {})
/// Mapping of user IDs to their push preferences.
///
/// Users whose user-global preferences were not touched by the upsert call
/// (the server returns `null` for them) are omitted from this map.
@JsonKey(fromJson: _userPreferencesFromJson)
late Map<String, PushPreference> userPreferences;

/// Mapping of user IDs to their channel-specific push preferences
Expand All @@ -846,3 +849,14 @@ class UpsertPushPreferencesResponse extends _BaseResponse {
static UpsertPushPreferencesResponse fromJson(Map<String, dynamic> json) =>
_$UpsertPushPreferencesResponseFromJson(json);
}

Map<String, PushPreference> _userPreferencesFromJson(
Map<String, dynamic>? json,
) {
if (json == null) return {};
return {
for (final MapEntry(:key, :value) in json.entries)
if (value != null)
key: PushPreference.fromJson(value as Map<String, dynamic>),
};
}
8 changes: 2 additions & 6 deletions packages/stream_chat/lib/src/core/api/responses.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/stream_chat/test/src/core/api/responses_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4457,7 +4457,8 @@ void main() {
},
"user2": {
"chat_level": "none"
}
},
"user3": null
},
"user_channel_preferences": {
"user1": {
Expand All @@ -4482,7 +4483,10 @@ void main() {
);

expect(response.userPreferences, isA<Map<String, PushPreference>>());
// user3 had a `null` value in the response (no user-global prefs were
// touched by the upsert) — should be filtered outs.
expect(response.userPreferences, hasLength(2));
expect(response.userPreferences.containsKey('user3'), isFalse);

// Test user1 preferences
final user1Prefs = response.userPreferences['user1']!;
Expand Down
Loading