|
2 | 2 |
|
3 | 3 | import { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useRef } from 'react'; |
4 | 4 | import { Channel, Event, ExtendableGenerics } from 'stream-chat'; |
5 | | -import uniqBy from 'lodash.uniqby'; |
6 | 5 |
|
7 | 6 | import { |
8 | 7 | extractSortValue, |
@@ -68,7 +67,9 @@ type HandleChannelHiddenParameters<SCG extends ExtendableGenerics> = BaseParamet |
68 | 67 | RepeatedParameters<SCG>; |
69 | 68 |
|
70 | 69 | type HandleChannelVisibleParameters<SCG extends ExtendableGenerics> = |
71 | | - BaseParameters<SCG> & RepeatedParameters<SCG>; |
| 70 | + BaseParameters<SCG> & |
| 71 | + RepeatedParameters<SCG> & |
| 72 | + Required<Pick<ChannelListProps<SCG>, 'sort' | 'filters'>>; |
72 | 73 |
|
73 | 74 | type HandleChannelTruncatedParameters<SCG extends ExtendableGenerics> = |
74 | 75 | BaseParameters<SCG> & RepeatedParameters<SCG>; |
@@ -194,7 +195,6 @@ export const useChannelListShapeDefaults = <SCG extends ExtendableGenerics>() => |
194 | 195 | moveChannelUpwards({ |
195 | 196 | channels, |
196 | 197 | channelToMove: channel, |
197 | | - channelToMoveIndexWithinChannels: -1, |
198 | 198 | sort, |
199 | 199 | }), |
200 | 200 | ); |
@@ -239,7 +239,6 @@ export const useChannelListShapeDefaults = <SCG extends ExtendableGenerics>() => |
239 | 239 | moveChannelUpwards({ |
240 | 240 | channels, |
241 | 241 | channelToMove: channel, |
242 | | - channelToMoveIndexWithinChannels: -1, |
243 | 242 | sort, |
244 | 243 | }), |
245 | 244 | ); |
@@ -353,20 +352,36 @@ export const useChannelListShapeDefaults = <SCG extends ExtendableGenerics>() => |
353 | 352 | async ({ |
354 | 353 | customHandler, |
355 | 354 | event, |
| 355 | + filters, |
356 | 356 | setChannels, |
| 357 | + sort, |
357 | 358 | }: HandleChannelVisibleParameters<SCG>) => { |
358 | 359 | if (typeof customHandler === 'function') { |
359 | 360 | return customHandler(setChannels, event); |
360 | 361 | } |
361 | 362 |
|
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; |
369 | 376 | } |
| 377 | + |
| 378 | + setChannels((channels) => |
| 379 | + moveChannelUpwards({ |
| 380 | + channels, |
| 381 | + channelToMove: channel, |
| 382 | + sort, |
| 383 | + }), |
| 384 | + ); |
370 | 385 | }, |
371 | 386 | [client], |
372 | 387 | ); |
@@ -586,7 +601,9 @@ export const usePrepareShapeHandlers = <SCG extends ExtendableGenerics>({ |
586 | 601 | defaults.handleChannelVisible({ |
587 | 602 | customHandler: onChannelVisible, |
588 | 603 | event, |
| 604 | + filters, |
589 | 605 | setChannels, |
| 606 | + sort, |
590 | 607 | }); |
591 | 608 | break; |
592 | 609 | case 'channel.truncated': |
|
0 commit comments