stream-chat-react-native-core 5.15.0-beta.5 → 5.15.0-beta.7

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 (29) hide show
  1. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +24 -56
  2. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  3. package/lib/commonjs/store/apis/index.js +4 -4
  4. package/lib/commonjs/store/apis/index.js.map +1 -1
  5. package/lib/commonjs/store/apis/{upsertLastSyncedAt.js → upsertUserSyncStatus.js} +4 -4
  6. package/lib/commonjs/store/apis/upsertUserSyncStatus.js.map +1 -0
  7. package/lib/commonjs/utils/DBSyncManager.js +18 -12
  8. package/lib/commonjs/utils/DBSyncManager.js.map +1 -1
  9. package/lib/commonjs/version.json +1 -1
  10. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +24 -56
  11. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  12. package/lib/module/store/apis/index.js +4 -4
  13. package/lib/module/store/apis/index.js.map +1 -1
  14. package/lib/module/store/apis/{upsertLastSyncedAt.js → upsertUserSyncStatus.js} +4 -4
  15. package/lib/module/store/apis/upsertUserSyncStatus.js.map +1 -0
  16. package/lib/module/utils/DBSyncManager.js +18 -12
  17. package/lib/module/utils/DBSyncManager.js.map +1 -1
  18. package/lib/module/version.json +1 -1
  19. package/lib/typescript/store/apis/index.d.ts +1 -1
  20. package/lib/typescript/store/apis/upsertUserSyncStatus.d.ts +4 -0
  21. package/package.json +1 -1
  22. package/src/components/ChannelList/hooks/usePaginatedChannels.ts +8 -49
  23. package/src/store/apis/index.ts +1 -1
  24. package/src/store/apis/{upsertLastSyncedAt.ts → upsertUserSyncStatus.ts} +1 -1
  25. package/src/utils/DBSyncManager.ts +5 -2
  26. package/src/version.json +1 -1
  27. package/lib/commonjs/store/apis/upsertLastSyncedAt.js.map +0 -1
  28. package/lib/module/store/apis/upsertLastSyncedAt.js.map +0 -1
  29. package/lib/typescript/store/apis/upsertLastSyncedAt.d.ts +0 -4
@@ -1,12 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
 
3
- import type {
4
- Channel,
5
- ChannelFilters,
6
- ChannelOptions,
7
- ChannelSort,
8
- MessageResponse,
9
- } from 'stream-chat';
3
+ import type { Channel, ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat';
10
4
 
11
5
  import { useActiveChannelsRefContext } from '../../../contexts/activeChannelsRefContext/ActiveChannelsRefContext';
12
6
  import { useChatContext } from '../../../contexts/chatContext/ChatContext';
@@ -16,7 +10,6 @@ import { getChannelsForFilterSort } from '../../../store/apis/getChannelsForFilt
16
10
  import type { DefaultStreamChatGenerics } from '../../../types/types';
17
11
  import { ONE_SECOND_IN_MS } from '../../../utils/date';
18
12
  import { DBSyncManager } from '../../../utils/DBSyncManager';
19
- import { MessageStatusTypes } from '../../../utils/utils';
20
13
  import { MAX_QUERY_CHANNELS_LIMIT } from '../utils';
21
14
 
22
15
  const waitSeconds = (seconds: number) =>
@@ -108,35 +101,18 @@ export const usePaginatedChannels = <
108
101
  };
109
102
 
