Skip to content

Commit

Permalink
Merge pull request #124 from sendbird/v4.2.24
Browse files Browse the repository at this point in the history
Add 4.2.24.
  • Loading branch information
sf-tyler-jeong authored Oct 8, 2024
2 parents bc9631c + 15194ac commit 1727cfb
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v4.2.24 (Oct 8, 2024)

### Improvements
- Fixed bugs regarding the events for `hide()` in `GroupChannel`
- Fixed the message deletion bug in db regarding `resetMyHistory()`

## v4.2.23 (Sep 13, 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.23
sendbird_chat_sdk: ^4.2.24
```
- Run `flutter pub get` command in your project directory.
Expand Down
7 changes: 6 additions & 1 deletion lib/src/internal/db/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,12 @@ class DB {
int timestamp,
) async {
return await CChannelMessage.getStartingPointMessages(
_chat, _isar, channelType, channelUrl, timestamp);
_chat,
_isar,
channelType,
channelUrl,
timestamp,
);
}

Future<void> deleteChannelMessage(String rootId) async {
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.23';
const sdkVersion = '4.2.24';

// Internal implementation for main class. Do not directly access this class.
class Chat with WidgetsBindingObserver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class InternalGroupChannelHandlerForCollectionManager
void onChannelHidden(GroupChannel channel) {
_collectionManager.sendEventsToGroupChannelCollectionList(
eventSource: CollectionEventSource.eventChannelHidden,
deletedChannelUrls: [channel.channelUrl],
updatedChannels: [channel],
);
}

Expand Down
66 changes: 63 additions & 3 deletions lib/src/internal/main/chat_manager/db_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,65 @@ class DBManager {
required int timestamp,
required MessageListParams params,
required bool isPrevious,
int? messageOffsetTimestamp,
}) async {
if (isEnabled()) {
return await _db.getMessages(
List<RootMessage> messages = await _db.getMessages(
channelType,
channelUrl,
sendingStatus,
timestamp,
params,
isPrevious,
);

if (channelType == ChannelType.group && messageOffsetTimestamp != null) {
return _applyMessageOffsetTimestamp(
channelType: channelType,
channelUrl: channelUrl,
messages: messages,
messageOffsetTimestamp: messageOffsetTimestamp,
);
} else {
return messages;
}
}
return [];
}

Future<List<RootMessage>> _applyMessageOffsetTimestamp({
required ChannelType channelType,
required String channelUrl,
required List<RootMessage> messages,
required int messageOffsetTimestamp,
}) async {
List<RootMessage> resultMessages = [];
List<String> deletedMessageIds = [];

for (final message in messages) {
if (message.createdAt < messageOffsetTimestamp) {
deletedMessageIds.add(message.rootId);
} else {
resultMessages.add(message);
}
}

if (deletedMessageIds.isNotEmpty) {
await _db.deleteMessagesInChunk(
channelUrl: channelUrl,
rootIds: deletedMessageIds,
);

for (final messageId in deletedMessageIds) {
await _db.deleteUserMessage(messageId);
await _db.deleteFileMessage(messageId);
await _db.deleteAdminMessage(messageId);
}
}

return resultMessages;
}

Future<List<BaseMessage>> getPendingMessages({
required ChannelType channelType,
required String channelUrl,
Expand Down Expand Up @@ -533,10 +578,25 @@ class DBManager {
required ChannelType channelType,
required String channelUrl,
required int timestamp,
int? messageOffsetTimestamp,
}) async {
if (isEnabled()) {
return await _db.getStartingPointMessages(
channelType, channelUrl, timestamp);
List<RootMessage> messages = await _db.getStartingPointMessages(
channelType,
channelUrl,
timestamp,
);

if (channelType == ChannelType.group && messageOffsetTimestamp != null) {
return _applyMessageOffsetTimestamp(
channelType: channelType,
channelUrl: channelUrl,
messages: messages,
messageOffsetTimestamp: messageOffsetTimestamp,
);
} else {
return messages;
}
}
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ class GroupChannelCollection {
}
}

if (checkToUpdateChannel == false) {
if (checkToUpdateChannel) {
if (eventSource == CollectionEventSource.eventChannelHidden) {
return _canAddChannel(query: _query, channel: addedChannel);
}
} else {
//+ DBManager
if (_chat.dbManager.isEnabled()) {
if (await _chat.dbManager.canAddChannel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,18 @@ abstract class BaseMessageCollection {
final localInitializeParams = MessageListParams()
..copyWith(_initializeParams);

final int? messageOffsetTimestamp = (_channel is GroupChannel)
? (_channel as GroupChannel).messageOffsetTimestamp
: null;

final localPreviousMessages = await _chat.dbManager.getMessages(
channelType: _channel.channelType,
channelUrl: _channel.channelUrl,
sendingStatus: SendingStatus.succeeded,
timestamp: _startingPoint,
params: localInitializeParams..inclusive = false,
isPrevious: true,
messageOffsetTimestamp: messageOffsetTimestamp,
);

List<RootMessage> localStartingPointMessages = [];
Expand All @@ -234,6 +239,7 @@ abstract class BaseMessageCollection {
channelType: _channel.channelType,
channelUrl: _channel.channelUrl,
timestamp: _startingPoint,
messageOffsetTimestamp: messageOffsetTimestamp,
);
localStartingPointMessages.addAll(messages);
}
Expand All @@ -245,6 +251,7 @@ abstract class BaseMessageCollection {
timestamp: _startingPoint,
params: localInitializeParams..inclusive = false,
isPrevious: false,
messageOffsetTimestamp: messageOffsetTimestamp,
);

if (_initializeParams.reverse) {
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.23
version: 4.2.24
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 1727cfb

Please sign in to comment.