@@ -11,11 +11,10 @@ import {
1111
1212const useFetchChatData = ( showRoles ) => {
1313 const { RCInstance } = useContext ( RCContext ) ;
14- const setMemberRoles = useMemberStore ( ( state ) => state . setMemberRoles ) ;
15- const isChannelPrivate = useChannelStore ( ( state ) => state . isChannelPrivate ) ;
1614 const setMessages = useMessageStore ( ( state ) => state . setMessages ) ;
1715 const setMessagesOffset = useMessageStore ( ( state ) => state . setMessagesOffset ) ;
1816 const setAdmins = useMemberStore ( ( state ) => state . setAdmins ) ;
17+ const setMemberRoles = useMemberStore ( ( state ) => state . setMemberRoles ) ;
1918 const permissionsRef = useRef ( null ) ;
2019 const setStarredMessages = useStarredMessageStore (
2120 ( state ) => state . setStarredMessages
@@ -127,10 +126,26 @@ const useFetchChatData = (showRoles) => {
127126 return ;
128127 }
129128
129+ let channelIsPrivate = false ;
130+ if ( ! anonymousMode ) {
131+ const { channelInfo, setChannelInfo, setIsChannelPrivate } =
132+ useChannelStore . getState ( ) ;
133+ if ( channelInfo ?. _id ) {
134+ channelIsPrivate = channelInfo . t === 'p' ;
135+ } else {
136+ const res = await RCInstance . channelInfo ( ) ;
137+ if ( res ?. success ) {
138+ setChannelInfo ( res . room ) ;
139+ channelIsPrivate = res . room . t === 'p' ;
140+ if ( channelIsPrivate ) setIsChannelPrivate ( true ) ;
141+ }
142+ }
143+ }
144+
130145 const { messages, count } = await RCInstance . getMessages (
131146 anonymousMode ,
132147 undefined ,
133- anonymousMode ? false : isChannelPrivate
148+ channelIsPrivate
134149 ) ;
135150
136151 if ( messages ) {
@@ -143,7 +158,7 @@ const useFetchChatData = (showRoles) => {
143158 }
144159
145160 if ( showRoles ) {
146- const { roles } = await RCInstance . getChannelRoles ( isChannelPrivate ) ;
161+ const { roles } = await RCInstance . getChannelRoles ( channelIsPrivate ) ;
147162 const fetchedRoles = await RCInstance . getUserRoles ( ) ;
148163 const fetchedAdmins = fetchedRoles ?. result ;
149164
@@ -167,7 +182,6 @@ const useFetchChatData = (showRoles) => {
167182 [
168183 isUserAuthenticated ,
169184 RCInstance ,
170- isChannelPrivate ,
171185 showRoles ,
172186 setMessages ,
173187 setAdmins ,
0 commit comments