stream-chat-react-native-core 5.0.0-beta.0 → 5.0.0-beta.3

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 (165) hide show
  1. package/lib/commonjs/components/Attachment/FileAttachment.js +16 -7
  2. package/lib/commonjs/components/Attachment/FileAttachment.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/Gallery.js +19 -17
  4. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  5. package/lib/commonjs/components/Attachment/Giphy.js +10 -10
  6. package/lib/commonjs/components/Attachment/Giphy.js.map +1 -1
  7. package/lib/commonjs/components/Attachment/utils/getGiphyMimeType.js +15 -0
  8. package/lib/commonjs/components/Attachment/utils/getGiphyMimeType.js.map +1 -0
  9. package/lib/commonjs/components/Channel/Channel.js +1 -1
  10. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  11. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js +16 -4
  12. package/lib/commonjs/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
  13. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +12 -7
  14. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  15. package/lib/commonjs/components/ChannelPreview/ChannelPreview.js +10 -6
  16. package/lib/commonjs/components/ChannelPreview/ChannelPreview.js.map +1 -1
  17. package/lib/commonjs/components/ImageGallery/ImageGallery.js +38 -30
  18. package/lib/commonjs/components/ImageGallery/ImageGallery.js.map +1 -1
  19. package/lib/commonjs/components/ImageGallery/components/ImageGrid.js +2 -2
  20. package/lib/commonjs/components/ImageGallery/components/ImageGrid.js.map +1 -1
  21. package/lib/commonjs/components/ImageGallery/hooks/useImageGalleryGestures.js +6 -0
  22. package/lib/commonjs/components/ImageGallery/hooks/useImageGalleryGestures.js.map +1 -1
  23. package/lib/commonjs/components/Message/Message.js +6 -6
  24. package/lib/commonjs/components/Message/Message.js.map +1 -1
  25. package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js +7 -3
  26. package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
  27. package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js +1 -1
  28. package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js.map +1 -1
  29. package/lib/commonjs/components/MessageList/MessageList.js +5 -5
  30. package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
  31. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js +13 -14
  32. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  33. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.md +1 -1
  34. package/lib/commonjs/index.js +13 -1
  35. package/lib/commonjs/index.js.map +1 -1
  36. package/lib/commonjs/mock-builders/DB/mock.js +1 -13
  37. package/lib/commonjs/mock-builders/DB/mock.js.map +1 -1
  38. package/lib/commonjs/mock-builders/event/messageNew.js +2 -0
  39. package/lib/commonjs/mock-builders/event/messageNew.js.map +1 -1
  40. package/lib/commonjs/store/QuickSqliteClient.js +7 -3
  41. package/lib/commonjs/store/QuickSqliteClient.js.map +1 -1
  42. package/lib/commonjs/store/apis/getChannels.js +2 -15
  43. package/lib/commonjs/store/apis/getChannels.js.map +1 -1
  44. package/lib/commonjs/store/apis/getChannelsForFilterSort.js +37 -0
  45. package/lib/commonjs/store/apis/getChannelsForFilterSort.js.map +1 -0
  46. package/lib/commonjs/store/apis/index.js +264 -0
  47. package/lib/commonjs/store/apis/index.js.map +1 -0
  48. package/lib/commonjs/store/apis/queries/selectChannelIdsForFilterSort.js +1 -1
  49. package/lib/commonjs/store/apis/queries/selectChannelIdsForFilterSort.js.map +1 -1
  50. package/lib/commonjs/store/apis/queries/selectChannels.js +2 -2
  51. package/lib/commonjs/store/apis/queries/selectChannels.js.map +1 -1
  52. package/lib/commonjs/store/sqlite-utils/appendWhereCluase.js +1 -2
  53. package/lib/commonjs/store/sqlite-utils/appendWhereCluase.js.map +1 -1
  54. package/lib/commonjs/test-utils/BetterSqlite.js +54 -0
  55. package/lib/commonjs/test-utils/BetterSqlite.js.map +1 -0
  56. package/lib/commonjs/version.json +1 -1
  57. package/lib/module/components/Attachment/FileAttachment.js +16 -7
  58. package/lib/module/components/Attachment/FileAttachment.js.map +1 -1
  59. package/lib/module/components/Attachment/Gallery.js +19 -17
  60. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  61. package/lib/module/components/Attachment/Giphy.js +10 -10
  62. package/lib/module/components/Attachment/Giphy.js.map +1 -1
  63. package/lib/module/components/Attachment/utils/getGiphyMimeType.js +15 -0
  64. package/lib/module/components/Attachment/utils/getGiphyMimeType.js.map +1 -0
  65. package/lib/module/components/Channel/Channel.js +1 -1
  66. package/lib/module/components/Channel/Channel.js.map +1 -1
  67. package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js +16 -4
  68. package/lib/module/components/ChannelList/hooks/listeners/useNewMessage.js.map +1 -1
  69. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +12 -7
  70. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  71. package/lib/module/components/ChannelPreview/ChannelPreview.js +10 -6
  72. package/lib/module/components/ChannelPreview/ChannelPreview.js.map +1 -1
  73. package/lib/module/components/ImageGallery/ImageGallery.js +38 -30
  74. package/lib/module/components/ImageGallery/ImageGallery.js.map +1 -1
  75. package/lib/module/components/ImageGallery/components/ImageGrid.js +2 -2
  76. package/lib/module/components/ImageGallery/components/ImageGrid.js.map +1 -1
  77. package/lib/module/components/ImageGallery/hooks/useImageGalleryGestures.js +6 -0
  78. package/lib/module/components/ImageGallery/hooks/useImageGalleryGestures.js.map +1 -1
  79. package/lib/module/components/Message/Message.js +6 -6
  80. package/lib/module/components/Message/Message.js.map +1 -1
  81. package/lib/module/components/Message/MessageSimple/MessageTextContainer.js +7 -3
  82. package/lib/module/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
  83. package/lib/module/components/Message/MessageSimple/utils/renderText.js +1 -1
  84. package/lib/module/components/Message/MessageSimple/utils/renderText.js.map +1 -1
  85. package/lib/module/components/MessageList/MessageList.js +5 -5
  86. package/lib/module/components/MessageList/MessageList.js.map +1 -1
  87. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js +13 -14
  88. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  89. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.md +1 -1
  90. package/lib/module/index.js +13 -1
  91. package/lib/module/index.js.map +1 -1
  92. package/lib/module/mock-builders/DB/mock.js +1 -13
  93. package/lib/module/mock-builders/DB/mock.js.map +1 -1
  94. package/lib/module/mock-builders/event/messageNew.js +2 -0
  95. package/lib/module/mock-builders/event/messageNew.js.map +1 -1
  96. package/lib/module/store/QuickSqliteClient.js +7 -3
  97. package/lib/module/store/QuickSqliteClient.js.map +1 -1
  98. package/lib/module/store/apis/getChannels.js +2 -15
  99. package/lib/module/store/apis/getChannels.js.map +1 -1
  100. package/lib/module/store/apis/getChannelsForFilterSort.js +37 -0
  101. package/lib/module/store/apis/getChannelsForFilterSort.js.map +1 -0
  102. package/lib/module/store/apis/index.js +264 -0
  103. package/lib/module/store/apis/index.js.map +1 -0
  104. package/lib/module/store/apis/queries/selectChannelIdsForFilterSort.js +1 -1
  105. package/lib/module/store/apis/queries/selectChannelIdsForFilterSort.js.map +1 -1
  106. package/lib/module/store/apis/queries/selectChannels.js +2 -2
  107. package/lib/module/store/apis/queries/selectChannels.js.map +1 -1
  108. package/lib/module/store/sqlite-utils/appendWhereCluase.js +1 -2
  109. package/lib/module/store/sqlite-utils/appendWhereCluase.js.map +1 -1
  110. package/lib/module/test-utils/BetterSqlite.js +54 -0
  111. package/lib/module/test-utils/BetterSqlite.js.map +1 -0
  112. package/lib/module/version.json +1 -1
  113. package/lib/typescript/components/Attachment/Gallery.d.ts +1 -1
  114. package/lib/typescript/components/Attachment/Giphy.d.ts +1 -1
  115. package/lib/typescript/components/Attachment/utils/getGiphyMimeType.d.ts +6 -0
  116. package/lib/typescript/components/ImageGallery/components/ImageGrid.d.ts +1 -1
  117. package/lib/typescript/components/ImageGallery/hooks/useImageGalleryGestures.d.ts +2 -1
  118. package/lib/typescript/components/Message/Message.d.ts +9 -3
  119. package/lib/typescript/components/MessageList/MessageList.d.ts +1 -1
  120. package/lib/typescript/contexts/imageGalleryContext/ImageGalleryContext.d.ts +9 -10
  121. package/lib/typescript/index.d.ts +2 -0
  122. package/lib/typescript/store/QuickSqliteClient.d.ts +4 -0
  123. package/lib/typescript/store/apis/getChannels.d.ts +13 -5
  124. package/lib/typescript/store/apis/getChannelsForFilterSort.d.ts +17 -0
  125. package/lib/typescript/store/apis/index.d.ts +20 -0
  126. package/lib/typescript/store/apis/queries/selectChannelIdsForFilterSort.d.ts +10 -1
  127. package/lib/typescript/{__tests__/utils → test-utils}/BetterSqlite.d.ts +1 -1
  128. package/package.json +5 -4
  129. package/src/__tests__/offline-feature.test.js +1 -2
  130. package/src/components/Attachment/FileAttachment.tsx +3 -0
  131. package/src/components/Attachment/Gallery.tsx +20 -17
  132. package/src/components/Attachment/Giphy.tsx +8 -8
  133. package/src/components/Attachment/utils/getGiphyMimeType.ts +13 -0
  134. package/src/components/Channel/Channel.tsx +1 -1
  135. package/src/components/ChannelList/__tests__/ChannelList.test.js +28 -0
  136. package/src/components/ChannelList/hooks/listeners/useNewMessage.ts +18 -5
  137. package/src/components/ChannelList/hooks/usePaginatedChannels.ts +19 -10
  138. package/src/components/ChannelPreview/ChannelPreview.tsx +6 -3
  139. package/src/components/ImageGallery/ImageGallery.tsx +32 -19
  140. package/src/components/ImageGallery/__tests__/ImageGallery.test.tsx +6 -6
  141. package/src/components/ImageGallery/__tests__/ImageGalleryFooter.test.tsx +3 -3
  142. package/src/components/ImageGallery/__tests__/ImageGalleryGrid.test.tsx +3 -3
  143. package/src/components/ImageGallery/__tests__/ImageGalleryHeader.test.tsx +3 -3
  144. package/src/components/ImageGallery/components/ImageGrid.tsx +3 -3
  145. package/src/components/ImageGallery/hooks/useImageGalleryGestures.tsx +16 -0
  146. package/src/components/Message/Message.tsx +9 -1
  147. package/src/components/Message/MessageSimple/MessageTextContainer.tsx +22 -2
  148. package/src/components/Message/MessageSimple/__tests__/__snapshots__/MessageAvatar.test.js.snap +1 -0
  149. package/src/components/Message/MessageSimple/utils/renderText.tsx +1 -1
  150. package/src/components/MessageList/MessageList.tsx +6 -6
  151. package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap +4 -0
  152. package/src/contexts/imageGalleryContext/ImageGalleryContext.md +1 -1
  153. package/src/contexts/imageGalleryContext/ImageGalleryContext.tsx +19 -14
  154. package/src/index.ts +3 -0
  155. package/src/mock-builders/DB/mock.ts +4 -9
  156. package/src/mock-builders/event/messageNew.js +2 -0
  157. package/src/store/QuickSqliteClient.ts +11 -7
  158. package/src/store/apis/getChannels.ts +17 -14
  159. package/src/store/apis/getChannelsForFilterSort.ts +45 -0
  160. package/src/store/apis/index.ts +20 -0
  161. package/src/store/apis/queries/selectChannelIdsForFilterSort.ts +12 -2
  162. package/src/store/apis/queries/selectChannels.ts +9 -3
  163. package/src/store/sqlite-utils/appendWhereCluase.ts +1 -2
  164. package/src/{__tests__/utils → test-utils}/BetterSqlite.js +1 -1
  165. package/src/version.json +1 -1
