stream-chat-react-native-core 4.7.0-beta.6 → 4.7.1-beta.2

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.
Files changed (167) hide show
  1. package/lib/commonjs/components/Attachment/Card.js +61 -21
  2. package/lib/commonjs/components/Attachment/Card.js.map +1 -1
  3. package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
  4. package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
  5. package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
  6. package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
  7. package/lib/commonjs/components/Reply/Reply.js +12 -12
  8. package/lib/commonjs/components/Reply/Reply.js.map +1 -1
  9. package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
  10. package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
  11. package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
  12. package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  13. package/lib/commonjs/contexts/channelContext/ChannelContext.js +14 -4
  14. package/lib/commonjs/contexts/channelContext/ChannelContext.js.map +1 -1
  15. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js +14 -4
  16. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
  17. package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
  18. package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
  19. package/lib/commonjs/contexts/chatContext/ChatContext.js +14 -4
  20. package/lib/commonjs/contexts/chatContext/ChatContext.js.map +1 -1
  21. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
  22. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  23. package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js +2 -2
  24. package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js.map +1 -1
  25. package/lib/commonjs/contexts/messageContext/MessageContext.js +14 -4
  26. package/lib/commonjs/contexts/messageContext/MessageContext.js.map +1 -1
  27. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +16 -6
  28. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  29. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
  30. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  31. package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
  32. package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
  33. package/lib/commonjs/contexts/messagesContext/MessagesContext.js +14 -4
  34. package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
  35. package/lib/commonjs/contexts/overlayContext/OverlayContext.js +13 -3
  36. package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
  37. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +12 -12
  38. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
  39. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
  40. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  41. package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
  42. package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
  43. package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js +14 -4
  44. package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
  45. package/lib/commonjs/contexts/themeContext/ThemeContext.js +13 -7
  46. package/lib/commonjs/contexts/themeContext/ThemeContext.js.map +1 -1
  47. package/lib/commonjs/contexts/themeContext/utils/theme.js +9 -0
  48. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  49. package/lib/commonjs/contexts/threadContext/ThreadContext.js +14 -4
  50. package/lib/commonjs/contexts/threadContext/ThreadContext.js.map +1 -1
  51. package/lib/commonjs/contexts/translationContext/TranslationContext.js +15 -6
  52. package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
  53. package/lib/commonjs/contexts/typingContext/TypingContext.js +14 -4
  54. package/lib/commonjs/contexts/typingContext/TypingContext.js.map +1 -1
  55. package/lib/commonjs/contexts/utils/defaultBaseContextValue.js +7 -0
  56. package/lib/commonjs/contexts/utils/defaultBaseContextValue.js.map +1 -0
  57. package/lib/commonjs/contexts/utils/isTestEnvironment.js +11 -0
  58. package/lib/commonjs/contexts/utils/isTestEnvironment.js.map +1 -0
  59. package/lib/commonjs/mock-builders/mock.js +30 -5
  60. package/lib/commonjs/mock-builders/mock.js.map +1 -1
  61. package/lib/commonjs/version.json +1 -1
  62. package/lib/module/components/Attachment/Card.js +61 -21
  63. package/lib/module/components/Attachment/Card.js.map +1 -1
  64. package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
  65. package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
  66. package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
  67. package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
  68. package/lib/module/components/Reply/Reply.js +12 -12
  69. package/lib/module/components/Reply/Reply.js.map +1 -1
  70. package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
  71. package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
  72. package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
  73. package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  74. package/lib/module/contexts/channelContext/ChannelContext.js +14 -4
  75. package/lib/module/contexts/channelContext/ChannelContext.js.map +1 -1
  76. package/lib/module/contexts/channelsContext/ChannelsContext.js +14 -4
  77. package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
  78. package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
  79. package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
  80. package/lib/module/contexts/chatContext/ChatContext.js +14 -4
  81. package/lib/module/contexts/chatContext/ChatContext.js.map +1 -1
  82. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
  83. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  84. package/lib/module/contexts/keyboardContext/KeyboardContext.js +2 -2
  85. package/lib/module/contexts/keyboardContext/KeyboardContext.js.map +1 -1
  86. package/lib/module/contexts/messageContext/MessageContext.js +14 -4
  87. package/lib/module/contexts/messageContext/MessageContext.js.map +1 -1
  88. package/lib/module/contexts/messageInputContext/MessageInputContext.js +16 -6
  89. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  90. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
  91. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  92. package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
  93. package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
  94. package/lib/module/contexts/messagesContext/MessagesContext.js +14 -4
  95. package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
  96. package/lib/module/contexts/overlayContext/OverlayContext.js +13 -3
  97. package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
  98. package/lib/module/contexts/overlayContext/OverlayProvider.js +12 -12
  99. package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
  100. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
  101. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  102. package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
  103. package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
  104. package/lib/module/contexts/suggestionsContext/SuggestionsContext.js +14 -4
  105. package/lib/module/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
  106. package/lib/module/contexts/themeContext/ThemeContext.js +13 -7
  107. package/lib/module/contexts/themeContext/ThemeContext.js.map +1 -1
  108. package/lib/module/contexts/themeContext/utils/theme.js +9 -0
  109. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  110. package/lib/module/contexts/threadContext/ThreadContext.js +14 -4
  111. package/lib/module/contexts/threadContext/ThreadContext.js.map +1 -1
  112. package/lib/module/contexts/translationContext/TranslationContext.js +15 -6
  113. package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
  114. package/lib/module/contexts/typingContext/TypingContext.js +14 -4
  115. package/lib/module/contexts/typingContext/TypingContext.js.map +1 -1
  116. package/lib/module/contexts/utils/defaultBaseContextValue.js +7 -0
  117. package/lib/module/contexts/utils/defaultBaseContextValue.js.map +1 -0
  118. package/lib/module/contexts/utils/isTestEnvironment.js +11 -0
  119. package/lib/module/contexts/utils/isTestEnvironment.js.map +1 -0
  120. package/lib/module/mock-builders/mock.js +30 -5
  121. package/lib/module/mock-builders/mock.js.map +1 -1
  122. package/lib/module/version.json +1 -1
  123. package/lib/typescript/contexts/__tests__/index.test.d.ts +1 -0
  124. package/lib/typescript/contexts/keyboardContext/KeyboardContext.d.ts +6 -2
  125. package/lib/typescript/contexts/themeContext/ThemeContext.d.ts +5 -2
  126. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +6 -0
  127. package/lib/typescript/contexts/utils/defaultBaseContextValue.d.ts +1 -0
  128. package/lib/typescript/contexts/utils/isTestEnvironment.d.ts +1 -0
  129. package/lib/typescript/mock-builders/mock.d.ts +2 -2
  130. package/package.json +1 -1
  131. package/src/components/Attachment/Card.tsx +29 -6
  132. package/src/components/Attachment/__tests__/Attachment.test.js +0 -14
  133. package/src/components/Attachment/__tests__/Giphy.test.js +9 -5
  134. package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx +1 -0
  135. package/src/components/ImageGallery/components/__tests__/ImageGalleryHeader.test.tsx +5 -3
  136. package/src/components/MessageInput/SendMessageDisallowedIndicator.tsx +1 -0
  137. package/src/components/MessageInput/__tests__/FileUploadPreview.test.js +1 -1
  138. package/src/components/Reply/Reply.tsx +6 -3
  139. package/src/contexts/__tests__/index.test.tsx +103 -0
  140. package/src/contexts/activeChannelsRefContext/ActiveChannelsRefContext.tsx +1 -0
  141. package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx +18 -4
  142. package/src/contexts/channelContext/ChannelContext.tsx +18 -2
  143. package/src/contexts/channelsContext/ChannelsContext.tsx +18 -2
  144. package/src/contexts/channelsStateContext/ChannelsStateContext.tsx +19 -10
  145. package/src/contexts/chatContext/ChatContext.tsx +15 -2
  146. package/src/contexts/imageGalleryContext/ImageGalleryContext.tsx +18 -3
  147. package/src/contexts/keyboardContext/KeyboardContext.tsx +2 -1
  148. package/src/contexts/messageContext/MessageContext.tsx +19 -2
  149. package/src/contexts/messageInputContext/MessageInputContext.tsx +22 -4
  150. package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +19 -3
  151. package/src/contexts/messageOverlayContext/hooks/useResettableState.test.tsx +1 -0
  152. package/src/contexts/messagesContext/MessagesContext.tsx +19 -2
  153. package/src/contexts/overlayContext/OverlayContext.tsx +17 -2
  154. package/src/contexts/overlayContext/OverlayProvider.tsx +1 -0
  155. package/src/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.tsx +18 -3
  156. package/src/contexts/paginatedMessageListContext/PaginatedMessageListContext.tsx +15 -3
  157. package/src/contexts/suggestionsContext/SuggestionsContext.tsx +19 -2
  158. package/src/contexts/suggestionsContext/__tests__/Suggestions.test.js +1 -0
  159. package/src/contexts/themeContext/ThemeContext.tsx +19 -5
  160. package/src/contexts/themeContext/utils/theme.ts +15 -0
  161. package/src/contexts/threadContext/ThreadContext.tsx +16 -2
  162. package/src/contexts/translationContext/TranslationContext.tsx +18 -4
  163. package/src/contexts/typingContext/TypingContext.tsx +17 -2
  164. package/src/contexts/utils/defaultBaseContextValue.ts +1 -0
  165. package/src/contexts/utils/isTestEnvironment.ts +1 -0
  166. package/src/mock-builders/mock.js +16 -3
  167. package/src/version.json +1 -1
