stream-chat-react-native-core 5.11.3-beta.2 → 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.
@@ -65,6 +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)(false),
69
+ _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
70
+ initialisedDatabase = _useState6[0],
71
+ setInitialisedDatabase = _useState6[1];
68
72
  var mutedUsers = (0, _useMutedUsers.useMutedUsers)(client);
69
73
  var debugRef = (0, _DebugContext.useDebugContext)();
70
74
  var isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;
@@ -81,11 +85,20 @@ var ChatWithContext = function ChatWithContext(props) {
81
85
  data: client.user
82
86
  });
83
87
  }
84
- }, [client]);
88
+ }, [client, enableOfflineSupport]);
85
89
  var setActiveChannel = function setActiveChannel(newChannel) {
86
90
  return setChannel(newChannel);
87
91
  };
88
- var appSettings = (0, _useAppSettings.useAppSettings)(client, isOnline, enableOfflineSupport);
92
+ (0, _react.useEffect)(function () {
93
+ var _client$user;
94
+ if ((_client$user = client.user) != null && _client$user.id && enableOfflineSupport) {
95
+ setInitialisedDatabase(false);
96
+ _QuickSqliteClient.QuickSqliteClient.initializeDatabase();
97
+ _DBSyncManager.DBSyncManager.init(client);
98
+ setInitialisedDatabase(true);
99
+ }
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, initialisedDatabase);
89
102
  var chatContext = (0, _useCreateChatContext.useCreateChatContext)({
90
103
  appSettings: appSettings,
91
104
  channel: channel,
@@ -97,13 +110,6 @@ var ChatWithContext = function ChatWithContext(props) {
97
110
  mutedUsers: mutedUsers,
98
111
  setActiveChannel: setActiveChannel
99
112
  });
100
- (0, _react.useEffect)(function () {
101
- var _client$user;
102
- if ((_client$user = client.user) != null && _client$user.id && enableOfflineSupport) {
103
- _QuickSqliteClient.QuickSqliteClient.initializeDatabase();
104
- _DBSyncManager.DBSyncManager.init(client);
105
- }
106
- }, [client == null ? void 0 : (_client$user2 = client.user) == null ? void 0 : _client$user2.id]);
107
113
  (0, _useSyncDatabase.useSyncDatabase)({
108
114
  client: client,
109
115
  enableOfflineSupport: enableOfflineSupport
@@ -114,7 +120,7 @@ var ChatWithContext = function ChatWithContext(props) {
114
120
  __self: _this,
115
121
  __source: {
116
122
  fileName: _jsxFileName,
117
- lineNumber: 228,
123
+ lineNumber: 232,
118
124
  columnNumber: 5
119
125
  }
120
126
  }, _react["default"].createElement(_TranslationContext.TranslationProvider, {
@@ -124,7 +130,7 @@ var ChatWithContext = function ChatWithContext(props) {
124
130
  __self: _this,
125
131
  __source: {
126
132
  fileName: _jsxFileName,
127
- lineNumber: 229,
133
+ lineNumber: 233,
128
134
  columnNumber: 7
129
135
  }
130
136
  }, _react["default"].createElement(_ThemeContext.ThemeProvider, {
@@ -132,14 +138,14 @@ var ChatWithContext = function ChatWithContext(props) {
132
138
  __self: _this,
133
139
  __source: {
134
140
  fileName: _jsxFileName,
135
- lineNumber: 232,
141
+ lineNumber: 236,
136
142
  columnNumber: 9
137
143
  }
138
144
  }, _react["default"].createElement(_ChannelsStateContext.ChannelsStateProvider, {
139
145
  __self: _this,
140
146
  __source: {
141
147
  fileName: _jsxFileName,
142
- lineNumber: 233,
148
+ lineNumber: 237,
143
149
  columnNumber: 11
144
150
  }
145
151
  }, children))));
@@ -153,7 +159,7 @@ var Chat = function Chat(props) {
153
159
  __self: _this,
154
160
  __source: {
155
161
  fileName: _jsxFileName,
156
- lineNumber: 268,
162
+ lineNumber: 272,
157
163
  columnNumber: 10
158
164
  }
159
165
  }));
@@ -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","mutedUsers","useMutedUsers","debugRef","useDebugContext","isDebugModeEnabled","__DEV__","current","useEffect","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","persistUserOnConnectionFailure","setEventType","setSendEventParams","action","data","user","setActiveChannel","newChannel","appSettings","useAppSettings","chatContext","useCreateChatContext","_client$user","id","QuickSqliteClient","initializeDatabase","DBSyncManager","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 /**\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 const appSettings = useAppSettings(client, isOnline, enableOfflineSupport);\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 useEffect(() => {\n if (client.user?.id && enableOfflineSupport) {\n QuickSqliteClient.initializeDatabase();\n DBSyncManager.init(client as unknown as StreamChat);\n }\n }, [client?.user?.id]);\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,O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AClE,KAAK,EAAEA,KAAM;IAAAwD,MAAA,EAAA/F,KAAA;IAAAgG,QAAA;MAAAC,QAAA,EAAAhG,YAAA;MAAAiG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAC1B1H,MAAA,YAAAmH,aAAA,CAACxG,qBAAA,CAAAsH,qBAAqB;IAAAX,MAAA,EAAA/F,KAAA;IAAAgG,QAAA;MAAAC,QAAA,EAAAhG,YAAA;MAAAiG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAsBtE,QAAQ,CAAyB,CAC/D,CACI,CACT;AAEnB,CAAC;AAuBM,IAAM8E,IAAI,GAAG,SAAPA,IAAIA,CAGfjF,KAAuD,EACpD;EACH,IAAAkF,kBAAA,GAAkB,IAAAC,iCAAiB,GAAE;IAA7BtE,KAAK,GAAAqE,kBAAA,CAALrE,KAAK;EAEb,OAAO9D,MAAA,YAAAmH,aAAA,CAACnE,eAAe,MAAA4E,SAAA;IAAO9D,KAAK,EAALA;EAAK,GAAQb,KAAK;IAAAqE,MAAA,EAAA/F,KAAA;IAAAgG,QAAA;MAAAC,QAAA,EAAAhG,YAAA;MAAAiG,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,IAAAkB,kBAAA,GAAAlB,OAAA;AAEA,IAAAmB,cAAA,GAAAnB,OAAA;AAEA,IAAAoB,QAAA,GAAApB,OAAA;AAA6C,IAAAqB,KAAA;EAAAC,YAAA;AAAA,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAA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,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],
@@ -33,7 +33,7 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
33
33
  }
34
34
  return _context.abrupt("return");
35
35
  case 2:
36
- if (!(!isOnline && enableOfflineSupport)) {
36
+ if (!(!isOnline && enableOfflineSupport && initialisedDatabase)) {
37
37
  _context.next = 6;
38
38
  break;
39
39
  }
@@ -75,7 +75,7 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
75
75
  return function () {
76
76
  isMounted.current = false;
77
77
  };
78
- }, [client, isOnline]);
78
+ }, [client, isOnline, initialisedDatabase]);
79
79
  return appSettings;
80
80
  };
81
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","_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): 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) {\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]);\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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Ac,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,CAAChC,MAAM,EAAEC,QAAQ,CAAC,CAAC;EAEtB,OAAOM,WAAW;AACpB,CAAC;AAACgC,OAAA,CAAAxC,cAAA,GAAAA,cAAA"}
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,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAA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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)(false),
69
+ _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
70
+ initialisedDatabase = _useState6[0],
71
+ setInitialisedDatabase = _useState6[1];
68
72
  var mutedUsers = (0, _useMutedUsers.useMutedUsers)(client);
69
73
  var debugRef = (0, _DebugContext.useDebugContext)();
70
74
  var isDebugModeEnabled = __DEV__ && debugRef && debugRef.current;
@@ -81,11 +85,20 @@ var ChatWithContext = function ChatWithContext(props) {
81
85
  data: client.user
82
86
  });
83
87
  }
84
- }, [client]);
88
+ }, [client, enableOfflineSupport]);
85
89
  var setActiveChannel = function setActiveChannel(newChannel) {
86
90
  return setChannel(newChannel);
87
91
  };
88
- var appSettings = (0, _useAppSettings.useAppSettings)(client, isOnline, enableOfflineSupport);
92
+ (0, _react.useEffect)(function () {
93
+ var _client$user;
94
+ if ((_client$user = client.user) != null && _client$user.id && enableOfflineSupport) {
95
+ setInitialisedDatabase(false);
96
+ _QuickSqliteClient.QuickSqliteClient.initializeDatabase();
97
+ _DBSyncManager.DBSyncManager.init(client);
98
+ setInitialisedDatabase(true);
99
+ }
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, initialisedDatabase);
89
102
  var chatContext = (0, _useCreateChatContext.useCreateChatContext)({
90
103
  appSettings: appSettings,
91
104
  channel: channel,
@@ -97,13 +110,6 @@ var ChatWithContext = function ChatWithContext(props) {
97
110
  mutedUsers: mutedUsers,
98
111
  setActiveChannel: setActiveChannel
99
112
  });
100
- (0, _react.useEffect)(function () {
101
- var _client$user;
102
- if ((_client$user = client.user) != null && _client$user.id && enableOfflineSupport) {
103
- _QuickSqliteClient.QuickSqliteClient.initializeDatabase();
104
- _DBSyncManager.DBSyncManager.init(client);
105
- }
106
- }, [client == null ? void 0 : (_client$user2 = client.user) == null ? void 0 : _client$user2.id]);
107
113
  (0, _useSyncDatabase.useSyncDatabase)({
108
114
  client: client,
109
115
  enableOfflineSupport: enableOfflineSupport
@@ -114,7 +120,7 @@ var ChatWithContext = function ChatWithContext(props) {
114
120
  __self: _this,
115
121
  __source: {
116
122
  fileName: _jsxFileName,
117
- lineNumber: 228,
123
+ lineNumber: 232,
118
124
  columnNumber: 5
119
125
  }
120
126
  }, _react["default"].createElement(_TranslationContext.TranslationProvider, {
@@ -124,7 +130,7 @@ var ChatWithContext = function ChatWithContext(props) {
124
130
  __self: _this,
125
131
  __source: {
126
132
  fileName: _jsxFileName,
127
- lineNumber: 229,
133
+ lineNumber: 233,
128
134
  columnNumber: 7
129
135
  }
130
136
  }, _react["default"].createElement(_ThemeContext.ThemeProvider, {
@@ -132,14 +138,14 @@ var ChatWithContext = function ChatWithContext(props) {
132
138
  __self: _this,
133
139
  __source: {
134
140
  fileName: _jsxFileName,
135
- lineNumber: 232,
141
+ lineNumber: 236,
136
142
  columnNumber: 9
137
143
  }
138
144
  }, _react["default"].createElement(_ChannelsStateContext.ChannelsStateProvider, {
139
145
  __self: _this,
140
146
  __source: {
141
147
  fileName: _jsxFileName,
142
- lineNumber: 233,
148
+ lineNumber: 237,
143
149
  columnNumber: 11
144
150
  }
145
151
  }, children))));
@@ -153,7 +159,7 @@ var Chat = function Chat(props) {
153
159
  __self: _this,
154
160
  __source: {
155
161
  fileName: _jsxFileName,
156
- lineNumber: 268,
162
+ lineNumber: 272,
157
163
  columnNumber: 10
158
164
  }
159
165
  }));
@@ -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","mutedUsers","useMutedUsers","debugRef","useDebugContext","isDebugModeEnabled","__DEV__","current","useEffect","setUserAgent","SDK","Platform","OS","version","recoverStateOnReconnect","persistUserOnConnectionFailure","setEventType","setSendEventParams","action","data","user","setActiveChannel","newChannel","appSettings","useAppSettings","chatContext","useCreateChatContext","_client$user","id","QuickSqliteClient","initializeDatabase","DBSyncManager","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 /**\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 const appSettings = useAppSettings(client, isOnline, enableOfflineSupport);\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 useEffect(() => {\n if (client.user?.id && enableOfflineSupport) {\n QuickSqliteClient.initializeDatabase();\n DBSyncManager.init(client as unknown as StreamChat);\n }\n }, [client?.user?.id]);\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,IAAAkB,kBAAA,GAAAlB,OAAA;AAEA,IAAAmB,cAAA,GAAAnB,OAAA;AAEA,IAAAoB,QAAA,GAAApB,OAAA;AAA6C,IAAAqB,KAAA;EAAAC,YAAA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H,aAAA,CAACxG,qBAAA,CAAAsH,qBAAqB;IAAAX,MAAA,EAAA/F,KAAA;IAAAgG,QAAA;MAAAC,QAAA,EAAAhG,YAAA;MAAAiG,UAAA;MAAAC,YAAA;IAAA;EAAA,GAAsBtE,QAAQ,CAAyB,CAC/D,CACI,CACT;AAEnB,CAAC;AAuBM,IAAM8E,IAAI,GAAG,SAAPA,IAAIA,CAGfjF,KAAuD,EACpD;EACH,IAAAkF,kBAAA,GAAkB,IAAAC,iCAAiB,GAAE;IAA7BtE,KAAK,GAAAqE,kBAAA,CAALrE,KAAK;EAEb,OAAO9D,MAAA,YAAAmH,aAAA,CAACnE,eAAe,MAAA4E,SAAA;IAAO9D,KAAK,EAALA;EAAK,GAAQb,KAAK;IAAAqE,MAAA,EAAA/F,KAAA;IAAAgG,QAAA;MAAAC,QAAA,EAAAhG,YAAA;MAAAiG,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,IAAAkB,kBAAA,GAAAlB,OAAA;AAEA,IAAAmB,cAAA,GAAAnB,OAAA;AAEA,IAAAoB,QAAA,GAAApB,OAAA;AAA6C,IAAAqB,KAAA;EAAAC,YAAA;AAAA,SAAAC,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,SAAAzB,wBAAA6B,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,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AC5G,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],
@@ -33,7 +33,7 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
33
33
  }
34
34
  return _context.abrupt("return");
35
35
  case 2:
36
- if (!(!isOnline && enableOfflineSupport)) {
36
+ if (!(!isOnline && enableOfflineSupport && initialisedDatabase)) {
37
37
  _context.next = 6;
38
38
  break;
39
39
  }
@@ -75,7 +75,7 @@ var useAppSettings = function useAppSettings(client, isOnline, enableOfflineSupp
75
75
  return function () {
76
76
  isMounted.current = false;
77
77
  };
78
- }, [client, isOnline]);
78
+ }, [client, isOnline, initialisedDatabase]);
79
79
  return appSettings;
80
80
  };
81
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","_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): 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) {\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]);\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,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AACuB,OAAO,GAAG,KAAK;IAC3B,CAAC;EACH,CAAC,EAAE,CAAChC,MAAM,EAAEC,QAAQ,CAAC,CAAC;EAEtB,OAAOM,WAAW;AACpB,CAAC;AAACgC,OAAA,CAAAxC,cAAA,GAAAA,cAAA"}
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,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YA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cAAAJ,QAAA,CAAAC,IAAA;cAAAD,QAAA,CAAAE,IAAA;cAAA,OAKF3B,MAAM,CAAC8B,cAAc,EAAE;YAAA;cAA3CtB,aAAW,GAAAiB,QAAA,CAAAO,IAAA;cACjB,IAAItB,SAAS,CAACuB,OAAO,EAAE;gBACrBxB,cAAc,CAACD,aAAW,CAAC;gBAC3BN,oBAAoB,IAClB3B,KAAK,CAAC2D,iBAAiB,CAAC;kBACtB1B,WAAW,EAAXA,aAAW;kBACXuB,aAAa,EAAE/B,MAAM,CAAC4B;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"}
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.11.3-beta.2"
2
+ "version": "5.11.3-beta.4"
3
3
  }
@@ -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) => AppSettingsAPIResponse | null;
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.2",
4
+ "version": "5.11.3-beta.4",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -167,6 +167,8 @@ const ChatWithContext = <
167
167
  closeConnectionOnBackground,
168
168
  );
169
169
 
170
+ const [initialisedDatabase, setInitialisedDatabase] = useState(false);
171
+
170
172
  /**
171
173
  * Setup muted user listener
172
174
  * TODO: reimplement
@@ -192,11 +194,20 @@ const ChatWithContext = <
192
194
  data: client.user,
193
195
  });
194
196
  }
195
- }, [client]);
197
+ }, [client, enableOfflineSupport]);
196
198
 
197
199
  const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);
198
200
 
199
- const appSettings = useAppSettings(client, isOnline, enableOfflineSupport);
201
+ useEffect(() => {
202
+ if (client.user?.id && enableOfflineSupport) {
203
+ setInitialisedDatabase(false);
204
+ QuickSqliteClient.initializeDatabase();
205
+ DBSyncManager.init(client as unknown as StreamChat);
206
+ setInitialisedDatabase(true);
207
+ }
208
+ }, [client?.user?.id, enableOfflineSupport]);
209
+
210
+ const appSettings = useAppSettings(client, isOnline, enableOfflineSupport, initialisedDatabase);
200
211
 
201
212
  const chatContext = useCreateChatContext({
202
213
  appSettings,
@@ -210,13 +221,6 @@ const ChatWithContext = <
210
221
  setActiveChannel,
211
222
  });
212
223
 
213
- useEffect(() => {
214
- if (client.user?.id && enableOfflineSupport) {
215
- QuickSqliteClient.initializeDatabase();
216
- DBSyncManager.init(client as unknown as StreamChat);
217
- }
218
- }, [client?.user?.id]);
219
-
220
224
  useSyncDatabase({
221
225
  client,
222
226
  enableOfflineSupport,
@@ -22,6 +22,7 @@ describe('useAppSettings', () => {
22
22
  } as unknown as StreamChat,
23
23
  isOnline,
24
24
  false,
25
+ false,
25
26
  );
26
27
 
27
28
  return <Text>{JSON.stringify(appSettings)}</Text>;
@@ -10,6 +10,7 @@ export const useAppSettings = <
10
10
  client: StreamChat<StreamChatGenerics>,
11
11
  isOnline: boolean | null,
12
12
  enableOfflineSupport: boolean,
13
+ initialisedDatabase: boolean,
13
14
  ): AppSettingsAPIResponse | null => {
14
15
  const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);
15
16
  const isMounted = useRef(true);
@@ -18,7 +19,7 @@ export const useAppSettings = <
18
19
  async function enforeAppSettings() {
19
20
  if (!client.userID) return;
20
21
 
21
- if (!isOnline && enableOfflineSupport) {
22
+ if (!isOnline && enableOfflineSupport && initialisedDatabase) {
22
23
  const appSettings = dbApi.getAppSettings({ currentUserId: client.userID });
23
24
  setAppSettings(appSettings);
24
25
  return;
@@ -46,7 +47,7 @@ export const useAppSettings = <
46
47
  return () => {
47
48
  isMounted.current = false;
48
49
  };
49
- }, [client, isOnline]);
50
+ }, [client, isOnline, initialisedDatabase]);
50
51
 
51
52
  return appSettings;
52
53
  };
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.11.3-beta.2"
2
+ "version": "5.11.3-beta.4"
3
3
  }