stream-chat-react-native-core 4.7.0 → 4.7.1

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
@@ -0,0 +1,11 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.isTestEnvironment = void 0;
5
+
6
+ var isTestEnvironment = function isTestEnvironment() {
7
+ return process.env.NODE_ENV === 'test';
8
+ };
9
+
10
+ exports.isTestEnvironment = isTestEnvironment;
11
+ //# sourceMappingURL=isTestEnvironment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["isTestEnvironment.ts"],"names":["isTestEnvironment","process","env","NODE_ENV"],"mappings":";;;;;AAAO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB;AAAA,SAAMC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAA/B;AAAA,CAA1B","sourcesContent":["export const isTestEnvironment = () => process.env.NODE_ENV === 'test';\n"]}
@@ -29,6 +29,9 @@ var setUser = function setUser(client, user) {
29
29
  };
30
30
 
31
31
  function mockClient(client) {
32
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
33
+ var _options$disableAppSe = options.disableAppSettings,
34
+ disableAppSettings = _options$disableAppSe === void 0 ? true : _options$disableAppSe;
32
35
  jest.spyOn(client, '_setToken').mockImplementation();
33
36
  jest.spyOn(client, '_setupConnection').mockImplementation();
34
37
  client.tokenManager = {
@@ -40,31 +43,53 @@ function mockClient(client) {
40
43
  })
41
44
  };
42
45
  client.setUser = setUser.bind(null, client);
46
+
47
+ if (disableAppSettings) {
48
+ client.getAppSettings = jest.fn(function () {
49
+ return {};
50
+ });
51
+ }
52
+
43
53
  return client;
44
54
  }
45
55
 
46
56
  var getTestClient = function getTestClient() {
47
- return mockClient(new _streamChat.StreamChat(apiKey));
57
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
58
+ return mockClient(new _streamChat.StreamChat(apiKey), options);
48
59
  };
49
60
 
50
61
  exports.getTestClient = getTestClient;
51
62
 