@@ -4,7 +4,10 @@ import type { ChannelState } from 'stream-chat';
4
4
 
5
5
  import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
6
6
  import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
7
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
8
+
7
9
  import { getDisplayName } from '../utils/getDisplayName';
10
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
8
11
 
9
12
  export type ThreadContextValue<
10
13
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -21,7 +24,7 @@ export type ThreadContextValue<
21
24
  threadMessages: ChannelState<StreamChatGenerics>['threads'][string];
22
25
  };
23
26
 
24
- export const ThreadContext = React.createContext({} as ThreadContextValue);
27
+ export const ThreadContext = React.createContext(DEFAULT_BASE_CONTEXT_VALUE as ThreadContextValue);
25
28
 
26
29
  export const ThreadProvider = <
27
30
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -38,8 +41,19 @@ export const ThreadProvider = <
38
41
 
39
42
  export const useThreadContext = <
40
43
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
41
- >() => useContext(ThreadContext) as unknown as ThreadContextValue<StreamChatGenerics>;
44
+ >() => {
45
+ const contextValue = useContext(
46
+ ThreadContext,
47
+ ) as unknown as ThreadContextValue<StreamChatGenerics>;
48
+
49
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
50
+ throw new Error(
51
+ `The useThreadContext hook was called outside of the ThreadContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
52
+ );
53
+ }
42
54
 
55
+ return contextValue;
56
+ };
43
57
  /**
44
58
  * Typescript currently does not support partial inference so if ThreadContext
45
59
  * typing is desired while using the HOC withThreadContextContext the Props for the
@@ -6,8 +6,8 @@ import type { TFunction } from 'i18next';
6
6
  import type { Moment } from 'moment';
7
7
 
8
8
  import type { DefaultStreamChatGenerics } from '../../types/types';
9
-
10
9
  import { getDisplayName } from '../utils/getDisplayName';
10
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
11
11
 
12
12
  export const isDayOrMoment = (output: TDateTimeParserOutput): output is Dayjs.Dayjs | Moment =>
13
13
  (output as Dayjs.Dayjs | Moment).isSame != null;
@@ -23,10 +23,14 @@ export type TranslationContextValue = {
23
23
  tDateTimeParser: TDateTimeParser;
24
24
  };
25
25
 
26
- export const TranslationContext = React.createContext<TranslationContextValue>({
26
+ const defaultTranslationContextValue: TranslationContextValue = {
27
27
  t: (key: string) => key,
28
28
  tDateTimeParser: (input) => Dayjs(input),
29
- });
29
+ };
30
+
31
+ export const TranslationContext = React.createContext<TranslationContextValue>(
32
+ defaultTranslationContextValue,
33
+ );
30
34
 
31
35
  export const TranslationProvider: React.FC<{
32
36
  value: TranslationContextValue;
@@ -34,7 +38,17 @@ export const TranslationProvider: React.FC<{
34
38
  <TranslationContext.Provider value={value}>{children}</TranslationContext.Provider>
35
39
  );
36
40
 
37
- export const useTranslationContext = () => useContext(TranslationContext);
41
+ export const useTranslationContext = () => {
42
+ const contextValue = useContext(TranslationContext);
43
+
44
+ if (contextValue === defaultTranslationContextValue && !isTestEnvironment()) {
45
+ throw new Error(
46
+ `The useTranslationContext hook was called outside the TranslationContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider)(https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
47
+ );
48
+ }
49
+
50
+ return contextValue;
51
+ };
38
52
 
