11import type { StreamChat } from './client' ;
2- import type {
3- DefaultGenerics ,
4- ExtendableGenerics ,
5- Event ,
6- ChannelOptions ,
7- ChannelStateOptions ,
8- ChannelFilters ,
9- ChannelSort ,
10- } from './types' ;
2+ import type { Event , ChannelOptions , ChannelStateOptions , ChannelFilters , ChannelSort } from './types' ;
113import { StateStore , ValueOrPatch , isPatch } from './store' ;
124import { Channel } from './channel' ;
135import {
@@ -22,41 +14,35 @@ import {
2214 uniqBy ,
2315} from './utils' ;
2416
25- export type ChannelManagerPagination < SCG extends ExtendableGenerics = DefaultGenerics > = {
26- filters : ChannelFilters < SCG > ;
17+ export type ChannelManagerPagination = {
18+ filters : ChannelFilters ;
2719 hasNext : boolean ;
2820 isLoading : boolean ;
2921 isLoadingNext : boolean ;
3022 options : ChannelOptions ;
31- sort : ChannelSort < SCG > ;
23+ sort : ChannelSort ;
3224} ;
3325
34- export type ChannelManagerState < SCG extends ExtendableGenerics = DefaultGenerics > = {
35- channels : Channel < SCG > [ ] ;
26+ export type ChannelManagerState = {
27+ channels : Channel [ ] ;
3628 /**
3729 * This value will become true the first time queryChannels is successfully executed and
3830 * will remain false otherwise. It's used as a control property regarding whether the list
3931 * has been initialized yet (i.e a query has already been done at least once) or not. We do
4032 * this to prevent state.channels from being forced to be nullable.
4133 */
4234 initialized : boolean ;
43- pagination : ChannelManagerPagination < SCG > ;
35+ pagination : ChannelManagerPagination ;
4436} ;
4537
46- export type ChannelSetterParameterType < SCG extends ExtendableGenerics = DefaultGenerics > = ValueOrPatch <
47- ChannelManagerState < SCG > [ 'channels' ]
48- > ;
49- export type ChannelSetterType < SCG extends ExtendableGenerics = DefaultGenerics > = (
50- arg : ChannelSetterParameterType < SCG > ,
51- ) => void ;
38+ export type ChannelSetterParameterType = ValueOrPatch < ChannelManagerState [ 'channels' ] > ;
39+ export type ChannelSetterType = ( arg : ChannelSetterParameterType ) => void ;
5240
5341export type GenericEventHandlerType < T extends unknown [ ] > = (
5442 ...args : T
5543) => void | ( ( ) => void ) | ( ( ...args : T ) => Promise < void > ) | Promise < void > ;
56- export type EventHandlerType < SCG extends ExtendableGenerics = DefaultGenerics > = GenericEventHandlerType < [ Event < SCG > ] > ;
57- export type EventHandlerOverrideType < SCG extends ExtendableGenerics = DefaultGenerics > = GenericEventHandlerType <
58- [ ChannelSetterType < SCG > , Event < SCG > ]
59- > ;
44+ export type EventHandlerType = GenericEventHandlerType < [ Event ] > ;
45+ export type EventHandlerOverrideType = GenericEventHandlerType < [ ChannelSetterType , Event ] > ;
6046
6147export type ChannelManagerEventTypes =
6248 | 'notification.added_to_channel'
@@ -80,8 +66,8 @@ export type ChannelManagerEventHandlerNames =
8066 | 'notificationNewMessageHandler'
8167 | 'notificationRemovedFromChannelHandler' ;
8268
83- export type ChannelManagerEventHandlerOverrides < SCG extends ExtendableGenerics = DefaultGenerics > = Partial <
84- Record < ChannelManagerEventHandlerNames , EventHandlerOverrideType < SCG > >
69+ export type ChannelManagerEventHandlerOverrides = Partial <
70+ Record < ChannelManagerEventHandlerNames , EventHandlerOverrideType >
8571> ;
8672
8773export const channelManagerEventToHandlerMapping : {
@@ -144,12 +130,12 @@ export const DEFAULT_CHANNEL_MANAGER_PAGINATION_OPTIONS = {
144130 *
145131 * @internal
146132 */
147- export class ChannelManager < SCG extends ExtendableGenerics = DefaultGenerics > {
148- public readonly state : StateStore < ChannelManagerState < SCG > > ;
149- private client : StreamChat < SCG > ;
133+ export class ChannelManager {
134+ public readonly state : StateStore < ChannelManagerState > ;
135+ private client : StreamChat ;
150136 private unsubscribeFunctions : Set < ( ) => void > = new Set ( ) ;
151- private eventHandlers : Map < string , EventHandlerType < SCG > > = new Map ( ) ;
152- private eventHandlerOverrides : Map < string , EventHandlerOverrideType < SCG > > = new Map ( ) ;
137+ private eventHandlers : Map < string , EventHandlerType > = new Map ( ) ;
138+ private eventHandlerOverrides : Map < string , EventHandlerOverrideType > = new Map ( ) ;
153139 private options : ChannelManagerOptions = { } ;
154140 private stateOptions : ChannelStateOptions = { } ;
155141
@@ -158,12 +144,12 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
158144 eventHandlerOverrides = { } ,
159145 options = { } ,
160146 } : {
161- client : StreamChat < SCG > ;
162- eventHandlerOverrides ?: ChannelManagerEventHandlerOverrides < SCG > ;
147+ client : StreamChat ;
148+ eventHandlerOverrides ?: ChannelManagerEventHandlerOverrides ;
163149 options ?: ChannelManagerOptions ;
164150 } ) {
165151 this . client = client ;
166- this . state = new StateStore < ChannelManagerState < SCG > > ( {
152+ this . state = new StateStore < ChannelManagerState > ( {
167153 channels : [ ] ,
168154 pagination : {
169155 isLoading : false ,
@@ -178,7 +164,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
178164 this . setEventHandlerOverrides ( eventHandlerOverrides ) ;
179165 this . setOptions ( options ) ;
180166 this . eventHandlers = new Map (
181- Object . entries < EventHandlerType < SCG > > ( {
167+ Object . entries < EventHandlerType > ( {
182168 channelDeletedHandler : this . channelDeletedHandler ,
183169 channelHiddenHandler : this . channelHiddenHandler ,
184170 channelVisibleHandler : this . channelVisibleHandler ,
@@ -191,7 +177,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
191177 ) ;
192178 }
193179
194- public setChannels = ( valueOrFactory : ChannelSetterParameterType < SCG > ) => {
180+ public setChannels = ( valueOrFactory : ChannelSetterParameterType ) => {
195181 this . state . next ( ( current ) => {
196182 const { channels : currentChannels } = current ;
197183 const newChannels = isPatch ( valueOrFactory ) ? valueOrFactory ( currentChannels ) : valueOrFactory ;
@@ -205,25 +191,25 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
205191 } ) ;
206192 } ;
207193
208- public setEventHandlerOverrides = ( eventHandlerOverrides : ChannelManagerEventHandlerOverrides < SCG > = { } ) => {
194+ public setEventHandlerOverrides = ( eventHandlerOverrides : ChannelManagerEventHandlerOverrides = { } ) => {
209195 const truthyEventHandlerOverrides = Object . entries ( eventHandlerOverrides ) . reduce <
210- Partial < ChannelManagerEventHandlerOverrides < SCG > >
196+ Partial < ChannelManagerEventHandlerOverrides >
211197 > ( ( acc , [ key , value ] ) => {
212198 if ( value ) {
213- acc [ key as keyof ChannelManagerEventHandlerOverrides < SCG > ] = value ;
199+ acc [ key as keyof ChannelManagerEventHandlerOverrides ] = value ;
214200 }
215201 return acc ;
216202 } , { } ) ;
217- this . eventHandlerOverrides = new Map ( Object . entries < EventHandlerOverrideType < SCG > > ( truthyEventHandlerOverrides ) ) ;
203+ this . eventHandlerOverrides = new Map ( Object . entries < EventHandlerOverrideType > ( truthyEventHandlerOverrides ) ) ;
218204 } ;
219205
220206 public setOptions = ( options : ChannelManagerOptions = { } ) => {
221207 this . options = { ...DEFAULT_CHANNEL_MANAGER_OPTIONS , ...options } ;
222208 } ;
223209
224210 public queryChannels = async (
225- filters : ChannelFilters < SCG > ,
226- sort : ChannelSort < SCG > = [ ] ,
211+ filters : ChannelFilters ,
212+ sort : ChannelSort = [ ] ,
227213 options : ChannelOptions = { } ,
228214 stateOptions : ChannelStateOptions = { } ,
229215 ) => {
@@ -294,7 +280,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
294280 const newOptions = { ...options , offset : newOffset } ;
295281
296282 this . state . partialNext ( {
297- channels : uniqBy < Channel < SCG > > ( [ ...( channels || [ ] ) , ...nextChannels ] , 'cid' ) ,
283+ channels : uniqBy < Channel > ( [ ...( channels || [ ] ) , ...nextChannels ] , 'cid' ) ,
298284 pagination : {
299285 ...pagination ,
300286 hasNext : ( nextChannels ?. length ?? 0 ) >= limit ,
@@ -313,7 +299,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
313299 }
314300 } ;
315301
316- private notificationAddedToChannelHandler = async ( event : Event < SCG > ) => {
302+ private notificationAddedToChannelHandler = async ( event : Event ) => {
317303 const { id, type, members } = event ?. channel ?? { } ;
318304
319305 if ( ! type || ! this . options . allowNotLoadedChannelPromotionForEvent ?. [ 'notification.added_to_channel' ] ) {
@@ -349,7 +335,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
349335 ) ;
350336 } ;
351337
352- private channelDeletedHandler = ( event : Event < SCG > ) => {
338+ private channelDeletedHandler = ( event : Event ) => {
353339 const { channels } = this . state . getLatestValue ( ) ;
354340 if ( ! channels ) {
355341 return ;
@@ -368,7 +354,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
368354
369355 private channelHiddenHandler = this . channelDeletedHandler ;
370356
371- private newMessageHandler = ( event : Event < SCG > ) => {
357+ private newMessageHandler = ( event : Event ) => {
372358 const { pagination, channels } = this . state . getLatestValue ( ) ;
373359 if ( ! channels ) {
374360 return ;
@@ -417,7 +403,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
417403 ) ;
418404 } ;
419405
420- private notificationNewMessageHandler = async ( event : Event < SCG > ) => {
406+ private notificationNewMessageHandler = async ( event : Event ) => {
421407 const { id, type } = event ?. channel ?? { } ;
422408
423409 if ( ! id || ! type ) {
@@ -454,7 +440,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
454440 ) ;
455441 } ;
456442
457- private channelVisibleHandler = async ( event : Event < SCG > ) => {
443+ private channelVisibleHandler = async ( event : Event ) => {
458444 const { channel_type : channelType , channel_id : channelId } = event ;
459445
460446 if ( ! channelType || ! channelId ) {
@@ -493,7 +479,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
493479
494480 private notificationRemovedFromChannelHandler = this . channelDeletedHandler ;
495481
496- private memberUpdatedHandler = ( event : Event < SCG > ) => {
482+ private memberUpdatedHandler = ( event : Event ) => {
497483 const { pagination, channels } = this . state . getLatestValue ( ) ;
498484 const { filters, sort } = pagination ;
499485 if (
@@ -557,7 +543,7 @@ export class ChannelManager<SCG extends ExtendableGenerics = DefaultGenerics> {
557543 this . setChannels ( newChannels ) ;
558544 } ;
559545
560- private subscriptionOrOverride = ( event : Event < SCG > ) => {
546+ private subscriptionOrOverride = ( event : Event ) => {
561547 const handlerName = channelManagerEventToHandlerMapping [ event . type as ChannelManagerEventTypes ] ;
562548 const defaultEventHandler = this . eventHandlers . get ( handlerName ) ;
563549 const eventHandlerOverride = this . eventHandlerOverrides . get ( handlerName ) ;
0 commit comments