Skip to content

Commit 59fcdc5

Browse files
committed
feat: sync api and reactions to sync api as well as ws
1 parent c6b8f26 commit 59fcdc5

File tree

7 files changed

+124
-81
lines changed

7 files changed

+124
-81
lines changed

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"react-native-svg": "15.11.2",
149149
"react-test-renderer": "19.0.0",
150150
"typescript": "5.8.2",
151-
"typescript-eslint": "^8.25.0",
151+
"typescript-eslint": "^8.29.0",
152152
"uuid": "^11.1.0"
153153
},
154154
"resolutions": {

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,33 +161,33 @@ export const handleEventToSyncDB = async (event: Event, client: StreamChat, flus
161161
}
162162
}
163163

164-
if (type === 'reaction.updated') {
165-
const message = event.message;
166-
if (message && event.reaction) {
167-
// We update the entire message to make sure we also update reaction_groups
168-
return await queriesWithChannelGuard((flushOverride) =>
169-
updateMessage({
170-
flush: flushOverride,
171-
message,
172-
}),
173-
);
174-
}
175-
}
176-
177-
if (type === 'reaction.new' || type === 'reaction.deleted') {
178-
const message = event.message;
179-
if (message && !message.parent_id) {
180-
// Here we are relying on the fact message.latest_reactions always includes
181-
// the new reaction. So we first delete all the existing reactions and populate
182-
// the reactions table with message.latest_reactions
183-
return await queriesWithChannelGuard((flushOverride) =>
184-
updateMessage({
185-
flush: flushOverride,
186-
message,
187-
}),
188-
);
189-
}
190-
}
164+
// if (type === 'reaction.updated') {
165+
// const message = event.message;
166+
// if (message && event.reaction) {
167+
// // We update the entire message to make sure we also update reaction_groups
168+
// return await queriesWithChannelGuard((flushOverride) =>
169+
// updateMessage({
170+
// flush: flushOverride,
171+
// message,
172+
// }),
173+
// );
174+
// }
175+
// }
176+
//
177+
// if (type === 'reaction.new' || type === 'reaction.deleted') {
178+
// const message = event.message;
179+
// if (message && !message.parent_id) {
180+
// // Here we are relying on the fact message.latest_reactions always includes
181+
// // the new reaction. So we first delete all the existing reactions and populate
182+
// // the reactions table with message.latest_reactions
183+
// return await queriesWithChannelGuard((flushOverride) =>
184+
// updateMessage({
185+
// flush: flushOverride,
186+
// message,
187+
// }),
188+
// );
189+
// }
190+
// }
191191

