@@ -7,11 +7,11 @@ import React, {
7
7
useReducer ,
8
8
useRef ,
9
9
} from 'react' ;
10
+ import { ChannelState as StreamChannelState } from 'stream-chat' ;
10
11
11
12
import type { DefaultStreamChatGenerics } from '../../types/types' ;
12
13
import { ActiveChannelsProvider } from '../activeChannelsRefContext/ActiveChannelsRefContext' ;
13
14
14
- import type { ChannelContextValue } from '../channelContext/ChannelContext' ;
15
15
import type { PaginatedMessageListContextValue } from '../paginatedMessageListContext/PaginatedMessageListContext' ;
16
16
import type { ThreadContextValue } from '../threadContext/ThreadContext' ;
17
17
import type { TypingContextValue } from '../typingContext/TypingContext' ;
@@ -22,14 +22,13 @@ import { isTestEnvironment } from '../utils/isTestEnvironment';
22
22
export type ChannelState <
23
23
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
24
24
> = {
25
- members : ChannelContextValue < StreamChatGenerics > [ 'members' ] ;
25
+ members : StreamChannelState < StreamChatGenerics > [ 'members' ] ;
26
26
messages : PaginatedMessageListContextValue < StreamChatGenerics > [ 'messages' ] ;
27
- read : ChannelContextValue < StreamChatGenerics > [ 'read' ] ;
28
- subscriberCount : number ;
27
+ read : StreamChannelState < StreamChatGenerics > [ 'read' ] ;
29
28
threadMessages : ThreadContextValue < StreamChatGenerics > [ 'threadMessages' ] ;
30
29
typing : TypingContextValue < StreamChatGenerics > [ 'typing' ] ;
31
- watcherCount : ChannelContextValue < StreamChatGenerics > [ 'watcherCount' ] ;
32
- watchers : ChannelContextValue < StreamChatGenerics > [ 'watchers' ] ;
30
+ watcherCount : number ;
31
+ watchers : StreamChannelState < StreamChatGenerics > [ 'watchers' ] ;
33
32
} ;
34
33
35
34
type ChannelsState <
@@ -56,25 +55,12 @@ type SetStateAction<
56
55
type : 'SET_STATE' ;
57
56
} ;
58
57
59
- type IncreaseSubscriberCountAction = {
60
- payload : { cid : string } ;
61
- type : 'INCREASE_SUBSCRIBER_COUNT' ;
62
- } ;
63
- type DecreaseSubscriberCountAction = {
64
- payload : { cid : string } ;
65
- type : 'DECREASE_SUBSCRIBER_COUNT' ;
66
- } ;
67
-
68
58
type Action < StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics > =
69
- | SetStateAction < StreamChatGenerics >
70
- | IncreaseSubscriberCountAction
71
- | DecreaseSubscriberCountAction ;
59
+ SetStateAction < StreamChatGenerics > ;
72
60
73
61
export type ChannelsStateContextValue <
74
62
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
75
63
> = {
76
- decreaseSubscriberCount : ( value : { cid : string } ) => void ;
77
- increaseSubscriberCount : ( value : { cid : string } ) => void ;
78
64
setState : ( value : Payload < Keys , StreamChatGenerics > ) => void ;
79
65
state : ChannelsState < StreamChatGenerics > ;
80
66
} ;
@@ -95,39 +81,6 @@ function reducer(state: ChannelsState, action: Action) {
95
81
} ,
96
82
} ;
97
83
98
- case 'INCREASE_SUBSCRIBER_COUNT' : {
99
- const currentCount = state [ action . payload . cid ] ?. subscriberCount ?? 0 ;
100
- return {
101
- ...state ,
102
- [ action . payload . cid ] : {
103
- ...( state [ action . payload . cid ] || { } ) ,
104
- subscriberCount : currentCount + 1 ,
105
- } ,
106
- } ;
107
- }
108
-
109
- case 'DECREASE_SUBSCRIBER_COUNT' : {
110
- const currentCount = state [ action . payload . cid ] ?. subscriberCount ?? 0 ;
111
-
112
- // If there last subscribed Channel component unsubscribes, we clear the channel state.
113
- if ( currentCount <= 1 ) {
114
- const stateShallowCopy = {
115
- ...state ,
116
- } ;
117
-
118
- delete stateShallowCopy [ action . payload . cid ] ;
119
-
120
- return stateShallowCopy ;
121
- }
122
-
123
- return {
124
- ...state ,
125
- [ action . payload . cid ] : {
126
- ...( state [ action . payload . cid ] || { } ) ,
127
- subscriberCount : currentCount - 1 ,
128
- } ,
129
- } ;
130
- }
131
84
default :
132
85
throw new Error ( ) ;
133
86
}
@@ -150,18 +103,8 @@ export const ChannelsStateProvider = <
150
103
dispatch ( { payload, type : 'SET_STATE' } ) ;
151
104
} , [ ] ) ;
152
105
153
- const increaseSubscriberCount = useCallback ( ( payload : { cid : string } ) => {
154
- dispatch ( { payload, type : 'INCREASE_SUBSCRIBER_COUNT' } ) ;
155
- } , [ ] ) ;
156
-
157
- const decreaseSubscriberCount = useCallback ( ( payload : { cid : string } ) => {
158
- dispatch ( { payload, type : 'DECREASE_SUBSCRIBER_COUNT' } ) ;
159
- } , [ ] ) ;
160
-
161
106
const value = useMemo (
162
107
( ) => ( {
163
- decreaseSubscriberCount,
164
- increaseSubscriberCount,
165
108
setState,
166
109
state,
167
110
} ) ,
0 commit comments