diff --git a/CHANGELOG.md b/CHANGELOG.md index 535d428..40ea259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,16 @@ +## v4.2.11 (Apr 18, 2024) + +### Improvements +- Fixed the bug that there are duplicate channels in `GroupChannelCollection` +- Added default mimeType in `FileMessageCreateParams` + ## v4.2.10 (Apr 9, 2024) ### Features - Added the privacy manifest file for iOS ### Improvements -- Fixed the bug that there are duplicated channels in `GroupChannelCollection` +- Fixed the bug that there are duplicate channels in `GroupChannelCollection` ## v4.2.9 (Apr 3, 2024) diff --git a/README.md b/README.md index 12da381..4929164 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Before installing Sendbird Chat SDK, you need to create a Sendbird application o ```yaml dependencies: - sendbird_chat_sdk: ^4.2.10 + sendbird_chat_sdk: ^4.2.11 ``` - 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 cac13a5..6e28be6 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.10'; +const sdkVersion = '4.2.11'; // Internal implementation for main class. Do not directly access this class. class Chat with WidgetsBindingObserver { diff --git a/lib/src/internal/main/chat_manager/collection_manager/group_channel_collection_manager.dart b/lib/src/internal/main/chat_manager/collection_manager/group_channel_collection_manager.dart index 0f7f073..b935088 100644 --- a/lib/src/internal/main/chat_manager/collection_manager/group_channel_collection_manager.dart +++ b/lib/src/internal/main/chat_manager/collection_manager/group_channel_collection_manager.dart @@ -170,15 +170,7 @@ extension GroupChannelCollectionManager on CollectionManager { if (addedChannels != null && addedChannels.isNotEmpty) { for (final addedChannel in addedChannels) { - bool isChannelExists = false; - for (final channel in channelCollection.channelList) { - if (channel.channelUrl == addedChannel.channelUrl) { - isChannelExists = true; - break; - } - } - - if (!isChannelExists) { + if (!_isChannelExists(channelCollection, addedChannel.channelUrl)) { if (await channelCollection.canAddChannel( eventSource, addedChannel)) { addedChannelsForEvent.add(addedChannel); @@ -187,7 +179,7 @@ extension GroupChannelCollectionManager on CollectionManager { } if (addedChannelsForEvent.isNotEmpty) { - channelCollection.channelList.addAll(addedChannelsForEvent); + _addChannel(channelCollection, addedChannelsForEvent); } } @@ -220,15 +212,7 @@ extension GroupChannelCollectionManager on CollectionManager { if (eventSource == CollectionEventSource.channelChangeLogs && !isUpdatedChannelInChannelList) { - bool isChannelExists = false; - for (final channel in channelCollection.channelList) { - if (channel.channelUrl == updatedChannel.channelUrl) { - isChannelExists = true; - break; - } - } - - if (!isChannelExists) { + if (!_isChannelExists(channelCollection, updatedChannel.channelUrl)) { if (await channelCollection.canAddChannel( eventSource, updatedChannel)) { addedChannelsForEvent.add(updatedChannel); @@ -238,7 +222,7 @@ extension GroupChannelCollectionManager on CollectionManager { } if (addedChannelsForEvent.isNotEmpty) { - channelCollection.channelList.addAll(addedChannelsForEvent); + _addChannel(channelCollection, addedChannelsForEvent); } } @@ -282,4 +266,36 @@ extension GroupChannelCollectionManager on CollectionManager { } } } + + bool _isChannelExists(GroupChannelCollection collection, String channelUrl) { + for (final channel in collection.channelList) { + if (channel.channelUrl == channelUrl) { + return true; + } + } + return false; + } + + void _addChannel( + GroupChannelCollection channelCollection, + List addedChannels, + ) { + final channelList = channelCollection.channelList; + for (final addedChannel in addedChannels) { + bool isUpdated = false; + + for (int index = 0; index < channelList.length; index++) { + final channel = channelList[index]; + if (addedChannel.channelUrl == channel.channelUrl) { + channelList[index] = addedChannel; + isUpdated = true; + break; + } + } + + if (isUpdated == false) { + channelList.add(addedChannel); + } + } + } } diff --git a/lib/src/public/main/collection/group_channel_collection/group_channel_collection.dart b/lib/src/public/main/collection/group_channel_collection/group_channel_collection.dart index f94ed6e..d53bf13 100644 --- a/lib/src/public/main/collection/group_channel_collection/group_channel_collection.dart +++ b/lib/src/public/main/collection/group_channel_collection/group_channel_collection.dart @@ -239,15 +239,15 @@ class GroupChannelCollection { GroupChannel addedChannel, { bool checkToUpdateChannel = false, }) async { + if (_isLoadedOnce == false) { + return false; + } + if (eventSource == CollectionEventSource.channelCacheLoadMore || eventSource == CollectionEventSource.channelLoadMore) { return true; } - if (_isLoadedOnce == false) { - return false; - } - if (channelList.isNotEmpty && hasMore) { final a = channelList.last; final b = addedChannel; diff --git a/lib/src/public/main/params/message/file_message_create_params.dart b/lib/src/public/main/params/message/file_message_create_params.dart index 9fe4868..dd28a2d 100644 --- a/lib/src/public/main/params/message/file_message_create_params.dart +++ b/lib/src/public/main/params/message/file_message_create_params.dart @@ -63,13 +63,13 @@ class FileMessageCreateParams extends BaseMessageCreateParams { break; } } else { - fileMimeType = lookupMimeType(file.path)!; + fileMimeType = lookupMimeType(file.path); } fileInfo = FileInfo.fromFile( fileName: fileName ?? 'file', file: file, - mimeType: fileMimeType, + mimeType: fileMimeType ?? 'application/octet-stream', ); } @@ -99,7 +99,8 @@ class FileMessageCreateParams extends BaseMessageCreateParams { pushNotificationDeliveryOption: pushNotificationDeliveryOption, isPinnedMessage: isPinnedMessage, ) { - String? fileMimeType = lookupMimeType('', headerBytes: fileBytes); + final fileMimeType = lookupMimeType('', headerBytes: fileBytes); + if (fileMimeType != null) { mimeType = fileMimeType; } else if (mimeType == null) { @@ -109,7 +110,7 @@ class FileMessageCreateParams extends BaseMessageCreateParams { fileInfo = FileInfo.fromFileBytes( fileBytes: fileBytes, fileName: fileName ?? 'file', - mimeType: mimeType, + mimeType: mimeType ?? 'application/octet-stream', ); } @@ -130,8 +131,8 @@ class FileMessageCreateParams extends BaseMessageCreateParams { PushNotificationDeliveryOption.normal, bool isPinnedMessage = false, }) : fileInfo = FileInfo.fromFileUrl( - fileName: fileName ?? 'image', - mimeType: mimeType ?? 'image/jpeg', + fileName: fileName ?? 'file', + mimeType: mimeType ?? 'application/octet-stream', fileUrl: fileUrl, fileSize: fileSize, ), diff --git a/pubspec.yaml b/pubspec.yaml index 8b07108..d07871b 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.10 +version: 4.2.11 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