110
103
  try {
111
- // If failed messages were present in DB it would be in the channel state now and be overwritten by the queryChannels call
112
- // So we store them in a separate object and add them back to the channel state after the queryChannels call
113
- const failedMessagesInDb: Map<string, MessageResponse<StreamChatGenerics>[]> = new Map();
114
- if (enableOfflineSupport) {
115
- for (const cid in client.activeChannels) {
116
- const failedMessages = getFailedMessages(client.activeChannels[cid]);
117
- if (failedMessages) failedMessagesInDb.set(cid, failedMessages);
118
- }
119
- }
120
-
121
104
  /**
122
105
  * We skipInitialization here for handling race condition between ChannelList, Channel (and Thread)
123
106
  * when they all (may) update the channel state at the same time (when connection state recovers)
124
107
  * TODO: if we move the channel state to a single context and share it between ChannelList, Channel and Thread we can remove this
125
108
  */
126
109
  const channelQueryResponse = await client.queryChannels(filters, sort, newOptions, {
127
- skipInitialization: activeChannels.current,
110
+ skipInitialization: enableOfflineSupport ? undefined : activeChannels.current,
128
111
  });
129
112
  if (isQueryStale() || !isMountedRef.current) {
130
113
  return;
131
114
  }
132
115
 
133
- if (failedMessagesInDb.size) {
134
- for (const cid in client.activeChannels) {
135
- const msgsToAdd = failedMessagesInDb.get(cid);
136
- if (msgsToAdd) client.activeChannels[cid].state.addMessagesSorted(msgsToAdd);
137
- }
138
- }
139
-
140
116
  const newChannels =
141
117
  queryType === 'loadChannels' && !staticChannelsActive && channels
142
118
  ? [...channels, ...channelQueryResponse]
@@ -224,11 +200,12 @@ export const usePaginatedChannels = <
224
200
  });
225
201
 
226
202
  if (channelsFromDB) {
227
- setChannels(
228
- client.hydrateActiveChannels(channelsFromDB, {
229
- offlineMode: true,
230
- }),
231
- );
203
+ const offlineChannels = client.hydrateActiveChannels(channelsFromDB, {
204
+ offlineMode: true,
205
+ skipInitialization: [], // passing empty array will clear out the existing messages from channel state, this removes the possibility of duplicate messages
206
+ });
207
+
208
+ setChannels(offlineChannels);
232
209
  setStaticChannelsActive(true);
233
210
  }
234
211
  } catch (e) {
@@ -292,21 +269,3 @@ export const usePaginatedChannels = <
292
269
  staticChannelsActive,
293
270
  };
294
271
  };
295
-
296
- function getFailedMessages<
297
- StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
298
- >(channel: Channel<StreamChatGenerics>): MessageResponse<StreamChatGenerics>[] | undefined {
299
- const failedMsgs = channel.state.messages.filter((m) => m.status === MessageStatusTypes.FAILED);
300
- if (failedMsgs.length) {
301
- return failedMsgs.map(
302
- (m) =>
303
- ({
304
- ...m,
305
- created_at: m.created_at.toISOString(),
306
- pinned_at: m.pinned_at ? m.pinned_at.toISOString() : null,
307
- updated_at: m.updated_at.toISOString(),
308
- } as MessageResponse<StreamChatGenerics>),
309
- );
310
- }
311
- return undefined;
312
- }
@@ -17,7 +17,7 @@ export * from './upsertAppSettings';
17
17
  export * from './upsertChannelData';
18
18
  export * from './upsertChannels';
19
19
  export * from './upsertCidsForQuery';
20
- export * from './upsertLastSyncedAt';
20
+ export * from './upsertUserSyncStatus';
21
21
  export * from './upsertMembers';
22
22
  export * from './upsertMessages';
23
23
  export * from './upsertReads';
@@ -1,7 +1,7 @@
1
1
  import { QuickSqliteClient } from '../QuickSqliteClient';
