Skip to content

Commit

Permalink
Merge pull request #120 from sendbird/v4.2.22
Browse files Browse the repository at this point in the history
Add 4.2.22.
  • Loading branch information
sf-tyler-jeong authored Aug 23, 2024
2 parents 57876e9 + d2e8cce commit aa39620
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 55 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v4.2.22 (Aug 23, 2024)

### Improvements
- Fixed the bugs regarding the channel change logs on multi `GroupChannelCollection`s

## v4.2.21 (Aug 16, 2024)

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Before installing Sendbird Chat SDK, you need to create a Sendbird application o

```yaml
dependencies:
sendbird_chat_sdk: ^4.2.21
sendbird_chat_sdk: ^4.2.22
```
- Run `flutter pub get` command in your project directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CChannelInfo {
Chat chat, Isar isar, ChannelInfo info) async {
final cChannelInfo = CChannelInfo.fromChannelInfo(info);

// ChangeLogInfo
// ChannelInfo
await chat.dbManager.write(() async {
await isar.cChannelInfos.clear();
await isar.cChannelInfos.put(cChannelInfo);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/internal/main/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ part 'chat_notifications.dart';
part 'chat_push.dart';
part 'chat_user.dart';

const sdkVersion = '4.2.21';
const sdkVersion = '4.2.22';

// Internal implementation for main class. Do not directly access this class.
class Chat with WidgetsBindingObserver {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/internal/main/chat/chat_caching.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extension ChatCaching on Chat {
}

Future<void> clearCachedMessages(String channelUrl) async {
await dbManager.deleteGroupChannels([channelUrl]);
await dbManager.deleteFeedChannels([channelUrl]);
await dbManager.clearMessagesInChannel(channelUrl);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2023 Sendbird, Inc. All rights reserved.

import 'dart:async';

import 'package:collection/collection.dart';
import 'package:sendbird_chat_sdk/sendbird_chat_sdk.dart';
import 'package:sendbird_chat_sdk/src/internal/db/schema/channel/meta/channel_info.dart';
Expand All @@ -25,6 +27,7 @@ class CollectionManager {
final List<GroupChannelCollection> groupChannelCollections = [];
int lastRequestTsForGroupChannelChangeLogs = 0;
String? lastRequestTokenForGroupChannelChangeLogs;
bool isDoingGroupChannelBackSync = false;

// MessageCollection
final List<BaseMessageCollection> baseMessageCollections = [];
Expand All @@ -34,7 +37,8 @@ class CollectionManager {
String? lastRequestTokenForPollChangeLogs;
int lastRequestTsForMessagesGap = 0;

bool isGroupChannelCollectionsRefreshing = false;
Completer<GroupChannelChangeLogsResult>?
groupChannelCollectionsRefreshingCompleter;
bool isBaseMessageCollectionsRefreshing = false;

CollectionManager({required Chat chat}) : _chat = chat {
Expand Down Expand Up @@ -96,19 +100,28 @@ class CollectionManager {
Future<void> refreshGroupChannelCollections() async {
sbLog.d(StackTrace.current);

isGroupChannelCollectionsRefreshing = true;

List<Future<dynamic>> futures = [];

if (groupChannelCollections.isNotEmpty) {
futures.add(_requestGroupChannelChangeLogs());
}
GroupChannelChangeLogsResult result;

if (groupChannelCollectionsRefreshingCompleter == null) {
groupChannelCollectionsRefreshingCompleter =
Completer<GroupChannelChangeLogsResult>();
result = await _requestGroupChannelChangeLogs();
groupChannelCollectionsRefreshingCompleter?.complete(result);
groupChannelCollectionsRefreshingCompleter = null;
} else {
result = await groupChannelCollectionsRefreshingCompleter!.future;
}

if (futures.isNotEmpty) {
await Future.wait(futures);
if (result.updatedChannels.isNotEmpty ||
result.deletedChannelUrls.isNotEmpty) {
sendEventsToGroupChannelCollectionList(
eventSource: CollectionEventSource.channelChangeLogs,
updatedChannels: result.updatedChannels,
deletedChannelUrls: result.deletedChannelUrls,
);
}
}

isGroupChannelCollectionsRefreshing = false;
}

Future<void> _refreshBaseMessageCollections() async {
Expand Down Expand Up @@ -844,3 +857,13 @@ class InternalFeedChannelHandlerForCollectionManager
// }
// }
}

class GroupChannelChangeLogsResult {
final List<GroupChannel> updatedChannels;
final List<String> deletedChannelUrls;

GroupChannelChangeLogsResult({
required this.updatedChannels,
required this.deletedChannelUrls,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ extension GroupChannelCollectionManager on CollectionManager {
//------------------------------//
// GroupChannel changeLogs
//------------------------------//
Future<void> _requestGroupChannelChangeLogs({
CollectionEventSource? eventSource,
}) async {
sbLog.d(StackTrace.current, '${eventSource?.toString()}');
Future<GroupChannelChangeLogsResult> _requestGroupChannelChangeLogs() async {
sbLog.d(StackTrace.current);

final params = GroupChannelChangeLogsParams();
final List<GroupChannel> updatedChannels = [];
Expand Down Expand Up @@ -102,8 +100,7 @@ extension GroupChannelCollectionManager on CollectionManager {
}
//- [DBManager]

sendEventsToGroupChannelCollectionList(
eventSource: eventSource ?? CollectionEventSource.channelChangeLogs,
return GroupChannelChangeLogsResult(
updatedChannels: updatedChannels,
deletedChannelUrls: deletedChannelUrls,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ extension MessageCollectionManager on CollectionManager {
}
//- [DBManager]

sendEventsToMessageCollection(
messageCollection: messageCollection,
baseChannel: channel,
eventSource: CollectionEventSource.messageChangeLogs,
sendingStatus: SendingStatus.succeeded,
updatedMessages: updatedMessages,
deletedMessageIds: deletedMessageIds,
);
if (updatedMessages.isNotEmpty || deletedMessageIds.isNotEmpty) {
sendEventsToMessageCollection(
messageCollection: messageCollection,
baseChannel: channel,
eventSource: CollectionEventSource.messageChangeLogs,
sendingStatus: SendingStatus.succeeded,
updatedMessages: updatedMessages,
deletedMessageIds: deletedMessageIds,
);
}
}

//------------------------------//
Expand Down Expand Up @@ -271,14 +273,16 @@ extension MessageCollectionManager on CollectionManager {
}
//- [DBManager]

sendEventsToMessageCollection(
messageCollection: messageCollection,
baseChannel: groupChannel,
eventSource: CollectionEventSource.pollChangeLogs,
sendingStatus: SendingStatus.succeeded,
updatedMessages: updatedMessages,
deletedMessageIds: deletedMessageIds,
);
if (updatedMessages.isNotEmpty || deletedMessageIds.isNotEmpty) {
sendEventsToMessageCollection(
messageCollection: messageCollection,
baseChannel: groupChannel,
eventSource: CollectionEventSource.pollChangeLogs,
sendingStatus: SendingStatus.succeeded,
updatedMessages: updatedMessages,
deletedMessageIds: deletedMessageIds,
);
}
}

//------------------------------//
Expand Down
16 changes: 9 additions & 7 deletions lib/src/internal/main/chat_manager/db_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class DBManager {
}

Future<void> write(Function writeFunc, {bool force = false}) async {
if (isEnabled() || force) {
if (isEnabled() || (_isInitialized && force)) {
try {
await _db.write(writeFunc);
} catch (e) {
Expand Down Expand Up @@ -310,9 +310,6 @@ class DBManager {
// ChannelAccess
await _db.deleteChannelAccess(channelUrl);

// ChannelInfo
await _db.deleteChannelInfo();

// Messages
await deleteMessagesInDeletedChannel(channelUrl);

Expand All @@ -322,6 +319,14 @@ class DBManager {
}
}

Future<void> clearMessagesInChannel(String channelUrl) async {
// Messages
await deleteMessagesInDeletedChannel(channelUrl);

// MessageChangeLogInfo
await _db.deleteMessageChangeLogInfo(channelUrl);
}

// FeedChannel
Future<void> upsertFeedChannels(List<FeedChannel> channels) async {
if (isEnabled()) {
Expand Down Expand Up @@ -356,9 +361,6 @@ class DBManager {
// ChannelAccess
await _db.deleteChannelAccess(channelUrl);

// ChannelInfo
await _db.deleteChannelInfo();

// Messages
await deleteMessagesInDeletedChannel(channelUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GroupChannelCollection {
//+ [DBManager]
int _fetchedCount = 0;
int _offset = 0;
bool _areGroupChannelChangeLogsFetchedOnce = false;

//- [DBManager]

Expand All @@ -51,9 +52,15 @@ class GroupChannelCollection {

//+ [DBManager]
if (_chat.dbManager.isEnabled()) {
runZonedGuarded(() {
_doBackSync(); // Do not await for performance
}, (error, stack) {});
if (_chat.collectionManager.isDoingGroupChannelBackSync == false) {
_chat.collectionManager.isDoingGroupChannelBackSync = true;
runZonedGuarded(() async {
await _doBackSync(); // Do not await for performance
_chat.collectionManager.isDoingGroupChannelBackSync = false;
}, (error, stack) {
_chat.collectionManager.isDoingGroupChannelBackSync = false;
});
}
}
//- [DBManager]

Expand Down Expand Up @@ -124,6 +131,7 @@ class GroupChannelCollection {
if (info != null && info.isChannelBackSyncCompleted) {
final channels = await _chat.dbManager
.getGroupChannels(query: _query, offset: _offset);

if (channels.isNotEmpty) {
localChannels.addAll(channels);
}
Expand All @@ -144,15 +152,17 @@ class GroupChannelCollection {
);
}

// Check
runZonedGuarded(() {
_chat.collectionManager
.refreshGroupChannelCollections(); // Do not await for performance
}, (error, stack) {});
if (_areGroupChannelChangeLogsFetchedOnce == false) {
_areGroupChannelChangeLogsFetchedOnce = true;
// Check
runZonedGuarded(() {
_chat.collectionManager
.refreshGroupChannelCollections(); // Do not await for performance
}, (error, stack) {});
}
}
}
//- [DBManager]

try {
if (localChannels.isNotEmpty) {
//+ [DBManager]
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.2.21
version: 4.2.22
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
Expand Down

0 comments on commit aa39620

Please sign in to comment.