diff --git a/CHANGELOG.md b/CHANGELOG.md index b4141951..25c09ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v4.0.4 (Jul 3, 2023) + +### Improvements +- Fixed the bug regarding `resendFileMessage()`. +- Fixed the bug regarding connectivity events. + ## v4.0.3 (Jun 30, 2023) ### Features diff --git a/README.md b/README.md index bec5560b..c6d2b76e 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.0.3 + sendbird_chat_sdk: ^4.0.4 ``` - 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 7488617b..b8ce246d 100644 --- a/lib/src/internal/main/chat/chat.dart +++ b/lib/src/internal/main/chat/chat.dart @@ -54,7 +54,7 @@ part 'chat_notifications.dart'; part 'chat_push.dart'; part 'chat_user.dart'; -const sdkVersion = '4.0.3'; +const sdkVersion = '4.0.4'; // Internal implementation for main class. Do not directly access this class. class Chat with WidgetsBindingObserver { @@ -165,6 +165,8 @@ class Chat with WidgetsBindingObserver { } void _listenConnectivityChangedEvent() { + sbLog.d(StackTrace.current); + String flutterTest = const String.fromEnvironment('FLUTTER_TEST'); if (flutterTest.isEmpty && kIsWeb) { flutterTest = ''; @@ -176,40 +178,37 @@ class Chat with WidgetsBindingObserver { : Platform.environment['FLUTTER_TEST'] == 'true'; if (!isTest) { - Connectivity().onConnectivityChanged.asBroadcastStream( - onCancel: (controller) => { - _connectivityResult = ConnectivityResult.none, - controller.pause(), - }, - onListen: (subscription) { - subscription.onData((data) async { - switch (data) { - case ConnectivityResult.none: - sbLog.d(StackTrace.current, 'ConnectivityResult.none'); - channelCache.markAsDirtyAll(); // Check - break; - case ConnectivityResult.mobile: - case ConnectivityResult.wifi: - case ConnectivityResult.ethernet: - case ConnectivityResult.vpn: - case ConnectivityResult.other: - sbLog.d( - StackTrace.current, '${data.toString()} => reconnect()'); - if (_connectivityResult == ConnectivityResult.none && - chatContext.sessionKey != null) { - await connectionManager.reconnect(reset: true); - } - break; - case ConnectivityResult.bluetooth: - sbLog.d(StackTrace.current, 'ConnectivityResult.bluetooth'); - break; - default: - sbLog.d(StackTrace.current, data.toString()); - break; - } - _connectivityResult = data; - }); - }); + sbLog.d( + StackTrace.current, 'Connectivity().onConnectivityChanged.listen()'); + + Connectivity() + .onConnectivityChanged + .listen((ConnectivityResult result) async { + sbLog.d(StackTrace.current, result.toString()); + + switch (result) { + case ConnectivityResult.none: + channelCache.markAsDirtyAll(); // Check + await connectionManager.disconnect(logout: false); + break; + case ConnectivityResult.mobile: + case ConnectivityResult.wifi: + case ConnectivityResult.ethernet: + case ConnectivityResult.vpn: + case ConnectivityResult.other: + if (_connectivityResult == ConnectivityResult.none && + chatContext.sessionKey != null) { + await connectionManager.reconnect(reset: true); + } + break; + case ConnectivityResult.bluetooth: + break; + default: + break; + } + + _connectivityResult = result; + }); } } diff --git a/lib/src/internal/main/chat_context/chat_context.dart b/lib/src/internal/main/chat_context/chat_context.dart index ca14c256..b6c14ed5 100644 --- a/lib/src/internal/main/chat_context/chat_context.dart +++ b/lib/src/internal/main/chat_context/chat_context.dart @@ -10,7 +10,7 @@ import 'package:sendbird_chat_sdk/src/public/main/chat/sendbird_chat_options.dar import 'package:sendbird_chat_sdk/src/public/main/model/info/app_info.dart'; class ChatContext { - final String appId; + String appId; SendbirdChatOptions options; String? appVersion; String? apiToken; // for test diff --git a/lib/src/internal/main/chat_manager/collection_manager/collection_manager.dart b/lib/src/internal/main/chat_manager/collection_manager/collection_manager.dart index 227a1306..e0aea02c 100644 --- a/lib/src/internal/main/chat_manager/collection_manager/collection_manager.dart +++ b/lib/src/internal/main/chat_manager/collection_manager/collection_manager.dart @@ -46,7 +46,9 @@ class CollectionManager { //------------------------------// void onReconnectSucceeded() { sbLog.d(StackTrace.current, 'onReconnectSucceeded()'); - requestGroupChannelChangeLogs(); + if (groupChannelCollections.isNotEmpty) { + requestGroupChannelChangeLogs(); + } for (final messageCollection in messageCollections) { if (messageCollection.isInitialized) { diff --git a/lib/src/internal/main/utils/async/async_queue.dart b/lib/src/internal/main/utils/async/async_queue.dart index f37bff8e..53ea6bc9 100644 --- a/lib/src/internal/main/utils/async/async_queue.dart +++ b/lib/src/internal/main/utils/async/async_queue.dart @@ -13,7 +13,9 @@ class AsyncQueue { final Map _completerMap = {}; Operation? _currentOperation; - Future enqueue(Operation operation) { + Future enqueue(Operation operation) { + sbLog.d(StackTrace.current); + _operationQueue.add(operation); final completer = Completer(); _completerMap[operation.hashCode] = completer; @@ -26,6 +28,8 @@ class AsyncQueue { } bool cancel(int hashCode) { + sbLog.d(StackTrace.current); + final completer = _completerMap.remove(hashCode); if (completer != null && !completer.isCompleted) { if (_currentOperation?.onCancel != null) { @@ -38,8 +42,11 @@ class AsyncQueue { } Future _execute() async { + sbLog.d(StackTrace.current); + while (true) { if (_operationQueue.isEmpty) { + sbLog.d(StackTrace.current); _isScheduled = false; return; } @@ -47,22 +54,34 @@ class AsyncQueue { var task = _operationQueue.removeFirst(); _currentOperation = task; - try { - if (task is AsyncTask) { - final res = await task.func(task.arg); + if (task is AsyncTask) { + dynamic res; + try { + res = await task.func(task.arg); + } catch (e) { + sbLog.e(StackTrace.current, 'e: $e'); + _isScheduled = false; + rethrow; + } finally { _completerMap.remove(task.hashCode)?.complete(res); - } else if (task is AsyncSimpleTask) { + } + } else if (task is AsyncSimpleTask) { + try { await task.func(); + } catch (e) { + sbLog.e(StackTrace.current, 'e: $e'); + _isScheduled = false; + rethrow; + } finally { _completerMap.remove(task.hashCode)?.complete(); } - } catch (e) { - sbLog.e(StackTrace.current, 'e: $e'); - rethrow; } } } void cleanUp() { + sbLog.d(StackTrace.current); + for (final operation in _operationQueue) { cancel(operation.hashCode); } diff --git a/lib/src/public/core/message/admin_message.dart b/lib/src/public/core/message/admin_message.dart index d57e2563..8655f659 100644 --- a/lib/src/public/core/message/admin_message.dart +++ b/lib/src/public/core/message/admin_message.dart @@ -31,7 +31,6 @@ class AdminMessage extends BaseMessage { int createdAt = 0, int updatedAt = 0, int? parentMessageId, - String? parentMessageText, Map? parentMessage, ThreadInfo? threadInfo, List? metaArrays, diff --git a/lib/src/public/core/message/base_message.dart b/lib/src/public/core/message/base_message.dart index f71dbb18..b0021af6 100644 --- a/lib/src/public/core/message/base_message.dart +++ b/lib/src/public/core/message/base_message.dart @@ -282,7 +282,8 @@ abstract class BaseMessage { errorCode == SendbirdError.internalServerError || errorCode == SendbirdError.rateLimitExceeded || errorCode == SendbirdError.socketTooManyMessages || - errorCode == SendbirdError.pendingError; + errorCode == SendbirdError.pendingError || + errorCode == SendbirdError.requestFailed; if (resendableError && (sendingStatus == SendingStatus.failed || sendingStatus == SendingStatus.canceled)) { diff --git a/lib/src/public/core/message/file_message.dart b/lib/src/public/core/message/file_message.dart index 25654ff6..1463ef60 100644 --- a/lib/src/public/core/message/file_message.dart +++ b/lib/src/public/core/message/file_message.dart @@ -82,7 +82,6 @@ class FileMessage extends BaseMessage { int createdAt = 0, int updatedAt = 0, int? parentMessageId, - String? parentMessageText, ThreadInfo? threadInfo, List? metaArrays, String? customType, diff --git a/lib/src/public/core/message/user_message.dart b/lib/src/public/core/message/user_message.dart index 4f5c30df..da60e3a9 100644 --- a/lib/src/public/core/message/user_message.dart +++ b/lib/src/public/core/message/user_message.dart @@ -56,7 +56,6 @@ class UserMessage extends BaseMessage { int createdAt = 0, int updatedAt = 0, int? parentMessageId, - String? parentMessageText, ThreadInfo? threadInfo, List? metaArrays, String? customType, diff --git a/lib/src/public/main/chat/sendbird_chat.dart b/lib/src/public/main/chat/sendbird_chat.dart index 8a7bdf5a..fd947bb0 100644 --- a/lib/src/public/main/chat/sendbird_chat.dart +++ b/lib/src/public/main/chat/sendbird_chat.dart @@ -40,7 +40,7 @@ class SendbirdChat { /// Alternative push template static const String pushTemplateAlternative = 'alternative'; - static SendbirdChat _instance = SendbirdChat._internal(); + static final SendbirdChat _instance = SendbirdChat._internal(); SendbirdChat._internal() : _chat = Chat(appId: '', options: SendbirdChatOptions()); @@ -64,9 +64,8 @@ class SendbirdChat { } _instance._chat.disconnect(); - _instance = SendbirdChat._internal(); - _instance._chat = - Chat(appId: appId, options: options ?? SendbirdChatOptions()); + _instance._chat.chatContext.appId = appId; + if (options != null) _instance._chat.chatContext.options = options; } /// Current SDK version. diff --git a/pubspec.yaml b/pubspec.yaml index 81276cf9..743962db 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.0.3 +version: 4.0.4 homepage: https://sendbird.com repository: https://github.com/sendbird/sendbird-chat-sdk-flutter documentation: https://sendbird.com/docs/chat/v4/flutter/getting-started/send-first-message