Skip to content

Commit 57876e9

Browse files
Merge pull request #117 from sendbird/v4.2.21
Add 4.2.21.
2 parents 00f5e8d + d03c20e commit 57876e9

File tree

11 files changed

+415
-57
lines changed

11 files changed

+415
-57
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v4.2.21 (Aug 16, 2024)
2+
3+
### Improvements
4+
- Fixed the bug when upserting a parent message regarding the error on isar
5+
- Fixed the bug regarding the channel filtering when local caching is not used
6+
- Fixed the bugs regarding the thumbnail caching for UIKit
7+
- Fixed a bug regarding reactions on offline mode
8+
19
## v4.2.20 (Jul 11, 2024)
210

311
### Improvements

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Before installing Sendbird Chat SDK, you need to create a Sendbird application o
5050

5151
```yaml
5252
dependencies:
53-
sendbird_chat_sdk: ^4.2.20
53+
sendbird_chat_sdk: ^4.2.21
5454
```
5555
5656
- Run `flutter pub get` command in your project directory.

lib/src/internal/db/schema/message/c_base_message.dart

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,35 @@ class CBaseMessage extends CRootMessage {
156156
static Future<void> upsert(Chat chat, Isar isar, BaseMessage message) async {
157157
// BaseMessage
158158
await chat.dbManager.write(() async {
159-
if (message is UserMessage) {
160-
await isar.cUserMessages.put(CUserMessage.fromUserMessage(message));
161-
} else if (message is FileMessage) {
162-
await isar.cFileMessages.put(CFileMessage.fromFileMessage(message));
163-
} else if (message is AdminMessage) {
164-
await isar.cAdminMessages.put(CAdminMessage.fromAdminMessage(message));
165-
}
159+
await _upsert(chat, isar, message);
160+
});
161+
}
166162

167-
// parentMessage
168-
if (message.parentMessage != null) {
169-
await CBaseMessage.upsert(chat, isar, message.parentMessage!);
170-
}
163+
static Future<void> _upsert(Chat chat, Isar isar, BaseMessage message) async {
164+
if (message is UserMessage) {
165+
await isar.cUserMessages.put(CUserMessage.fromUserMessage(message));
166+
} else if (message is FileMessage) {
167+
await isar.cFileMessages.put(CFileMessage.fromFileMessage(message));
168+
} else if (message is AdminMessage) {
169+
await isar.cAdminMessages.put(CAdminMessage.fromAdminMessage(message));
170+
}
171171

172-
// threadInfo
173-
if (message.threadInfo != null) {
174-
for (final user in message.threadInfo!.mostRepliesUsers) {
175-
await isar.cUsers.put(CUser.fromUser(user));
176-
}
177-
}
172+
// parentMessage
173+
if (message.parentMessage != null) {
174+
await _upsert(chat, isar, message.parentMessage!);
175+
}
178176

179-
// sender
180-
if (message.sender != null) {
181-
await isar.cUsers.put(CUser.fromUser(message.sender!));
177+
// threadInfo
178+
if (message.threadInfo != null) {
179+
for (final user in message.threadInfo!.mostRepliesUsers) {
180+
await isar.cUsers.put(CUser.fromUser(user));
182181
}
183-
});
182+
}
183+
184+
// sender
185+
if (message.sender != null) {
186+
await isar.cUsers.put(CUser.fromUser(message.sender!));
187+
}
184188
}
185189
}
186190

lib/src/internal/main/chat/chat.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ part 'chat_notifications.dart';
6262
part 'chat_push.dart';
6363
part 'chat_user.dart';
6464

65-
const sdkVersion = '4.2.20';
65+
const sdkVersion = '4.2.21';
6666