2
2
  import { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';
3
3
 
4
- export const upsertLastSyncedAt = ({
4
+ export const upsertUserSyncStatus = ({
5
5
  currentUserId,
6
6
  lastSyncedAt,
7
7
  }: {
@@ -2,7 +2,7 @@ import type { AxiosError } from 'axios';
2
2
  import type { APIErrorResponse, StreamChat } from 'stream-chat';
3
3
 
4
4
  import { handleEventToSyncDB } from '../components/Chat/hooks/handleEventToSyncDB';
5
- import { getAllChannelIds, getLastSyncedAt, upsertLastSyncedAt } from '../store/apis';
5
+ import { getAllChannelIds, getLastSyncedAt, upsertUserSyncStatus } from '../store/apis';
6
6
 
7
7
  import { addPendingTask } from '../store/apis/addPendingTask';
8
8
 
@@ -11,6 +11,7 @@ import { getPendingTasks } from '../store/apis/getPendingTasks';
11
11
  import { QuickSqliteClient } from '../store/QuickSqliteClient';
12
12
  import type { PendingTask, PreparedQueries } from '../store/types';
13
13
  import type { DefaultStreamChatGenerics } from '../types/types';
14
+
14
15
  /**
15
16
  * DBSyncManager has the responsibility to sync the channel states
16
17
  * within local database whenever possible.
@@ -95,6 +96,8 @@ export class DBSyncManager {
95
96
  currentUserId: this.client.user.id,
96
97
  });
97
98
  const cids = getAllChannelIds();
99
+ // If there are no channels, then there is no need to sync.
100
+ if (cids.length === 0) return;
98
101
 
99
102
  if (lastSyncedAt) {
100
103
  try {
@@ -113,7 +116,7 @@ export class DBSyncManager {
113
116
  QuickSqliteClient.resetDB();
114
117
  }
115
118
  }
116
- upsertLastSyncedAt({
119
+ upsertUserSyncStatus({
117
120
  currentUserId: this.client.user.id,
118
121
  lastSyncedAt: new Date().toString(),
119
122
  });
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.15.0-beta.5"
2
+ "version": "5.15.0-beta.7"
3
3
  }
@@ -1 +0,0 @@
1
- {"version":3,"names":["_QuickSqliteClient","require","_createUpsertQuery","upsertLastSyncedAt","_ref","currentUserId","lastSyncedAt","query","createUpsertQuery","userId","QuickSqliteClient","executeSql","apply","exports"],"sources":["upsertLastSyncedAt.ts"],"sourcesContent":["import { QuickSqliteClient } from '../QuickSqliteClient';\nimport { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';\n\nexport const upsertLastSyncedAt = ({\n currentUserId,\n lastSyncedAt,\n}: {\n currentUserId: string;\n lastSyncedAt: string;\n}) => {\n const query = createUpsertQuery('userSyncStatus', {\n lastSyncedAt,\n userId: currentUserId,\n });\n\n QuickSqliteClient.executeSql.apply(null, query);\n};\n"],"mappings":";;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAEO,IAAME,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAAC,IAAA,EAMzB;EAAA,IALJC,aAAa,GAAAD,IAAA,CAAbC,aAAa;IACbC,YAAY,GAAAF,IAAA,CAAZE,YAAY;EAKZ,IAAMC,KAAK,GAAG,IAAAC,oCAAiB,EAAC,gBAAgB,EAAE;IAChDF,YAAY,EAAZA,YAAY;IACZG,MAAM,EAAEJ;EACV,CAAC,CAAC;EAEFK,oCAAiB,CAACC,UAAU,CAACC,KAAK,CAAC,IAAI,EAAEL,KAAK,CAAC;AACjD,CAAC;AAACM,OAAA,CAAAV,kBAAA,GAAAA,kBAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"names":["_QuickSqliteClient","require","_createUpsertQuery","upsertLastSyncedAt","_ref","currentUserId","lastSyncedAt","query","createUpsertQuery","userId","QuickSqliteClient","executeSql","apply","exports"],"sources":["upsertLastSyncedAt.ts"],"sourcesContent":["import { QuickSqliteClient } from '../QuickSqliteClient';\nimport { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';\n\nexport const upsertLastSyncedAt = ({\n currentUserId,\n lastSyncedAt,\n}: {\n currentUserId: string;\n lastSyncedAt: string;\n}) => {\n const query = createUpsertQuery('userSyncStatus', {\n lastSyncedAt,\n userId: currentUserId,\n });\n\n QuickSqliteClient.executeSql.apply(null, query);\n};\n"],"mappings":";;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA;AAEO,IAAME,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAAC,IAAA,EAMzB;EAAA,IALJC,aAAa,GAAAD,IAAA,CAAbC,aAAa;IACbC,YAAY,GAAAF,IAAA,CAAZE,YAAY;EAKZ,IAAMC,KAAK,GAAG,IAAAC,oCAAiB,EAAC,gBAAgB,EAAE;IAChDF,YAAY,EAAZA,YAAY;IACZG,MAAM,EAAEJ;EACV,CAAC,CAAC;EAEFK,oCAAiB,CAACC,UAAU,CAACC,KAAK,CAAC,IAAI,EAAEL,KAAK,CAAC;AACjD,CAAC;AAACM,OAAA,CAAAV,kBAAA,GAAAA,kBAAA"}
@@ -1,4 +0,0 @@
1
- export declare const upsertLastSyncedAt: ({ currentUserId, lastSyncedAt, }: {
2
- currentUserId: string;
3
- lastSyncedAt: string;
4
- }) => void;