Skip to content

Commit 8e853fc

Browse files
committed
fix: duplicate filtering logic for custom channel queries
1 parent 466b82c commit 8e853fc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

projects/stream-chat-angular/src/lib/channel.service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,11 +1557,15 @@ export class ChannelService<
15571557

15581558
if (this.customChannelQuery) {
15591559
const result = await this.customChannelQuery(queryType);
1560-
const currentChannels = this.channels;
1561-
const filteredChannels = result.channels.filter(
1562-
(channel, index) =>
1563-
!currentChannels.slice(0, index).find((c) => c.cid === channel.cid),
1564-
);
1560+
const cids = new Set<string>();
1561+
const filteredChannels = result.channels.filter((c) => {
1562+
if (cids.has(c.cid)) {
1563+
return false;
1564+
} else {
1565+
cids.add(c.cid);
1566+
return true;
1567+
}
1568+
});
15651569
this.channelManager.setChannels(filteredChannels);
15661570
this.hasMoreChannelsSubject.next(result.hasMorePage);
15671571
} else {

0 commit comments

Comments
 (0)