@bitsocial/bitsocial-react-hooks 0.1.58 → 0.1.60
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/CHANGELOG.md +18 -0
- package/dist/hooks/comments.d.ts.map +1 -1
- package/dist/hooks/comments.js +13 -2
- package/dist/hooks/comments.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +52 -10
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/comments/comments-store.d.ts +3 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -1
- package/dist/stores/comments/comments-store.js +56 -8
- package/dist/stores/comments/comments-store.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,eAAO,MAAM,GAAG,QAAkD,CAAC;AACnE,OAAO,EAAW,QAAQ,EAAW,MAAM,aAAa,CAAC;AAqBzD,eAAO,MAAM,SAAS,EAAE,GAAQ,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,eAAO,MAAM,GAAG,QAAkD,CAAC;AACnE,OAAO,EAAW,QAAQ,EAAW,MAAM,aAAa,CAAC;AAqBzD,eAAO,MAAM,SAAS,EAAE,GAAQ,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAG1C,qBAAqB,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACtD,iBAAiB,EAAE,QAAQ,CAAC;IAC5B,sBAAsB,EAAE,QAAQ,CAAC;IACjC,qBAAqB,EAAE,QAAQ,CAAC;IAChC,cAAc,EAAE,QAAQ,CAAC;CAC1B,CAAC;AAuDF,QAAA,MAAM,aAAa,4EAygBjB,CAAC;AA8BH,eAAO,MAAM,kBAAkB,qBAsC9B,CAAC;AAGF,eAAO,MAAM,6BAA6B,qBAGzC,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -98,8 +98,29 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
98
98
|
const clearCommentUpdateFollowup = (commentCid) => {
|
|
99
99
|
delete sparseCommentFollowupRequested[commentCid];
|
|
100
100
|
};
|
|
101
|
+
const endOpeningUpdate = (commentCid) => {
|
|
102
|
+
if (!getState().openingUpdatesPending[commentCid]) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
setState((state) => {
|
|
106
|
+
const openingUpdatesPending = Object.assign({}, state.openingUpdatesPending);
|
|
107
|
+
delete openingUpdatesPending[commentCid];
|
|
108
|
+
return { openingUpdatesPending };
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
// When the last auto-update subscriber leaves during the opening update, stopping would abort
|
|
112
|
+
// it and leave a frozen useComment on a cached copy, so stop when that update ends instead.
|
|
113
|
+
const deferStopUntilOpeningUpdateEnds = (commentCid) => {
|
|
114
|
+
if (!getState().openingUpdatesPending[commentCid]) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
stopCommentAfterNextUpdate[commentCid] = true;
|
|
118
|
+
return true;
|
|
119
|
+
};
|
|
101
120
|
const stopLiveComment = (commentCid, comment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
121
|
clearCommentUpdateFollowup(commentCid);
|
|
122
|
+
// a stopped comment gets no further update from this cycle
|
|
123
|
+
endOpeningUpdate(commentCid);
|
|
103
124
|
const liveComment = comment || liveComments[commentCid];
|
|
104
125
|
if (typeof (liveComment === null || liveComment === void 0 ? void 0 : liveComment.stop) !== "function") {
|
|
105
126
|
return;
|
|
@@ -149,6 +170,7 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
149
170
|
}
|
|
150
171
|
}
|
|
151
172
|
maybeStopCommentAfterOneShotUpdate(commentCid, comment);
|
|
173
|
+
endOpeningUpdate(commentCid);
|
|
152
174
|
return updateError;
|
|
153
175
|
};
|
|
154
176
|
const isSparseCommentUpdate = (comment) => !!(comment === null || comment === void 0 ? void 0 : comment.timestamp) && !(comment === null || comment === void 0 ? void 0 : comment.updatedAt);
|
|
@@ -174,8 +196,16 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
174
196
|
initializedComments.add(comment);
|
|
175
197
|
liveComments[commentCid] = comment;
|
|
176
198
|
(_a = comment === null || comment === void 0 ? void 0 : comment.on) === null || _a === void 0 ? void 0 : _a.call(comment, "update", (updatedComment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
+
var _a, _b, _c;
|
|
177
200
|
updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment));
|
|
178
|
-
|
|
201
|
+
// A newer CommentUpdate ends the opening update, also for a reply whose cycle pkc-js never
|
|
202
|
+
// ends. pkc-js emits "update" for other changes too, like a resolved author name.
|
|
203
|
+
const isNewerCommentUpdate = ((_a = updatedComment.updatedAt) !== null && _a !== void 0 ? _a : 0) > ((_c = (_b = getState().comments[commentCid]) === null || _b === void 0 ? void 0 : _b.updatedAt) !== null && _c !== void 0 ? _c : 0);
|
|
204
|
+
const persisted = persistComment(commentCid, updatedComment);
|
|
205
|
+
if (isNewerCommentUpdate) {
|
|
206
|
+
endOpeningUpdate(commentCid);
|
|
207
|
+
}
|
|
208
|
+
yield persisted;
|
|
179
209
|
}));
|
|
180
210
|
(_b = comment === null || comment === void 0 ? void 0 : comment.on) === null || _b === void 0 ? void 0 : _b.call(comment, "updatingstatechange", (updatingState) => {
|
|
181
211
|
setState((state) => ({
|
|
@@ -200,6 +230,7 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
200
230
|
updatingState === "failed" ||
|
|
201
231
|
isUnchangedUpdateCycleEnd(updatingState, commentCid, comment)) {
|
|
202
232
|
maybeStopCommentAfterOneShotUpdate(commentCid, comment);
|
|
233
|
+
endOpeningUpdate(commentCid);
|
|
203
234
|
}
|
|
204
235
|
if (updatingState !== "waiting-retry") {
|
|
205
236
|
delete commentUpdateAttemptFailed[commentCid];
|
|
@@ -285,6 +316,12 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
285
316
|
return false;
|
|
286
317
|
});
|
|
287
318
|
};
|
|
319
|
+
// Whether the cycle update() began or joined has already ended, for a shared loop that will
|
|
320
|
+
// emit nothing more until its next poll (see waitForCommentUpdateCycle).
|
|
321
|
+
const isJoinedUpdateCycleSettled = (commentCid, comment) => typeof (comment === null || comment === void 0 ? void 0 : comment.updatedAt) === "number" &&
|
|
322
|
+
(comment.updatingState === "succeeded" ||
|
|
323
|
+
isUnchangedUpdateCycleEnd(comment.updatingState, commentCid, comment)) &&
|
|
324
|
+
!shouldWaitForSparseCommentFollowup(commentCid, comment);
|
|
288
325
|
// Waits for the update cycle that startUpdate() begins or joins. pkc-js runs one update loop
|
|
289
326
|
// per CID: when another instance already updates this comment (for example the account's own
|
|
290
327
|
// reply, whose update subscribes to its post), update() mirrors that shared loop instead of
|
|
@@ -329,11 +366,7 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
329
366
|
(_a = comment === null || comment === void 0 ? void 0 : comment.on) === null || _a === void 0 ? void 0 : _a.call(comment, "updatingstatechange", onUpdatingStateChange);
|
|
330
367
|
(_b = comment === null || comment === void 0 ? void 0 : comment.on) === null || _b === void 0 ? void 0 : _b.call(comment, "error", onError);
|
|
331
368
|
void ((_c = startUpdate()) === null || _c === void 0 ? void 0 : _c.then((updateStarted) => {
|
|
332
|
-
if (!updateStarted ||
|
|
333
|
-
settled ||
|
|
334
|
-
typeof (comment === null || comment === void 0 ? void 0 : comment.updatedAt) !== "number" ||
|
|
335
|
-
!isSettledUpdatingState(comment === null || comment === void 0 ? void 0 : comment.updatingState) ||
|
|
336
|
-
shouldWaitForSparseCommentFollowup(commentCid, comment)) {
|
|
369
|
+
if (!updateStarted || settled || !isJoinedUpdateCycleSettled(commentCid, comment)) {
|
|
337
370
|
return;
|
|
338
371
|
}
|
|
339
372
|
// No event will end this cycle, so detach a one-shot update here as the event would.
|
|
@@ -344,8 +377,10 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
344
377
|
return {
|
|
345
378
|
comments: {},
|
|
346
379
|
errors: {},
|
|
380
|
+
openingUpdatesPending: {},
|
|
347
381
|
addCommentToStore(commentCid, account, commentData) {
|
|
348
382
|
return __awaiter(this, void 0, void 0, function* () {
|
|
383
|
+
var _a;
|
|
349
384
|
const { comments } = getState();
|
|
350
385
|
const pendingKey = commentCid + account.id;
|
|
351
386
|
// comment is in store already, do nothing
|
|
@@ -363,22 +398,31 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
363
398
|
log("commentsStore.addCommentToStore", { commentCid, comment, account });
|
|
364
399
|
setState((state) => ({
|
|
365
400
|
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: utils.clone(comment) }),
|
|
401
|
+
openingUpdatesPending: Object.assign(Object.assign({}, state.openingUpdatesPending), { [commentCid]: true }),
|
|
366
402
|
}));
|
|
367
403
|
}
|
|
368
404
|
else {
|
|
369
405
|
comment = normalizeCommentCommunityAddress(comment);
|
|
370
406
|
setState((state) => ({
|
|
371
407
|
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: utils.clone(comment) }),
|
|
408
|
+
openingUpdatesPending: Object.assign(Object.assign({}, state.openingUpdatesPending), { [commentCid]: true }),
|
|
372
409
|
}));
|
|
373
410
|
// add comment replies pages to repliesPagesStore so they can be used in useComment
|
|
374
411
|
repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);
|
|
375
412
|
comment = yield ensureLiveComment(commentCid, account, mergeCommentData(commentCid, comment, commentData));
|
|
376
413
|
}
|
|
377
414
|
if (comment) {
|
|
378
|
-
|
|
415
|
+
const liveComment = comment;
|
|
416
|
+
void ((_a = requestCommentUpdate(commentCid, liveComment, { stopAfterNextUpdate: true })) === null || _a === void 0 ? void 0 : _a.then((updateStarted) => {
|
|
417
|
+
if (updateStarted && isJoinedUpdateCycleSettled(commentCid, liveComment)) {
|
|
418
|
+
maybeStopCommentAfterOneShotUpdate(commentCid, liveComment);
|
|
419
|
+
endOpeningUpdate(commentCid);
|
|
420
|
+
}
|
|
421
|
+
}));
|
|
379
422
|
}
|
|
380
423
|
}
|
|
381
424
|
catch (e) {
|
|
425
|
+
endOpeningUpdate(commentCid);
|
|
382
426
|
addCommentError(commentCid, e);
|
|
383
427
|
throw e;
|
|
384
428
|
}
|
|
@@ -402,6 +446,9 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
402
446
|
}));
|
|
403
447
|
}
|
|
404
448
|
if (!hasCommentAutoUpdateSubscribers(commentCid)) {
|
|
449
|
+
if (deferStopUntilOpeningUpdateEnds(commentCid)) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
405
452
|
yield stopLiveComment(commentCid, liveComment);
|
|
406
453
|
maybeReleaseStoppedLiveComment(commentCid, liveComment);
|
|
407
454
|
return;
|
|
@@ -417,7 +464,8 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
417
464
|
delete commentAutoUpdateSubscribers[commentCid];
|
|
418
465
|
}
|
|
419
466
|
}
|
|
420
|
-
if (hasCommentAutoUpdateSubscribers(commentCid)
|
|
467
|
+
if (hasCommentAutoUpdateSubscribers(commentCid) ||
|
|
468
|
+
deferStopUntilOpeningUpdateEnds(commentCid)) {
|
|
421
469
|
return;
|
|
422
470
|
}
|
|
423
471
|
delete stopCommentAfterNextUpdate[commentCid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AC,WAAM,CAAC,CAAA,CAAC;QACV,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,kBAAkB,wDAAI,CAAC;IACnC,CAAC,CAAA,CAAC,CACH,CAAC;IACF,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IAErB,mDAAmD;IACnD,aAAa,CAAC,OAAO,EAAE,CAAC;IACxB,yBAAyB;IACzB,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAS,EAAE;IACtD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACtF,MAAM,kBAAkB,EAAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import localForageLru from \"../../lib/localforage-lru\";\nconst commentsDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-comments\",\n size: 5000,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nexport const log = Logger(\"bitsocial-react-hooks:comments:stores\");\nimport { Comment, Comments, Account } from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport repliesPagesStore from \"../replies-pages\";\nimport { normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\n\nlet pkcGetCommentPending: { [key: string]: boolean } = {};\nconst liveComments: { [commentCid: string]: Comment } = {};\nconst liveCommentPromises: { [commentCid: string]: Promise<Comment> | undefined } = {};\nconst commentAutoUpdateSubscribers: {\n [commentCid: string]: { [subscriberId: string]: true };\n} = {};\nconst stopCommentAfterNextUpdate: { [commentCid: string]: boolean } = {};\nconst sparseCommentFollowupRequested: { [commentCid: string]: boolean } = {};\n// set when the current update attempt emitted an error, until the next attempt starts\nconst commentUpdateAttemptFailed: { [commentCid: string]: boolean } = {};\nconst initializedComments = new WeakSet<object>();\nconst trackedListeners = new WeakSet<object>();\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\nexport type CommentsState = {\n comments: Comments;\n errors: { [commentCid: string]: Error[] };\n addCommentToStore: Function;\n startCommentAutoUpdate: Function;\n stopCommentAutoUpdate: Function;\n refreshComment: Function;\n};\n\nconst removeCommentListener = (comment: any, event: string, listener: (...args: any[]) => void) => {\n if (typeof comment?.off === \"function\") {\n comment.off(event, listener);\n return;\n }\n if (typeof comment?.removeListener === \"function\") {\n comment.removeListener(event, listener);\n }\n};\n\nconst getCommentAutoUpdateSubscribersCount = (commentCid: string) =>\n Object.keys(commentAutoUpdateSubscribers[commentCid] || {}).length;\n\nconst hasCommentAutoUpdateSubscribers = (commentCid: string) =>\n getCommentAutoUpdateSubscribersCount(commentCid) > 0;\n\nconst mergeCommentData = (\n commentCid: string,\n ...commentDataList: (Comment | undefined)[]\n): Comment => {\n const mergedCommentData: Comment = { cid: commentCid };\n for (const commentData of commentDataList) {\n if (commentData && typeof commentData === \"object\") {\n Object.assign(mergedCommentData, utils.clone(commentData));\n }\n }\n mergedCommentData.cid = commentCid;\n return mergedCommentData;\n};\n\nconst releaseLiveComment = (commentCid: string, comment?: Comment) => {\n const liveComment = comment || liveComments[commentCid];\n if (liveComment) {\n const listenerIndex = listeners.indexOf(liveComment);\n if (listenerIndex !== -1) {\n listeners.splice(listenerIndex, 1);\n }\n }\n if (!comment || liveComments[commentCid] === liveComment) {\n delete liveComments[commentCid];\n }\n};\n\nconst maybeReleaseStoppedLiveComment = (commentCid: string, comment?: Comment) => {\n if (!comment || hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n if (liveComments[commentCid] !== comment) {\n return;\n }\n releaseLiveComment(commentCid, comment);\n};\n\nconst commentsStore = createStore<CommentsState>((setState: Function, getState: Function) => {\n const addCommentError = (commentCid: string, error: Error) => {\n setState((state: CommentsState) => {\n let commentErrors = state.errors[commentCid] || [];\n commentErrors = [...commentErrors, error];\n return { ...state, errors: { ...state.errors, [commentCid]: commentErrors } };\n });\n };\n\n const persistComment = async (commentCid: string, nextComment: Comment) => {\n const normalizedComment = normalizeCommentCommunityAddress(utils.clone(nextComment)) as Comment;\n // Store the update before the database write. pkc-js emits \"updatingstatechange\" right after\n // \"update\", so waiting on the write would let \"succeeded\" land on a CID-only entry, and a\n // frozen useComment would settle on that empty shell.\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: normalizedComment },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);\n\n await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\n\n return normalizedComment;\n };\n\n const clearCommentUpdateFollowup = (commentCid: string) => {\n delete sparseCommentFollowupRequested[commentCid];\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\n clearCommentUpdateFollowup(commentCid);\n const liveComment = comment || liveComments[commentCid];\n if (typeof liveComment?.stop !== \"function\") {\n return;\n }\n try {\n await liveComment.stop();\n } catch (error) {\n log.trace(\"comment.stop error\", { commentCid, comment: liveComment, error });\n }\n };\n\n const maybeStopCommentAfterOneShotUpdate = (commentCid: string, comment: Comment) => {\n if (!stopCommentAfterNextUpdate[commentCid]) {\n return;\n }\n delete stopCommentAfterNextUpdate[commentCid];\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n void stopLiveComment(commentCid, comment).finally(() => {\n maybeReleaseStoppedLiveComment(commentCid, comment);\n });\n };\n\n const toCommentUpdateError = (error: unknown) =>\n error instanceof Error ? error : Error(\"comment update failed\");\n\n const emitCommentError = (comment: Comment, error: Error) => {\n const emit = (comment as any)?.emit;\n if (typeof emit !== \"function\") {\n return;\n }\n try {\n emit.call(comment, \"error\", error);\n } catch (emitError) {\n if (emitError !== error) {\n log.trace(\"comment.update error event error\", { comment, error: emitError });\n }\n }\n };\n\n const handleCommentUpdateError = (commentCid: string, comment: Comment, error: unknown) => {\n const updateError = toCommentUpdateError(error);\n clearCommentUpdateFollowup(commentCid);\n\n if (!getState().errors[commentCid]?.includes(updateError)) {\n emitCommentError(comment, updateError);\n if (!getState().errors[commentCid]?.includes(updateError)) {\n addCommentError(commentCid, updateError);\n }\n }\n\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n return updateError;\n };\n\n const isSparseCommentUpdate = (comment: Comment) => !!comment?.timestamp && !comment?.updatedAt;\n\n // A CID-only comment update can settle after immutable IPFS data; one follow-up\n // update gives PKC a chance to load mutable community data such as replies.\n const shouldRequestSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n !sparseCommentFollowupRequested[commentCid] &&\n (stopCommentAfterNextUpdate[commentCid] || hasCommentAutoUpdateSubscribers(commentCid)) &&\n isSparseCommentUpdate(comment);\n\n const shouldWaitForSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n sparseCommentFollowupRequested[commentCid] && isSparseCommentUpdate(comment);\n\n // pkc-js ends an update cycle that found no newer CommentUpdate with \"waiting-retry\". A\n // retriable failure also ends in \"waiting-retry\", after an error event, and must keep retrying.\n // Once the comment has a CommentUpdate, an error-free \"waiting-retry\" settles a one-shot update\n // or refresh; until then, keep waiting for the first one.\n const isUnchangedUpdateCycleEnd = (updatingState: string, commentCid: string, comment: Comment) =>\n updatingState === \"waiting-retry\" &&\n !commentUpdateAttemptFailed[commentCid] &&\n typeof comment?.updatedAt === \"number\";\n\n const initializeComment = (commentCid: string, comment: Comment, account: Account) => {\n if (initializedComments.has(comment as object)) {\n liveComments[commentCid] = comment;\n return;\n }\n initializedComments.add(comment as object);\n liveComments[commentCid] = comment;\n\n comment?.on?.(\"update\", async (updatedComment: Comment) => {\n updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment)) as Comment;\n await persistComment(commentCid, updatedComment);\n });\n\n comment?.on?.(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommentsState) => ({\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], updatingState },\n },\n }));\n\n if (\n updatingState === \"succeeded\" &&\n shouldRequestSparseCommentFollowup(commentCid, comment)\n ) {\n sparseCommentFollowupRequested[commentCid] = true;\n requestCommentUpdate(commentCid, comment, {\n stopAfterNextUpdate: !!stopCommentAfterNextUpdate[commentCid],\n });\n return;\n }\n\n if (\n updatingState === \"succeeded\" &&\n (comment.updatedAt || sparseCommentFollowupRequested[commentCid])\n ) {\n clearCommentUpdateFollowup(commentCid);\n }\n if (updatingState === \"failed\") {\n clearCommentUpdateFollowup(commentCid);\n }\n\n if (\n updatingState === \"succeeded\" ||\n updatingState === \"failed\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment)\n ) {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n if (updatingState !== \"waiting-retry\") {\n delete commentUpdateAttemptFailed[commentCid];\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\n commentUpdateAttemptFailed[commentCid] = true;\n addCommentError(commentCid, error);\n });\n\n // set clients on comment so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n comment?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommentsState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.comments[commentCid]) {\n return {};\n }\n const clients = { ...state.comments[commentCid]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], clients },\n },\n };\n });\n },\n );\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n // if comment.timestamp isn't defined, it means the next update will contain the timestamp and author\n // which is used in addCidToAccountComment\n if (!comment?.timestamp) {\n comment?.once?.(\"update\", () =>\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(comment)\n .catch((error: any) =>\n log.error(\"accountsActionsInternal.addCidToAccountComment error\", { comment, error }),\n ),\n );\n }\n\n if (!trackedListeners.has(comment as object)) {\n trackedListeners.add(comment as object);\n listeners.push(comment);\n }\n };\n\n const ensureLiveComment = async (commentCid: string, account: Account, commentData?: Comment) => {\n if (liveComments[commentCid]) {\n return liveComments[commentCid];\n }\n if (liveCommentPromises[commentCid]) {\n return liveCommentPromises[commentCid] as Promise<Comment>;\n }\n\n const liveCommentPromise = (async () => {\n const initialComment = normalizeCommentCommunityAddress(\n mergeCommentData(commentCid, commentData),\n );\n const liveComment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(initialComment),\n ) as Comment;\n initializeComment(commentCid, liveComment, account);\n return liveComment;\n })();\n liveCommentPromises[commentCid] = liveCommentPromise;\n\n try {\n return await liveCommentPromise;\n } finally {\n if (liveCommentPromises[commentCid] === liveCommentPromise) {\n delete liveCommentPromises[commentCid];\n }\n }\n };\n\n const requestCommentUpdate = (\n commentCid: string,\n comment: Comment,\n options?: { stopAfterNextUpdate?: boolean },\n ) => {\n if (options?.stopAfterNextUpdate) {\n stopCommentAfterNextUpdate[commentCid] = true;\n } else {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n\n // Resolves whether update() started or attached to an update loop.\n return comment?.update?.().then(\n () => true,\n (error: unknown) => {\n const updateError = handleCommentUpdateError(commentCid, comment, error);\n log.trace(\"comment.update error\", { commentCid, comment, error: updateError });\n return false;\n },\n );\n };\n\n // Waits for the update cycle that startUpdate() begins or joins. pkc-js runs one update loop\n // per CID: when another instance already updates this comment (for example the account's own\n // reply, whose update subscribes to its post), update() mirrors that shared loop instead of\n // starting a cycle, and when auto-update subscribers keep this comment updating, update() does\n // nothing. Either loop only emits again on its next poll, up to a minute later on a quiet\n // community, but its latest CommentUpdate is current, so joining a loop that has already\n // settled settles as soon as update() returns.\n const waitForCommentUpdateCycle = (\n commentCid: string,\n comment: Comment,\n startUpdate: () => Promise<boolean> | undefined,\n ) =>\n new Promise<Comment>((resolve, reject) => {\n let settled = false;\n const settle = () => {\n settled = true;\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n };\n const isSettledUpdatingState = (updatingState: string) =>\n updatingState === \"succeeded\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment);\n\n const onUpdatingStateChange = (updatingState: string) => {\n if (isSettledUpdatingState(updatingState)) {\n if (shouldWaitForSparseCommentFollowup(commentCid, comment)) {\n return;\n }\n settle();\n return;\n }\n if (updatingState === \"failed\") {\n settled = true;\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\n settled = true;\n cleanup();\n reject(error);\n };\n\n const cleanup = () => {\n removeCommentListener(comment, \"updatingstatechange\", onUpdatingStateChange);\n removeCommentListener(comment, \"error\", onError);\n };\n\n comment?.on?.(\"updatingstatechange\", onUpdatingStateChange);\n comment?.on?.(\"error\", onError);\n\n void startUpdate()?.then((updateStarted) => {\n if (\n !updateStarted ||\n settled ||\n typeof comment?.updatedAt !== \"number\" ||\n !isSettledUpdatingState(comment?.updatingState) ||\n shouldWaitForSparseCommentFollowup(commentCid, comment)\n ) {\n return;\n }\n // No event will end this cycle, so detach a one-shot update here as the event would.\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n settle();\n });\n });\n\n return {\n comments: {},\n errors: {},\n\n async addCommentToStore(commentCid: string, account: Account, commentData?: Comment) {\n const { comments } = getState();\n const pendingKey = commentCid + account.id;\n\n // comment is in store already, do nothing\n let comment: Comment | undefined = comments[commentCid];\n if (comment || pkcGetCommentPending[pendingKey]) {\n return;\n }\n pkcGetCommentPending[pendingKey] = true;\n\n try {\n // try to find comment in database\n comment = await getCommentFromDatabase(commentCid, account, commentData);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, commentData);\n comment = normalizeCommentCommunityAddress(comment);\n log(\"commentsStore.addCommentToStore\", { commentCid, comment, account });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n } else {\n comment = normalizeCommentCommunityAddress(comment);\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);\n\n comment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, comment, commentData),\n );\n }\n\n if (comment) {\n requestCommentUpdate(commentCid, comment, { stopAfterNextUpdate: true });\n }\n } catch (e: any) {\n addCommentError(commentCid, e);\n throw e;\n } finally {\n pkcGetCommentPending[pendingKey] = false;\n }\n },\n\n async startCommentAutoUpdate(\n commentCid: string,\n subscriberId: string,\n account: Account,\n commentData?: Comment,\n ) {\n const hadAutoUpdateSubscribers = hasCommentAutoUpdateSubscribers(commentCid);\n commentAutoUpdateSubscribers[commentCid] = {\n ...(commentAutoUpdateSubscribers[commentCid] || {}),\n [subscriberId]: true,\n };\n\n if (hadAutoUpdateSubscribers && liveComments[commentCid]) {\n return;\n }\n\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (!storedComment) {\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(liveComment) },\n }));\n }\n\n if (!hasCommentAutoUpdateSubscribers(commentCid)) {\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n return;\n }\n\n requestCommentUpdate(commentCid, liveComment);\n },\n\n async stopCommentAutoUpdate(commentCid: string, subscriberId: string) {\n if (commentAutoUpdateSubscribers[commentCid]) {\n delete commentAutoUpdateSubscribers[commentCid][subscriberId];\n if (Object.keys(commentAutoUpdateSubscribers[commentCid]).length === 0) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n }\n\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n\n delete stopCommentAfterNextUpdate[commentCid];\n const liveComment = liveComments[commentCid];\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n },\n\n async refreshComment(commentCid: string, account: Account, commentData?: Comment) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n return waitForCommentUpdateCycle(commentCid, liveComment, () =>\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n }),\n );\n },\n };\n});\n\nconst getCommentFromDatabase = async (\n commentCid: string,\n account: Account,\n initialCommentData?: Comment,\n) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(\n mergeCommentData(commentCid, commentData, initialCommentData),\n ),\n );\n return comment;\n } catch (e) {\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createComment(cachedComment)\", {\n cachedComment: commentData,\n error: e,\n });\n }\n};\n\n// reset store in between tests\nconst originalState = commentsStore.getState();\n// async function because some stores have async init\nexport const resetCommentsStore = async () => {\n pkcGetCommentPending = {};\n for (const commentCid in commentAutoUpdateSubscribers) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n for (const commentCid in stopCommentAfterNextUpdate) {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n for (const commentCid in sparseCommentFollowupRequested) {\n delete sparseCommentFollowupRequested[commentCid];\n }\n for (const commentCid in commentUpdateAttemptFailed) {\n delete commentUpdateAttemptFailed[commentCid];\n }\n for (const commentCid in liveCommentPromises) {\n delete liveCommentPromises[commentCid];\n }\n for (const commentCid in liveComments) {\n delete liveComments[commentCid];\n }\n\n // remove all event listeners\n await Promise.all(\n listeners.map(async (listener: any) => {\n try {\n if (typeof listener?.stop === \"function\") {\n await listener.stop();\n }\n } catch {}\n listener?.removeAllListeners?.();\n }),\n );\n listeners.length = 0;\n\n // destroy all component subscriptions to the store\n commentsStore.destroy();\n // restore original state\n commentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommentsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear();\n await resetCommentsStore();\n};\n\nexport default commentsStore;\n"]}
|
|
1
|
+
{"version":3,"file":"comments-store.js","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,MAAM,gBAAgB,GAAG,cAAc,CAAC,cAAc,CAAC;IACrD,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AACH,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAEnE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAExE,IAAI,oBAAoB,GAA+B,EAAE,CAAC;AAC1D,MAAM,YAAY,GAAsC,EAAE,CAAC;AAC3D,MAAM,mBAAmB,GAA2D,EAAE,CAAC;AACvF,MAAM,4BAA4B,GAE9B,EAAE,CAAC;AACP,MAAM,0BAA0B,GAAsC,EAAE,CAAC;AACzE,MAAM,8BAA8B,GAAsC,EAAE,CAAC;AAC7E,sFAAsF;AACtF,MAAM,0BAA0B,GAAsC,EAAE,CAAC;AACzE,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ACH,CAAC;IACF,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IAErB,mDAAmD;IACnD,aAAa,CAAC,OAAO,EAAE,CAAC;IACxB,yBAAyB;IACzB,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAS,EAAE;IACtD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACtF,MAAM,kBAAkB,EAAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import localForageLru from \"../../lib/localforage-lru\";\nconst commentsDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-comments\",\n size: 5000,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nexport const log = Logger(\"bitsocial-react-hooks:comments:stores\");\nimport { Comment, Comments, Account } from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport repliesPagesStore from \"../replies-pages\";\nimport { normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\n\nlet pkcGetCommentPending: { [key: string]: boolean } = {};\nconst liveComments: { [commentCid: string]: Comment } = {};\nconst liveCommentPromises: { [commentCid: string]: Promise<Comment> | undefined } = {};\nconst commentAutoUpdateSubscribers: {\n [commentCid: string]: { [subscriberId: string]: true };\n} = {};\nconst stopCommentAfterNextUpdate: { [commentCid: string]: boolean } = {};\nconst sparseCommentFollowupRequested: { [commentCid: string]: boolean } = {};\n// set when the current update attempt emitted an error, until the next attempt starts\nconst commentUpdateAttemptFailed: { [commentCid: string]: boolean } = {};\nconst initializedComments = new WeakSet<object>();\nconst trackedListeners = new WeakSet<object>();\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\nexport type CommentsState = {\n comments: Comments;\n errors: { [commentCid: string]: Error[] };\n // CIDs whose update requested by addCommentToStore has not ended yet. A frozen useComment or\n // useComments waits for it, so a copy cached on an earlier visit is not frozen in place.\n openingUpdatesPending: { [commentCid: string]: true };\n addCommentToStore: Function;\n startCommentAutoUpdate: Function;\n stopCommentAutoUpdate: Function;\n refreshComment: Function;\n};\n\nconst removeCommentListener = (comment: any, event: string, listener: (...args: any[]) => void) => {\n if (typeof comment?.off === \"function\") {\n comment.off(event, listener);\n return;\n }\n if (typeof comment?.removeListener === \"function\") {\n comment.removeListener(event, listener);\n }\n};\n\nconst getCommentAutoUpdateSubscribersCount = (commentCid: string) =>\n Object.keys(commentAutoUpdateSubscribers[commentCid] || {}).length;\n\nconst hasCommentAutoUpdateSubscribers = (commentCid: string) =>\n getCommentAutoUpdateSubscribersCount(commentCid) > 0;\n\nconst mergeCommentData = (\n commentCid: string,\n ...commentDataList: (Comment | undefined)[]\n): Comment => {\n const mergedCommentData: Comment = { cid: commentCid };\n for (const commentData of commentDataList) {\n if (commentData && typeof commentData === \"object\") {\n Object.assign(mergedCommentData, utils.clone(commentData));\n }\n }\n mergedCommentData.cid = commentCid;\n return mergedCommentData;\n};\n\nconst releaseLiveComment = (commentCid: string, comment?: Comment) => {\n const liveComment = comment || liveComments[commentCid];\n if (liveComment) {\n const listenerIndex = listeners.indexOf(liveComment);\n if (listenerIndex !== -1) {\n listeners.splice(listenerIndex, 1);\n }\n }\n if (!comment || liveComments[commentCid] === liveComment) {\n delete liveComments[commentCid];\n }\n};\n\nconst maybeReleaseStoppedLiveComment = (commentCid: string, comment?: Comment) => {\n if (!comment || hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n if (liveComments[commentCid] !== comment) {\n return;\n }\n releaseLiveComment(commentCid, comment);\n};\n\nconst commentsStore = createStore<CommentsState>((setState: Function, getState: Function) => {\n const addCommentError = (commentCid: string, error: Error) => {\n setState((state: CommentsState) => {\n let commentErrors = state.errors[commentCid] || [];\n commentErrors = [...commentErrors, error];\n return { ...state, errors: { ...state.errors, [commentCid]: commentErrors } };\n });\n };\n\n const persistComment = async (commentCid: string, nextComment: Comment) => {\n const normalizedComment = normalizeCommentCommunityAddress(utils.clone(nextComment)) as Comment;\n // Store the update before the database write. pkc-js emits \"updatingstatechange\" right after\n // \"update\", so waiting on the write would let \"succeeded\" land on a CID-only entry, and a\n // frozen useComment would settle on that empty shell.\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: normalizedComment },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);\n\n await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\n\n return normalizedComment;\n };\n\n const clearCommentUpdateFollowup = (commentCid: string) => {\n delete sparseCommentFollowupRequested[commentCid];\n };\n\n const endOpeningUpdate = (commentCid: string) => {\n if (!getState().openingUpdatesPending[commentCid]) {\n return;\n }\n setState((state: CommentsState) => {\n const openingUpdatesPending = { ...state.openingUpdatesPending };\n delete openingUpdatesPending[commentCid];\n return { openingUpdatesPending };\n });\n };\n\n // When the last auto-update subscriber leaves during the opening update, stopping would abort\n // it and leave a frozen useComment on a cached copy, so stop when that update ends instead.\n const deferStopUntilOpeningUpdateEnds = (commentCid: string) => {\n if (!getState().openingUpdatesPending[commentCid]) {\n return false;\n }\n stopCommentAfterNextUpdate[commentCid] = true;\n return true;\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\n clearCommentUpdateFollowup(commentCid);\n // a stopped comment gets no further update from this cycle\n endOpeningUpdate(commentCid);\n const liveComment = comment || liveComments[commentCid];\n if (typeof liveComment?.stop !== \"function\") {\n return;\n }\n try {\n await liveComment.stop();\n } catch (error) {\n log.trace(\"comment.stop error\", { commentCid, comment: liveComment, error });\n }\n };\n\n const maybeStopCommentAfterOneShotUpdate = (commentCid: string, comment: Comment) => {\n if (!stopCommentAfterNextUpdate[commentCid]) {\n return;\n }\n delete stopCommentAfterNextUpdate[commentCid];\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n void stopLiveComment(commentCid, comment).finally(() => {\n maybeReleaseStoppedLiveComment(commentCid, comment);\n });\n };\n\n const toCommentUpdateError = (error: unknown) =>\n error instanceof Error ? error : Error(\"comment update failed\");\n\n const emitCommentError = (comment: Comment, error: Error) => {\n const emit = (comment as any)?.emit;\n if (typeof emit !== \"function\") {\n return;\n }\n try {\n emit.call(comment, \"error\", error);\n } catch (emitError) {\n if (emitError !== error) {\n log.trace(\"comment.update error event error\", { comment, error: emitError });\n }\n }\n };\n\n const handleCommentUpdateError = (commentCid: string, comment: Comment, error: unknown) => {\n const updateError = toCommentUpdateError(error);\n clearCommentUpdateFollowup(commentCid);\n\n if (!getState().errors[commentCid]?.includes(updateError)) {\n emitCommentError(comment, updateError);\n if (!getState().errors[commentCid]?.includes(updateError)) {\n addCommentError(commentCid, updateError);\n }\n }\n\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n endOpeningUpdate(commentCid);\n return updateError;\n };\n\n const isSparseCommentUpdate = (comment: Comment) => !!comment?.timestamp && !comment?.updatedAt;\n\n // A CID-only comment update can settle after immutable IPFS data; one follow-up\n // update gives PKC a chance to load mutable community data such as replies.\n const shouldRequestSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n !sparseCommentFollowupRequested[commentCid] &&\n (stopCommentAfterNextUpdate[commentCid] || hasCommentAutoUpdateSubscribers(commentCid)) &&\n isSparseCommentUpdate(comment);\n\n const shouldWaitForSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n sparseCommentFollowupRequested[commentCid] && isSparseCommentUpdate(comment);\n\n // pkc-js ends an update cycle that found no newer CommentUpdate with \"waiting-retry\". A\n // retriable failure also ends in \"waiting-retry\", after an error event, and must keep retrying.\n // Once the comment has a CommentUpdate, an error-free \"waiting-retry\" settles a one-shot update\n // or refresh; until then, keep waiting for the first one.\n const isUnchangedUpdateCycleEnd = (updatingState: string, commentCid: string, comment: Comment) =>\n updatingState === \"waiting-retry\" &&\n !commentUpdateAttemptFailed[commentCid] &&\n typeof comment?.updatedAt === \"number\";\n\n const initializeComment = (commentCid: string, comment: Comment, account: Account) => {\n if (initializedComments.has(comment as object)) {\n liveComments[commentCid] = comment;\n return;\n }\n initializedComments.add(comment as object);\n liveComments[commentCid] = comment;\n\n comment?.on?.(\"update\", async (updatedComment: Comment) => {\n updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment)) as Comment;\n // A newer CommentUpdate ends the opening update, also for a reply whose cycle pkc-js never\n // ends. pkc-js emits \"update\" for other changes too, like a resolved author name.\n const isNewerCommentUpdate =\n (updatedComment.updatedAt ?? 0) > (getState().comments[commentCid]?.updatedAt ?? 0);\n const persisted = persistComment(commentCid, updatedComment);\n if (isNewerCommentUpdate) {\n endOpeningUpdate(commentCid);\n }\n await persisted;\n });\n\n comment?.on?.(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommentsState) => ({\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], updatingState },\n },\n }));\n\n if (\n updatingState === \"succeeded\" &&\n shouldRequestSparseCommentFollowup(commentCid, comment)\n ) {\n sparseCommentFollowupRequested[commentCid] = true;\n requestCommentUpdate(commentCid, comment, {\n stopAfterNextUpdate: !!stopCommentAfterNextUpdate[commentCid],\n });\n return;\n }\n\n if (\n updatingState === \"succeeded\" &&\n (comment.updatedAt || sparseCommentFollowupRequested[commentCid])\n ) {\n clearCommentUpdateFollowup(commentCid);\n }\n if (updatingState === \"failed\") {\n clearCommentUpdateFollowup(commentCid);\n }\n\n if (\n updatingState === \"succeeded\" ||\n updatingState === \"failed\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment)\n ) {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n endOpeningUpdate(commentCid);\n }\n if (updatingState !== \"waiting-retry\") {\n delete commentUpdateAttemptFailed[commentCid];\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\n commentUpdateAttemptFailed[commentCid] = true;\n addCommentError(commentCid, error);\n });\n\n // set clients on comment so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n comment?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommentsState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.comments[commentCid]) {\n return {};\n }\n const clients = { ...state.comments[commentCid]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], clients },\n },\n };\n });\n },\n );\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n // if comment.timestamp isn't defined, it means the next update will contain the timestamp and author\n // which is used in addCidToAccountComment\n if (!comment?.timestamp) {\n comment?.once?.(\"update\", () =>\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(comment)\n .catch((error: any) =>\n log.error(\"accountsActionsInternal.addCidToAccountComment error\", { comment, error }),\n ),\n );\n }\n\n if (!trackedListeners.has(comment as object)) {\n trackedListeners.add(comment as object);\n listeners.push(comment);\n }\n };\n\n const ensureLiveComment = async (commentCid: string, account: Account, commentData?: Comment) => {\n if (liveComments[commentCid]) {\n return liveComments[commentCid];\n }\n if (liveCommentPromises[commentCid]) {\n return liveCommentPromises[commentCid] as Promise<Comment>;\n }\n\n const liveCommentPromise = (async () => {\n const initialComment = normalizeCommentCommunityAddress(\n mergeCommentData(commentCid, commentData),\n );\n const liveComment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(initialComment),\n ) as Comment;\n initializeComment(commentCid, liveComment, account);\n return liveComment;\n })();\n liveCommentPromises[commentCid] = liveCommentPromise;\n\n try {\n return await liveCommentPromise;\n } finally {\n if (liveCommentPromises[commentCid] === liveCommentPromise) {\n delete liveCommentPromises[commentCid];\n }\n }\n };\n\n const requestCommentUpdate = (\n commentCid: string,\n comment: Comment,\n options?: { stopAfterNextUpdate?: boolean },\n ) => {\n if (options?.stopAfterNextUpdate) {\n stopCommentAfterNextUpdate[commentCid] = true;\n } else {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n\n // Resolves whether update() started or attached to an update loop.\n return comment?.update?.().then(\n () => true,\n (error: unknown) => {\n const updateError = handleCommentUpdateError(commentCid, comment, error);\n log.trace(\"comment.update error\", { commentCid, comment, error: updateError });\n return false;\n },\n );\n };\n\n // Whether the cycle update() began or joined has already ended, for a shared loop that will\n // emit nothing more until its next poll (see waitForCommentUpdateCycle).\n const isJoinedUpdateCycleSettled = (commentCid: string, comment: Comment) =>\n typeof comment?.updatedAt === \"number\" &&\n (comment.updatingState === \"succeeded\" ||\n isUnchangedUpdateCycleEnd(comment.updatingState, commentCid, comment)) &&\n !shouldWaitForSparseCommentFollowup(commentCid, comment);\n\n // Waits for the update cycle that startUpdate() begins or joins. pkc-js runs one update loop\n // per CID: when another instance already updates this comment (for example the account's own\n // reply, whose update subscribes to its post), update() mirrors that shared loop instead of\n // starting a cycle, and when auto-update subscribers keep this comment updating, update() does\n // nothing. Either loop only emits again on its next poll, up to a minute later on a quiet\n // community, but its latest CommentUpdate is current, so joining a loop that has already\n // settled settles as soon as update() returns.\n const waitForCommentUpdateCycle = (\n commentCid: string,\n comment: Comment,\n startUpdate: () => Promise<boolean> | undefined,\n ) =>\n new Promise<Comment>((resolve, reject) => {\n let settled = false;\n const settle = () => {\n settled = true;\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n };\n const isSettledUpdatingState = (updatingState: string) =>\n updatingState === \"succeeded\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment);\n\n const onUpdatingStateChange = (updatingState: string) => {\n if (isSettledUpdatingState(updatingState)) {\n if (shouldWaitForSparseCommentFollowup(commentCid, comment)) {\n return;\n }\n settle();\n return;\n }\n if (updatingState === \"failed\") {\n settled = true;\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\n settled = true;\n cleanup();\n reject(error);\n };\n\n const cleanup = () => {\n removeCommentListener(comment, \"updatingstatechange\", onUpdatingStateChange);\n removeCommentListener(comment, \"error\", onError);\n };\n\n comment?.on?.(\"updatingstatechange\", onUpdatingStateChange);\n comment?.on?.(\"error\", onError);\n\n void startUpdate()?.then((updateStarted) => {\n if (!updateStarted || settled || !isJoinedUpdateCycleSettled(commentCid, comment)) {\n return;\n }\n // No event will end this cycle, so detach a one-shot update here as the event would.\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n settle();\n });\n });\n\n return {\n comments: {},\n errors: {},\n openingUpdatesPending: {},\n\n async addCommentToStore(commentCid: string, account: Account, commentData?: Comment) {\n const { comments } = getState();\n const pendingKey = commentCid + account.id;\n\n // comment is in store already, do nothing\n let comment: Comment | undefined = comments[commentCid];\n if (comment || pkcGetCommentPending[pendingKey]) {\n return;\n }\n pkcGetCommentPending[pendingKey] = true;\n\n try {\n // try to find comment in database\n comment = await getCommentFromDatabase(commentCid, account, commentData);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, commentData);\n comment = normalizeCommentCommunityAddress(comment);\n log(\"commentsStore.addCommentToStore\", { commentCid, comment, account });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n openingUpdatesPending: { ...state.openingUpdatesPending, [commentCid]: true },\n }));\n } else {\n comment = normalizeCommentCommunityAddress(comment);\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n openingUpdatesPending: { ...state.openingUpdatesPending, [commentCid]: true },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);\n\n comment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, comment, commentData),\n );\n }\n\n if (comment) {\n const liveComment = comment;\n void requestCommentUpdate(commentCid, liveComment, { stopAfterNextUpdate: true })?.then(\n (updateStarted: boolean) => {\n if (updateStarted && isJoinedUpdateCycleSettled(commentCid, liveComment)) {\n maybeStopCommentAfterOneShotUpdate(commentCid, liveComment);\n endOpeningUpdate(commentCid);\n }\n },\n );\n }\n } catch (e: any) {\n endOpeningUpdate(commentCid);\n addCommentError(commentCid, e);\n throw e;\n } finally {\n pkcGetCommentPending[pendingKey] = false;\n }\n },\n\n async startCommentAutoUpdate(\n commentCid: string,\n subscriberId: string,\n account: Account,\n commentData?: Comment,\n ) {\n const hadAutoUpdateSubscribers = hasCommentAutoUpdateSubscribers(commentCid);\n commentAutoUpdateSubscribers[commentCid] = {\n ...(commentAutoUpdateSubscribers[commentCid] || {}),\n [subscriberId]: true,\n };\n\n if (hadAutoUpdateSubscribers && liveComments[commentCid]) {\n return;\n }\n\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (!storedComment) {\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(liveComment) },\n }));\n }\n\n if (!hasCommentAutoUpdateSubscribers(commentCid)) {\n if (deferStopUntilOpeningUpdateEnds(commentCid)) {\n return;\n }\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n return;\n }\n\n requestCommentUpdate(commentCid, liveComment);\n },\n\n async stopCommentAutoUpdate(commentCid: string, subscriberId: string) {\n if (commentAutoUpdateSubscribers[commentCid]) {\n delete commentAutoUpdateSubscribers[commentCid][subscriberId];\n if (Object.keys(commentAutoUpdateSubscribers[commentCid]).length === 0) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n }\n\n if (\n hasCommentAutoUpdateSubscribers(commentCid) ||\n deferStopUntilOpeningUpdateEnds(commentCid)\n ) {\n return;\n }\n\n delete stopCommentAfterNextUpdate[commentCid];\n const liveComment = liveComments[commentCid];\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n },\n\n async refreshComment(commentCid: string, account: Account, commentData?: Comment) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n return waitForCommentUpdateCycle(commentCid, liveComment, () =>\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n }),\n );\n },\n };\n});\n\nconst getCommentFromDatabase = async (\n commentCid: string,\n account: Account,\n initialCommentData?: Comment,\n) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(\n mergeCommentData(commentCid, commentData, initialCommentData),\n ),\n );\n return comment;\n } catch (e) {\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createComment(cachedComment)\", {\n cachedComment: commentData,\n error: e,\n });\n }\n};\n\n// reset store in between tests\nconst originalState = commentsStore.getState();\n// async function because some stores have async init\nexport const resetCommentsStore = async () => {\n pkcGetCommentPending = {};\n for (const commentCid in commentAutoUpdateSubscribers) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n for (const commentCid in stopCommentAfterNextUpdate) {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n for (const commentCid in sparseCommentFollowupRequested) {\n delete sparseCommentFollowupRequested[commentCid];\n }\n for (const commentCid in commentUpdateAttemptFailed) {\n delete commentUpdateAttemptFailed[commentCid];\n }\n for (const commentCid in liveCommentPromises) {\n delete liveCommentPromises[commentCid];\n }\n for (const commentCid in liveComments) {\n delete liveComments[commentCid];\n }\n\n // remove all event listeners\n await Promise.all(\n listeners.map(async (listener: any) => {\n try {\n if (typeof listener?.stop === \"function\") {\n await listener.stop();\n }\n } catch {}\n listener?.removeAllListeners?.();\n }),\n );\n listeners.length = 0;\n\n // destroy all component subscriptions to the store\n commentsStore.destroy();\n // restore original state\n commentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommentsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear();\n await resetCommentsStore();\n};\n\nexport default commentsStore;\n"]}
|