Skip to content

Commit 5472bf6

Browse files
committed
fix: concurrent modification and last message update
The `channels.keys` iterable is now cloned before iteration to prevent concurrent modification exceptions. Additionally, the logic for updating a channel's `lastMessageAt` timestamp has been corrected to consider all messages, not just the very last one.
1 parent e196980 commit 5472bf6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/stream_chat/lib/src/client/channel.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,8 +3530,11 @@ class ChannelClientState {
35303530

35313531
// Calculate the new last message at time.
35323532
var lastMessageAt = _channelState.channel?.lastMessageAt;
3533-
final lastMessage = updatedChannelMessages.lastOrNull;
3534-
if (lastMessage != null && _shouldUpdateChannelLastMessageAt(lastMessage)) {
3533+
final lastMessage = updatedChannelMessages.lastWhereOrNull(
3534+
_shouldUpdateChannelLastMessageAt,
3535+
);
3536+
3537+
if (lastMessage != null) {
35353538
lastMessageAt = [lastMessageAt, lastMessage.createdAt].nonNulls.max;
35363539
}
35373540

packages/stream_chat/lib/src/client/client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ class ClientState {
22912291

22922292
// Iterate through all the available channels and send the event
22932293
// to be handled by the respective channel instances.
2294-
for (final cid in channels.keys) {
2294+
for (final cid in [...channels.keys]) {
22952295
final channelEvent = event.copyWith(cid: cid);
22962296
_client.handleEvent(channelEvent);
22972297
}

0 commit comments

Comments
 (0)