stream-chat-react-native-core 5.11.3-beta.3 → 5.11.3-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Chat/Chat.js +8 -8
- package/lib/commonjs/components/Chat/Chat.js.map +1 -1
- package/lib/commonjs/components/Chat/hooks/useAppSettings.js +15 -21
- package/lib/commonjs/components/Chat/hooks/useAppSettings.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Chat/Chat.js +8 -8
- package/lib/module/components/Chat/Chat.js.map +1 -1
- package/lib/module/components/Chat/hooks/useAppSettings.js +15 -21
- package/lib/module/components/Chat/hooks/useAppSettings.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Chat/hooks/useAppSettings.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/Chat/Chat.tsx +6 -6
- package/src/components/Chat/hooks/useAppSettings.ts +3 -4
- package/src/version.json +1 -1
|
@@ -65,10 +65,10 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
65
65
|
var _useIsOnline = (0, _useIsOnline2.useIsOnline)(client, closeConnectionOnBackground),
|
|
66
66
|
connectionRecovering = _useIsOnline.connectionRecovering,
|
|
67
67
|
isOnline = _useIsOnline.isOnline;
|
|
68
|
-
var _useState5 = (0, _react.useState)(
|
|
68
|
+
var _useState5 = (0, _react.useState)(false),
|
|
69
69
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
initialisedDatabase = _useState6[0],
|
|
71
|
+
setInitialisedDatabase = _useState6[1];
|
|
72
72
|
var mutedUsers = (0, _useMutedUsers.useMutedUsers)(client);
|
|
73
73
|
var debugRef = (0, _DebugContext.useDebugContext)();
|
|
74
74
|
var isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;
|
|
@@ -85,20 +85,20 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
85
85
|
data: client.user
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
}, [client]);
|
|
88
|
+
}, [client, enableOfflineSupport]);
|
|
89
89
|
var setActiveChannel = function setActiveChannel(newChannel) {
|
|
90
90
|
return setChannel(newChannel);
|
|
91
91
|
};
|
|
92
92
|
(0, _react.useEffect)(function () {
|
|
93
93
|
var _client$user;
|
|
94
94
|
if ((_client$user = client.user) != null && _client$user.id && enableOfflineSupport) {
|
|
95
|
-
|
|
95
|
+
setInitialisedDatabase(false);
|
|
96
96
|
_QuickSqliteClient.QuickSqliteClient.initializeDatabase();
|
|
97
97
|
_DBSyncManager.DBSyncManager.init(client);
|
|
98
|
-
|
|
98
|
+
setInitialisedDatabase(true);
|
|
99
99
|
}
|
|
100
100
|
}, [client == null ? void 0 : (_client$user2 = client.user) == null ? void 0 : _client$user2.id, enableOfflineSupport]);
|
|
101
|
-
var appSettings = (0, _useAppSettings.useAppSettings)(client, isOnline, enableOfflineSupport,
|
|
101
|
+
var appSettings = (0, _useAppSettings.useAppSettings)(client, isOnline, enableOfflineSupport, initialisedDatabase);
|
|
102
102
|
var chatContext = (0, _useCreateChatContext.useCreateChatContext)({
|
|
103
103
|
appSettings: appSettings,
|
|
104
104
|
channel: channel,
|
|
@@ -114,7 +114,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
114
114
|
client: client,
|
|
115
115
|
enableOfflineSupport: enableOfflineSupport
|
|
116
116
|
});
|
|
117
|
-
if (loadingTranslators
|
|
117
|
+
if (loadingTranslators) return null;
|
|
118
118
|
return _react["default"].createElement(_ChatContext.ChatProvider, {
|
|
119
119
|
value: chatContext,
|
|
120
120
|
__self: _this,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_dayjs","_interopRequireDefault","_useAppSettings","_useCreateChatContext","_useIsOnline2","_useMutedUsers","_useSyncDatabase","_ChannelsStateContext","_ChatContext","_DebugContext","_OverlayContext","_ThemeContext","_TranslationContext","_useStreami18n","_init","_native","_QuickSqliteClient","_DBSyncManager","_version","_this","_jsxFileName","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","init","ChatWithContext","props","_client$user2","_client$user3","children","client","_props$closeConnectio","closeConnectionOnBackground","_props$enableOfflineS","enableOfflineSupport","i18nInstance","_props$ImageComponent","ImageComponent","Image","style","_useState","useState","_useState2","_slicedToArray2","channel","setChannel","_useState3","t","tDateTimeParser","input","Dayjs","_useState4","translators","setTranslators","loadingTranslators","useStreami18n","_useIsOnline","useIsOnline","connectionRecovering","isOnline","_useState5","_useState6","initialisingDatabase","setInitialisingDatabase","mutedUsers","useMutedUsers","debugRef","useDebugContext","isDebugModeEnabled","__DEV__","current","useEffect","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","persistUserOnConnectionFailure","setEventType","setSendEventParams","action","data","user","setActiveChannel","newChannel","_client$user","id","QuickSqliteClient","initializeDatabase","DBSyncManager","appSettings","useAppSettings","chatContext","useCreateChatContext","useSyncDatabase","createElement","ChatProvider","value","__self","__source","fileName","lineNumber","columnNumber","TranslationProvider","_extends2","userLanguage","language","DEFAULT_USER_LANGUAGE","ThemeProvider","ChannelsStateProvider","Chat","_useOverlayContext","useOverlayContext","exports"],"sources":["Chat.tsx"],"sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Image, Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel, StreamChat } from 'stream-chat';\n\nimport { useAppSettings } from './hooks/useAppSettings';\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { useSyncDatabase } from './hooks/useSyncDatabase';\n\nimport { ChannelsStateProvider } from '../../contexts/channelsStateContext/ChannelsStateContext';\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useDebugContext } from '../../contexts/debugContext/DebugContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n DEFAULT_USER_LANGUAGE,\n TranslationProvider,\n TranslatorFunctions,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\nimport init from '../../init';\n\nimport { SDK } from '../../native';\nimport { QuickSqliteClient } from '../../store/QuickSqliteClient';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { DBSyncManager } from '../../utils/DBSyncManager';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\ninit();\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> &\n Partial<Pick<ChatContextValue<StreamChatGenerics>, 'ImageComponent'>> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Enables offline storage and loading for chat data.\n */\n enableOfflineSupport?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n };\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const {\n children,\n client,\n closeConnectionOnBackground = true,\n enableOfflineSupport = false,\n i18nInstance,\n ImageComponent = Image,\n style,\n } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslatorFunctions>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n const [initialisingDatabase, setInitialisingDatabase] = useState(enableOfflineSupport);\n\n /**\n * Setup muted user listener\n * TODO: reimplement\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n const debugRef = useDebugContext();\n const isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;\n\n useEffect(() => {\n if (client) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n client.persistUserOnConnectionFailure = enableOfflineSupport;\n }\n\n if (isDebugModeEnabled) {\n if (debugRef.current.setEventType) debugRef.current.setEventType('send');\n if (debugRef.current.setSendEventParams)\n debugRef.current.setSendEventParams({\n action: 'Client',\n data: client.user,\n });\n }\n }, [client]);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n useEffect(() => {\n if (client.user?.id && enableOfflineSupport) {\n setInitialisingDatabase(true);\n QuickSqliteClient.initializeDatabase();\n DBSyncManager.init(client as unknown as StreamChat);\n setInitialisingDatabase(false);\n }\n }, [client?.user?.id, enableOfflineSupport]);\n\n const appSettings = useAppSettings(client, isOnline, enableOfflineSupport, initialisingDatabase);\n\n const chatContext = useCreateChatContext({\n appSettings,\n channel,\n client,\n connectionRecovering,\n enableOfflineSupport,\n ImageComponent,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n useSyncDatabase({\n client,\n enableOfflineSupport,\n });\n\n if (loadingTranslators || initialisingDatabase) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider\n value={{ ...translators, userLanguage: client.user?.language || DEFAULT_USER_LANGUAGE }}\n >\n <ThemeProvider style={style}>\n <ChannelsStateProvider<StreamChatGenerics>>{children}</ChannelsStateProvider>\n </ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAIA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AAEA,IAAAQ,gBAAA,GAAAR,OAAA;AAEA,IAAAS,qBAAA,GAAAT,OAAA;AACA,IAAAU,YAAA,GAAAV,OAAA;AACA,IAAAW,aAAA,GAAAX,OAAA;AACA,IAAAY,eAAA,GAAAZ,OAAA;AACA,IAAAa,aAAA,GAAAb,OAAA;AAEA,IAAAc,mBAAA,GAAAd,OAAA;AAKA,IAAAe,cAAA,GAAAf,OAAA;AACA,IAAAgB,KAAA,GAAAb,sBAAA,CAAAH,OAAA;AAEA,IAAAiB,OAAA,GAAAjB,OAAA;AACA,IAA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EAAA9E,aAAA,GAAAE,MAAM,CAACqD,IAAI,qBAAXvD,aAAA,CAAa+E,QAAQ,KAAIC;IAAqB,EAAG;IAAAT,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAExF9H,MAAA,YAAAuH,aAAA,CAACxG,aAAA,CAAAqH,aAAa;IAACtE,KAAK,EAAEA,KAAM;IAAA4D,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAC1B9H,MAAA,YAAAuH,aAAA,CAAC5G,qBAAA,CAAA0H,qBAAqB;IAAAX,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAsB1E,QAAQ,CAAyB,CAC/D,CACI,CACT;AAEnB,CAAC;AAuBM,IAAMkF,IAAI,GAAG,SAAPA,IAAIA,CAGfrF,KAAuD,EACpD;EACH,IAAAsF,kBAAA,GAAkB,IAAAC,iCAAiB,GAAE;IAA7B1E,KAAK,GAAAyE,kBAAA,CAALzE,KAAK;EAEb,OAAO9D,MAAA,YAAAuH,aAAA,CAACvE,eAAe,MAAAgF,SAAA;IAAOlE,KAAK,EAALA;EAAK,GAAQb,KAAK;IAAAyE,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAI;AACtD,CAAC;AAACW,OAAA,CAAAH,IAAA,GAAAA,IAAA"}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_dayjs","_interopRequireDefault","_useAppSettings","_useCreateChatContext","_useIsOnline2","_useMutedUsers","_useSyncDatabase","_ChannelsStateContext","_ChatContext","_DebugContext","_OverlayContext","_ThemeContext","_TranslationContext","_useStreami18n","_init","_native","_QuickSqliteClient","_DBSyncManager","_version","_this","_jsxFileName","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","init","ChatWithContext","props","_client$user2","_client$user3","children","client","_props$closeConnectio","closeConnectionOnBackground","_props$enableOfflineS","enableOfflineSupport","i18nInstance","_props$ImageComponent","ImageComponent","Image","style","_useState","useState","_useState2","_slicedToArray2","channel","setChannel","_useState3","t","tDateTimeParser","input","Dayjs","_useState4","translators","setTranslators","loadingTranslators","useStreami18n","_useIsOnline","useIsOnline","connectionRecovering","isOnline","_useState5","_useState6","initialisedDatabase","setInitialisedDatabase","mutedUsers","useMutedUsers","debugRef","useDebugContext","isDebugModeEnabled","__DEV__","current","useEffect","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","persistUserOnConnectionFailure","setEventType","setSendEventParams","action","data","user","setActiveChannel","newChannel","_client$user","id","QuickSqliteClient","initializeDatabase","DBSyncManager","appSettings","useAppSettings","chatContext","useCreateChatContext","useSyncDatabase","createElement","ChatProvider","value","__self","__source","fileName","lineNumber","columnNumber","TranslationProvider","_extends2","userLanguage","language","DEFAULT_USER_LANGUAGE","ThemeProvider","ChannelsStateProvider","Chat","_useOverlayContext","useOverlayContext","exports"],"sources":["Chat.tsx"],"sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Image, Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel, StreamChat } from 'stream-chat';\n\nimport { useAppSettings } from './hooks/useAppSettings';\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { useSyncDatabase } from './hooks/useSyncDatabase';\n\nimport { ChannelsStateProvider } from '../../contexts/channelsStateContext/ChannelsStateContext';\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useDebugContext } from '../../contexts/debugContext/DebugContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n DEFAULT_USER_LANGUAGE,\n TranslationProvider,\n TranslatorFunctions,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\nimport init from '../../init';\n\nimport { SDK } from '../../native';\nimport { QuickSqliteClient } from '../../store/QuickSqliteClient';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { DBSyncManager } from '../../utils/DBSyncManager';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\ninit();\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> &\n Partial<Pick<ChatContextValue<StreamChatGenerics>, 'ImageComponent'>> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Enables offline storage and loading for chat data.\n */\n enableOfflineSupport?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n };\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const {\n children,\n client,\n closeConnectionOnBackground = true,\n enableOfflineSupport = false,\n i18nInstance,\n ImageComponent = Image,\n style,\n } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslatorFunctions>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n const [initialisedDatabase, setInitialisedDatabase] = useState(false);\n\n /**\n * Setup muted user listener\n * TODO: reimplement\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n const debugRef = useDebugContext();\n const isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;\n\n useEffect(() => {\n if (client) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n client.persistUserOnConnectionFailure = enableOfflineSupport;\n }\n\n if (isDebugModeEnabled) {\n if (debugRef.current.setEventType) debugRef.current.setEventType('send');\n if (debugRef.current.setSendEventParams)\n debugRef.current.setSendEventParams({\n action: 'Client',\n data: client.user,\n });\n }\n }, [client, enableOfflineSupport]);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n useEffect(() => {\n if (client.user?.id && enableOfflineSupport) {\n setInitialisedDatabase(false);\n QuickSqliteClient.initializeDatabase();\n DBSyncManager.init(client as unknown as StreamChat);\n setInitialisedDatabase(true);\n }\n }, [client?.user?.id, enableOfflineSupport]);\n\n const appSettings = useAppSettings(client, isOnline, enableOfflineSupport, initialisedDatabase);\n\n const chatContext = useCreateChatContext({\n appSettings,\n channel,\n client,\n connectionRecovering,\n enableOfflineSupport,\n ImageComponent,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n useSyncDatabase({\n client,\n enableOfflineSupport,\n });\n\n if (loadingTranslators) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider\n value={{ ...translators, userLanguage: client.user?.language || DEFAULT_USER_LANGUAGE }}\n >\n <ThemeProvider style={style}>\n <ChannelsStateProvider<StreamChatGenerics>>{children}</ChannelsStateProvider>\n </ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAIA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AAEA,IAAAQ,gBAAA,GAAAR,OAAA;AAEA,IAAAS,qBAAA,GAAAT,OAAA;AACA,IAAAU,YAAA,GAAAV,OAAA;AACA,IAAAW,aAAA,GAAAX,OAAA;AACA,IAAAY,eAAA,GAAAZ,OAAA;AACA,IAAAa,aAAA,GAAAb,OAAA;AAEA,IAAAc,mBAAA,GAAAd,OAAA;AAKA,IAAAe,cAAA,GAAAf,OAAA;AACA,IAAAgB,KAAA,GAAAb,sBAAA,CAAAH,OAAA;AAEA,IAAAiB,OAAA,GAAAjB,OAAA;AACA,IAAAk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9E,aAAA,GAAAE,MAAM,CAACqD,IAAI,qBAAXvD,aAAA,CAAa+E,QAAQ,KAAIC;IAAqB,EAAG;IAAAT,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAExF9H,MAAA,YAAAuH,aAAA,CAACxG,aAAA,CAAAqH,aAAa;IAACtE,KAAK,EAAEA,KAAM;IAAA4D,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAC1B9H,MAAA,YAAAuH,aAAA,CAAC5G,qBAAA,CAAA0H,qBAAqB;IAAAX,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAsB1E,QAAQ,CAAyB,CAC/D,CACI,CACT;AAEnB,CAAC;AAuBM,IAAMkF,IAAI,GAAG,SAAPA,IAAIA,CAGfrF,KAAuD,EACpD;EACH,IAAAsF,kBAAA,GAAkB,IAAAC,iCAAiB,GAAE;IAA7B1E,KAAK,GAAAyE,kBAAA,CAALzE,KAAK;EAEb,OAAO9D,MAAA,YAAAuH,aAAA,CAACvE,eAAe,MAAAgF,SAAA;IAAOlE,KAAK,EAALA;EAAK,GAAQb,KAAK;IAAAyE,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAI;AACtD,CAAC;AAACW,OAAA,CAAAH,IAAA,GAAAA,IAAA"}
|
|
@@ -11,7 +11,7 @@ var _react = require("react");
|
|
|
11
11
|
var dbApi = _interopRequireWildcard(require("../../../store/apis"));
|
|
12
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupport,
|
|
14
|
+
var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupport, initialisedDatabase) {
|
|
15
15
|
var _useState = (0, _react.useState)(null),
|
|
16
16
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
17
17
|
appSettings = _useState2[0],
|
|
@@ -27,20 +27,14 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
27
27
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
28
28
|
while (1) switch (_context.prev = _context.next) {
|
|
29
29
|
case 0:
|
|
30
|
-
if (
|
|
30
|
+
if (client.userID) {
|
|
31
31
|
_context.next = 2;
|
|
32
32
|
break;
|
|
33
33
|
}
|
|
34
34
|
return _context.abrupt("return");
|
|
35
35
|
case 2:
|
|
36
|
-
if (
|
|
37
|
-
_context.next =
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
return _context.abrupt("return");
|
|
41
|
-
case 4:
|
|
42
|
-
if (!(!isOnline && enableOfflineSupport)) {
|
|
43
|
-
_context.next = 8;
|
|
36
|
+
if (!(!isOnline && enableOfflineSupport && initialisedDatabase)) {
|
|
37
|
+
_context.next = 6;
|
|
44
38
|
break;
|
|
45
39
|
}
|
|
46
40
|
_appSettings = dbApi.getAppSettings({
|
|
@@ -48,11 +42,11 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
48
42
|
});
|
|
49
43
|
setAppSettings(_appSettings);
|
|
50
44
|
return _context.abrupt("return");
|
|
51
|
-
case
|
|
52
|
-
_context.prev =
|
|
53
|
-
_context.next =
|
|
45
|
+
case 6:
|
|
46
|
+
_context.prev = 6;
|
|
47
|
+
_context.next = 9;
|
|
54
48
|
return client.getAppSettings();
|
|
55
|
-
case
|
|
49
|
+
case 9:
|
|
56
50
|
_appSettings2 = _context.sent;
|
|
57
51
|
if (isMounted.current) {
|
|
58
52
|
setAppSettings(_appSettings2);
|
|
@@ -61,19 +55,19 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
61
55
|
currentUserId: client.userID
|
|
62
56
|
});
|
|
63
57
|
}
|
|
64
|
-
_context.next =
|
|
58
|
+
_context.next = 16;
|
|
65
59
|
break;
|
|
66
|
-
case
|
|
67
|
-
_context.prev =
|
|
68
|
-
_context.t0 = _context["catch"](
|
|
60
|
+
case 13:
|
|
61
|
+
_context.prev = 13;
|
|
62
|
+
_context.t0 = _context["catch"](6);
|
|
69
63
|
if (_context.t0 instanceof Error) {
|
|
70
64
|
console.error("An error occurred while getting app settings: " + _context.t0);
|
|
71
65
|
}
|
|
72
|
-
case
|
|
66
|
+
case 16:
|
|
73
67
|
case "end":
|
|
74
68
|
return _context.stop();
|
|
75
69
|
}
|
|
76
|
-
}, _callee, null, [[
|
|
70
|
+
}, _callee, null, [[6, 13]]);
|
|
77
71
|
}));
|
|
78
72
|
return _enforeAppSettings.apply(this, arguments);
|
|
79
73
|
}
|
|
@@ -81,7 +75,7 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
81
75
|
return function () {
|
|
82
76
|
isMounted.current = false;
|
|
83
77
|
};
|
|
84
|
-
}, [client, isOnline,
|
|
78
|
+
}, [client, isOnline, initialisedDatabase]);
|
|
85
79
|
return appSettings;
|
|
86
80
|
};
|
|
87
81
|
exports.useAppSettings = useAppSettings;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","dbApi","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","useAppSettings","client","isOnline","enableOfflineSupport","
|
|
1
|
+
{"version":3,"names":["_react","require","dbApi","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","useAppSettings","client","isOnline","enableOfflineSupport","initialisedDatabase","_useState","useState","_useState2","_slicedToArray2","appSettings","setAppSettings","isMounted","useRef","useEffect","enforeAppSettings","_enforeAppSettings","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","_appSettings","_appSettings2","wrap","_callee$","_context","prev","next","userID","abrupt","getAppSettings","currentUserId","sent","current","upsertAppSettings","t0","Error","console","error","stop","exports"],"sources":["useAppSettings.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';\n\nimport * as dbApi from '../../../store/apis';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\nexport const useAppSettings = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n client: StreamChat<StreamChatGenerics>,\n isOnline: boolean | null,\n enableOfflineSupport: boolean,\n initialisedDatabase: boolean,\n): AppSettingsAPIResponse | null => {\n const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);\n const isMounted = useRef(true);\n\n useEffect(() => {\n async function enforeAppSettings() {\n if (!client.userID) return;\n\n if (!isOnline && enableOfflineSupport && initialisedDatabase) {\n const appSettings = dbApi.getAppSettings({ currentUserId: client.userID });\n setAppSettings(appSettings);\n return;\n }\n\n try {\n const appSettings = await client.getAppSettings();\n if (isMounted.current) {\n setAppSettings(appSettings);\n enableOfflineSupport &&\n dbApi.upsertAppSettings({\n appSettings,\n currentUserId: client.userID as string,\n });\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`An error occurred while getting app settings: ${error}`);\n }\n }\n }\n\n enforeAppSettings();\n\n return () => {\n isMounted.current = false;\n };\n }, [client, isOnline, initialisedDatabase]);\n\n return appSettings;\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAC,uBAAA,CAAAF,OAAA;AAA6C,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAF,wBAAAM,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,aAAAE,OAAA,CAAAF,GAAA,yBAAAA,GAAA,uCAAAA,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SA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"}
|
|
@@ -65,10 +65,10 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
65
65
|
var _useIsOnline = (0, _useIsOnline2.useIsOnline)(client, closeConnectionOnBackground),
|
|
66
66
|
connectionRecovering = _useIsOnline.connectionRecovering,
|
|
67
67
|
isOnline = _useIsOnline.isOnline;
|
|
68
|
-
var _useState5 = (0, _react.useState)(
|
|
68
|
+
var _useState5 = (0, _react.useState)(false),
|
|
69
69
|
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
initialisedDatabase = _useState6[0],
|
|
71
|
+
setInitialisedDatabase = _useState6[1];
|
|
72
72
|
var mutedUsers = (0, _useMutedUsers.useMutedUsers)(client);
|
|
73
73
|
var debugRef = (0, _DebugContext.useDebugContext)();
|
|
74
74
|
var isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;
|
|
@@ -85,20 +85,20 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
85
85
|
data: client.user
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
}, [client]);
|
|
88
|
+
}, [client, enableOfflineSupport]);
|
|
89
89
|
var setActiveChannel = function setActiveChannel(newChannel) {
|
|
90
90
|
return setChannel(newChannel);
|
|
91
91
|
};
|
|
92
92
|
(0, _react.useEffect)(function () {
|
|
93
93
|
var _client$user;
|
|
94
94
|
if ((_client$user = client.user) != null && _client$user.id && enableOfflineSupport) {
|
|
95
|
-
|
|
95
|
+
setInitialisedDatabase(false);
|
|
96
96
|
_QuickSqliteClient.QuickSqliteClient.initializeDatabase();
|
|
97
97
|
_DBSyncManager.DBSyncManager.init(client);
|
|
98
|
-
|
|
98
|
+
setInitialisedDatabase(true);
|
|
99
99
|
}
|
|
100
100
|
}, [client == null ? void 0 : (_client$user2 = client.user) == null ? void 0 : _client$user2.id, enableOfflineSupport]);
|
|
101
|
-
var appSettings = (0, _useAppSettings.useAppSettings)(client, isOnline, enableOfflineSupport,
|
|
101
|
+
var appSettings = (0, _useAppSettings.useAppSettings)(client, isOnline, enableOfflineSupport, initialisedDatabase);
|
|
102
102
|
var chatContext = (0, _useCreateChatContext.useCreateChatContext)({
|
|
103
103
|
appSettings: appSettings,
|
|
104
104
|
channel: channel,
|
|
@@ -114,7 +114,7 @@ var ChatWithContext = function ChatWithContext(props) {
|
|
|
114
114
|
client: client,
|
|
115
115
|
enableOfflineSupport: enableOfflineSupport
|
|
116
116
|
});
|
|
117
|
-
if (loadingTranslators
|
|
117
|
+
if (loadingTranslators) return null;
|
|
118
118
|
return _react["default"].createElement(_ChatContext.ChatProvider, {
|
|
119
119
|
value: chatContext,
|
|
120
120
|
__self: _this,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_dayjs","_interopRequireDefault","_useAppSettings","_useCreateChatContext","_useIsOnline2","_useMutedUsers","_useSyncDatabase","_ChannelsStateContext","_ChatContext","_DebugContext","_OverlayContext","_ThemeContext","_TranslationContext","_useStreami18n","_init","_native","_QuickSqliteClient","_DBSyncManager","_version","_this","_jsxFileName","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","init","ChatWithContext","props","_client$user2","_client$user3","children","client","_props$closeConnectio","closeConnectionOnBackground","_props$enableOfflineS","enableOfflineSupport","i18nInstance","_props$ImageComponent","ImageComponent","Image","style","_useState","useState","_useState2","_slicedToArray2","channel","setChannel","_useState3","t","tDateTimeParser","input","Dayjs","_useState4","translators","setTranslators","loadingTranslators","useStreami18n","_useIsOnline","useIsOnline","connectionRecovering","isOnline","_useState5","_useState6","initialisingDatabase","setInitialisingDatabase","mutedUsers","useMutedUsers","debugRef","useDebugContext","isDebugModeEnabled","__DEV__","current","useEffect","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","persistUserOnConnectionFailure","setEventType","setSendEventParams","action","data","user","setActiveChannel","newChannel","_client$user","id","QuickSqliteClient","initializeDatabase","DBSyncManager","appSettings","useAppSettings","chatContext","useCreateChatContext","useSyncDatabase","createElement","ChatProvider","value","__self","__source","fileName","lineNumber","columnNumber","TranslationProvider","_extends2","userLanguage","language","DEFAULT_USER_LANGUAGE","ThemeProvider","ChannelsStateProvider","Chat","_useOverlayContext","useOverlayContext","exports"],"sources":["Chat.tsx"],"sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Image, Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel, StreamChat } from 'stream-chat';\n\nimport { useAppSettings } from './hooks/useAppSettings';\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { useSyncDatabase } from './hooks/useSyncDatabase';\n\nimport { ChannelsStateProvider } from '../../contexts/channelsStateContext/ChannelsStateContext';\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useDebugContext } from '../../contexts/debugContext/DebugContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n DEFAULT_USER_LANGUAGE,\n TranslationProvider,\n TranslatorFunctions,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\nimport init from '../../init';\n\nimport { SDK } from '../../native';\nimport { QuickSqliteClient } from '../../store/QuickSqliteClient';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { DBSyncManager } from '../../utils/DBSyncManager';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\ninit();\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> &\n Partial<Pick<ChatContextValue<StreamChatGenerics>, 'ImageComponent'>> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Enables offline storage and loading for chat data.\n */\n enableOfflineSupport?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n };\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const {\n children,\n client,\n closeConnectionOnBackground = true,\n enableOfflineSupport = false,\n i18nInstance,\n ImageComponent = Image,\n style,\n } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslatorFunctions>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n const [initialisingDatabase, setInitialisingDatabase] = useState(enableOfflineSupport);\n\n /**\n * Setup muted user listener\n * TODO: reimplement\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n const debugRef = useDebugContext();\n const isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;\n\n useEffect(() => {\n if (client) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n client.persistUserOnConnectionFailure = enableOfflineSupport;\n }\n\n if (isDebugModeEnabled) {\n if (debugRef.current.setEventType) debugRef.current.setEventType('send');\n if (debugRef.current.setSendEventParams)\n debugRef.current.setSendEventParams({\n action: 'Client',\n data: client.user,\n });\n }\n }, [client]);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n useEffect(() => {\n if (client.user?.id && enableOfflineSupport) {\n setInitialisingDatabase(true);\n QuickSqliteClient.initializeDatabase();\n DBSyncManager.init(client as unknown as StreamChat);\n setInitialisingDatabase(false);\n }\n }, [client?.user?.id, enableOfflineSupport]);\n\n const appSettings = useAppSettings(client, isOnline, enableOfflineSupport, initialisingDatabase);\n\n const chatContext = useCreateChatContext({\n appSettings,\n channel,\n client,\n connectionRecovering,\n enableOfflineSupport,\n ImageComponent,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n useSyncDatabase({\n client,\n enableOfflineSupport,\n });\n\n if (loadingTranslators || initialisingDatabase) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider\n value={{ ...translators, userLanguage: client.user?.language || DEFAULT_USER_LANGUAGE }}\n >\n <ThemeProvider style={style}>\n <ChannelsStateProvider<StreamChatGenerics>>{children}</ChannelsStateProvider>\n </ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\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;AAEnB,CAAC;AAuBM,IAAMkF,IAAI,GAAG,SAAPA,IAAIA,CAGfrF,KAAuD,EACpD;EACH,IAAAsF,kBAAA,GAAkB,IAAAC,iCAAiB,GAAE;IAA7B1E,KAAK,GAAAyE,kBAAA,CAALzE,KAAK;EAEb,OAAO9D,MAAA,YAAAuH,aAAA,CAACvE,eAAe,MAAAgF,SAAA;IAAOlE,KAAK,EAALA;EAAK,GAAQb,KAAK;IAAAyE,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAI;AACtD,CAAC;AAACW,OAAA,CAAAH,IAAA,GAAAA,IAAA"}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_dayjs","_interopRequireDefault","_useAppSettings","_useCreateChatContext","_useIsOnline2","_useMutedUsers","_useSyncDatabase","_ChannelsStateContext","_ChatContext","_DebugContext","_OverlayContext","_ThemeContext","_TranslationContext","_useStreami18n","_init","_native","_QuickSqliteClient","_DBSyncManager","_version","_this","_jsxFileName","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","init","ChatWithContext","props","_client$user2","_client$user3","children","client","_props$closeConnectio","closeConnectionOnBackground","_props$enableOfflineS","enableOfflineSupport","i18nInstance","_props$ImageComponent","ImageComponent","Image","style","_useState","useState","_useState2","_slicedToArray2","channel","setChannel","_useState3","t","tDateTimeParser","input","Dayjs","_useState4","translators","setTranslators","loadingTranslators","useStreami18n","_useIsOnline","useIsOnline","connectionRecovering","isOnline","_useState5","_useState6","initialisedDatabase","setInitialisedDatabase","mutedUsers","useMutedUsers","debugRef","useDebugContext","isDebugModeEnabled","__DEV__","current","useEffect","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","persistUserOnConnectionFailure","setEventType","setSendEventParams","action","data","user","setActiveChannel","newChannel","_client$user","id","QuickSqliteClient","initializeDatabase","DBSyncManager","appSettings","useAppSettings","chatContext","useCreateChatContext","useSyncDatabase","createElement","ChatProvider","value","__self","__source","fileName","lineNumber","columnNumber","TranslationProvider","_extends2","userLanguage","language","DEFAULT_USER_LANGUAGE","ThemeProvider","ChannelsStateProvider","Chat","_useOverlayContext","useOverlayContext","exports"],"sources":["Chat.tsx"],"sourcesContent":["import React, { PropsWithChildren, useEffect, useState } from 'react';\nimport { Image, Platform } from 'react-native';\n\nimport Dayjs from 'dayjs';\n\nimport type { Channel, StreamChat } from 'stream-chat';\n\nimport { useAppSettings } from './hooks/useAppSettings';\nimport { useCreateChatContext } from './hooks/useCreateChatContext';\nimport { useIsOnline } from './hooks/useIsOnline';\nimport { useMutedUsers } from './hooks/useMutedUsers';\n\nimport { useSyncDatabase } from './hooks/useSyncDatabase';\n\nimport { ChannelsStateProvider } from '../../contexts/channelsStateContext/ChannelsStateContext';\nimport { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';\nimport { useDebugContext } from '../../contexts/debugContext/DebugContext';\nimport { useOverlayContext } from '../../contexts/overlayContext/OverlayContext';\nimport { DeepPartial, ThemeProvider } from '../../contexts/themeContext/ThemeContext';\nimport type { Theme } from '../../contexts/themeContext/utils/theme';\nimport {\n DEFAULT_USER_LANGUAGE,\n TranslationProvider,\n TranslatorFunctions,\n} from '../../contexts/translationContext/TranslationContext';\nimport { useStreami18n } from '../../hooks/useStreami18n';\nimport init from '../../init';\n\nimport { SDK } from '../../native';\nimport { QuickSqliteClient } from '../../store/QuickSqliteClient';\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { DBSyncManager } from '../../utils/DBSyncManager';\nimport type { Streami18n } from '../../utils/Streami18n';\nimport { version } from '../../version.json';\n\ninit();\n\nexport type ChatProps<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = Pick<ChatContextValue<StreamChatGenerics>, 'client'> &\n Partial<Pick<ChatContextValue<StreamChatGenerics>, 'ImageComponent'>> & {\n /**\n * When false, ws connection won't be disconnection upon backgrounding the app.\n * To receive push notifications, its necessary that user doesn't have active\n * websocket connection. So by default, we disconnect websocket connection when\n * app goes to background, and reconnect when app comes to foreground.\n */\n closeConnectionOnBackground?: boolean;\n /**\n * Enables offline storage and loading for chat data.\n */\n enableOfflineSupport?: boolean;\n /**\n * Instance of Streami18n class should be provided to Chat component to enable internationalization.\n *\n * Stream provides following list of in-built translations:\n * 1. English (en)\n * 2. Dutch (nl)\n * 3. ...\n * 4. ...\n *\n * Simplest way to start using chat components in one of the in-built languages would be following:\n *\n * ```\n * const i18n = new Streami18n('nl');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * If you would like to override certain keys in in-built translation.\n * UI will be automatically updated in this case.\n *\n * ```\n * const i18n = new Streami18n('nl');\n *\n * i18n.registerTranslation('nl', {\n * 'Nothing yet...': 'Nog Niet ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} en {{ secondUser }} zijn aan het typen...',\n * });\n *\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n *\n * You can use the same function to add whole new language.\n *\n * ```\n * const i18n = new Streami18n('it');\n *\n * i18n.registerTranslation('it', {\n * 'Nothing yet...': 'Non ancora ...',\n * '{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} a {{ secondUser }} stanno scrivendo...',\n * });\n *\n * // Make sure to call setLanguage to reflect new language in UI.\n * i18n.setLanguage('it');\n * <Chat client={chatClient} i18nInstance={i18n}>\n * ...\n * </Chat>\n * ```\n */\n i18nInstance?: Streami18n;\n /**\n * You can pass the theme object to customize the styles of Chat components. You can check the default theme in [theme.ts](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/contexts/themeContext/utils/theme.ts)\n *\n * Please check section about [themes in cookbook](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#theme) for details.\n *\n * ```\n * import type { DeepPartial, Theme } from 'stream-chat-react-native';\n *\n * const theme: DeepPartial<Theme> = {\n * messageSimple: {\n * file: {\n * container: {\n * backgroundColor: 'red',\n * },\n * icon: {\n * height: 16,\n * width: 16,\n * },\n * },\n * },\n * };\n *\n * <Chat style={theme}>\n * </Chat>\n * ```\n *\n * @overrideType object\n */\n style?: DeepPartial<Theme>;\n };\n\nconst ChatWithContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const {\n children,\n client,\n closeConnectionOnBackground = true,\n enableOfflineSupport = false,\n i18nInstance,\n ImageComponent = Image,\n style,\n } = props;\n\n const [channel, setChannel] = useState<Channel<StreamChatGenerics>>();\n const [translators, setTranslators] = useState<TranslatorFunctions>({\n t: (key: string) => key,\n tDateTimeParser: (input?: string | number | Date) => Dayjs(input),\n });\n\n /**\n * Setup translators\n */\n const loadingTranslators = useStreami18n({ i18nInstance, setTranslators });\n\n /**\n * Setup connection event listeners\n */\n const { connectionRecovering, isOnline } = useIsOnline<StreamChatGenerics>(\n client,\n closeConnectionOnBackground,\n );\n\n const [initialisedDatabase, setInitialisedDatabase] = useState(false);\n\n /**\n * Setup muted user listener\n * TODO: reimplement\n */\n const mutedUsers = useMutedUsers<StreamChatGenerics>(client);\n\n const debugRef = useDebugContext();\n const isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;\n\n useEffect(() => {\n if (client) {\n client.setUserAgent(`${SDK}-${Platform.OS}-${version}`);\n // This is to disable recovery related logic in js client, since we handle it in this SDK\n client.recoverStateOnReconnect = false;\n client.persistUserOnConnectionFailure = enableOfflineSupport;\n }\n\n if (isDebugModeEnabled) {\n if (debugRef.current.setEventType) debugRef.current.setEventType('send');\n if (debugRef.current.setSendEventParams)\n debugRef.current.setSendEventParams({\n action: 'Client',\n data: client.user,\n });\n }\n }, [client, enableOfflineSupport]);\n\n const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);\n\n useEffect(() => {\n if (client.user?.id && enableOfflineSupport) {\n setInitialisedDatabase(false);\n QuickSqliteClient.initializeDatabase();\n DBSyncManager.init(client as unknown as StreamChat);\n setInitialisedDatabase(true);\n }\n }, [client?.user?.id, enableOfflineSupport]);\n\n const appSettings = useAppSettings(client, isOnline, enableOfflineSupport, initialisedDatabase);\n\n const chatContext = useCreateChatContext({\n appSettings,\n channel,\n client,\n connectionRecovering,\n enableOfflineSupport,\n ImageComponent,\n isOnline,\n mutedUsers,\n setActiveChannel,\n });\n\n useSyncDatabase({\n client,\n enableOfflineSupport,\n });\n\n if (loadingTranslators) return null;\n\n return (\n <ChatProvider<StreamChatGenerics> value={chatContext}>\n <TranslationProvider\n value={{ ...translators, userLanguage: client.user?.language || DEFAULT_USER_LANGUAGE }}\n >\n <ThemeProvider style={style}>\n <ChannelsStateProvider<StreamChatGenerics>>{children}</ChannelsStateProvider>\n </ThemeProvider>\n </TranslationProvider>\n </ChatProvider>\n );\n};\n\n/**\n * Chat - Wrapper component for Chat. The needs to be placed around any other chat components.\n * This Chat component provides the ChatContext to all other components.\n *\n * The ChatContext provides the following props:\n *\n * - channel - currently active channel\n * - client - client connection\n * - connectionRecovering - whether or not websocket is reconnecting\n * - isOnline - whether or not set user is active\n * - setActiveChannel - function to set the currently active channel\n *\n * The Chat Component takes the following generics in order:\n * - At (AttachmentType) - custom Attachment object extension\n * - Ct (ChannelType) - custom Channel object extension\n * - Co (CommandType) - custom Command string union extension\n * - Ev (EventType) - custom Event object extension\n * - Me (MessageType) - custom Message object extension\n * - Re (ReactionType) - custom Reaction object extension\n * - Us (UserType) - custom User object extension\n */\nexport const Chat = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n props: PropsWithChildren<ChatProps<StreamChatGenerics>>,\n) => {\n const { style } = useOverlayContext();\n\n return <ChatWithContext {...{ style }} {...props} />;\n};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nB,CAAC;AAuBM,IAAMkF,IAAI,GAAG,SAAPA,IAAIA,CAGfrF,KAAuD,EACpD;EACH,IAAAsF,kBAAA,GAAkB,IAAAC,iCAAiB,GAAE;IAA7B1E,KAAK,GAAAyE,kBAAA,CAALzE,KAAK;EAEb,OAAO9D,MAAA,YAAAuH,aAAA,CAACvE,eAAe,MAAAgF,SAAA;IAAOlE,KAAK,EAALA;EAAK,GAAQb,KAAK;IAAAyE,MAAA,EAAAnG,KAAA;IAAAoG,QAAA;MAAAC,QAAA,EAAApG,YAAA;MAAAqG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAI;AACtD,CAAC;AAACW,OAAA,CAAAH,IAAA,GAAAA,IAAA"}
|
|
@@ -11,7 +11,7 @@ var _react = require("react");
|
|
|
11
11
|
var dbApi = _interopRequireWildcard(require("../../../store/apis"));
|
|
12
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupport,
|
|
14
|
+
var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupport, initialisedDatabase) {
|
|
15
15
|
var _useState = (0, _react.useState)(null),
|
|
16
16
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
17
17
|
appSettings = _useState2[0],
|
|
@@ -27,20 +27,14 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
27
27
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
28
28
|
while (1) switch (_context.prev = _context.next) {
|
|
29
29
|
case 0:
|
|
30
|
-
if (
|
|
30
|
+
if (client.userID) {
|
|
31
31
|
_context.next = 2;
|
|
32
32
|
break;
|
|
33
33
|
}
|
|
34
34
|
return _context.abrupt("return");
|
|
35
35
|
case 2:
|
|
36
|
-
if (
|
|
37
|
-
_context.next =
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
return _context.abrupt("return");
|
|
41
|
-
case 4:
|
|
42
|
-
if (!(!isOnline && enableOfflineSupport)) {
|
|
43
|
-
_context.next = 8;
|
|
36
|
+
if (!(!isOnline && enableOfflineSupport && initialisedDatabase)) {
|
|
37
|
+
_context.next = 6;
|
|
44
38
|
break;
|
|
45
39
|
}
|
|
46
40
|
_appSettings = dbApi.getAppSettings({
|
|
@@ -48,11 +42,11 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
48
42
|
});
|
|
49
43
|
setAppSettings(_appSettings);
|
|
50
44
|
return _context.abrupt("return");
|
|
51
|
-
case
|
|
52
|
-
_context.prev =
|
|
53
|
-
_context.next =
|
|
45
|
+
case 6:
|
|
46
|
+
_context.prev = 6;
|
|
47
|
+
_context.next = 9;
|
|
54
48
|
return client.getAppSettings();
|
|
55
|
-
case
|
|
49
|
+
case 9:
|
|
56
50
|
_appSettings2 = _context.sent;
|
|
57
51
|
if (isMounted.current) {
|
|
58
52
|
setAppSettings(_appSettings2);
|
|
@@ -61,19 +55,19 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
61
55
|
currentUserId: client.userID
|
|
62
56
|
});
|
|
63
57
|
}
|
|
64
|
-
_context.next =
|
|
58
|
+
_context.next = 16;
|
|
65
59
|
break;
|
|
66
|
-
case
|
|
67
|
-
_context.prev =
|
|
68
|
-
_context.t0 = _context["catch"](
|
|
60
|
+
case 13:
|
|
61
|
+
_context.prev = 13;
|
|
62
|
+
_context.t0 = _context["catch"](6);
|
|
69
63
|
if (_context.t0 instanceof Error) {
|
|
70
64
|
console.error("An error occurred while getting app settings: " + _context.t0);
|
|
71
65
|
}
|
|
72
|
-
case
|
|
66
|
+
case 16:
|
|
73
67
|
case "end":
|
|
74
68
|
return _context.stop();
|
|
75
69
|
}
|
|
76
|
-
}, _callee, null, [[
|
|
70
|
+
}, _callee, null, [[6, 13]]);
|
|
77
71
|
}));
|
|
78
72
|
return _enforeAppSettings.apply(this, arguments);
|
|
79
73
|
}
|
|
@@ -81,7 +75,7 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
|
|
|
81
75
|
return function () {
|
|
82
76
|
isMounted.current = false;
|
|
83
77
|
};
|
|
84
|
-
}, [client, isOnline,
|
|
78
|
+
}, [client, isOnline, initialisedDatabase]);
|
|
85
79
|
return appSettings;
|
|
86
80
|
};
|
|
87
81
|
exports.useAppSettings = useAppSettings;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","dbApi","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","useAppSettings","client","isOnline","enableOfflineSupport","
|
|
1
|
+
{"version":3,"names":["_react","require","dbApi","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","useAppSettings","client","isOnline","enableOfflineSupport","initialisedDatabase","_useState","useState","_useState2","_slicedToArray2","appSettings","setAppSettings","isMounted","useRef","useEffect","enforeAppSettings","_enforeAppSettings","apply","arguments","_asyncToGenerator2","_regenerator","mark","_callee","_appSettings","_appSettings2","wrap","_callee$","_context","prev","next","userID","abrupt","getAppSettings","currentUserId","sent","current","upsertAppSettings","t0","Error","console","error","stop","exports"],"sources":["useAppSettings.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';\n\nimport * as dbApi from '../../../store/apis';\nimport type { DefaultStreamChatGenerics } from '../../../types/types';\nexport const useAppSettings = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n client: StreamChat<StreamChatGenerics>,\n isOnline: boolean | null,\n enableOfflineSupport: boolean,\n initialisedDatabase: boolean,\n): AppSettingsAPIResponse | null => {\n const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);\n const isMounted = useRef(true);\n\n useEffect(() => {\n async function enforeAppSettings() {\n if (!client.userID) return;\n\n if (!isOnline && enableOfflineSupport && initialisedDatabase) {\n const appSettings = dbApi.getAppSettings({ currentUserId: client.userID });\n setAppSettings(appSettings);\n return;\n }\n\n try {\n const appSettings = await client.getAppSettings();\n if (isMounted.current) {\n setAppSettings(appSettings);\n enableOfflineSupport &&\n dbApi.upsertAppSettings({\n appSettings,\n currentUserId: client.userID as string,\n });\n }\n } catch (error: unknown) {\n if (error instanceof Error) {\n console.error(`An error occurred while getting app settings: ${error}`);\n }\n }\n }\n\n enforeAppSettings();\n\n return () => {\n isMounted.current = false;\n };\n }, [client, isOnline, initialisedDatabase]);\n\n return appSettings;\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAC,uBAAA,CAAAF,OAAA;AAA6C,SAAAG,yBAA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AAC4B;gBACxB,CAAC,CAAC;cACN;cAACH,QAAA,CAAAE,IAAA;cAAA;YAAA;cAAAF,QAAA,CAAAC,IAAA;cAAAD,QAAA,CAAAU,EAAA,GAAAV,QAAA;cAED,IAAIA,QAAA,CAAAU,EAAA,YAAiBC,KAAK,EAAE;gBAC1BC,OAAO,CAACC,KAAK,oDAAAb,QAAA,CAAAU,EAAA,CAA0D;cACzE;YAAC;YAAA;cAAA,OAAAV,QAAA,CAAAc,IAAA;UAAA;QAAA,GAAAnB,OAAA;MAAA,CAEJ;MAAA,OAAAN,kBAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAEDH,iBAAiB,EAAE;IAEnB,OAAO,YAAM;MACXH,SAAS,CAACuB,OAAO,GAAG,KAAK;IAC3B,CAAC;EACH,CAAC,EAAE,CAACjC,MAAM,EAAEC,QAAQ,EAAEE,mBAAmB,CAAC,CAAC;EAE3C,OAAOK,WAAW;AACpB,CAAC;AAACgC,OAAA,CAAAzC,cAAA,GAAAA,cAAA"}
|
package/lib/module/version.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';
|
|
2
2
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
3
|
-
export declare const useAppSettings: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(client: StreamChat<StreamChatGenerics>, isOnline: boolean | null, enableOfflineSupport: boolean,
|
|
3
|
+
export declare const useAppSettings: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(client: StreamChat<StreamChatGenerics>, isOnline: boolean | null, enableOfflineSupport: boolean, initialisedDatabase: boolean) => AppSettingsAPIResponse | null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-react-native-core",
|
|
3
3
|
"description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "5.11.3-beta.
|
|
4
|
+
"version": "5.11.3-beta.4",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -167,7 +167,7 @@ const ChatWithContext = <
|
|
|
167
167
|
closeConnectionOnBackground,
|
|
168
168
|
);
|
|
169
169
|
|
|
170
|
-
const [
|
|
170
|
+
const [initialisedDatabase, setInitialisedDatabase] = useState(false);
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* Setup muted user listener
|
|
@@ -194,20 +194,20 @@ const ChatWithContext = <
|
|
|
194
194
|
data: client.user,
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
}, [client]);
|
|
197
|
+
}, [client, enableOfflineSupport]);
|
|
198
198
|
|
|
199
199
|
const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);
|
|
200
200
|
|
|
201
201
|
useEffect(() => {
|
|
202
202
|
if (client.user?.id && enableOfflineSupport) {
|
|
203
|
-
|
|
203
|
+
setInitialisedDatabase(false);
|
|
204
204
|
QuickSqliteClient.initializeDatabase();
|
|
205
205
|
DBSyncManager.init(client as unknown as StreamChat);
|
|
206
|
-
|
|
206
|
+
setInitialisedDatabase(true);
|
|
207
207
|
}
|
|
208
208
|
}, [client?.user?.id, enableOfflineSupport]);
|
|
209
209
|
|
|
210
|
-
const appSettings = useAppSettings(client, isOnline, enableOfflineSupport,
|
|
210
|
+
const appSettings = useAppSettings(client, isOnline, enableOfflineSupport, initialisedDatabase);
|
|
211
211
|
|
|
212
212
|
const chatContext = useCreateChatContext({
|
|
213
213
|
appSettings,
|
|
@@ -226,7 +226,7 @@ const ChatWithContext = <
|
|
|
226
226
|
enableOfflineSupport,
|
|
227
227
|
});
|
|
228
228
|
|
|
229
|
-
if (loadingTranslators
|
|
229
|
+
if (loadingTranslators) return null;
|
|
230
230
|
|
|
231
231
|
return (
|
|
232
232
|
<ChatProvider<StreamChatGenerics> value={chatContext}>
|
|
@@ -10,17 +10,16 @@ export const useAppSettings = <
|
|
|
10
10
|
client: StreamChat<StreamChatGenerics>,
|
|
11
11
|
isOnline: boolean | null,
|
|
12
12
|
enableOfflineSupport: boolean,
|
|
13
|
-
|
|
13
|
+
initialisedDatabase: boolean,
|
|
14
14
|
): AppSettingsAPIResponse | null => {
|
|
15
15
|
const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);
|
|
16
16
|
const isMounted = useRef(true);
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
async function enforeAppSettings() {
|
|
20
|
-
if (initialisingDatabase) return;
|
|
21
20
|
if (!client.userID) return;
|
|
22
21
|
|
|
23
|
-
if (!isOnline && enableOfflineSupport) {
|
|
22
|
+
if (!isOnline && enableOfflineSupport && initialisedDatabase) {
|
|
24
23
|
const appSettings = dbApi.getAppSettings({ currentUserId: client.userID });
|
|
25
24
|
setAppSettings(appSettings);
|
|
26
25
|
return;
|
|
@@ -48,7 +47,7 @@ export const useAppSettings = <
|
|
|
48
47
|
return () => {
|
|
49
48
|
isMounted.current = false;
|
|
50
49
|
};
|
|
51
|
-
}, [client, isOnline,
|
|
50
|
+
}, [client, isOnline, initialisedDatabase]);
|
|
52
51
|
|
|
53
52
|
return appSettings;
|
|
54
53
|
};
|
package/src/version.json
CHANGED