Skip to content

Commit 187c656

Browse files
authored
Merge pull request #222 from sendbird/chore/allow-chat-options
[CLNP-6034] chore: enable overriding all chat options
2 parents c804ee2 + e06a76d commit 187c656

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

packages/uikit-react-native/src/containers/SendbirdUIKitContainer.tsx

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,8 @@ export const SendbirdUIKit = Object.freeze({
7272
},
7373
});
7474

75-
export type ChatOmittedInitParams = Omit<
76-
SendbirdChatParams<[GroupChannelModule, OpenChannelModule]>,
77-
(typeof chatOmitKeys)[number]
78-
>;
79-
80-
const chatOmitKeys = [
81-
'appId',
82-
'newInstance',
83-
'modules',
84-
'debugMode',
85-
'appVersion',
86-
'localCacheEnabled',
87-
'useAsyncStorageStore',
88-
'useMMKVStorageStore',
89-
] as const;
90-
function sanitizeChatOptions<T extends Record<string, unknown>>(chatOptions: T): T {
91-
const opts = { ...chatOptions };
92-
chatOmitKeys.forEach((key) => delete opts[key]);
93-
return opts;
94-
}
75+
export type ChatOmittedInitParams = SendbirdChatParams<[GroupChannelModule, OpenChannelModule]>;
76+
9577
export type SendbirdUIKitContainerProps = React.PropsWithChildren<{
9678
appId: string;
9779
platformServices: {
@@ -184,7 +166,7 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {
184166

185167
const [internalStorage] = useState(() => new InternalLocalCacheStorage(chatOptions.localCacheStorage));
186168
const [sdkInstance, setSdkInstance] = useState<SendbirdChatSDK>(() => {
187-
const sendbird = initializeSendbird(appId, sanitizeChatOptions(chatOptions));
169+
const sendbird = initializeSendbird(appId, chatOptions);
188170
unsubscribes.current = sendbird.unsubscribes;
189171
return sendbird.chatSDK;
190172
});
@@ -196,7 +178,7 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {
196178

197179
useLayoutEffect(() => {
198180
if (!isFirstMount) {
199-
const sendbird = initializeSendbird(appId, sanitizeChatOptions(chatOptions));
181+
const sendbird = initializeSendbird(appId, chatOptions);
200182
setSdkInstance(sendbird.chatSDK);
201183
unsubscribes.current = sendbird.unsubscribes;
202184
}
@@ -307,24 +289,24 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {
307289
);
308290
};
309291

310-
interface InitOptions extends ChatOmittedInitParams {
292+
type InitOptions = Partial<ChatOmittedInitParams> & {
311293
localCacheStorage: LocalCacheStorage;
312294
onInitialized?: (sdk: SendbirdChatSDK) => SendbirdChatSDK;
313-
}
295+
};
314296
const initializeSendbird = (appId: string, options: InitOptions) => {
315297
let chatSDK: SendbirdChatSDK;
316298
const unsubscribes: Array<() => void> = [];
317299
const { localCacheStorage, onInitialized, ...chatInitParams } = options;
318300

319301
const isMMKVStorage = 'getString' in localCacheStorage;
320302
chatSDK = SendbirdChat.init({
321-
...chatInitParams,
322303
appId,
323304
newInstance: true,
324305
modules: [new GroupChannelModule(), new OpenChannelModule()],
325306
localCacheEnabled: true,
326307
useMMKVStorageStore: isMMKVStorage ? (localCacheStorage as MMKV) : undefined,
327308
useAsyncStorageStore: !isMMKVStorage ? (localCacheStorage as AsyncStorageStatic) : undefined,
309+
...chatInitParams,
328310
});
329311

330312
if (onInitialized) {

0 commit comments

Comments
 (0)