stream-chat-react-native-core 5.0.0-offline-support.0 → 5.0.0-offline-support.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.
- package/lib/commonjs/components/ChannelList/ChannelList.js +2 -2
- package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/listeners/handleEventToSyncDB.js +2 -47
- package/lib/commonjs/components/ChannelList/hooks/listeners/handleEventToSyncDB.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +2 -2
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/ChannelAvatar.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +12 -16
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/commonjs/mock-builders/event/memberAdded.js.map +1 -1
- package/lib/commonjs/mock-builders/event/memberRemoved.js.map +1 -1
- package/lib/commonjs/mock-builders/event/memberUpdated.js.map +1 -1
- package/lib/commonjs/mock-builders/event/reactionDeleted.js.map +1 -1
- package/lib/commonjs/mock-builders/event/reactionNew.js.map +1 -1
- package/lib/commonjs/mock-builders/event/reactionUpdated.js.map +1 -1
- package/lib/commonjs/store/sqlite-utils/appendWhereCluase.js +2 -1
- package/lib/commonjs/store/sqlite-utils/appendWhereCluase.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/ChannelList/ChannelList.js +2 -2
- package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/listeners/handleEventToSyncDB.js +2 -47
- package/lib/module/components/ChannelList/hooks/listeners/handleEventToSyncDB.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +2 -2
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/module/components/ChannelPreview/ChannelAvatar.js.map +1 -1
- package/lib/module/components/MessageList/MessageList.js +1 -1
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/contexts/overlayContext/OverlayProvider.js +12 -16
- package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/module/mock-builders/event/memberAdded.js.map +1 -1
- package/lib/module/mock-builders/event/memberRemoved.js.map +1 -1
- package/lib/module/mock-builders/event/memberUpdated.js.map +1 -1
- package/lib/module/mock-builders/event/reactionDeleted.js.map +1 -1
- package/lib/module/mock-builders/event/reactionNew.js.map +1 -1
- package/lib/module/mock-builders/event/reactionUpdated.js.map +1 -1
- package/lib/module/store/sqlite-utils/appendWhereCluase.js +2 -1
- package/lib/module/store/sqlite-utils/appendWhereCluase.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts +1 -1
- package/package.json +2 -2
- package/src/__tests__/offline-feature.test.js +149 -109
- package/src/components/ChannelList/ChannelList.tsx +1 -1
- package/src/components/ChannelList/hooks/listeners/handleEventToSyncDB.ts +15 -48
- package/src/components/ChannelList/hooks/usePaginatedChannels.ts +1 -1
- package/src/components/ChannelPreview/ChannelAvatar.tsx +3 -3
- package/src/components/MessageList/MessageList.tsx +1 -1
- package/src/contexts/overlayContext/OverlayProvider.tsx +0 -3
- package/src/mock-builders/event/memberAdded.js +7 -8
- package/src/mock-builders/event/memberRemoved.js +7 -8
- package/src/mock-builders/event/memberUpdated.js +7 -8
- package/src/mock-builders/event/reactionDeleted.js +8 -9
- package/src/mock-builders/event/reactionNew.js +8 -9
- package/src/mock-builders/event/reactionUpdated.js +8 -9
- package/src/store/sqlite-utils/appendWhereCluase.ts +3 -1
- package/src/version.json +1 -1
|
@@ -14,9 +14,10 @@ var appendWhereClause = function appendWhereClause(selectQuery, whereCondition)
|
|
|
14
14
|
|
|
15
15
|
for (var key in whereCondition) {
|
|
16
16
|
var value = whereCondition[key];
|
|
17
|
+
if (value === undefined) continue;
|
|
17
18
|
|
|
18
19
|
if (Array.isArray(value)) {
|
|
19
|
-
if (
|
|
20
|
+
if (value.length === 0) continue;
|
|
20
21
|
var questionMarks = Array(Object.keys(value).length).fill('?').join(',');
|
|
21
22
|
whereClause.push(key + " in (" + questionMarks + ")");
|
|
22
23
|
whereParams.push.apply(whereParams, (0, _toConsumableArray2["default"])(value));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["appendWhereCluase.ts"],"names":["appendWhereClause","selectQuery","whereCondition","whereClause","whereParams","key","value","Array","isArray","length","questionMarks","Object","keys","fill","join","push"],"mappings":";;;;;;;;;AAGO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,CAC/BC,WAD+B,EAE/BC,cAF+B,EAG5B;AACH,MAAI,CAACA,cAAL,EAAqB,OAAO,CAACD,WAAD,EAAc,EAAd,CAAP;AAErB,MAAME,WAAW,GAAG,EAApB;AACA,MAAMC,WAAsB,GAAG,EAA/B;;AAEA,OAAK,IAAMC,GAAX,IAAkBH,cAAlB,EAAkC;AAChC,QAAMI,KAAc,GAAGJ,cAAc,CAACG,GAAD,CAArC
|
|
1
|
+
{"version":3,"sources":["appendWhereCluase.ts"],"names":["appendWhereClause","selectQuery","whereCondition","whereClause","whereParams","key","value","undefined","Array","isArray","length","questionMarks","Object","keys","fill","join","push"],"mappings":";;;;;;;;;AAGO,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,CAC/BC,WAD+B,EAE/BC,cAF+B,EAG5B;AACH,MAAI,CAACA,cAAL,EAAqB,OAAO,CAACD,WAAD,EAAc,EAAd,CAAP;AAErB,MAAME,WAAW,GAAG,EAApB;AACA,MAAMC,WAAsB,GAAG,EAA/B;;AAEA,OAAK,IAAMC,GAAX,IAAkBH,cAAlB,EAAkC;AAChC,QAAMI,KAAc,GAAGJ,cAAc,CAACG,GAAD,CAArC;AACA,QAAIC,KAAK,KAAKC,SAAd,EAAyB;;AAEzB,QAAIC,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAJ,EAA0B;AACxB,UAAIA,KAAK,CAACI,MAAN,KAAiB,CAArB,EAAwB;AACxB,UAAMC,aAAa,GAAGH,KAAK,CAACI,MAAM,CAACC,IAAP,CAAYP,KAAZ,EAAmBI,MAApB,CAAL,CAAiCI,IAAjC,CAAsC,GAAtC,EAA2CC,IAA3C,CAAgD,GAAhD,CAAtB;AACAZ,MAAAA,WAAW,CAACa,IAAZ,CAAoBX,GAApB,aAA+BM,aAA/B;AACAP,MAAAA,WAAW,CAACY,IAAZ,OAAAZ,WAAW,sCAASE,KAAT,EAAX;AACD,KALD,MAKO;AACLH,MAAAA,WAAW,CAACa,IAAZ,CAAoBX,GAApB;AACAD,MAAAA,WAAW,CAACY,IAAZ,CAAiBV,KAAjB;AACD;AACF;;AAED,MAAI,CAACF,WAAW,CAACM,MAAjB,EAAyB;AACvB,WAAO,CAACT,WAAD,EAAc,EAAd,CAAP;AACD;;AAED,SAAO,CAAIA,WAAJ,eAAyBE,WAAW,CAACY,IAAZ,CAAiB,OAAjB,CAAzB,EAAsDX,WAAtD,CAAP;AACD,CA7BM","sourcesContent":["import type { Schema } from '../schema';\nimport type { PreparedQueries, TableColumnNames } from '../types';\n\nexport const appendWhereClause = <T extends keyof Schema>(\n selectQuery: string,\n whereCondition?: Partial<{ [k in TableColumnNames<T>]: any }>,\n) => {\n if (!whereCondition) return [selectQuery, []];\n\n const whereClause = [];\n const whereParams: unknown[] = [];\n\n for (const key in whereCondition) {\n const value: unknown = whereCondition[key];\n if (value === undefined) continue;\n\n if (Array.isArray(value)) {\n if (value.length === 0) continue;\n const questionMarks = Array(Object.keys(value).length).fill('?').join(',');\n whereClause.push(`${key} in (${questionMarks})`);\n whereParams.push(...value);\n } else {\n whereClause.push(`${key} = ?`);\n whereParams.push(value);\n }\n }\n\n if (!whereParams.length) {\n return [selectQuery, []];\n }\n\n return [`${selectQuery} WHERE ${whereClause.join(' AND ')}`, whereParams] as PreparedQueries;\n};\n"]}
|
package/lib/module/version.json
CHANGED
|
@@ -16,10 +16,10 @@ export declare const usePaginatedChannels: <StreamChatGenerics extends DefaultSt
|
|
|
16
16
|
loadingChannels: boolean;
|
|
17
17
|
loadingNextPage: boolean;
|
|
18
18
|
loadNextPage: QueryChannels | undefined;
|
|
19
|
-
staticChannelsActive: boolean;
|
|
20
19
|
refreshing: boolean;
|
|
21
20
|
refreshList: () => Promise<void> | undefined;
|
|
22
21
|
reloadList: () => Promise<void>;
|
|
23
22
|
setChannels: import("react").Dispatch<import("react").SetStateAction<Channel<StreamChatGenerics>[]>>;
|
|
23
|
+
staticChannelsActive: boolean;
|
|
24
24
|
};
|
|
25
25
|
export {};
|
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": "5.0.0-offline-support.
|
|
4
|
+
"version": "5.0.0-offline-support.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"react-art": "^17.0.2",
|
|
81
81
|
"react-native-markdown-package": "1.8.1",
|
|
82
82
|
"react-native-url-polyfill": "^1.3.0",
|
|
83
|
-
"stream-chat": "7.0.0-offline-support.
|
|
83
|
+
"stream-chat": "7.0.0-offline-support.2"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"react-native-svg": "^12.1.0"
|
|
@@ -66,7 +66,7 @@ const ChannelListComponent = (props) => {
|
|
|
66
66
|
);
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
const waitTill = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
69
|
+
const waitTill = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
70
70
|
|
|
71
71
|
describe('Offline support is disabled', () => {
|
|
72
72
|
let chatClient;
|
|
@@ -100,52 +100,57 @@ describe('Offline support is disabled', () => {
|
|
|
100
100
|
describe('Offline support is enabled', () => {
|
|
101
101
|
let chatClient;
|
|
102
102
|
let channels;
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
let allUsers;
|
|
105
105
|
let allMessages;
|
|
106
106
|
let allMembers;
|
|
107
107
|
let allReactions;
|
|
108
108
|
let allReads;
|
|
109
|
-
const getRandomInt = (lower, upper) => Math.floor(lower +
|
|
109
|
+
const getRandomInt = (lower, upper) => Math.floor(lower + Math.random() * (upper - lower + 1));
|
|
110
110
|
const createChannel = () => {
|
|
111
111
|
const id = uuidv4();
|
|
112
112
|
const cid = `messaging:${id}`;
|
|
113
113
|
const begin = getRandomInt(0, allUsers.length - 2); // begin shouldn't be the end of users.length
|
|
114
114
|
const end = getRandomInt(begin + 1, allUsers.length - 1);
|
|
115
115
|
const usersForMembers = allUsers.slice(begin, end);
|
|
116
|
-
const members = usersForMembers.map(user =>
|
|
117
|
-
|
|
118
|
-
user,
|
|
119
|
-
}));
|
|
120
|
-
const messages = Array(10).fill(1).map(() => {
|
|
121
|
-
const id = uuidv4();
|
|
122
|
-
const user = usersForMembers[getRandomInt(0, usersForMembers.length - 1)];
|
|
123
|
-
|
|
124
|
-
const begin = getRandomInt(0, usersForMembers.length - 2); // begin shouldn't be the end of users.length
|
|
125
|
-
const end = getRandomInt(begin + 1, usersForMembers.length - 1);
|
|
126
|
-
|
|
127
|
-
const usersForReactions = usersForMembers.slice(begin, end);
|
|
128
|
-
const reactions = usersForReactions.map((user) => generateReaction({
|
|
129
|
-
message_id: id,
|
|
130
|
-
user
|
|
131
|
-
}));
|
|
132
|
-
allReactions.push(...reactions);
|
|
133
|
-
return generateMessage({
|
|
116
|
+
const members = usersForMembers.map((user) =>
|
|
117
|
+
generateMember({
|
|
134
118
|
cid,
|
|
135
|
-
id,
|
|
136
|
-
latest_reactions: reactions,
|
|
137
119
|
user,
|
|
138
|
-
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
const messages = Array(10)
|
|
123
|
+
.fill(1)
|
|
124
|
+
.map(() => {
|
|
125
|
+
const id = uuidv4();
|
|
126
|
+
const user = usersForMembers[getRandomInt(0, usersForMembers.length - 1)];
|
|
127
|
+
|
|
128
|
+
const begin = getRandomInt(0, usersForMembers.length - 2); // begin shouldn't be the end of users.length
|
|
129
|
+
const end = getRandomInt(begin + 1, usersForMembers.length - 1);
|
|
130
|
+
|
|
131
|
+
const usersForReactions = usersForMembers.slice(begin, end);
|
|
132
|
+
const reactions = usersForReactions.map((user) =>
|
|
133
|
+
generateReaction({
|
|
134
|
+
message_id: id,
|
|
135
|
+
user,
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
allReactions.push(...reactions);
|
|
139
|
+
return generateMessage({
|
|
140
|
+
cid,
|
|
141
|
+
id,
|
|
142
|
+
latest_reactions: reactions,
|
|
143
|
+
user,
|
|
144
|
+
userId: user.id,
|
|
145
|
+
});
|
|
139
146
|
});
|
|
140
|
-
});
|
|
141
147
|
|
|
142
|
-
const reads = members.map(member => ({
|
|
148
|
+
const reads = members.map((member) => ({
|
|
143
149
|
last_read: new Date(new Date().setDate(new Date().getDate() - getRandomInt(0, 20))),
|
|
144
150
|
unread_messages: getRandomInt(0, messages.length),
|
|
145
151
|
user: member.user,
|
|
146
152
|
}));
|
|
147
153
|
|
|
148
|
-
|
|
149
154
|
allMessages.push(...messages);
|
|
150
155
|
allMembers.push(...members);
|
|
151
156
|
allReads.push(...reads);
|
|
@@ -165,7 +170,9 @@ describe('Offline support is enabled', () => {
|
|
|
165
170
|
allMembers = [];
|
|
166
171
|
allReactions = [];
|
|
167
172
|
allReads = [];
|
|
168
|
-
channels = Array(10)
|
|
173
|
+
channels = Array(10)
|
|
174
|
+
.fill(1)
|
|
175
|
+
.map(() => createChannel());
|
|
169
176
|
|
|
170
177
|
chatClient = await getTestClientWithUser({ id: 'dan' });
|
|
171
178
|
});
|
|
@@ -196,7 +203,7 @@ describe('Offline support is enabled', () => {
|
|
|
196
203
|
const expectCIDsOnUIToBeInDB = (queryAllByA11yRole) => {
|
|
197
204
|
const channelIdsOnUI = queryAllByA11yRole('list-item').map(
|
|
198
205
|
(node) => node._fiber.pendingProps.testID,
|
|
199
|
-
|
|
206
|
+
);
|
|
200
207
|
|
|
201
208
|
const channelQueriesRows = BetterSqlite.selectFromTable('channelQueries');
|
|
202
209
|
const cidsInDB = JSON.parse(channelQueriesRows[0].cids);
|
|
@@ -214,7 +221,6 @@ describe('Offline support is enabled', () => {
|
|
|
214
221
|
});
|
|
215
222
|
};
|
|
216
223
|
|
|
217
|
-
|
|
218
224
|
const expectAllChannelsWithStateToBeInDB = (queryAllByA11yRole) => {
|
|
219
225
|
const channelIdsOnUI = queryAllByA11yRole('list-item').map(
|
|
220
226
|
(node) => node._fiber.pendingProps.testID,
|
|
@@ -238,19 +244,28 @@ describe('Offline support is enabled', () => {
|
|
|
238
244
|
});
|
|
239
245
|
|
|
240
246
|
messagesRows.forEach((row) => {
|
|
241
|
-
expect(allMessages.filter(m => m.id === row.id)).toHaveLength(1);
|
|
247
|
+
expect(allMessages.filter((m) => m.id === row.id)).toHaveLength(1);
|
|
242
248
|
});
|
|
243
249
|
membersRows.forEach((row) =>
|
|
244
|
-
expect(allMembers.filter(m => m.cid === row.cid && m.user.id === row.userId)).toHaveLength(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
expect(allUsers.filter(u => u.id === row.id)).toHaveLength(1),
|
|
250
|
+
expect(allMembers.filter((m) => m.cid === row.cid && m.user.id === row.userId)).toHaveLength(
|
|
251
|
+
1,
|
|
252
|
+
),
|
|
248
253
|
);
|
|
254
|
+
usersRows.forEach((row) => expect(allUsers.filter((u) => u.id === row.id)).toHaveLength(1));
|
|
249
255
|
reactionsRows.forEach((row) =>
|
|
250
|
-
expect(
|
|
256
|
+
expect(
|
|
257
|
+
allReactions.filter((r) => r.message_id === row.messageId && row.userId === r.user_id),
|
|
258
|
+
).toHaveLength(1),
|
|
251
259
|
);
|
|
252
260
|
readsRows.forEach((row) =>
|
|
253
|
-
expect(
|
|
261
|
+
expect(
|
|
262
|
+
allReads.filter(
|
|
263
|
+
(r) =>
|
|
264
|
+
r.last_read === row.lastRead &&
|
|
265
|
+
r.user.id === row.userId &&
|
|
266
|
+
r.unread_messages === row.unreadMessages,
|
|
267
|
+
),
|
|
268
|
+
).toHaveLength(1),
|
|
254
269
|
);
|
|
255
270
|
};
|
|
256
271
|
|
|
@@ -274,7 +289,7 @@ describe('Offline support is enabled', () => {
|
|
|
274
289
|
|
|
275
290
|
const { getByTestId, queryAllByA11yRole } = renderComponent();
|
|
276
291
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
277
|
-
|
|
292
|
+
|
|
278
293
|
expectCIDsOnUIToBeInDB(queryAllByA11yRole);
|
|
279
294
|
});
|
|
280
295
|
|
|
@@ -299,7 +314,7 @@ describe('Offline support is enabled', () => {
|
|
|
299
314
|
act(() => dispatchMessageNewEvent(chatClient, newMessage, channels[0].channel));
|
|
300
315
|
|
|
301
316
|
const messagesRows = BetterSqlite.selectFromTable('messages');
|
|
302
|
-
const matchingRows = messagesRows.filter(m => m.id === newMessage.id);
|
|
317
|
+
const matchingRows = messagesRows.filter((m) => m.id === newMessage.id);
|
|
303
318
|
|
|
304
319
|
expect(matchingRows.length).toBe(1);
|
|
305
320
|
});
|
|
@@ -330,14 +345,14 @@ describe('Offline support is enabled', () => {
|
|
|
330
345
|
|
|
331
346
|
const { getByTestId } = renderComponent();
|
|
332
347
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
333
|
-
|
|
334
|
-
const updatedMessage = {...channels[0].messages[0]};
|
|
348
|
+
|
|
349
|
+
const updatedMessage = { ...channels[0].messages[0] };
|
|
335
350
|
updatedMessage.text = uuidv4();
|
|
336
351
|
|
|
337
352
|
act(() => dispatchMessageUpdatedEvent(chatClient, updatedMessage, channels[0].channel));
|
|
338
353
|
|
|
339
354
|
const messagesRows = BetterSqlite.selectFromTable('messages');
|
|
340
|
-
const matchingRows = messagesRows.filter(m => m.id === updatedMessage.id);
|
|
355
|
+
const matchingRows = messagesRows.filter((m) => m.id === updatedMessage.id);
|
|
341
356
|
|
|
342
357
|
expect(matchingRows.length).toBe(1);
|
|
343
358
|
expect(matchingRows[0].text).toBe(updatedMessage.text);
|
|
@@ -360,10 +375,10 @@ describe('Offline support is enabled', () => {
|
|
|
360
375
|
expectCIDsOnUIToBeInDB(queryAllByA11yRole);
|
|
361
376
|
|
|
362
377
|
const channelsRows = BetterSqlite.selectFromTable('channels');
|
|
363
|
-
const matchingRows = channelsRows.filter(c => c.id === removedChannel.id);
|
|
378
|
+
const matchingRows = channelsRows.filter((c) => c.id === removedChannel.id);
|
|
364
379
|
|
|
365
380
|
const messagesRows = BetterSqlite.selectFromTable('messages');
|
|
366
|
-
const matchingMessagesRows = messagesRows.filter(m => m.cid === removedChannel.cid);
|
|
381
|
+
const matchingMessagesRows = messagesRows.filter((m) => m.cid === removedChannel.cid);
|
|
367
382
|
|
|
368
383
|
expect(matchingRows.length).toBe(0);
|
|
369
384
|
expect(matchingMessagesRows.length).toBe(0);
|
|
@@ -371,10 +386,10 @@ describe('Offline support is enabled', () => {
|
|
|
371
386
|
|
|
372
387
|
it('should add the channel to DB when user is added as member', async () => {
|
|
373
388
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
374
|
-
|
|
389
|
+
|
|
375
390
|
const { getByTestId, queryAllByA11yRole } = renderComponent();
|
|
376
391
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
377
|
-
|
|
392
|
+
|
|
378
393
|
const newChannel = createChannel();
|
|
379
394
|
useMockedApis(chatClient, [getOrCreateChannelApi(newChannel)]);
|
|
380
395
|
|
|
@@ -389,10 +404,10 @@ describe('Offline support is enabled', () => {
|
|
|
389
404
|
|
|
390
405
|
expectCIDsOnUIToBeInDB(queryAllByA11yRole);
|
|
391
406
|
const channelsRows = BetterSqlite.selectFromTable('channels');
|
|
392
|
-
const matchingChannelsRows = channelsRows.filter(c => c.id === newChannel.channel.id);
|
|
407
|
+
const matchingChannelsRows = channelsRows.filter((c) => c.id === newChannel.channel.id);
|
|
393
408
|
|
|
394
409
|
const messagesRows = BetterSqlite.selectFromTable('messages');
|
|
395
|
-
const matchingMessagesRows = messagesRows.filter(m => m.cid === newChannel.channel.cid);
|
|
410
|
+
const matchingMessagesRows = messagesRows.filter((m) => m.cid === newChannel.channel.cid);
|
|
396
411
|
|
|
397
412
|
expect(matchingChannelsRows.length).toBe(1);
|
|
398
413
|
expect(matchingMessagesRows.length).toBe(newChannel.messages.length);
|
|
@@ -400,7 +415,7 @@ describe('Offline support is enabled', () => {
|
|
|
400
415
|
|
|
401
416
|
it('should remove the channel messages from DB when channel is truncated', async () => {
|
|
402
417
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
403
|
-
|
|
418
|
+
|
|
404
419
|
const { getByTestId, queryAllByA11yRole } = renderComponent();
|
|
405
420
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
406
421
|
|
|
@@ -417,19 +432,20 @@ describe('Offline support is enabled', () => {
|
|
|
417
432
|
expectCIDsOnUIToBeInDB(queryAllByA11yRole);
|
|
418
433
|
|
|
419
434
|
const messagesRows = BetterSqlite.selectFromTable('messages');
|
|
420
|
-
const matchingMessagesRows = messagesRows.filter(m => m.cid === channelToTruncate.cid);
|
|
435
|
+
const matchingMessagesRows = messagesRows.filter((m) => m.cid === channelToTruncate.cid);
|
|
421
436
|
|
|
422
437
|
expect(matchingMessagesRows.length).toBe(0);
|
|
423
438
|
});
|
|
424
439
|
|
|
425
440
|
it('should add a reaction to DB when a new reaction is added', async () => {
|
|
426
441
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
427
|
-
|
|
442
|
+
|
|
428
443
|
const { getByTestId } = renderComponent();
|
|
429
444
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
430
445
|
|
|
431
446
|
const targetChannel = channels[getRandomInt(0, channels.length - 1)];
|
|
432
|
-
const targetMessage =
|
|
447
|
+
const targetMessage =
|
|
448
|
+
targetChannel.messages[getRandomInt(0, targetChannel.messages.length - 1)];
|
|
433
449
|
const reactionMember = targetChannel.members[getRandomInt(0, targetChannel.members.length - 1)];
|
|
434
450
|
|
|
435
451
|
const newReaction = generateReaction({
|
|
@@ -439,19 +455,24 @@ describe('Offline support is enabled', () => {
|
|
|
439
455
|
});
|
|
440
456
|
const messageWithNewReaction = {
|
|
441
457
|
...targetMessage,
|
|
442
|
-
latest_reactions: [
|
|
443
|
-
...targetMessage.latest_reactions,
|
|
444
|
-
newReaction
|
|
445
|
-
]
|
|
458
|
+
latest_reactions: [...targetMessage.latest_reactions, newReaction],
|
|
446
459
|
};
|
|
447
460
|
|
|
448
|
-
act(() =>
|
|
461
|
+
act(() =>
|
|
462
|
+
dispatchReactionNewEvent(
|
|
463
|
+
chatClient,
|
|
464
|
+
newReaction,
|
|
465
|
+
messageWithNewReaction,
|
|
466
|
+
targetChannel.channel,
|
|
467
|
+
),
|
|
468
|
+
);
|
|
449
469
|
|
|
450
470
|
const reactionsRows = BetterSqlite.selectFromTable('reactions');
|
|
451
|
-
const matchingReactionsRows = reactionsRows.filter(
|
|
452
|
-
r
|
|
453
|
-
|
|
454
|
-
|
|
471
|
+
const matchingReactionsRows = reactionsRows.filter(
|
|
472
|
+
(r) =>
|
|
473
|
+
r.type === newReaction.type &&
|
|
474
|
+
r.userId === reactionMember.user.id &&
|
|
475
|
+
r.messageId === messageWithNewReaction.id,
|
|
455
476
|
);
|
|
456
477
|
|
|
457
478
|
expect(matchingReactionsRows.length).toBe(1);
|
|
@@ -459,35 +480,46 @@ describe('Offline support is enabled', () => {
|
|
|
459
480
|
|
|
460
481
|
it('should remove a reaction from DB when reaction is deleted', async () => {
|
|
461
482
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
462
|
-
|
|
483
|
+
|
|
463
484
|
const { getByTestId } = renderComponent();
|
|
464
485
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
465
486
|
|
|
466
487
|
const targetChannel = channels[getRandomInt(0, channels.length - 1)];
|
|
467
|
-
const targetMessage =
|
|
488
|
+
const targetMessage =
|
|
489
|
+
targetChannel.messages[getRandomInt(0, targetChannel.messages.length - 1)];
|
|
468
490
|
const reactionsOnTargetMessage = targetMessage.latest_reactions;
|
|
469
|
-
const reactionToBeRemoved =
|
|
491
|
+
const reactionToBeRemoved =
|
|
492
|
+
reactionsOnTargetMessage[getRandomInt(0, reactionsOnTargetMessage.length - 1)];
|
|
470
493
|
|
|
471
494
|
const reactionsRows = BetterSqlite.selectFromTable('reactions');
|
|
472
|
-
const matchingReactionsRows = reactionsRows.filter(
|
|
473
|
-
r
|
|
474
|
-
|
|
475
|
-
|
|
495
|
+
const matchingReactionsRows = reactionsRows.filter(
|
|
496
|
+
(r) =>
|
|
497
|
+
r.type === reactionToBeRemoved.type &&
|
|
498
|
+
r.userId === reactionToBeRemoved.user_id &&
|
|
499
|
+
r.messageId === targetMessage.id,
|
|
476
500
|
);
|
|
477
501
|
|
|
478
502
|
expect(matchingReactionsRows.length).toBe(1);
|
|
479
503
|
const messageWithoutDeletedReaction = {
|
|
480
504
|
...targetMessage,
|
|
481
|
-
latest_reactions: reactionsOnTargetMessage.filter(r => r !== reactionToBeRemoved)
|
|
505
|
+
latest_reactions: reactionsOnTargetMessage.filter((r) => r !== reactionToBeRemoved),
|
|
482
506
|
};
|
|
483
507
|
|
|
484
|
-
act(() =>
|
|
508
|
+
act(() =>
|
|
509
|
+
dispatchReactionDeletedEvent(
|
|
510
|
+
chatClient,
|
|
511
|
+
reactionToBeRemoved,
|
|
512
|
+
messageWithoutDeletedReaction,
|
|
513
|
+
targetChannel.channel,
|
|
514
|
+
),
|
|
515
|
+
);
|
|
485
516
|
|
|
486
517
|
const reactionsRowsAfterEvent = BetterSqlite.selectFromTable('reactions');
|
|
487
|
-
const matchingReactionsRowsAfterEvent = reactionsRowsAfterEvent.filter(
|
|
488
|
-
r
|
|
489
|
-
|
|
490
|
-
|
|
518
|
+
const matchingReactionsRowsAfterEvent = reactionsRowsAfterEvent.filter(
|
|
519
|
+
(r) =>
|
|
520
|
+
r.type === reactionToBeRemoved.type &&
|
|
521
|
+
r.userId === reactionToBeRemoved.user_id &&
|
|
522
|
+
r.messageId === messageWithoutDeletedReaction.id,
|
|
491
523
|
);
|
|
492
524
|
|
|
493
525
|
expect(matchingReactionsRowsAfterEvent.length).toBe(0);
|
|
@@ -495,22 +527,32 @@ describe('Offline support is enabled', () => {
|
|
|
495
527
|
|
|
496
528
|
it('should update a reaction in DB when reaction is updated', async () => {
|
|
497
529
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
498
|
-
|
|
530
|
+
|
|
499
531
|
const { getByTestId } = renderComponent();
|
|
500
532
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
501
533
|
|
|
502
534
|
const targetChannel = channels[getRandomInt(0, channels.length - 1)];
|
|
503
|
-
const targetMessage =
|
|
535
|
+
const targetMessage =
|
|
536
|
+
targetChannel.messages[getRandomInt(0, targetChannel.messages.length - 1)];
|
|
504
537
|
const reactionsOnTargetMessage = targetMessage.latest_reactions;
|
|
505
|
-
const reactionToBeUpdated =
|
|
538
|
+
const reactionToBeUpdated =
|
|
539
|
+
reactionsOnTargetMessage[getRandomInt(0, reactionsOnTargetMessage.length - 1)];
|
|
506
540
|
reactionToBeUpdated.type = 'wow';
|
|
507
541
|
|
|
508
|
-
act(() =>
|
|
542
|
+
act(() =>
|
|
543
|
+
dispatchReactionUpdatedEvent(
|
|
544
|
+
chatClient,
|
|
545
|
+
reactionToBeUpdated,
|
|
546
|
+
targetMessage,
|
|
547
|
+
targetChannel.channel,
|
|
548
|
+
),
|
|
549
|
+
);
|
|
509
550
|
const reactionsRows = BetterSqlite.selectFromTable('reactions');
|
|
510
|
-
const matchingReactionsRows = reactionsRows.filter(
|
|
511
|
-
r
|
|
512
|
-
|
|
513
|
-
|
|
551
|
+
const matchingReactionsRows = reactionsRows.filter(
|
|
552
|
+
(r) =>
|
|
553
|
+
r.type === reactionToBeUpdated.type &&
|
|
554
|
+
r.userId === reactionToBeUpdated.user_id &&
|
|
555
|
+
r.messageId === targetMessage.id,
|
|
514
556
|
);
|
|
515
557
|
|
|
516
558
|
expect(matchingReactionsRows.length).toBe(1);
|
|
@@ -518,18 +560,17 @@ describe('Offline support is enabled', () => {
|
|
|
518
560
|
|
|
519
561
|
it('should add a member to DB when a new member is added to channel', async () => {
|
|
520
562
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
521
|
-
|
|
563
|
+
|
|
522
564
|
const { getByTestId } = renderComponent();
|
|
523
565
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
524
566
|
|
|
525
567
|
const targetChannel = channels[getRandomInt(0, channels.length - 1)];
|
|
526
568
|
const newMember = generateMember();
|
|
527
569
|
act(() => dispatchMemberAddedEvent(chatClient, newMember, targetChannel.channel));
|
|
528
|
-
|
|
570
|
+
|
|
529
571
|
const membersRows = BetterSqlite.selectFromTable('members');
|
|
530
|
-
const matchingMembersRows = membersRows.filter(
|
|
531
|
-
m.cid === targetChannel.channel.cid
|
|
532
|
-
&& m.userId === newMember.user_id
|
|
572
|
+
const matchingMembersRows = membersRows.filter(
|
|
573
|
+
(m) => m.cid === targetChannel.channel.cid && m.userId === newMember.user_id,
|
|
533
574
|
);
|
|
534
575
|
|
|
535
576
|
expect(matchingMembersRows.length).toBe(1);
|
|
@@ -537,18 +578,17 @@ describe('Offline support is enabled', () => {
|
|
|
537
578
|
|
|
538
579
|
it('should remove a member from DB when a member is removed from channel', async () => {
|
|
539
580
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
540
|
-
|
|
581
|
+
|
|
541
582
|
const { getByTestId } = renderComponent();
|
|
542
583
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
543
584
|
|
|
544
585
|
const targetChannel = channels[getRandomInt(0, channels.length - 1)];
|
|
545
586
|
const targetMember = targetChannel.members[getRandomInt(0, targetChannel.members.length - 1)];
|
|
546
587
|
act(() => dispatchMemberRemovedEvent(chatClient, targetMember, targetChannel.channel));
|
|
547
|
-
|
|
588
|
+
|
|
548
589
|
const membersRows = BetterSqlite.selectFromTable('members');
|
|
549
|
-
const matchingMembersRows = membersRows.filter(
|
|
550
|
-
m.cid === targetChannel.channel.cid
|
|
551
|
-
&& m.userId === targetMember.user_id
|
|
590
|
+
const matchingMembersRows = membersRows.filter(
|
|
591
|
+
(m) => m.cid === targetChannel.channel.cid && m.userId === targetMember.user_id,
|
|
552
592
|
);
|
|
553
593
|
|
|
554
594
|
expect(matchingMembersRows.length).toBe(0);
|
|
@@ -556,7 +596,7 @@ describe('Offline support is enabled', () => {
|
|
|
556
596
|
|
|
557
597
|
it('should update the member in DB when a member of a channel is updated', async () => {
|
|
558
598
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
559
|
-
|
|
599
|
+
|
|
560
600
|
const { getByTestId } = renderComponent();
|
|
561
601
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
562
602
|
|
|
@@ -564,12 +604,13 @@ describe('Offline support is enabled', () => {
|
|
|
564
604
|
const targetMember = targetChannel.members[getRandomInt(0, targetChannel.members.length - 1)];
|
|
565
605
|
targetMember.role = 'admin';
|
|
566
606
|
act(() => dispatchMemberUpdatedEvent(chatClient, targetMember, targetChannel.channel));
|
|
567
|
-
|
|
607
|
+
|
|
568
608
|
const membersRows = BetterSqlite.selectFromTable('members');
|
|
569
|
-
const matchingMembersRows = membersRows.filter(
|
|
570
|
-
m
|
|
571
|
-
|
|
572
|
-
|
|
609
|
+
const matchingMembersRows = membersRows.filter(
|
|
610
|
+
(m) =>
|
|
611
|
+
m.cid === targetChannel.channel.cid &&
|
|
612
|
+
m.userId === targetMember.user_id &&
|
|
613
|
+
m.role === targetMember.role,
|
|
573
614
|
);
|
|
574
615
|
|
|
575
616
|
expect(matchingMembersRows.length).toBe(1);
|
|
@@ -578,21 +619,19 @@ describe('Offline support is enabled', () => {
|
|
|
578
619
|
|
|
579
620
|
it('should update the channel data in DB when a channel is updated', async () => {
|
|
580
621
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
581
|
-
|
|
622
|
+
|
|
582
623
|
const { getByTestId } = renderComponent();
|
|
583
624
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
584
625
|
|
|
585
626
|
const targetChannel = channels[getRandomInt(0, channels.length - 1)];
|
|
586
627
|
targetChannel.channel.name = uuidv4();
|
|
587
628
|
act(() => dispatchChannelUpdatedEvent(chatClient, targetChannel.channel));
|
|
588
|
-
|
|
629
|
+
|
|
589
630
|
const channelsRows = BetterSqlite.selectFromTable('channels');
|
|
590
|
-
const matchingChannelsRows = channelsRows.filter(c =>
|
|
591
|
-
c.cid === targetChannel.channel.cid
|
|
592
|
-
);
|
|
631
|
+
const matchingChannelsRows = channelsRows.filter((c) => c.cid === targetChannel.channel.cid);
|
|
593
632
|
|
|
594
633
|
expect(matchingChannelsRows.length).toBe(1);
|
|
595
|
-
|
|
634
|
+
|
|
596
635
|
const extraData = JSON.parse(matchingChannelsRows[0].extraData);
|
|
597
636
|
|
|
598
637
|
expect(extraData.name).toBe(targetChannel.channel.name);
|
|
@@ -600,17 +639,18 @@ describe('Offline support is enabled', () => {
|
|
|
600
639
|
|
|
601
640
|
it('should update reads in DB when channel is read', async () => {
|
|
602
641
|
useMockedApis(chatClient, [queryChannelsApi(channels)]);
|
|
603
|
-
|
|
642
|
+
|
|
604
643
|
const { getByTestId } = renderComponent();
|
|
605
644
|
await waitFor(() => expect(getByTestId('channel-list')).toBeTruthy());
|
|
606
645
|
const targetChannel = channels[getRandomInt(0, channels.length - 1)];
|
|
607
646
|
const targetMember = targetChannel.members[getRandomInt(0, targetChannel.members.length - 1)];
|
|
608
647
|
|
|
609
|
-
act(() => {
|
|
648
|
+
act(() => {
|
|
649
|
+
dispatchMessageReadEvent(chatClient, targetMember.user, targetChannel.channel);
|
|
650
|
+
});
|
|
610
651
|
const readsRows = BetterSqlite.selectFromTable('reads');
|
|
611
|
-
const matchingReadRows = readsRows.filter(
|
|
612
|
-
r.userId === targetMember.user_id
|
|
613
|
-
&& r.cid === targetChannel.cid
|
|
652
|
+
const matchingReadRows = readsRows.filter(
|
|
653
|
+
(r) => r.userId === targetMember.user_id && r.cid === targetChannel.cid,
|
|
614
654
|
);
|
|
615
655
|
|
|
616
656
|
expect(matchingReadRows.length).toBe(1);
|
|
@@ -252,11 +252,11 @@ export const ChannelList = <
|
|
|
252
252
|
loadingChannels,
|
|
253
253
|
loadingNextPage,
|
|
254
254
|
loadNextPage,
|
|
255
|
-
staticChannelsActive,
|
|
256
255
|
refreshing,
|
|
257
256
|
refreshList,
|
|
258
257
|
reloadList,
|
|
259
258
|
setChannels,
|
|
259
|
+
staticChannelsActive,
|
|
260
260
|
} = usePaginatedChannels<StreamChatGenerics>({
|
|
261
261
|
enableOfflineSupport,
|
|
262
262
|
filters,
|