192192
if (
193193
type === 'channel.updated' ||

package/src/store/OfflineDB.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export class OfflineDB extends AbstractOfflineDB {
6060

6161
getPendingTasks = api.getPendingTasks;
6262

63+
updateReaction = api.updateReaction;
64+
65+
insertReaction = api.insertReaction;
66+
67+
updateMessage = api.updateMessage;
68+
6369
resetDB = SqliteClient.resetDB;
6470

6571
executeSqlBatch = SqliteClient.executeSqlBatch;

package/src/store/apis/deleteReaction.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1-
import { Channel } from 'stream-chat';
1+
import { FormatMessageResponse, MessageResponse, ReactionResponse } from 'stream-chat';
22

33
import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
44
import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
55
import { SqliteClient } from '../SqliteClient';
66
import { PreparedQueries } from '../types';
77

88
export const deleteReaction = async ({
9-
channel,
109
flush = true,
11-
messageId,
12-
reactionType,
13-
userId,
10+
message,
11+
reaction,
1412
}: {
15-
channel: Channel;
16-
messageId: string;
17-
reactionType: string;
18-
userId: string;
13+
reaction: ReactionResponse;
14+
message?: MessageResponse | FormatMessageResponse;
1915
flush?: boolean;
2016
}) => {
2117
const queries: PreparedQueries[] = [];
2218

23-
const message = channel.state.messages.find(({ id }) => id === messageId);
24-
2519
if (!message) {
2620
return;
2721
}
2822

2923
queries.push(
3024
createDeleteQuery('reactions', {
31-
messageId,
32-
type: reactionType,
33-
userId,
25+
messageId: reaction.message_id,
26+
type: reaction.type,
27+
userId: reaction.user_id,
3428
}),
3529
);
3630

@@ -47,9 +41,7 @@ export const deleteReaction = async ({
4741
);
4842

4943
SqliteClient.logger?.('info', 'deleteReaction', {
50-
messageId,
51-
type: reactionType,
52-
userId,
44+
reaction,
5345
});
5446

5547
if (flush) {

package/src/store/apis/getLastSyncedAt.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const getLastSyncedAt = async ({
55
currentUserId,
66
}: {
77
currentUserId: string;
8-
}): Promise<number | undefined> => {
8+
}): Promise<string | undefined> => {
99
SqliteClient.logger?.('info', 'getLastSyncedAt', { currentUserId });
1010
const result = await SqliteClient.executeSql.apply(
1111
null,
@@ -14,8 +14,5 @@ export const getLastSyncedAt = async ({
1414
}),
1515
);
1616

17-
if (typeof result[0]?.lastSyncedAt === 'number') {
18-
return result[0]?.lastSyncedAt;
19-
}
20-
return undefined;
17+
return result[0]?.lastSyncedAt;
2118
};

package/src/store/apis/updateReaction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { FormatMessageResponse, MessageResponse, ReactionResponse } from 's
33
import { mapMessageToStorable } from '../mappers/mapMessageToStorable';
44
import { mapReactionToStorable } from '../mappers/mapReactionToStorable';
55
import { mapUserToStorable } from '../mappers/mapUserToStorable';
6+
import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
67
import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
78
import { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';
89
import { SqliteClient } from '../SqliteClient';
@@ -17,6 +18,7 @@ export const updateReaction = async ({
1718
reaction: ReactionResponse;
1819
flush?: boolean;
1920
}) => {
21+
console.log('EXECUTING UPDATE');
2022
const queries: PreparedQueries[] = [];
2123
let storableUser: ReturnType<typeof mapUserToStorable> | undefined;
2224

@@ -28,11 +30,12 @@ export const updateReaction = async ({
2830
const storableReaction = mapReactionToStorable(reaction);
2931

3032
queries.push(
31-
createUpdateQuery('reactions', storableReaction, {
33+
createDeleteQuery('reactions', {
3234
messageId: reaction.message_id,
3335
userId: reaction.user_id,
3436
}),
3537
);
38+
queries.push(createUpsertQuery('reactions', storableReaction));
3639

3740
let updatedReactionGroups: string | undefined;
3841
if (message.reaction_groups) {

package/yarn.lock

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,16 +2100,16 @@
21002100
dependencies:
21012101
"@types/yargs-parser" "*"
21022102

2103-
"@typescript-eslint/eslint-plugin@8.25.0":
2104-
version "8.25.0"
2105-
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.25.0.tgz#5e1d56f067e5808fa82d1b75bced82396e868a14"
2106-
integrity sha512-VM7bpzAe7JO/BFf40pIT1lJqS/z1F8OaSsUB3rpFJucQA4cOSuH2RVVVkFULN+En0Djgr29/jb4EQnedUo95KA==
2103+
"@typescript-eslint/eslint-plugin@8.29.0":
2104+
version "8.29.0"
2105+
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.29.0.tgz#151c4878700a5ad229ce6713d2674d58b626b3d9"
2106+
integrity sha512-PAIpk/U7NIS6H7TEtN45SPGLQaHNgB7wSjsQV/8+KYokAb2T/gloOA/Bee2yd4/yKVhPKe5LlaUGhAZk5zmSaQ==
21072107
dependencies:
21082108
"@eslint-community/regexpp" "^4.10.0"
2109-
"@typescript-eslint/scope-manager" "8.25.0"
2110-
"@typescript-eslint/type-utils" "8.25.0"
2111-
"@typescript-eslint/utils" "8.25.0"
2112-
"@typescript-eslint/visitor-keys" "8.25.0"
2109+
"@typescript-eslint/scope-manager" "8.29.0"
2110+
"@typescript-eslint/type-utils" "8.29.0"
2111+
"@typescript-eslint/utils" "8.29.0"
2112+
"@typescript-eslint/visitor-keys" "8.29.0"
21132113
graphemer "^1.4.0"
21142114
ignore "^5.3.1"
21152115
natural-compare "^1.4.0"
@@ -2131,15 +2131,15 @@
21312131
semver "^7.3.7"
21322132
tsutils "^3.21.0"
21332133

2134-
"@typescript-eslint/parser@8.25.0":
2135-
version "8.25.0"
2136-
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.25.0.tgz#58fb81c7b7a35184ba17583f3d7ac6c4f3d95be8"
2137-
integrity sha512-4gbs64bnbSzu4FpgMiQ1A+D+urxkoJk/kqlDJ2W//5SygaEiAP2B4GoS7TEdxgwol2el03gckFV9lJ4QOMiiHg==
2134+
"@typescript-eslint/parser@8.29.0":
2135+
version "8.29.0"
2136+
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.29.0.tgz#b98841e0a8099728cb8583da92326fcb7f5be1d2"
2137+
integrity sha512-8C0+jlNJOwQso2GapCVWWfW/rzaq7Lbme+vGUFKE31djwNncIpgXD7Cd4weEsDdkoZDjH0lwwr3QDQFuyrMg9g==
21382138
dependencies:
2139-
"@typescript-eslint/scope-manager" "8.25.0"
2140-
"@typescript-eslint/types" "8.25.0"
2141-
"@typescript-eslint/typescript-estree" "8.25.0"
2142-
"@typescript-eslint/visitor-keys" "8.25.0"
2139+
"@typescript-eslint/scope-manager" "8.29.0"
2140+
"@typescript-eslint/types" "8.29.0"
2141+
"@typescript-eslint/typescript-estree" "8.29.0"
2142+
"@typescript-eslint/visitor-keys" "8.29.0"
21432143
debug "^4.3.4"
21442144

21452145
"@typescript-eslint/parser@^5.30.5":
@@ -2168,6 +2168,14 @@
21682168
"@typescript-eslint/types" "8.25.0"
21692169
"@typescript-eslint/visitor-keys" "8.25.0"
21702170

2171+
"@typescript-eslint/[email protected]":
2172+
version "8.29.0"
2173+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.29.0.tgz#8fd9872823aef65ff71d3f6d1ec9316ace0b6bf3"
2174+
integrity sha512-aO1PVsq7Gm+tcghabUpzEnVSFMCU4/nYIgC2GOatJcllvWfnhrgW0ZEbnTxm36QsikmCN1K/6ZgM7fok2I7xNw==
2175+
dependencies:
2176+
"@typescript-eslint/types" "8.29.0"
2177+
"@typescript-eslint/visitor-keys" "8.29.0"
2178+
21712179
"@typescript-eslint/[email protected]":
21722180
version "5.62.0"
21732181
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.62.0.tgz#286f0389c41681376cdad96b309cedd17d70346a"
@@ -2178,13 +2186,13 @@
21782186
debug "^4.3.4"
21792187
tsutils "^3.21.0"
21802188

2181-
"@typescript-eslint/type-utils@8.25.0":
2182-
version "8.25.0"
2183-
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.25.0.tgz#ee0d2f67c80af5ae74b5d6f977e0f8ded0059677"
2184-
integrity sha512-d77dHgHWnxmXOPJuDWO4FDWADmGQkN5+tt6SFRZz/RtCWl4pHgFl3+WdYCn16+3teG09DY6XtEpf3gGD0a186g==
2189+
"@typescript-eslint/type-utils@8.29.0":
2190+
version "8.29.0"
2191+
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.29.0.tgz#98dcfd1193cb4e2b2d0294a8656ce5eb58c443a9"
2192+
integrity sha512-ahaWQ42JAOx+NKEf5++WC/ua17q5l+j1GFrbbpVKzFL/tKVc0aYY8rVSYUpUvt2hUP1YBr7mwXzx+E/DfUWI9Q==
21852193
dependencies:
2186-
"@typescript-eslint/typescript-estree" "8.25.0"
2187-
"@typescript-eslint/utils" "8.25.0"
2194+
"@typescript-eslint/typescript-estree" "8.29.0"
2195+
"@typescript-eslint/utils" "8.29.0"
21882196
debug "^4.3.4"
21892197
ts-api-utils "^2.0.1"
21902198

@@ -2198,6 +2206,11 @@
21982206
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.25.0.tgz#f91512c2f532b1d6a8826cadd0b0e5cd53cf97e0"
21992207
integrity sha512-+vUe0Zb4tkNgznQwicsvLUJgZIRs6ITeWSCclX1q85pR1iOiaj+4uZJIUp//Z27QWu5Cseiw3O3AR8hVpax7Aw==
22002208

2209+
"@typescript-eslint/[email protected]":
2210+
version "8.29.0"
2211+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.29.0.tgz#65add70ab4ef66beaa42a5addf87dab2b05b1f33"
2212+
integrity sha512-wcJL/+cOXV+RE3gjCyl/V2G877+2faqvlgtso/ZRbTCnZazh0gXhe+7gbAnfubzN2bNsBtZjDvlh7ero8uIbzg==
2213+
22012214
"@typescript-eslint/[email protected]":
22022215
version "5.62.0"
22032216
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b"
@@ -2225,6 +2238,20 @@
22252238
semver "^7.6.0"
22262239
ts-api-utils "^2.0.1"
22272240

2241+
"@typescript-eslint/[email protected]":
2242+
version "8.29.0"
2243+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.29.0.tgz#d201a4f115327ec90496307c9958262285065b00"
2244+
integrity sha512-yOfen3jE9ISZR/hHpU/bmNvTtBW1NjRbkSFdZOksL1N+ybPEE7UVGMwqvS6CP022Rp00Sb0tdiIkhSCe6NI8ow==
2245+
dependencies:
2246+
"@typescript-eslint/types" "8.29.0"
2247+
"@typescript-eslint/visitor-keys" "8.29.0"
2248+
debug "^4.3.4"
2249+
fast-glob "^3.3.2"
2250+
is-glob "^4.0.3"
2251+
minimatch "^9.0.4"
2252+
semver "^7.6.0"
2253+
ts-api-utils "^2.0.1"
2254+
22282255
"@typescript-eslint/[email protected]", "@typescript-eslint/utils@^5.10.0":
22292256
version "5.62.0"
22302257
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86"
@@ -2239,7 +2266,17 @@
22392266
eslint-scope "^5.1.1"
22402267
semver "^7.3.7"
22412268

2242-
"@typescript-eslint/[email protected]", "@typescript-eslint/utils@^6.0.0 || ^7.0.0 || ^8.0.0":
2269+
"@typescript-eslint/[email protected]":
2270+
version "8.29.0"
2271+
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.29.0.tgz#d6d22b19c8c4812a874f00341f686b45b9fe895f"
2272+
integrity sha512-gX/A0Mz9Bskm8avSWFcK0gP7cZpbY4AIo6B0hWYFCaIsz750oaiWR4Jr2CI+PQhfW1CpcQr9OlfPS+kMFegjXA==
2273+
dependencies:
2274+
"@eslint-community/eslint-utils" "^4.4.0"
2275+
"@typescript-eslint/scope-manager" "8.29.0"
2276+
"@typescript-eslint/types" "8.29.0"
2277+
"@typescript-eslint/typescript-estree" "8.29.0"
2278+
2279+
"@typescript-eslint/utils@^6.0.0 || ^7.0.0 || ^8.0.0":
22432280
version "8.25.0"
22442281
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.25.0.tgz#3ea2f9196a915ef4daa2c8eafd44adbd7d56d08a"
22452282
integrity sha512-syqRbrEv0J1wywiLsK60XzHnQe/kRViI3zwFALrNEgnntn1l24Ra2KvOAWwWbWZ1lBZxZljPDGOq967dsl6fkA==
@@ -2265,6 +2302,14 @@
22652302
"@typescript-eslint/types" "8.25.0"
22662303
eslint-visitor-keys "^4.2.0"
22672304

2305+
"@typescript-eslint/[email protected]":
2306+
version "8.29.0"
2307+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.29.0.tgz#2356336c9efdc3597ffcd2aa1ce95432852b743d"
2308+
integrity sha512-Sne/pVz8ryR03NFK21VpN88dZ2FdQXOlq3VIklbrTYEt8yXtRFr9tvUhqvCeKjqYk5FSim37sHbooT6vzBTZcg==
2309+
dependencies:
2310+
"@typescript-eslint/types" "8.29.0"
2311+
eslint-visitor-keys "^4.2.0"
2312+
22682313
abort-controller@^3.0.0:
22692314
version "3.0.0"
22702315
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
@@ -8083,14 +8128,14 @@ typed-array-length@^1.0.7:
80838128
possible-typed-array-names "^1.0.0"
80848129
reflect.getprototypeof "^1.0.6"
80858130

8086-
typescript-eslint@^8.25.0:
8087-
version "8.25.0"
8088-
resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-8.25.0.tgz#73047c157cd70ee93cf2f9243f1599d21cf60239"
8089-
integrity sha512-TxRdQQLH4g7JkoFlYG3caW5v1S6kEkz8rqt80iQJZUYPq1zD1Ra7HfQBJJ88ABRaMvHAXnwRvRB4V+6sQ9xN5Q==
8131+
typescript-eslint@^8.29.0:
8132+
version "8.29.0"
8133+
resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-8.29.0.tgz#fc059b4c840889e5180dd822594eb46fa4619093"
8134+
integrity sha512-ep9rVd9B4kQsZ7ZnWCVxUE/xDLUUUsRzE0poAeNu+4CkFErLfuvPt/qtm2EpnSyfvsR0S6QzDFSrPCFBwf64fg==
80908135
dependencies:
8091-
"@typescript-eslint/eslint-plugin" "8.25.0"
8092-
"@typescript-eslint/parser" "8.25.0"
8093-
"@typescript-eslint/utils" "8.25.0"
8136+
"@typescript-eslint/eslint-plugin" "8.29.0"
8137+
"@typescript-eslint/parser" "8.29.0"
8138+
"@typescript-eslint/utils" "8.29.0"
80948139

80958140
[email protected], typescript@^5.0.4:
80968141
version "5.8.2"

0 commit comments

Comments
 (0)