@@ -1,36 +1,39 @@
1
- import type { DefaultStreamChatGenerics } from 'src/types/types';
2
- import type { ChannelAPIResponse, ChannelFilters, ChannelSort } from 'stream-chat';
1
+ import type { ChannelAPIResponse } from 'stream-chat';
3
2
 
4
3
  import { getMessages } from './getChannelMessages';
5
4
  import { getMembers } from './getMembers';
6
5
  import { getReads } from './getReads';
7
- import { selectChannelIdsForFilterSort } from './queries/selectChannelIdsForFilterSort';
8
6
  import { selectChannels } from './queries/selectChannels';
9
7
 
8
+ import type { DefaultStreamChatGenerics } from '../../types/types';
10
9
  import { mapStorableToChannel } from '../mappers/mapStorableToChannel';
11
10
 
11
+ /**
12
+ * Returns the list of channels with state enriched for given channel ids.
13
+ *
14
+ * @param {Object} param
15
+ * @param {Array} param.channelIds List of channel ids to fetch.
16
+ * @param {Array} param.currentUserId Id of the current logged in user.
17
+ *
18
+ * @returns {Array} Channels with enriched state.
19
+ */
12
20
  export const getChannels = <
13
21
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
14
22
  >({
23
+ channelIds,
15
24
  currentUserId,
16
- filters,
17
- sort,
18
25
  }: {
26
+ channelIds: string[];
19
27
  currentUserId: string;
20
- filters?: ChannelFilters<StreamChatGenerics>;
21
- sort?: ChannelSort<StreamChatGenerics>;
22
28
  }): Omit<ChannelAPIResponse<StreamChatGenerics>, 'duration'>[] => {
23
- if (!filters && !sort) {
24
- console.warn('Please provide the query (filters/sort) to fetch channels from DB');
25
- return [];
26
- }
27
-
28
- const channelIds = selectChannelIdsForFilterSort({ filters, sort });
29
29
  const channels = selectChannels({ channelIds });
30
30
 
31
31
  const cidVsMembers = getMembers<StreamChatGenerics>({ channelIds });
32
32
  const cidVsReads = getReads<StreamChatGenerics>({ channelIds });
33
- const cidVsMessages = getMessages<StreamChatGenerics>({ channelIds, currentUserId });
33
+ const cidVsMessages = getMessages<StreamChatGenerics>({
34
+ channelIds,
35
+ currentUserId,
36
+ });
34
37
 
35
38
  // Enrich the channels with state
36
39
  return channels.map((c) => ({
@@ -0,0 +1,45 @@
1
+ import type { DefaultStreamChatGenerics } from 'src/types/types';
2
+ import type { ChannelAPIResponse, ChannelFilters, ChannelSort } from 'stream-chat';
3
+
4
+ import { getChannels } from './getChannels';
5
+ import { selectChannelIdsForFilterSort } from './queries/selectChannelIdsForFilterSort';
6
+
7
+ /**
8
+ * Gets the channels from database for given filter and sort query.
9
+ *
10
+ * @param {Object} param
11
+ * @param {string} param.currentUserId Id of current logged in user
12
+ * @param {Object} param.filters Filters for channels https://getstream.io/chat/docs/javascript/query_channels/?language=javascript&q=su#query-parameters
13
+ * @param {Object} param.sort Sort for channels https://getstream.io/chat/docs/javascript/query_channels/?language=javascript&q=su#query-parameters
14
+ *
15
+ * @returns Array of channels corresponding to filters & sort. Returns null if filters + sort query doesn't exist in "channelQueries" table.
16
+ */
17
+ export const getChannelsForFilterSort = <
18
+ StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
19
+ >({
20
+ currentUserId,
21
+ filters,
22
+ sort,
23
+ }: {
24
+ currentUserId: string;
25
+ filters?: ChannelFilters<StreamChatGenerics>;
26
+ sort?: ChannelSort<StreamChatGenerics>;
27
+ }): Omit<ChannelAPIResponse<StreamChatGenerics>, 'duration'>[] | null => {
28
+ if (!filters && !sort) {
29
+ console.warn('Please provide the query (filters/sort) to fetch channels from DB');
30
+ return null;
31
+ }
32
+
33
+ const channelIds = selectChannelIdsForFilterSort({ filters, sort });
34
+
35
+ if (!channelIds) return null;
36
+
37
+ if (channelIds.length === 0) {
38
+ return [];
39
+ }
40
+
41
+ return getChannels({
42
+ channelIds,
43
+ currentUserId,
44
+ });
45
+ };
@@ -0,0 +1,20 @@
1
+ export * from './deleteChannel';
2
+ export * from './deleteMember';
3
+ export * from './deleteMessagesForChannel';
4
+ export * from './deleteReactions';
5
+ export * from './getAllChannelIds';
6
+ export * from './getChannelMessages';
7
+ export * from './getChannels';
8
+ export * from './getChannelsForFilterSort';
9
+ export * from './getLastSyncedAt';
10
+ export * from './getMembers';
11
+ export * from './getReads';
12
+ export * from './updateMessage';
13
+ export * from './updateReaction';
14
+ export * from './upsertChannelData';
15
+ export * from './upsertChannels';
16
+ export * from './upsertCidsForQuery';
17
+ export * from './upsertLastSyncedAt';
18
+ export * from './upsertMembers';
19
+ export * from './upsertMessages';
20
+ export * from './upsertReads';
@@ -6,6 +6,16 @@ import { createSelectQuery } from '../../sqlite-utils/createSelectQuery';
6
6
 
7
7
  import { convertFilterSortToQuery } from '../utils/convertFilterSortToQuery';
8
8
 
9
+ /**
10
+ * Gets the channel ids from database for given filter and sort query.
11
+ *
12
+ * @param {Object} param
13
+ * @param {Object} param.filters Filters for channels https://getstream.io/chat/docs/javascript/query_channels/?language=javascript&q=su#query-parameters
14
+ * @param {Object} param.sort Sort for channels https://getstream.io/chat/docs/javascript/query_channels/?language=javascript&q=su#query-parameters
15
+ *
16
+ * @returns Array of channel ids corresponding to filters & sort. Returns null if filters + sort query doesn't exist in "channelQueries" table.
17
+ */
18
+
9
19
  export const selectChannelIdsForFilterSort = <
10
20
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
11
21
  >({
@@ -14,7 +24,7 @@ export const selectChannelIdsForFilterSort = <
14
24
  }: {
15
25
  filters?: ChannelFilters<StreamChatGenerics>;
16
26
  sort?: ChannelSort<StreamChatGenerics>;
17
- }): string[] => {
27
+ }): string[] | null => {
18
28
  const query = convertFilterSortToQuery({ filters, sort });
19
29
  const results = QuickSqliteClient.executeSql.apply(
20
30
  null,
@@ -24,5 +34,5 @@ export const selectChannelIdsForFilterSort = <
24
34
  );
25
35
 
26
36
  const channelIdsStr = results?.[0]?.cids;
27
- return channelIdsStr ? JSON.parse(channelIdsStr) : [];
37
+ return channelIdsStr ? JSON.parse(channelIdsStr) : null;
28
38
  };
@@ -5,9 +5,15 @@ import type { TableRowJoinedUser } from '../../types';
5
5
  export const selectChannels = ({
6
6
  channelIds,
7
7
  }: { channelIds?: string[] } = {}): TableRowJoinedUser<'channels'>[] => {
8
- const query = createSelectQuery('channels', ['*'], {
9
- cid: channelIds,
10
- });
8
+ const query = createSelectQuery(
9
+ 'channels',
10
+ ['*'],
11
+ channelIds
12
+ ? {
13
+ cid: channelIds,
14
+ }
15
+ : undefined,
16
+ );
11
17
 
12
18
  const result = QuickSqliteClient.executeSql.apply(null, query);
13
19
 
@@ -15,7 +15,6 @@ export const appendWhereClause = <T extends keyof Schema>(
15
15
  if (value === undefined) continue;
16
16
 
17
17
  if (Array.isArray(value)) {
18
- if (value.length === 0) continue;
19
18
  const questionMarks = Array(Object.keys(value).length).fill('?').join(',');
20
19
  whereClause.push(`${key} in (${questionMarks})`);
21
20
  whereParams.push(...value);
@@ -25,7 +24,7 @@ export const appendWhereClause = <T extends keyof Schema>(
25
24
  }
26
25
  }
27
26
 
28
- if (!whereParams.length) {
27
+ if (!whereParams.length && !whereClause.length) {
29
28
  return [selectQuery, []];
30
29
  }
31
30
 
@@ -1,6 +1,6 @@
1
1
  import Database from 'better-sqlite3';
2
2
 
3
- import { tables } from '../../store/schema';
3
+ import { tables } from '../store/schema';
4
4
 
5
5
  export class BetterSqlite {
6
6
  db = null;
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.0.0-beta.0"
2
+ "version": "5.0.0-beta.3"
3
3
  }