Skip to content

Commit

Permalink
feat: add localCacheEncryption interface to container prop
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Sep 19, 2023
1 parent 7d4688b commit 3341992
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SBUConfig, UIKitConfigProvider } from '@sendbird/uikit-tools';
import type {
PartialDeep,
SendbirdChatSDK,
SendbirdEncryption,
SendbirdGroupChannel,
SendbirdGroupChannelCreateParams,
SendbirdMember,
Expand Down Expand Up @@ -72,6 +73,7 @@ export type SendbirdUIKitContainerProps = React.PropsWithChildren<{
};
chatOptions: {
localCacheStorage: LocalCacheStorage;
localCacheEncryption?: SendbirdEncryption;
onInitialized?: (sdkInstance: SendbirdChatSDK) => SendbirdChatSDK;
} & Partial<ChatRelatedFeaturesInUIKit>;
uikitOptions?: PartialDeep<{
Expand Down Expand Up @@ -137,7 +139,7 @@ const SendbirdUIKitContainer = ({

const [internalStorage] = useState(() => new InternalLocalCacheStorage(chatOptions.localCacheStorage));
const [sdkInstance, setSdkInstance] = useState<SendbirdChatSDK>(() => {
const sendbird = initializeSendbird(appId, internalStorage, chatOptions.onInitialized);
const sendbird = initializeSendbird(appId, { internalStorage, ...chatOptions });
unsubscribes.current = sendbird.unsubscribes;
return sendbird.chatSDK;
});
Expand Down Expand Up @@ -165,7 +167,7 @@ const SendbirdUIKitContainer = ({

useLayoutEffect(() => {
if (!isFirstMount) {
const sendbird = initializeSendbird(appId, internalStorage, chatOptions.onInitialized);
const sendbird = initializeSendbird(appId, { internalStorage, ...chatOptions });
setSdkInstance(sendbird.chatSDK);
unsubscribes.current = sendbird.unsubscribes;
}
Expand Down Expand Up @@ -270,18 +272,23 @@ const SendbirdUIKitContainer = ({

const initializeSendbird = (
appId: string,
internalStorage?: InternalLocalCacheStorage,
onInitialized?: (sdk: SendbirdChatSDK) => SendbirdChatSDK,
options: {
internalStorage?: InternalLocalCacheStorage;
onInitialized?: (sdk: SendbirdChatSDK) => SendbirdChatSDK;
localCacheEncryption?: SendbirdEncryption;
},
) => {
const unsubscribes: Array<() => void> = [];
let chatSDK: SendbirdChatSDK;
const unsubscribes: Array<() => void> = [];
const { internalStorage, localCacheEncryption, onInitialized } = options;

chatSDK = Sendbird.init({
appId,
newInstance: true,
modules: [new GroupChannelModule(), new OpenChannelModule()],
localCacheEnabled: Boolean(internalStorage),
useAsyncStorageStore: internalStorage as never,
newInstance: true,
localCacheEncryption,
});

if (onInitialized) {
Expand Down
3 changes: 2 additions & 1 deletion packages/uikit-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
Emoji,
EmojiCategory,
EmojiContainer,
Encryption,
Participant,
RestrictedUser,
SendbirdError as SBError,
Expand Down Expand Up @@ -79,7 +80,6 @@ export type OnBeforeHandler<T> = (params: T) => T | Promise<T>;
export interface UserStruct {
userId: string;
}

export type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;
export type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;
export type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;
Expand Down Expand Up @@ -123,6 +123,7 @@ export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
export type SendbirdMessageSearchQuery = MessageSearchQuery;

export type SendbirdError = SBError;
export type SendbirdEncryption = Encryption;

export interface SendbirdDataPayload {
app_id: string;
Expand Down

0 comments on commit 3341992

Please sign in to comment.