Skip to content

Commit

Permalink
Add 4.0.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
sf-tyler-jeong committed Jul 3, 2023
1 parent ccc12b8 commit 9169d8d
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 55 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
69 changes: 34 additions & 35 deletions lib/src/internal/main/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = '';
Expand All @@ -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;
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/internal/main/chat_context/chat_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 27 additions & 8 deletions lib/src/internal/main/utils/async/async_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class AsyncQueue<T> {
final Map<int, Completer> _completerMap = {};
Operation? _currentOperation;

Future enqueue(Operation operation) {
Future<void> enqueue(Operation operation) {
sbLog.d(StackTrace.current);

_operationQueue.add(operation);
final completer = Completer();
_completerMap[operation.hashCode] = completer;
Expand All @@ -26,6 +28,8 @@ class AsyncQueue<T> {
}

bool cancel(int hashCode) {
sbLog.d(StackTrace.current);

final completer = _completerMap.remove(hashCode);
if (completer != null && !completer.isCompleted) {
if (_currentOperation?.onCancel != null) {
Expand All @@ -38,31 +42,46 @@ class AsyncQueue<T> {
}

Future _execute() async {
sbLog.d(StackTrace.current);

while (true) {
if (_operationQueue.isEmpty) {
sbLog.d(StackTrace.current);
_isScheduled = false;
return;
}

var task = _operationQueue.removeFirst();
_currentOperation = task;

try {
if (task is AsyncTask<T>) {
final res = await task.func(task.arg);
if (task is AsyncTask<T>) {
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);
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/public/core/message/admin_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class AdminMessage extends BaseMessage {
int createdAt = 0,
int updatedAt = 0,
int? parentMessageId,
String? parentMessageText,
Map<String, dynamic>? parentMessage,
ThreadInfo? threadInfo,
List<MessageMetaArray>? metaArrays,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/public/core/message/base_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
1 change: 0 additions & 1 deletion lib/src/public/core/message/file_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class FileMessage extends BaseMessage {
int createdAt = 0,
int updatedAt = 0,
int? parentMessageId,
String? parentMessageText,
ThreadInfo? threadInfo,
List<MessageMetaArray>? metaArrays,
String? customType,
Expand Down
1 change: 0 additions & 1 deletion lib/src/public/core/message/user_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class UserMessage extends BaseMessage {
int createdAt = 0,
int updatedAt = 0,
int? parentMessageId,
String? parentMessageText,
ThreadInfo? threadInfo,
List<MessageMetaArray>? metaArrays,
String? customType,
Expand Down
7 changes: 3 additions & 4 deletions lib/src/public/main/chat/sendbird_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9169d8d

Please sign in to comment.