Skip to content

Commit b2d906c

Browse files
committed
fix: [Flutter Web] TypeError JSArray
1 parent 89fd302 commit b2d906c

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,11 @@ class Channel {
566566
// update or remove attachment from message.
567567
final List<Attachment> newAttachments;
568568
if (remove) {
569-
newAttachments = [...message!.attachments]..removeAt(index);
569+
newAttachments = <Attachment>[...message!.attachments]
570+
..removeAt(index);
570571
} else {
571-
newAttachments = [...message!.attachments]..[index] = attachment;
572+
newAttachments = <Attachment>[...message!.attachments]..[index] =
573+
attachment;
572574
}
573575

574576
final updatedMessage = message!.copyWith(attachments: newAttachments);
@@ -1307,7 +1309,9 @@ class Channel {
13071309
final now = DateTime.now();
13081310
final user = _client.state.currentUser;
13091311

1310-
var latestReactions = [...message.latestReactions ?? <Reaction>[]];
1312+
var latestReactions = <Reaction>[
1313+
...message.latestReactions ?? <Reaction>[]
1314+
];
13111315
if (enforceUnique) {
13121316
latestReactions.removeWhere((it) => it.userId == user!.id);
13131317
}
@@ -1382,15 +1386,17 @@ class Channel {
13821386
reactionScores.update(type, (value) => value - 1);
13831387
}
13841388

1385-
final latestReactions = [...?message.latestReactions]..removeWhere((r) =>
1386-
r.userId == reaction.userId &&
1387-
r.type == reaction.type &&
1388-
r.messageId == reaction.messageId);
1389+
final latestReactions = <Reaction>[...?message.latestReactions]
1390+
..removeWhere((r) =>
1391+
r.userId == reaction.userId &&
1392+
r.type == reaction.type &&
1393+
r.messageId == reaction.messageId);
13891394

1390-
final ownReactions = [...?message.ownReactions]..removeWhere((r) =>
1391-
r.userId == reaction.userId &&
1392-
r.type == reaction.type &&
1393-
r.messageId == reaction.messageId);
1395+
final ownReactions = <Reaction>[...?message.ownReactions]..removeWhere(
1396+
(r) =>
1397+
r.userId == reaction.userId &&
1398+
r.type == reaction.type &&
1399+
r.messageId == reaction.messageId);
13941400

13951401
final newMessage = message.copyWith(
13961402
reactionCounts: reactionCounts..removeWhere((_, value) => value == 0),
@@ -2235,7 +2241,7 @@ class ChannelClientState {
22352241
final user = event.user;
22362242
if (user == null) return;
22372243

2238-
final existingMembers = [...?channelState.members];
2244+
final existingMembers = <Member>[...?channelState.members];
22392245
final existingMembership = channelState.membership;
22402246

22412247
// Return if the user is not a existing member of the channel.
@@ -2371,7 +2377,7 @@ class ChannelClientState {
23712377
}
23722378

23732379
void _updateMember(Member member) {
2374-
final currentMembers = [...members];
2380+
final currentMembers = <Member>[...members];
23752381
final memberIndex = currentMembers.indexWhere(
23762382
(m) => m.userId == member.userId,
23772383
);
@@ -2405,8 +2411,10 @@ class ChannelClientState {
24052411

24062412
/// Retry failed message.
24072413
Future<void> retryFailedMessages() async {
2408-
final failedMessages = [...messages, ...threads.values.expand((v) => v)]
2409-
.where((it) => it.state.isFailed);
2414+
final failedMessages = <Message>[
2415+
...messages,
2416+
...threads.values.expand((v) => v)
2417+
].where((it) => it.state.isFailed);
24102418
_retryQueue.add(failedMessages);
24112419
}
24122420

@@ -2787,7 +2795,7 @@ class ChannelClientState {
27872795
if (message.parentId == null || message.showInChannel == true) {
27882796
// Create a new list of messages to avoid modifying the original
27892797
// list directly.
2790-
var newMessages = [...messages];
2798+
var newMessages = <Message>[...messages];
27912799
final oldIndex = newMessages.indexWhere((m) => m.id == message.id);
27922800

27932801
if (oldIndex != -1) {
@@ -2869,7 +2877,7 @@ class ChannelClientState {
28692877
/// Updates the list of pinned messages based on the current message's
28702878
/// pinned status.
28712879
List<Message> _updatePinnedMessages(Message message) {
2872-
final newPinnedMessages = [...pinnedMessages];
2880+
final newPinnedMessages = <Message>[...pinnedMessages];
28732881
final oldPinnedIndex =
28742882
newPinnedMessages.indexWhere((m) => m.id == message.id);
28752883

@@ -2914,10 +2922,11 @@ class ChannelClientState {
29142922
}
29152923

29162924
// Remove regular message, thread message shown in channel
2917-
var updatedMessages = [...messages]..removeWhere((e) => e.id == message.id);
2925+
var updatedMessages = <Message>[...messages]
2926+
..removeWhere((e) => e.id == message.id);
29182927

29192928
// Remove quoted message reference from every message if available.
2920-
updatedMessages = [...updatedMessages].map((it) {
2929+
updatedMessages = <Message>[...updatedMessages].map((it) {
29212930
// Early return if the message doesn't have a quoted message.
29222931
if (it.quotedMessageId != message.id) return it;
29232932

0 commit comments

Comments
 (0)