Skip to content

Commit

Permalink
chore: enable overriding all chat options
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Dec 11, 2024
1 parent c804ee2 commit 7b0448a
Showing 1 changed file with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,6 @@ export type ChatOmittedInitParams = Omit<
(typeof chatOmitKeys)[number]
>;

const chatOmitKeys = [
'appId',
'newInstance',
'modules',
'debugMode',
'appVersion',
'localCacheEnabled',
'useAsyncStorageStore',
'useMMKVStorageStore',
] as const;
function sanitizeChatOptions<T extends Record<string, unknown>>(chatOptions: T): T {
const opts = { ...chatOptions };
chatOmitKeys.forEach((key) => delete opts[key]);
return opts;
}
export type SendbirdUIKitContainerProps = React.PropsWithChildren<{
appId: string;
platformServices: {
Expand Down Expand Up @@ -184,7 +169,7 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {

const [internalStorage] = useState(() => new InternalLocalCacheStorage(chatOptions.localCacheStorage));
const [sdkInstance, setSdkInstance] = useState<SendbirdChatSDK>(() => {
const sendbird = initializeSendbird(appId, sanitizeChatOptions(chatOptions));
const sendbird = initializeSendbird(appId, chatOptions);
unsubscribes.current = sendbird.unsubscribes;
return sendbird.chatSDK;
});
Expand All @@ -196,7 +181,7 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {

useLayoutEffect(() => {
if (!isFirstMount) {
const sendbird = initializeSendbird(appId, sanitizeChatOptions(chatOptions));
const sendbird = initializeSendbird(appId, chatOptions);
setSdkInstance(sendbird.chatSDK);
unsubscribes.current = sendbird.unsubscribes;
}
Expand Down Expand Up @@ -318,13 +303,13 @@ const initializeSendbird = (appId: string, options: InitOptions) => {

const isMMKVStorage = 'getString' in localCacheStorage;
chatSDK = SendbirdChat.init({
...chatInitParams,
appId,
newInstance: true,
modules: [new GroupChannelModule(), new OpenChannelModule()],
localCacheEnabled: true,
useMMKVStorageStore: isMMKVStorage ? (localCacheStorage as MMKV) : undefined,
useAsyncStorageStore: !isMMKVStorage ? (localCacheStorage as AsyncStorageStatic) : undefined,
...chatInitParams,
});

if (onInitialized) {
Expand Down

0 comments on commit 7b0448a

Please sign in to comment.