@@ -2,7 +2,7 @@ import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
22import { Platform } from 'react-native' ;
33import { SafeAreaProvider } from 'react-native-safe-area-context' ;
44
5- import Sendbird , { DeviceOsPlatform , SendbirdPlatform , SendbirdProduct } from '@sendbird/chat' ;
5+ import SendbirdChat , { DeviceOsPlatform , SendbirdChatParams , SendbirdPlatform , SendbirdProduct } from '@sendbird/chat' ;
66import { GroupChannelModule } from '@sendbird/chat/groupChannel' ;
77import { OpenChannelModule } from '@sendbird/chat/openChannel' ;
88import type { HeaderStyleContextType , UIKitTheme } from '@sendbird/uikit-react-native-foundation' ;
@@ -18,7 +18,6 @@ import { SBUConfig, UIKitConfigProvider } from '@sendbird/uikit-tools';
1818import type {
1919 PartialDeep ,
2020 SendbirdChatSDK ,
21- SendbirdEncryption ,
2221 SendbirdGroupChannel ,
2322 SendbirdGroupChannelCreateParams ,
2423 SendbirdMember ,
@@ -52,7 +51,6 @@ import VERSION from '../version';
5251import InternalErrorBoundaryContainer from './InternalErrorBoundaryContainer' ;
5352
5453const NetInfo = SBUDynamicModule . get ( '@react-native-community/netinfo' , 'warn' ) ;
55- type UnimplementedFeatures = 'enableVoiceMessage' | 'threadReplySelectType' | 'replyType' ;
5654export const SendbirdUIKit = Object . freeze ( {
5755 VERSION ,
5856 PLATFORM : Platform . OS . toLowerCase ( ) ,
@@ -63,6 +61,27 @@ export const SendbirdUIKit = Object.freeze({
6361 } ,
6462} ) ;
6563
64+ type UnimplementedFeatures = 'enableVoiceMessage' | 'threadReplySelectType' | 'replyType' ;
65+ export type ChatOmittedInitParams = Omit <
66+ SendbirdChatParams < [ GroupChannelModule , OpenChannelModule ] > ,
67+ ( typeof chatOmitKeys ) [ number ]
68+ > ;
69+
70+ const chatOmitKeys = [
71+ 'appId' ,
72+ 'newInstance' ,
73+ 'modules' ,
74+ 'debugMode' ,
75+ 'appVersion' ,
76+ 'localCacheEnabled' ,
77+ 'useAsyncStorageStore' ,
78+ ] as const ;
79+ function sanitizeChatOptions < T extends Record < string , unknown > > ( chatOptions : T ) : T {
80+ const opts = { ...chatOptions } ;
81+ chatOmitKeys . forEach ( ( key ) => delete opts [ key ] ) ;
82+ return opts ;
83+ }
84+
6685export type SendbirdUIKitContainerProps = React . PropsWithChildren < {
6786 appId : string ;
6887 platformServices : {
@@ -73,9 +92,9 @@ export type SendbirdUIKitContainerProps = React.PropsWithChildren<{
7392 } ;
7493 chatOptions : {
7594 localCacheStorage : LocalCacheStorage ;
76- localCacheEncryption ?: SendbirdEncryption ;
7795 onInitialized ?: ( sdkInstance : SendbirdChatSDK ) => SendbirdChatSDK ;
78- } & Partial < ChatRelatedFeaturesInUIKit > ;
96+ } & Partial < ChatOmittedInitParams > &
97+ Partial < ChatRelatedFeaturesInUIKit > ;
7998 uikitOptions ?: PartialDeep < {
8099 common : SBUConfig [ 'common' ] ;
81100 groupChannel : Omit < SBUConfig [ 'groupChannel' ] [ 'channel' ] , UnimplementedFeatures > & {
@@ -143,7 +162,7 @@ const SendbirdUIKitContainer = ({
143162
144163 const [ internalStorage ] = useState ( ( ) => new InternalLocalCacheStorage ( chatOptions . localCacheStorage ) ) ;
145164 const [ sdkInstance , setSdkInstance ] = useState < SendbirdChatSDK > ( ( ) => {
146- const sendbird = initializeSendbird ( appId , { internalStorage, ...chatOptions } ) ;
165+ const sendbird = initializeSendbird ( appId , { internalStorage, ...sanitizeChatOptions ( chatOptions ) } ) ;
147166 unsubscribes . current = sendbird . unsubscribes ;
148167 return sendbird . chatSDK ;
149168 } ) ;
@@ -171,7 +190,7 @@ const SendbirdUIKitContainer = ({
171190
172191 useLayoutEffect ( ( ) => {
173192 if ( ! isFirstMount ) {
174- const sendbird = initializeSendbird ( appId , { internalStorage, ...chatOptions } ) ;
193+ const sendbird = initializeSendbird ( appId , { internalStorage, ...sanitizeChatOptions ( chatOptions ) } ) ;
175194 setSdkInstance ( sendbird . chatSDK ) ;
176195 unsubscribes . current = sendbird . unsubscribes ;
177196 }
@@ -270,25 +289,22 @@ const SendbirdUIKitContainer = ({
270289 ) ;
271290} ;
272291
273- const initializeSendbird = (
274- appId : string ,
275- options : {
276- internalStorage ?: InternalLocalCacheStorage ;
277- onInitialized ?: ( sdk : SendbirdChatSDK ) => SendbirdChatSDK ;
278- localCacheEncryption ?: SendbirdEncryption ;
279- } ,
280- ) => {
292+ interface InitOptions extends ChatOmittedInitParams {
293+ internalStorage : InternalLocalCacheStorage ;
294+ onInitialized ?: ( sdk : SendbirdChatSDK ) => SendbirdChatSDK ;
295+ }
296+ const initializeSendbird = ( appId : string , options : InitOptions ) => {
281297 let chatSDK : SendbirdChatSDK ;
282298 const unsubscribes : Array < ( ) => void > = [ ] ;
283- const { internalStorage, localCacheEncryption , onInitialized } = options ;
299+ const { internalStorage, onInitialized , ... chatInitParams } = options ;
284300
285- chatSDK = Sendbird . init ( {
301+ chatSDK = SendbirdChat . init ( {
302+ ...chatInitParams ,
286303 appId,
287304 newInstance : true ,
288305 modules : [ new GroupChannelModule ( ) , new OpenChannelModule ( ) ] ,
289- localCacheEnabled : Boolean ( internalStorage ) ,
306+ localCacheEnabled : true ,
290307 useAsyncStorageStore : internalStorage as never ,
291- localCacheEncryption,
292308 } ) ;
293309
294310 if ( onInitialized ) {
0 commit comments