diff --git a/CHANGELOG.md b/CHANGELOG.md index b79604b..f6849ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,12 @@ +## v4.2.2 (Fed 15, 2024) + +### Improvements +- Fixed the bug where `votedPollOptionIds` in `Poll` is always empty + ## v4.2.1 (Fed 5, 2024) ### Improvements -- Fixed the bug where `getCachedMetaData()` in `BaseChannel` is not being updated when deleting metadata. +- Fixed the bug where `getCachedMetaData()` in `BaseChannel` is not being updated when deleting metadata ## v4.2.0 (Jan 31, 2024) diff --git a/README.md b/README.md index 7fcb4be..4def82b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Before installing Sendbird Chat SDK, you need to create a Sendbird application o ```yaml dependencies: - sendbird_chat_sdk: ^4.2.1 + sendbird_chat_sdk: ^4.2.2 ``` - Run `flutter pub get` command in your project directory. diff --git a/lib/src/internal/main/chat/chat.dart b/lib/src/internal/main/chat/chat.dart index 295e4a3..4d81016 100644 --- a/lib/src/internal/main/chat/chat.dart +++ b/lib/src/internal/main/chat/chat.dart @@ -60,7 +60,7 @@ part 'chat_notifications.dart'; part 'chat_push.dart'; part 'chat_user.dart'; -const sdkVersion = '4.2.1'; +const sdkVersion = '4.2.2'; // Internal implementation for main class. Do not directly access this class. class Chat with WidgetsBindingObserver { diff --git a/lib/src/public/main/model/poll/poll.dart b/lib/src/public/main/model/poll/poll.dart index 820ae48..9b5be34 100644 --- a/lib/src/public/main/model/poll/poll.dart +++ b/lib/src/public/main/model/poll/poll.dart @@ -58,7 +58,7 @@ class Poll { /// Contains optionIds which the current user voted on. /// If the current user has not voted, this list will be empty. - @JsonKey(defaultValue: []) + @JsonKey(name: 'voted_option_ids', defaultValue: []) List? votedPollOptionIds; Poll({ @@ -149,9 +149,12 @@ class Poll { if (event.json['poll']['allow_multiple_votes'] != null) { allowMultipleVotes = event.json['poll']['allow_multiple_votes']; } - if (event.json['poll']['voted_poll_option_ids'] != null) { - votedPollOptionIds = event.json['poll']['voted_poll_option_ids']; - } + + // voted_option_ids is not coming from PEDI, so validate it by SDK itself + final optionIds = options.map((option) => option.id).toSet(); + final validVotedOptionIds = + votedPollOptionIds?.toSet().intersection(optionIds).toList(); + votedPollOptionIds = validVotedOptionIds; return true; } else { @@ -175,6 +178,13 @@ class Poll { options.firstWhere((e) => (e.id == optionId)).voteCount = voteCount; } } + + if (event.json['voted_option_ids'] != null) { + votedPollOptionIds = (event.json['voted_option_ids'] as List?) + ?.map((e) => e as int) + .toList() ?? + []; + } } else { return false; } diff --git a/lib/src/public/main/model/poll/poll.g.dart b/lib/src/public/main/model/poll/poll.g.dart index 2a356d7..cf6ce76 100644 --- a/lib/src/public/main/model/poll/poll.g.dart +++ b/lib/src/public/main/model/poll/poll.g.dart @@ -25,7 +25,7 @@ Poll _$PollFromJson(Map json) => Poll( createdBy: json['created_by'] as String?, allowUserSuggestion: json['allow_user_suggestion'] as bool? ?? false, allowMultipleVotes: json['allow_multiple_votes'] as bool? ?? false, - votedPollOptionIds: (json['voted_poll_option_ids'] as List?) + votedPollOptionIds: (json['voted_option_ids'] as List?) ?.map((e) => e as int) .toList() ?? [], @@ -45,7 +45,7 @@ Map _$PollToJson(Poll instance) => { 'created_by': instance.createdBy, 'allow_user_suggestion': instance.allowUserSuggestion, 'allow_multiple_votes': instance.allowMultipleVotes, - 'voted_poll_option_ids': instance.votedPollOptionIds, + 'voted_option_ids': instance.votedPollOptionIds, }; const _$PollStatusEnumMap = { diff --git a/pubspec.yaml b/pubspec.yaml index 5ef911f..e41258c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: sendbird_chat_sdk description: With Sendbird Chat for Flutter, you can easily build an in-app chat with all the essential messaging features. -version: 4.2.1 +version: 4.2.2 homepage: https://sendbird.com repository: https://github.com/sendbird/sendbird-chat-sdk-flutter documentation: https://sendbird.com/docs/chat/sdk/v4/flutter/getting-started/send-first-message