Skip to content

Commit 339bf4f

Browse files
committed
feat: move queryChannels events to LLC
1 parent f509a27 commit 339bf4f

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

package/src/components/ChannelList/ChannelList.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ export const ChannelList = (props: ChannelListProps) => {
370370
return;
371371
}
372372

373-
upsertCidsForQuery({
374-
cids: channels.map((c) => c.cid),
375-
filters,
376-
sort,
377-
});
373+
// upsertCidsForQuery({
374+
// cids: channels.map((c) => c.cid),
375+
// filters,
376+
// sort,
377+
// });
378378
// eslint-disable-next-line react-hooks/exhaustive-deps
379379
}, [channelIdsStr, staticChannelsActive]);
380380

package/src/components/ChannelList/hooks/usePaginatedChannels.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -234,35 +234,34 @@ export const usePaginatedChannels = ({
234234
// Any time DB is synced, we need to update the UI with local DB channels first,
235235
// and then call queryChannels to ensure any new channels are added to UI.
236236
listener = DBSyncManager.onSyncStatusChange(async (syncStatus) => {
237-
if (syncStatus) {
238-
const loadingChannelsSucceeded = await loadOfflineChannels();
239-
if (loadingChannelsSucceeded) {
240-
await reloadList();
241-
setForceUpdate((u) => u + 1);
242-
}
243-
}
237+
// if (syncStatus) {
238+
// const loadingChannelsSucceeded = await loadOfflineChannels();
239+
// if (loadingChannelsSucceeded) {
240+
// await reloadList();
241+
// setForceUpdate((u) => u + 1);
242+
// }
243+
// }
244244
});
245245
// On start, load the channels from local db.
246-
loadOfflineChannels().then((success) => {
247-
// If db is already synced (sync api and pending api calls), then
248-
// right away call queryChannels.
249-
if (success) {
250-
const dbSyncStatus = DBSyncManager.getSyncStatus();
251-
if (dbSyncStatus) {
252-
reloadList();
253-
}
254-
}
255-
});
246+
// loadOfflineChannels().then((success) => {
247+
// // If db is already synced (sync api and pending api calls), then
248+
// // right away call queryChannels.
249+
// if (success) {
250+
// const dbSyncStatus = DBSyncManager.getSyncStatus();
251+
// if (dbSyncStatus) {
252+
// reloadList();
253+
// }
254+
// }
255+
// });
256256
} else {
257257
listener = client.on('connection.changed', async (event) => {
258258
if (event.online) {
259259
await refreshList();
260260
setForceUpdate((u) => u + 1);
261261
}
262262
});
263-
264-
reloadList();
265263
}
264+
reloadList();
266265

267266
return () => listener?.unsubscribe?.();
268267
// eslint-disable-next-line react-hooks/exhaustive-deps

package/src/components/Chat/Chat.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { useStreami18n } from '../../hooks/useStreami18n';
2424
import init from '../../init';
2525

2626
import { NativeHandlers } from '../../native';
27+
import { OfflineDB } from '../../store/OfflineDB';
2728
import { SqliteClient } from '../../store/SqliteClient';
2829

2930
import { DBSyncManager } from '../../utils/DBSyncManager';
@@ -213,6 +214,11 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
213214
}
214215

215216
const initializeDatabase = () => {
217+
// TODO: Rethink this, it looks ugly
218+
console.log('TESTING2', client);
219+
const offlineDBInstance = new OfflineDB({ client });
220+
console.log(offlineDBInstance);
221+
client.setOfflineDBApi(offlineDBInstance);
216222
// This acts as a lock for some very rare occurrences of concurrency
217223
// issues we've encountered before with the QuickSqliteClient being
218224
// uninitialized before it's being invoked.

package/src/components/Chat/hooks/handleEventToSyncDB.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ export const handleEventToSyncDB = async (event: Event, client: StreamChat, flus
227227
}
228228
}
229229

230-
if (type === 'channels.queried') {
231-
if (event.queriedChannels?.channels?.length) {
232-
return upsertChannels({
233-
channels: event.queriedChannels?.channels,
234-
flush,
235-
isLatestMessagesSet: event.queriedChannels?.isLatestMessageSet,
236-
});
237-
}
238-
}
230+
// if (type === 'channels.queried') {
231+
// if (event.queriedChannels?.channels?.length) {
232+
// return upsertChannels({
233+
// channels: event.queriedChannels?.channels,
234+
// flush,
235+
// isLatestMessagesSet: event.queriedChannels?.isLatestMessageSet,
236+
// });
237+
// }
238+
// }
239239

240240
if (type === 'member.added' || type === 'member.updated') {
241241
const member = event.member;

package/src/store/OfflineDB.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { AbstractOfflineDB, GetChannelsForQueryType, GetChannelsType } from 'stream-chat';
2+
3+
import * as api from './apis';
4+
5+
export class OfflineDB extends AbstractOfflineDB {
6+
upsertCidsForQuery = api.upsertCidsForQuery;
7+
upsertChannels = api.upsertChannels;
8+
// FIXME
9+
getChannels = ({ cids, userId }: GetChannelsType) =>
10+
api.getChannels({ channelIds: cids, currentUserId: userId });
11+
// FIXME
12+
getChannelsForQuery = ({ userId, filters, sort }: GetChannelsForQueryType) =>
13+
api.getChannelsForFilterSort({ currentUserId: userId, filters, sort });
14+
}

0 commit comments

Comments
 (0)