Skip to content

Commit 2d2e2e5

Browse files
fix: make channel.visible respect archived and pinned channels (#2633)
### 🎯 Goal References: GetStream/stream-chat-react-native#2925
1 parent a428dc9 commit 2d2e2e5

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/components/ChannelList/hooks/useChannelListShape.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useRef } from 'react';
44
import { Channel, Event, ExtendableGenerics } from 'stream-chat';
5-
import uniqBy from 'lodash.uniqby';
65

76
import {
87
extractSortValue,
@@ -68,7 +67,9 @@ type HandleChannelHiddenParameters<SCG extends ExtendableGenerics> = BaseParamet
6867
RepeatedParameters<SCG>;
6968

7069
type HandleChannelVisibleParameters<SCG extends ExtendableGenerics> =
71-
BaseParameters<SCG> & RepeatedParameters<SCG>;
70+
BaseParameters<SCG> &
71+
RepeatedParameters<SCG> &
72+
Required<Pick<ChannelListProps<SCG>, 'sort' | 'filters'>>;
7273

7374
type HandleChannelTruncatedParameters<SCG extends ExtendableGenerics> =
7475
BaseParameters<SCG> & RepeatedParameters<SCG>;
@@ -194,7 +195,6 @@ export const useChannelListShapeDefaults = <SCG extends ExtendableGenerics>() =>
194195
moveChannelUpwards({
195196
channels,
196197
channelToMove: channel,
197-
channelToMoveIndexWithinChannels: -1,
198198
sort,
199199
}),
200200
);
@@ -239,7 +239,6 @@ export const useChannelListShapeDefaults = <SCG extends ExtendableGenerics>() =>
239239
moveChannelUpwards({
240240
channels,
241241
channelToMove: channel,
242-
channelToMoveIndexWithinChannels: -1,
243242
sort,
244243
}),
245244
);
@@ -353,20 +352,36 @@ export const useChannelListShapeDefaults = <SCG extends ExtendableGenerics>() =>
353352
async ({
354353
customHandler,
355354
event,
355+
filters,
356356
setChannels,
357+
sort,
357358
}: HandleChannelVisibleParameters<SCG>) => {
358359
if (typeof customHandler === 'function') {
359360
return customHandler(setChannels, event);
360361
}
361362

362-
if (event.type && event.channel_type && event.channel_id) {
363-
const channel = await getChannel({
364-
client,
365-
id: event.channel_id,
366-
type: event.channel_type,
367-
});
368-
setChannels((channels) => uniqBy([channel, ...channels], 'cid'));
363+
if (!event.channel) {
364+
return;
365+
}
366+
367+
const channel = await getChannel({
368+
client,
369+
id: event.channel.id,
370+
type: event.channel.type,
371+
});
372+
373+
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
374+
if (isChannelArchived(channel) && considerArchivedChannels && !filters.archived) {
375+
return;
369376
}
377+
378+
setChannels((channels) =>
379+
moveChannelUpwards({
380+
channels,
381+
channelToMove: channel,
382+
sort,
383+
}),
384+
);
370385
},
371386
[client],
372387
);
@@ -586,7 +601,9 @@ export const usePrepareShapeHandlers = <SCG extends ExtendableGenerics>({
586601
defaults.handleChannelVisible({
587602
customHandler: onChannelVisible,
588603
event,
604+
filters,
589605
setChannels,
606+
sort,
590607
});
591608
break;
592609
case 'channel.truncated':

0 commit comments

Comments
 (0)