52
63
  var getTestClientWithUser = function () {
53
64
  var _ref = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(user) {
54
- var client;
65
+ var options,
66
+ _options$disableAppSe2,
67
+ disableAppSettings,
68
+ client,
69
+ _args = arguments;
70
+
55
71
  return _regenerator["default"].wrap(function _callee$(_context) {
56
72
  while (1) {
57
73
  switch (_context.prev = _context.next) {
58
74
  case 0:
75
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
76
+ _options$disableAppSe2 = options.disableAppSettings, disableAppSettings = _options$disableAppSe2 === void 0 ? true : _options$disableAppSe2;
59
77
  client = mockClient(new _streamChat.StreamChat(apiKey));
60
- _context.next = 3;
78
+ _context.next = 5;
61
79
  return setUser(client, user);
62
80
 
63
- case 3:
81
+ case 5:
64
82
  client.wsPromise = Promise.resolve();
83
+
84
+ if (disableAppSettings) {
85
+ client.getAppSettings = jest.fn(function () {
86
+ return {};
87
+ });
88
+ }
89
+
65
90
  return _context.abrupt("return", client);
66
91
 
67
- case 5:
92
+ case 8:
68
93
  case "end":
69
94
  return _context.stop();
70
95
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["mock.js"],"names":["apiKey","token","setUser","client","user","Promise","resolve","connectionId","mutes","_user","userID","id","userToken","mockClient","jest","spyOn","mockImplementation","tokenManager","getToken","fn","tokenReady","bind","getTestClient","StreamChat","getTestClientWithUser","wsPromise","getRandomInt","min","max","Math","ceil","floor","random"],"mappings":";;;;;;;;;;;;;AAGA;;AAEA,IAAMA,MAAM,GAAG,SAAf;AACA,IAAMC,KAAK,GAAG,aAAd;;AAEA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,MAAD,EAASC,IAAT;AAAA,SACd,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAa;AACvBH,IAAAA,MAAM,CAACI,YAAP,GAAsB,oBAAtB;AACAJ,IAAAA,MAAM,CAACC,IAAP,GAAcA,IAAd;AACAD,IAAAA,MAAM,CAACC,IAAP,CAAYI,KAAZ,GAAoB,EAApB;AACAL,IAAAA,MAAM,CAACM,KAAP,iCAAoBL,IAApB;AACAD,IAAAA,MAAM,CAACO,MAAP,GAAgBN,IAAI,CAACO,EAArB;AACAR,IAAAA,MAAM,CAACS,SAAP,GAAmBX,KAAnB;AACAK,IAAAA,OAAO;AACR,GARD,CADc;AAAA,CAAhB;;AAWA,SAASO,UAAT,CAAoBV,MAApB,EAA4B;AAC1BW,EAAAA,IAAI,CAACC,KAAL,CAAWZ,MAAX,EAAmB,WAAnB,EAAgCa,kBAAhC;AACAF,EAAAA,IAAI,CAACC,KAAL,CAAWZ,MAAX,EAAmB,kBAAnB,EAAuCa,kBAAvC;AACAb,EAAAA,MAAM,CAACc,YAAP,GAAsB;AACpBC,IAAAA,QAAQ,EAAEJ,IAAI,CAACK,EAAL,CAAQ;AAAA,aAAMlB,KAAN;AAAA,KAAR,CADU;AAEpBmB,IAAAA,UAAU,EAAEN,IAAI,CAACK,EAAL,CAAQ;AAAA,aAAM,IAAN;AAAA,KAAR;AAFQ,GAAtB;AAIAhB,EAAAA,MAAM,CAACD,OAAP,GAAiBA,OAAO,CAACmB,IAAR,CAAa,IAAb,EAAmBlB,MAAnB,CAAjB;AACA,SAAOA,MAAP;AACD;;AAEM,IAAMmB,aAAa,GAAG,SAAhBA,aAAgB;AAAA,SAAMT,UAAU,CAAC,IAAIU,sBAAJ,CAAevB,MAAf,CAAD,CAAhB;AAAA,CAAtB;;;;AAEA,IAAMwB,qBAAqB;AAAA,6EAAG,iBAAOpB,IAAP;AAAA;AAAA;AAAA;AAAA;AAAA;AAC7BD,YAAAA,MAD6B,GACpBU,UAAU,CAAC,IAAIU,sBAAJ,CAAevB,MAAf,CAAD,CADU;AAAA;AAAA,mBAE7BE,OAAO,CAACC,MAAD,EAASC,IAAT,CAFsB;;AAAA;AAGnCD,YAAAA,MAAM,CAACsB,SAAP,GAAmBpB,OAAO,CAACC,OAAR,EAAnB;AAHmC,6CAI5BH,MAJ4B;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAH;;AAAA,kBAArBqB,qBAAqB;AAAA;AAAA;AAAA,GAA3B;;;;AAOA,IAAME,YAAY,GAAG,SAAfA,YAAe,CAACC,GAAD,EAAMC,GAAN,EAAc;AACxCD,EAAAA,GAAG,GAAGE,IAAI,CAACC,IAAL,CAAUH,GAAV,CAAN;AACAC,EAAAA,GAAG,GAAGC,IAAI,CAACE,KAAL,CAAWH,GAAX,CAAN;AACA,SAAOC,IAAI,CAACE,KAAL,CAAWF,IAAI,CAACG,MAAL,MAAiBJ,GAAG,GAAGD,GAAvB,CAAX,IAA0CA,GAAjD;AACD,CAJM","sourcesContent":["/* eslint no-underscore-dangle: 0 */\n/* eslint no-param-reassign: 0 */\n\nimport { StreamChat } from 'stream-chat';\n\nconst apiKey = 'API_KEY';\nconst token = 'dummy_token';\n\nconst setUser = (client, user) =>\n new Promise((resolve) => {\n client.connectionId = 'dumm_connection_id';\n client.user = user;\n client.user.mutes = [];\n client._user = { ...user };\n client.userID = user.id;\n client.userToken = token;\n resolve();\n });\n\nfunction mockClient(client) {\n jest.spyOn(client, '_setToken').mockImplementation();\n jest.spyOn(client, '_setupConnection').mockImplementation();\n client.tokenManager = {\n getToken: jest.fn(() => token),\n tokenReady: jest.fn(() => true),\n };\n client.setUser = setUser.bind(null, client);\n return client;\n}\n\nexport const getTestClient = () => mockClient(new StreamChat(apiKey));\n\nexport const getTestClientWithUser = async (user) => {\n const client = mockClient(new StreamChat(apiKey));\n await setUser(client, user);\n client.wsPromise = Promise.resolve();\n return client;\n};\n\nexport const getRandomInt = (min, max) => {\n min = Math.ceil(min);\n max = Math.floor(max);\n return Math.floor(Math.random() * (max - min)) + min; // The maximum is exclusive and the minimum is inclusive\n};\n"]}
1
+ {"version":3,"sources":["mock.js"],"names":["apiKey","token","setUser","client","user","Promise","resolve","connectionId","mutes","_user","userID","id","userToken","mockClient","options","disableAppSettings","jest","spyOn","mockImplementation","tokenManager","getToken","fn","tokenReady","bind","getAppSettings","getTestClient","StreamChat","getTestClientWithUser","wsPromise","getRandomInt","min","max","Math","ceil","floor","random"],"mappings":";;;;;;;;;;;;;AAGA;;AAEA,IAAMA,MAAM,GAAG,SAAf;AACA,IAAMC,KAAK,GAAG,aAAd;;AAEA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,MAAD,EAASC,IAAT;AAAA,SACd,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAa;AACvBH,IAAAA,MAAM,CAACI,YAAP,GAAsB,oBAAtB;AACAJ,IAAAA,MAAM,CAACC,IAAP,GAAcA,IAAd;AACAD,IAAAA,MAAM,CAACC,IAAP,CAAYI,KAAZ,GAAoB,EAApB;AACAL,IAAAA,MAAM,CAACM,KAAP,iCAAoBL,IAApB;AACAD,IAAAA,MAAM,CAACO,MAAP,GAAgBN,IAAI,CAACO,EAArB;AACAR,IAAAA,MAAM,CAACS,SAAP,GAAmBX,KAAnB;AACAK,IAAAA,OAAO;AACR,GARD,CADc;AAAA,CAAhB;;AAWA,SAASO,UAAT,CAAoBV,MAApB,EAA0C;AAAA,MAAdW,OAAc,uEAAJ,EAAI;AACxC,8BAAsCA,OAAtC,CAAQC,kBAAR;AAAA,MAAQA,kBAAR,sCAA6B,IAA7B;AAEAC,EAAAA,IAAI,CAACC,KAAL,CAAWd,MAAX,EAAmB,WAAnB,EAAgCe,kBAAhC;AACAF,EAAAA,IAAI,CAACC,KAAL,CAAWd,MAAX,EAAmB,kBAAnB,EAAuCe,kBAAvC;AACAf,EAAAA,MAAM,CAACgB,YAAP,GAAsB;AACpBC,IAAAA,QAAQ,EAAEJ,IAAI,CAACK,EAAL,CAAQ;AAAA,aAAMpB,KAAN;AAAA,KAAR,CADU;AAEpBqB,IAAAA,UAAU,EAAEN,IAAI,CAACK,EAAL,CAAQ;AAAA,aAAM,IAAN;AAAA,KAAR;AAFQ,GAAtB;AAIAlB,EAAAA,MAAM,CAACD,OAAP,GAAiBA,OAAO,CAACqB,IAAR,CAAa,IAAb,EAAmBpB,MAAnB,CAAjB;;AAEA,MAAIY,kBAAJ,EAAwB;AACtBZ,IAAAA,MAAM,CAACqB,cAAP,GAAwBR,IAAI,CAACK,EAAL,CAAQ;AAAA,aAAO,EAAP;AAAA,KAAR,CAAxB;AACD;;AAED,SAAOlB,MAAP;AACD;;AAEM,IAAMsB,aAAa,GAAG,SAAhBA,aAAgB;AAAA,MAACX,OAAD,uEAAW,EAAX;AAAA,SAAkBD,UAAU,CAAC,IAAIa,sBAAJ,CAAe1B,MAAf,CAAD,EAAyBc,OAAzB,CAA5B;AAAA,CAAtB;;;;AAEA,IAAMa,qBAAqB;AAAA,6EAAG,iBAAOvB,IAAP;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAaU,YAAAA,OAAb,2DAAuB,EAAvB;AAAA,qCACGA,OADH,CAC3BC,kBAD2B,EAC3BA,kBAD2B,uCACN,IADM;AAE7BZ,YAAAA,MAF6B,GAEpBU,UAAU,CAAC,IAAIa,sBAAJ,CAAe1B,MAAf,CAAD,CAFU;AAAA;AAAA,mBAG7BE,OAAO,CAACC,MAAD,EAASC,IAAT,CAHsB;;AAAA;AAInCD,YAAAA,MAAM,CAACyB,SAAP,GAAmBvB,OAAO,CAACC,OAAR,EAAnB;;AAEA,gBAAIS,kBAAJ,EAAwB;AACtBZ,cAAAA,MAAM,CAACqB,cAAP,GAAwBR,IAAI,CAACK,EAAL,CAAQ;AAAA,uBAAO,EAAP;AAAA,eAAR,CAAxB;AACD;;AARkC,6CAU5BlB,MAV4B;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAH;;AAAA,kBAArBwB,qBAAqB;AAAA;AAAA;AAAA,GAA3B;;;;AAaA,IAAME,YAAY,GAAG,SAAfA,YAAe,CAACC,GAAD,EAAMC,GAAN,EAAc;AACxCD,EAAAA,GAAG,GAAGE,IAAI,CAACC,IAAL,CAAUH,GAAV,CAAN;AACAC,EAAAA,GAAG,GAAGC,IAAI,CAACE,KAAL,CAAWH,GAAX,CAAN;AACA,SAAOC,IAAI,CAACE,KAAL,CAAWF,IAAI,CAACG,MAAL,MAAiBJ,GAAG,GAAGD,GAAvB,CAAX,IAA0CA,GAAjD;AACD,CAJM","sourcesContent":["/* eslint no-underscore-dangle: 0 */\n/* eslint no-param-reassign: 0 */\n\nimport { StreamChat } from 'stream-chat';\n\nconst apiKey = 'API_KEY';\nconst token = 'dummy_token';\n\nconst setUser = (client, user) =>\n new Promise((resolve) => {\n client.connectionId = 'dumm_connection_id';\n client.user = user;\n client.user.mutes = [];\n client._user = { ...user };\n client.userID = user.id;\n client.userToken = token;\n resolve();\n });\n\nfunction mockClient(client, options = {}) {\n const { disableAppSettings = true } = options;\n\n jest.spyOn(client, '_setToken').mockImplementation();\n jest.spyOn(client, '_setupConnection').mockImplementation();\n client.tokenManager = {\n getToken: jest.fn(() => token),\n tokenReady: jest.fn(() => true),\n };\n client.setUser = setUser.bind(null, client);\n\n if (disableAppSettings) {\n client.getAppSettings = jest.fn(() => ({}));\n }\n\n return client;\n}\n\nexport const getTestClient = (options = {}) => mockClient(new StreamChat(apiKey), options);\n\nexport const getTestClientWithUser = async (user, options = {}) => {\n const { disableAppSettings = true } = options;\n const client = mockClient(new StreamChat(apiKey));\n await setUser(client, user);\n client.wsPromise = Promise.resolve();\n\n if (disableAppSettings) {\n client.getAppSettings = jest.fn(() => ({}));\n }\n\n return client;\n};\n\nexport const getRandomInt = (min, max) => {\n min = Math.ceil(min);\n max = Math.floor(max);\n return Math.floor(Math.random() * (max - min)) + min; // The maximum is exclusive and the minimum is inclusive\n};\n"]}
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "4.7.0"
2
+ "version": "4.7.1"
3
3
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -3,9 +3,13 @@ import type { DefaultStreamChatGenerics } from '../../types/types';
3
3
  export declare type KeyboardContextValue = {
4
4
  dismissKeyboard: () => void;
5
5
  };
6
- export declare const KeyboardContext: React.Context<KeyboardContextValue>;
6
+ export declare const KeyboardContext: React.Context<{
7
+ dismissKeyboard: () => void;
8
+ }>;
7
9
  export declare const KeyboardProvider: React.FC<{
8
10
  value: KeyboardContextValue;
9
11
  }>;
10
- export declare const useKeyboardContext: () => KeyboardContextValue;
12
+ export declare const useKeyboardContext: () => {
13
+ dismissKeyboard: () => void;
14
+ };
11
15
  export declare const withKeyboardContext: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(Component: React.ComponentType<StreamChatGenerics>) => React.FC<Omit<StreamChatGenerics, "dismissKeyboard">>;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { PropsWithChildren } from 'react';
2
2
  import { Theme } from './utils/theme';
3
3
  export declare type DeepPartial<T> = {
4
4
  [P in keyof T]?: DeepPartial<T[P]>;
@@ -11,9 +11,12 @@ export declare type MergedThemesParams = {
11
11
  style?: DeepPartial<Theme>;
12
12
  theme?: Theme;
13
13
  };
14
+ export declare type ThemeContextValue = {
15
+ theme: Theme;
16
+ };
14
17
  export declare const mergeThemes: (params: MergedThemesParams) => Theme;
15
18
  export declare const ThemeContext: React.Context<Theme>;
16
- export declare const ThemeProvider: React.FC<ThemeProviderInputValue>;
19
+ export declare const ThemeProvider: React.FC<PropsWithChildren<ThemeProviderInputValue & Partial<ThemeContextValue>>>;
17
20
  export declare const useTheme: () => {
18
21
  theme: Theme;
19
22
  };
@@ -373,6 +373,12 @@ export declare type Theme = {
373
373
  title: TextStyle;
374
374
  };
375
375
  noURI: ViewStyle;
376
+ playButtonStyle: {
377
+ durationTextStyle: TextStyle;
378
+ roundedView: ViewStyle;
379
+ videoContainer: ViewStyle;
380
+ };
381
+ playIcon: IconProps;
376
382
  };
377
383
  container: ViewStyle;
378
384
  content: {
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_BASE_CONTEXT_VALUE: {};
@@ -0,0 +1 @@
1
+ export declare const isTestEnvironment: () => boolean;
@@ -1,3 +1,3 @@
1
- export function getTestClient(): any;
2
- export function getTestClientWithUser(user: any): Promise<any>;
1
+ export function getTestClient(options?: {}): any;
2
+ export function getTestClientWithUser(user: any, options?: {}): Promise<any>;
3
3
  export function getRandomInt(min: any, max: any): any;
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": "4.7.0",
4
+ "version": "4.7.1",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import {
3
- Image,
3
+ ImageBackground,
4
4
  ImageStyle,
5
5
  StyleProp,
6
6
  StyleSheet,
@@ -24,6 +24,7 @@ import {
24
24
  useMessagesContext,
25
25
  } from '../../contexts/messagesContext/MessagesContext';
26
26
  import { useTheme } from '../../contexts/themeContext/ThemeContext';
27
+ import { Play } from '../../icons/Play';
27
28
  import type { DefaultStreamChatGenerics } from '../../types/types';
28
29
  import { makeImageCompatibleUrl } from '../../utils/utils';
29
30
 
@@ -41,13 +42,15 @@ const styles = StyleSheet.create({
41
42
  },
42
43
  authorNameMask: {
43
44
  bottom: 0,
44
- left: 8,
45
+ left: 2,
45
46
  position: 'absolute',
46
47
  },
47
48
  cardCover: {
49
+ alignItems: 'center',
48
50
  borderRadius: 8,
49
51
  height: 140,
50
- marginHorizontal: 8,
52
+ justifyContent: 'center',
53
+ marginHorizontal: 2,
51
54
  },
52
55
  cardFooter: {
53
56
  flexDirection: 'row',
@@ -62,6 +65,14 @@ const styles = StyleSheet.create({
62
65
  fontSize: 12,
63
66
  marginHorizontal: 8,
64
67
  },
68
+ playButtonStyle: {
69
+ alignItems: 'center',
70
+ borderRadius: 50,
71
+ elevation: 2,
72
+ height: 36,
73
+ justifyContent: 'center',
74
+ width: 36,
75
+ },
65
76
  title: {
66
77
  fontSize: 12,
67
78
  marginHorizontal: 8,
@@ -116,11 +127,12 @@ const CardWithContext = <
116
127
  text,
117
128
  thumb_url,
118
129
  title,
130
+ type,
119
131
  } = props;
120
132
 
121
133
  const {
122
134
  theme: {
123
- colors: { accent_blue, black, blue_alice, transparent },
135
+ colors: { accent_blue, black, blue_alice, transparent, white },
124
136
  messageSimple: {
125
137
  card: {
126
138
  authorName,
@@ -132,6 +144,8 @@ const CardWithContext = <
132
144
  cover,
133
145
  footer: { description, title: titleStyle, ...footerStyle },
134
146
  noURI,
147
+ playButtonStyle: { roundedView },
148
+ playIcon: { height, width },
135
149
  },
136
150
  },
137
151
  },
@@ -141,6 +155,8 @@ const CardWithContext = <
141
155
 
142
156
  const defaultOnPress = () => openUrlSafely(og_scrape_url || uri);
143
157
 
158
+ const isVideoCard = type === 'video' && og_scrape_url;
159
+
144
160
  return (
145
161
  <TouchableOpacity
146
162
  disabled={preventPress}
@@ -181,11 +197,18 @@ const CardWithContext = <
181
197
  {CardCover && <CardCover {...props} />}
182
198
  {uri && !CardCover && (
183
199
  <View>
184
- <Image
200
+ <ImageBackground
201
+ imageStyle={styles.cardCover}
185
202
  resizeMode='cover'
186
203
  source={{ uri: makeImageCompatibleUrl(uri) }}
187
204
  style={[styles.cardCover, cover, stylesProp.cardCover]}
188
- />
205
+ >
206
+ {isVideoCard ? (
207
+ <View style={[styles.playButtonStyle, roundedView, { backgroundColor: white }]}>
208
+ <Play height={height} pathFill={black} width={width} />
209
+ </View>
210
+ ) : null}
211
+ </ImageBackground>
189
212
  {author_name && (
190
213
  <View style={[styles.authorNameMask, authorNameMask, stylesProp.authorNameMask]}>
191
214
  <View
@@ -8,7 +8,6 @@ import { ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
8
8
  import {
9
9
  generateAttachmentAction,
10
10
  generateAudioAttachment,
11
- generateCardAttachment,
12
11
  generateFileAttachment,
13
12
  generateImageAttachment,
14
13
  } from '../../../mock-builders/generator/attachment';
@@ -107,17 +106,4 @@ describe('Attachment', () => {
107
106
  expect(handleAction).toHaveBeenCalledTimes(2);
108
107
  });
109
108
  });
110
-
111
- it('should render "Card" if attachment type is not recognized', async () => {
112
- const { getByTestId } = render(
113
- getAttachmentComponent({
114
- attachment: generateCardAttachment({
115
- type: Date.now().toString(),
116
- }),
117
- }),
118
- );
119
- await waitFor(() => {
120
- expect(getByTestId('card-attachment')).toBeTruthy();
121
- });
122
- });
123
109
  });
@@ -251,10 +251,12 @@ describe('Giphy', () => {
251
251
  </OverlayProvider>,
252
252
  );
253
253
 
254
- expect(queryByTestId('giphy-action-attachment')).toBeTruthy();
255
- expect(getByTestId('cancel-action-button')).toBeTruthy();
256
- expect(getByTestId('shuffle-action-button')).toBeTruthy();
257
- expect(getByTestId('send-action-button')).toBeTruthy();
254
+ await waitFor(() => {
255
+ expect(queryByTestId('giphy-action-attachment')).toBeTruthy();
256
+ expect(getByTestId('cancel-action-button')).toBeTruthy();
257
+ expect(getByTestId('shuffle-action-button')).toBeTruthy();
258
+ expect(getByTestId('send-action-button')).toBeTruthy();
259
+ });
258
260
  });
259
261
 
260
262
  it('giphy attachment UI should render within the message list', async () => {
@@ -285,6 +287,8 @@ describe('Giphy', () => {
285
287
  </OverlayProvider>,
286
288
  );
287
289
 
288
- expect(queryByTestId('giphy-attachment')).toBeTruthy();
290
+ await waitFor(() => {
291
+ expect(queryByTestId('giphy-attachment')).toBeTruthy();
292
+ });
289
293
  });
290
294
  });
@@ -197,6 +197,7 @@ export const AutoCompleteSuggestionList = <
197
197
  ) => {
198
198
  const { AutoCompleteSuggestionHeader, AutoCompleteSuggestionItem } =
199
199
  useSuggestionsContext<StreamChatGenerics>();
200
+
200
201
  return (
201
202
  <MemoizedAutoCompleteSuggestionList
202
203
  {...{ AutoCompleteSuggestionHeader, AutoCompleteSuggestionItem }}
@@ -4,13 +4,13 @@ import { useSharedValue } from 'react-native-reanimated';
4
4
 
5
5
  import { renderHook } from '@testing-library/react-hooks';
6
6
 
7
- import { render } from '@testing-library/react-native';
7
+ import { render, waitFor } from '@testing-library/react-native';
8
8
 
9
9
  import { ThemeProvider } from '../../../../contexts/themeContext/ThemeContext';
10
10
 
11
11
  import { ImageGalleryHeader } from '../ImageGalleryHeader';
12
12
 
13
- it('doesnt fail if fromNow is not available on first render', () => {
13
+ it('doesnt fail if fromNow is not available on first render', async () => {
14
14
  try {
15
15
  let sharedValueOpacity: Animated.SharedValue<number>;
16
16
  let sharedValueVisible: Animated.SharedValue<number>;
@@ -32,7 +32,9 @@ it('doesnt fail if fromNow is not available on first render', () => {
32
32
  />
33
33
  </ThemeProvider>,
34
34
  );
35
- expect(getAllByText('Unknown User')).toBeTruthy();
35
+ await waitFor(() => {
36
+ expect(getAllByText('Unknown User')).toBeTruthy();
37
+ });
36
38
  } catch (error: unknown) {
37
39
  if (error instanceof Error) {
38
40
  throw new Error(`Error encountered on first render of ImageGalleryHeader: ${error.message}`);
@@ -27,6 +27,7 @@ export const SendMessageDisallowedIndicator = () => {
27
27
  },
28
28
  },
29
29
  } = useTheme();
30
+
30
31
  return (
31
32
  <View
32
33
  style={[
@@ -256,7 +256,7 @@ describe('FileUploadPreview', () => {
256
256
  generateFileUploadPreview({ id: 'file-upload-id-1', state: FileState.UPLOADING }),
257
257
  generateFileUploadPreview({ id: 'file-upload-id-2', state: FileState.UPLOADED }),
258
258
  generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.UPLOAD_FAILED }),
259
- generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.NOT_SUPPORTED }),
259
+ generateFileUploadPreview({ id: 'file-upload-id-4', state: FileState.NOT_SUPPORTED }),
260
260
  ];
261
261
  const removeFile = jest.fn();
262
262
  const uploadFile = jest.fn();
@@ -88,12 +88,15 @@ const getMessageType = <
88
88
 
89
89
  const isLastAttachmentVideo = lastAttachment.type === 'video';
90
90
 
91
- const isLastAttachmentGiphy = lastAttachment.type === 'giphy' || lastAttachment.type === 'imgur';
91
+ const isLastAttachmentGiphy =
92
+ lastAttachment?.type === 'giphy' || lastAttachment?.type === 'imgur';
92
93
 
93
94
  const isLastAttachmentImageOrGiphy =
94
- lastAttachment.type === 'image' && !lastAttachment.title_link && !lastAttachment.og_scrape_url;
95
+ lastAttachment?.type === 'image' &&
96
+ !lastAttachment?.title_link &&
97
+ !lastAttachment?.og_scrape_url;
95
98
 
96
- const isLastAttachmentImage = lastAttachment.image_url || lastAttachment.thumb_url;
99
+ const isLastAttachmentImage = lastAttachment?.image_url || lastAttachment?.thumb_url;
97
100
 
98
101
  if (isLastAttachmentFile) {
99
102
  messageType = 'file';
@@ -0,0 +1,103 @@
1
+ import React from 'react';
2
+ import { View } from 'react-native';
3
+
4
+ import { render } from '@testing-library/react-native';
5
+
6
+ import {
7
+ useAttachmentPickerContext,
8
+ useChannelContext,
9
+ useChannelsContext,
10
+ useChatContext,
11
+ useImageGalleryContext,
12
+ useMessageContext,
13
+ useMessageOverlayContext,
14
+ useMessagesContext,
15
+ useOverlayContext,
16
+ useOwnCapabilitiesContext,
17
+ usePaginatedMessageListContext,
18
+ useSuggestionsContext,
19
+ useTheme,
20
+ useThreadContext,
21
+ useTypingContext,
22
+ } from '../';
23
+ import { useChannelsStateContext } from '../channelsStateContext/ChannelsStateContext';
24
+
25
+ jest.mock('../utils/isTestEnvironment', () => ({ isTestEnvironment: jest.fn(() => false) }));
26
+ console.error = jest.fn();
27
+ describe('contexts hooks in a component throws an error with message when not wrapped in a provider', () => {
28
+ const TestComponent = ({ useContextHook }: { useContextHook(): void }) => {
29
+ useContextHook();
30
+ return <View />;
31
+ };
32
+
33
+ it.each([
34
+ [
35
+ useOverlayContext,
36
+ 'The useOverlayContext hook was called outside the OverlayContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider',
37
+ ],
38
+ [
39
+ usePaginatedMessageListContext,
40
+ 'The usePaginatedMessageListContext hook was called outside of the PaginatedMessageList provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel',
41
+ ],
42
+ [
43
+ useChannelsStateContext,
44
+ `The useChannelStateContext hook was called outside the ChannelStateContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
45
+ ],
46
+ [
47
+ useOwnCapabilitiesContext,
48
+ `The useOwnCapabilitiesContext hook was called outside the Channel Component. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
49
+ ],
50
+ [
51
+ useSuggestionsContext,
52
+ 'The useSuggestionsContext hook was called outside of the SuggestionsContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel',
53
+ ],
54
+ [
55
+ useTypingContext,
56
+ `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`,
57
+ ],
58
+ [
59
+ useTheme,
60
+ `The useThemeContext hook was called outside the ThemeContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
61
+ ],
62
+ [
63
+ useChannelContext,
64
+ `The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
65
+ ],
66
+ [
67
+ useChannelsContext,
68
+ `The useChannelsContext hook was called outside of the ChannelsContext provider. Make sure you have configured ChannelList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel-list`,
69
+ ],
70
+ [
71
+ useChatContext,
72
+ `The useChatContext hook was called outside the ChatContext Provider. Make sure you have configured Chat component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#chat`,
73
+ ],
74
+ [
75
+ useImageGalleryContext,
76
+ `The useImageGalleryContext hook was called outside the ImageGalleryContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
77
+ ],
78
+ [
79
+ useMessageContext,
80
+ `The useMessageContext hook was called outside of the MessageContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,
81
+ ],
82
+ [
83
+ useMessageOverlayContext,
84
+ `The useMessageOverlayContext hook was called outside the MessageOverlayContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
85
+ ],
86
+ [
87
+ useMessagesContext,
88
+ `The useMessagesContext hook was called outside of the MessagesContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,
89
+ ],
90
+ [
91
+ useThreadContext,
92
+ `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`,
93
+ ],
94
+ [
95
+ useAttachmentPickerContext,
96
+ `The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
97
+ ],
98
+ ])('calls %p results in error %p', (useContextHook, expectedErrorMessage) => {
99
+ expect(() => render(<TestComponent useContextHook={useContextHook} />)).toThrowError(
100
+ expectedErrorMessage,
101
+ );
102
+ });
103
+ });
@@ -1,6 +1,7 @@
1
1
  import React, { PropsWithChildren, useContext } from 'react';
2
2
 
3
3
  import type { UnknownType } from '../../types/types';
4
+
4
5
  import { getDisplayName } from '../utils/getDisplayName';
5
6
 
6
7
  type ActiveChannels = React.MutableRefObject<string[]>;
@@ -1,7 +1,10 @@
1
1
  import React, { PropsWithChildren, useContext, useEffect, useState } from 'react';
2
2
 
3
3
  import type { Asset, DefaultStreamChatGenerics, File } from '../../types/types';
4
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
5
+
4
6
  import { getDisplayName } from '../utils/getDisplayName';
7
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
5
8
 
6
9
  export type AttachmentPickerIconProps = {
7
10
  numberOfImageUploads: number;
@@ -55,8 +58,8 @@ export type AttachmentPickerContextValue = {
55
58
  selectedPicker?: 'images';
56
59
  };
57
60
 
58
- export const AttachmentPickerContext = React.createContext<AttachmentPickerContextValue>(
59
- {} as AttachmentPickerContextValue,
61
+ export const AttachmentPickerContext = React.createContext(
62
+ DEFAULT_BASE_CONTEXT_VALUE as AttachmentPickerContextValue,
60
63
  );
61
64
 
62
65
  export const AttachmentPickerProvider = ({
@@ -118,8 +121,19 @@ export const AttachmentPickerProvider = ({
118
121
  );
119
122
  };
120
123
 
121
- export const useAttachmentPickerContext = () =>
122
- useContext(AttachmentPickerContext) as unknown as AttachmentPickerContextValue;
124
+ export const useAttachmentPickerContext = () => {
125
+ const contextValue = useContext(
126
+ AttachmentPickerContext,
127
+ ) as unknown as AttachmentPickerContextValue;
128
+
129
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
130
+ throw new Error(
131
+ `The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
132
+ );
133
+ }
134
+
135
+ return contextValue;
136
+ };
123
137
 
124
138
  export const withAttachmentPickerContext = <
125
139
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -5,7 +5,10 @@ import type { Channel, ChannelState } from 'stream-chat';
5
5
  import type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';
6
6
  import type { LoadingProps } from '../../components/Indicators/LoadingIndicator';
7
7
  import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
8
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
9
+
8
10
  import { getDisplayName } from '../utils/getDisplayName';
11
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
9
12
 
10
13
  export type ChannelContextValue<
11
14
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -167,7 +170,9 @@ export type ChannelContextValue<
167
170
  watcherCount?: ChannelState<StreamChatGenerics>['watcher_count'];
168
171
  };
169
172
 
170
- export const ChannelContext = React.createContext({} as ChannelContextValue);
173
+ export const ChannelContext = React.createContext(
174
+ DEFAULT_BASE_CONTEXT_VALUE as ChannelContextValue,
175
+ );
171
176
 
172
177
  export const ChannelProvider = <
173
178
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -184,8 +189,19 @@ export const ChannelProvider = <
184
189
 
185
190
  export const useChannelContext = <
186
191
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
187
- >() => useContext(ChannelContext) as unknown as ChannelContextValue<StreamChatGenerics>;
192
+ >() => {
193
+ const contextValue = useContext(
194
+ ChannelContext,
195
+ ) as unknown as ChannelContextValue<StreamChatGenerics>;
188
196
 
197
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
198
+ throw new Error(
199
+ `The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
200
+ );
201
+ }
202
+
203
+ return contextValue;
204
+ };
189
205
  /**
190
206
  * Typescript currently does not support partial inference so if ChatContext
191
207
  * typing is desired while using the HOC withChannelContext the Props for the