39
53
  export const withTranslationContext = <
40
54
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -3,7 +3,10 @@ import React, { PropsWithChildren, useContext } from 'react';
3
3
  import type { ChannelState } from 'stream-chat';
4
4
 
5
5
  import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
6
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
7
+
6
8
  import { getDisplayName } from '../utils/getDisplayName';
9
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
7
10
 
8
11
  export type TypingContextValue<
9
12
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -11,7 +14,7 @@ export type TypingContextValue<
11
14
  typing: ChannelState<StreamChatGenerics>['typing'];
12
15
  };
13
16
 
14
- export const TypingContext = React.createContext({} as TypingContextValue);
17
+ export const TypingContext = React.createContext(DEFAULT_BASE_CONTEXT_VALUE as TypingContextValue);
15
18
 
16
19
  export const TypingProvider = <
17
20
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -28,7 +31,19 @@ export const TypingProvider = <
28
31
 
29
32
  export const useTypingContext = <
30
33
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
31
- >() => useContext(TypingContext) as unknown as TypingContextValue<StreamChatGenerics>;
34
+ >() => {
35
+ const contextValue = useContext(
36
+ TypingContext,
37
+ ) as unknown as TypingContextValue<StreamChatGenerics>;
38
+
39
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
40
+ throw new Error(
41
+ `The useTypingContext hook was called outside of the TypingContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
42
+ );
43
+ }
44
+
45
+ return contextValue;
46
+ };
32
47
 
33
48
  /**
34
49
  * Typescript currently does not support partial inference so if TypingContext
@@ -0,0 +1 @@
1
+ export const DEFAULT_BASE_CONTEXT_VALUE = {};
@@ -0,0 +1 @@
1
+ export const isTestEnvironment = () => process.env.NODE_ENV === 'test';
@@ -17,7 +17,9 @@ const setUser = (client, user) =>
17
17
  resolve();
18
18
  });
19
19
 
20
- function mockClient(client) {
20
+ function mockClient(client, options = {}) {
21
+ const { disableAppSettings = true } = options;
22
+
21
23
  jest.spyOn(client, '_setToken').mockImplementation();
22
24
  jest.spyOn(client, '_setupConnection').mockImplementation();
23
25
  client.tokenManager = {
@@ -25,15 +27,26 @@ function mockClient(client) {
25
27
  tokenReady: jest.fn(() => true),
26
28
  };
27
29
  client.setUser = setUser.bind(null, client);
30
+
31
+ if (disableAppSettings) {
32
+ client.getAppSettings = jest.fn(() => ({}));
33
+ }
34
+
28
35
  return client;
29
36
  }
30
37
 
31
- export const getTestClient = () => mockClient(new StreamChat(apiKey));
38
+ export const getTestClient = (options = {}) => mockClient(new StreamChat(apiKey), options);
32
39
 
33
- export const getTestClientWithUser = async (user) => {
40
+ export const getTestClientWithUser = async (user, options = {}) => {
41
+ const { disableAppSettings = true } = options;
34
42
  const client = mockClient(new StreamChat(apiKey));
35
43
  await setUser(client, user);
36
44
  client.wsPromise = Promise.resolve();
45
+
46
+ if (disableAppSettings) {
47
+ client.getAppSettings = jest.fn(() => ({}));
48
+ }
49
+
37
50
  return client;
38
51
  };
39
52
 
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "4.7.0-beta.6"
2
+ "version": "4.7.1-beta.2"
3
3
  }