6767
// Internal implementation for main class. Do not directly access this class.
6868
class Chat with WidgetsBindingObserver {
@@ -290,7 +290,7 @@ class Chat with WidgetsBindingObserver {
290290
}
291291

292292
AppInfo? getAppInfo() {
293-
sbLog.i(StackTrace.current);
293+
// sbLog.i(StackTrace.current);
294294
return chatContext.appInfo;
295295
}
296296

lib/src/internal/main/chat_manager/db_manager.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ class DBManager {
148148
await _db.write(writeFunc);
149149
} catch (e) {
150150
sbLog.e(StackTrace.current, e.toString());
151+
if (_chat.isTest) {
152+
rethrow;
153+
}
151154

152155
_chat.chatContext.options.useCollectionCaching = false;
153156
await clear();

lib/src/public/core/channel/base_channel/base_channel_message.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ extension BaseChannelMessage on BaseChannel {
7171
) as UserMessage;
7272

7373
if (this is GroupChannel) {
74-
pendingUserMessage.messageId =
75-
resendMessageId ?? DateTime.now().millisecondsSinceEpoch;
74+
pendingUserMessage.messageId = resendMessageId ?? 0;
7675

7776
for (final messageCollection
7877
in chat.collectionManager.baseMessageCollections) {
@@ -103,7 +102,8 @@ extension BaseChannelMessage on BaseChannel {
103102
final error = ConnectionRequiredException();
104103
pendingUserMessage
105104
..errorCode = error.code
106-
..sendingStatus = SendingStatus.failed;
105+
..sendingStatus = SendingStatus.failed
106+
..messageId = resendMessageId ?? DateTime.now().millisecondsSinceEpoch;
107107

108108
if (this is GroupChannel) {
109109
for (final messageCollection
@@ -160,7 +160,9 @@ extension BaseChannelMessage on BaseChannel {
160160
if (e is SendbirdException) {
161161
pendingUserMessage
162162
..errorCode = e.code ?? SendbirdError.unknownError
163-
..sendingStatus = SendingStatus.failed;
163+
..sendingStatus = SendingStatus.failed
164+
..messageId =
165+
resendMessageId ?? DateTime.now().millisecondsSinceEpoch;
164166

165167
if (this is GroupChannel) {
166168
for (final messageCollection
@@ -276,8 +278,7 @@ extension BaseChannelMessage on BaseChannel {
276278
pendingFileMessage.messageCreateParams = params;
277279

278280
if (this is GroupChannel) {
279-
pendingFileMessage.messageId =
280-
resendMessageId ?? DateTime.now().millisecondsSinceEpoch;
281+
pendingFileMessage.messageId = resendMessageId ?? 0;
281282

282283
for (final messageCollection
283284
in chat.collectionManager.baseMessageCollections) {
@@ -321,7 +322,10 @@ extension BaseChannelMessage on BaseChannel {
321322
.timeout(
322323
Duration(seconds: chat.chatContext.options.fileTransferTimeout),
323324
onTimeout: () {
324-
pendingFileMessage.sendingStatus = SendingStatus.failed;
325+
pendingFileMessage
326+
..sendingStatus = SendingStatus.failed
327+
..messageId =
328+
resendMessageId ?? DateTime.now().millisecondsSinceEpoch;
325329

326330
if (this is GroupChannel) {
327331
for (final messageCollection
@@ -377,7 +381,9 @@ extension BaseChannelMessage on BaseChannel {
377381
final error = ConnectionRequiredException();
378382
messageBeforeSent
379383
..errorCode = error.code
380-
..sendingStatus = SendingStatus.failed;
384+
..sendingStatus = SendingStatus.failed
385+
..messageId =
386+
resendMessageId ?? DateTime.now().millisecondsSinceEpoch;
381387

382388
if (this is GroupChannel) {
383389
for (final messageCollection
@@ -411,7 +417,8 @@ extension BaseChannelMessage on BaseChannel {
411417
result.payload,
412418
channelType: channelType,
413419
commandType: result.cmd,
414-
) as FileMessage;
420+
) as FileMessage
421+
..file = params.fileInfo.file; // Check
415422

416423
chat.collectionManager.onMessageSentByMe(
417424
channel: this,
@@ -482,7 +489,9 @@ extension BaseChannelMessage on BaseChannel {
482489
if (e is SendbirdException) {
483490
pendingFileMessage
484491
..errorCode = e.code ?? SendbirdError.unknownError
485-
..sendingStatus = SendingStatus.failed;
492+
..sendingStatus = SendingStatus.failed
493+
..messageId =
494+
resendMessageId ?? DateTime.now().millisecondsSinceEpoch;
486495

487496
if (this is GroupChannel) {
488497
for (final messageCollection

lib/src/public/core/message/base_message.dart

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -249,34 +249,39 @@ class BaseMessage extends RootMessage {
249249
bool applyReactionEvent(ReactionEvent event) {
250250
sbLog.i(StackTrace.current, 'event.key: ${event.key}');
251251

252-
if (event.messageId != messageId) {
253-
return false;
254-
}
252+
try {
253+
if (event.messageId != messageId) {
254+
return false;
255+
}
255256

256-
final keys = reactions?.map((e) => e.key).toList();
257-
final existIndex = keys?.indexWhere((e) => e == event.key) ?? -1;
258-
if (existIndex != -1) {
259-
final reaction = reactions?[existIndex];
260-
if (reaction != null && reaction.merge(event)) {
261-
if (event.operation == ReactionEventAction.delete &&
262-
reaction.userIds.isEmpty) {
263-
reactions?.removeWhere((e) => e.key == event.key);
257+
final keys = reactions?.map((e) => e.key).toList();
258+
final existIndex = keys?.indexWhere((e) => e == event.key) ?? -1;
259+
if (existIndex != -1) {
260+
final reaction = reactions?[existIndex];
261+
if (reaction != null && reaction.merge(event)) {
262+
if (event.operation == ReactionEventAction.delete &&
263+
reaction.userIds.isEmpty) {
264+
reactions?.removeWhere((e) => e.key == event.key);
265+
}
266+
return true;
267+
} else {
268+
return false;
264269
}
270+
} else if (event.operation == ReactionEventAction.add) {
271+
final reaction = Reaction(
272+
key: event.key,
273+
userIds: [event.userId],
274+
updatedAt: event.updatedAt,
275+
);
276+
reactions?.add(reaction);
265277
return true;
266278
} else {
267279
return false;
268280
}
269-
} else if (event.operation == ReactionEventAction.add) {
270-
final reaction = Reaction(
271-
key: event.key,
272-
userIds: [event.userId],
273-
updatedAt: event.updatedAt,
274-
);
275-
reactions?.add(reaction);
276-
return true;
277-
} else {
278-
return false;
281+
} catch (e) {
282+
sbLog.e(StackTrace.current, 'e: $e');
279283
}
284+
return false;
280285
}
281286

282287
/// Retrieves a [BaseMessage] object with a specified message ID.

lib/src/public/main/chat/sendbird_chat.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class SendbirdChat {
129129

130130
/// Returns current application information with [AppInfo].
131131
static AppInfo? getAppInfo() {
132-
sbLog.i(StackTrace.current);
132+
// sbLog.i(StackTrace.current);
133133
return _instance._chat.getAppInfo();
134134
}
135135

0 commit comments

Comments
 (0)