@bitsocial/bitsocial-react-hooks 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
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,mBAAmB,GAAG,IAAI,OAAO,EAAU,CAAC;AAClD,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAU,CAAC;AAE/C,6CAA6C;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAQ,EAAE,CAAC;AAWjC,MAAM,qBAAqB,GAAG,CAAC,OAAY,EAAE,KAAa,EAAE,QAAkC,EAAE,EAAE;IAChG,IAAI,OAAO,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAA,KAAK,UAAU,EAAE,CAAC;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;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 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 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 await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\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 return normalizedComment;\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\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 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 (updatingState === \"succeeded\" || updatingState === \"failed\") {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\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 =\n normalizeCommentCommunityAddress(utils.clone(commentData || { cid: commentCid })) ||\n ({ cid: commentCid } as Comment);\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 comment\n ?.update?.()\n .catch((error: unknown) => log.trace(\"comment.update error\", { commentCid, comment, error }));\n };\n\n const waitForCommentUpdateCycle = (commentCid: string, comment: Comment) =>\n new Promise<Comment>((resolve, reject) => {\n const onUpdatingStateChange = (updatingState: string) => {\n if (updatingState === \"succeeded\") {\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n return;\n }\n if (updatingState === \"failed\") {\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\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\n return {\n comments: {},\n errors: {},\n\n async addCommentToStore(commentCid: string, account: Account) {\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);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, { cid: commentCid });\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(commentCid, account, comment);\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(commentCid: string, subscriberId: string, account: Account) {\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 storedComment || ({ cid: commentCid } as Comment),\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) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n storedComment || ({ cid: commentCid } as Comment),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n const waitForUpdate = waitForCommentUpdateCycle(commentCid, liveComment);\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n });\n return waitForUpdate;\n },\n };\n});\n\nconst getCommentFromDatabase = async (commentCid: string, account: Account) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(await account.pkc.createComment(commentData));\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 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,O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,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 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 await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\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 return normalizedComment;\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\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 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 (updatingState === \"succeeded\" || updatingState === \"failed\") {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\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 comment\n ?.update?.()\n .catch((error: unknown) => log.trace(\"comment.update error\", { commentCid, comment, error }));\n };\n\n const waitForCommentUpdateCycle = (commentCid: string, comment: Comment) =>\n new Promise<Comment>((resolve, reject) => {\n const onUpdatingStateChange = (updatingState: string) => {\n if (updatingState === \"succeeded\") {\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n return;\n }\n if (updatingState === \"failed\") {\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\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\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 const waitForUpdate = waitForCommentUpdateCycle(commentCid, liveComment);\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n });\n return waitForUpdate;\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 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 +1 @@
1
- {"version":3,"file":"replies-store.d.ts","sourceRoot":"","sources":["../../../src/stores/replies/replies-store.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,OAAO,EAGP,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,aAAa,CAAC;AAwBrB,eAAO,MAAM,qB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AE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACzD,aAAa,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,eAAe,EAAE,QAAQ,CAAC;IAC1B,6BAA6B,EAAE,QAAQ,CAAC;IACxC,uBAAuB,EAAE,QAAQ,CAAC;IAClC,SAAS,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC;AAgBF,eAAO,MAAM,qBAAqB,GAAI,aAAa,OAAO,CAAC,kBAAkB,CAAC,WAG7E,CAAC;AAeF,QAAA,MAAM,YAAY,2EA2Sf,CAAC;AAkLJ,eAAO,MAAM,iCAAiC,GAC5C,SAAS,OAAO,EAChB,aAAa,OAAO,CAAC,kBAAkB,CAAC;;;CAoCzC,CAAC;AAKF,eAAO,MAAM,iBAAiB,qBAkB7B,CAAC;AAGF,eAAO,MAAM,4BAA4B,qBAGxC,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -39,6 +39,14 @@ export const feedOptionsToFeedName = (feedOptions) => {
39
39
  feedOptions = addDefaultFeedOptions(feedOptions);
40
40
  return `${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.accountId}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.commentCid}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.postCid}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.sortType}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.flat}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.onlyIfCached}-${(_a = feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.accountComments) === null || _a === void 0 ? void 0 : _a.newerThan}-${(_b = feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.accountComments) === null || _b === void 0 ? void 0 : _b.append}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.repliesPerPage}-${(_c = feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.filter) === null || _c === void 0 ? void 0 : _c.key}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.streamPage}`;
41
41
  };
42
+ const getFeedsUpdatedAts = (feedsOptions, comments) => {
43
+ var _a;
44
+ const feedsUpdatedAts = {};
45
+ for (const feedName in feedsOptions) {
46
+ feedsUpdatedAts[feedName] = (_a = comments[feedsOptions[feedName].commentCid]) === null || _a === void 0 ? void 0 : _a.updatedAt;
47
+ }
48
+ return feedsUpdatedAts;
49
+ };
42
50
  // don't updateFeeds more than once per updateFeedsMinIntervalTime
43
51
  let updateFeedsPending = false;
44
52
  let updateFeedsAgain = false;
@@ -196,8 +204,9 @@ const repliesStore = createStore((setState, getState) => ({
196
204
  const canonicalLoadedFeeds = yield getLoadedFeeds(feedsOptions, previousState.loadedFeeds, bufferedFeedsWithoutPreviousLoadedFeeds, accounts, { addAccountComments: false });
197
205
  const canonicalBufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(bufferedFeedsWithoutPreviousLoadedFeeds, canonicalLoadedFeeds);
198
206
  const canonicalFeedsHaveMore = getFeedsHaveMore(feedsOptions, canonicalBufferedFeeds, comments, repliesPages, accounts);
207
+ const canonicalFeedsUpdatedAts = getFeedsUpdatedAts(feedsOptions, comments);
199
208
  const loadedFeedsWithAccountComments = Object.assign({}, canonicalLoadedFeeds);
200
- const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, loadedFeedsWithAccountComments, canonicalFeedsHaveMore);
209
+ const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, loadedFeedsWithAccountComments, canonicalFeedsHaveMore, canonicalFeedsUpdatedAts);
201
210
  const loadedFeeds = accountCommentsChangedFeeds
202
211
  ? loadedFeedsWithAccountComments
203
212
  : canonicalLoadedFeeds;
@@ -386,7 +395,9 @@ export const getRepliesFirstPageSkipValidation = (comment, feedOptions) => {
386
395
  bufferedFeeds[feedName] = filteredSortedFeeds[feedName].splice(repliesPerPage);
387
396
  }
388
397
  const feedsHaveMore = getFeedsHaveMore(feedsOptions, bufferedFeeds, comments, repliesPages, accounts);
389
- addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore);
398
+ addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore, {
399
+ [feedName]: comment.updatedAt,
400
+ });
390
401
  return { replies: filteredSortedFeeds[feedName], hasMore: feedsHaveMore[feedName] };
391
402
  };
392
403
  // reset store in between tests
@@ -1 +1 @@
1
- {"version":3,"file":"replies-store.js","sourceRoot":"","sources":["../../../src/stores/replies/replies-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAY3D,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,6BAA6B,EAC7B,cAAc,EACd,kCAAkC,EAClC,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,2BAA2B,EAC3B,2CAA2C,EAC3C,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAEjB,+CAA+C;AAC/C,2BAA2B;AAC3B,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC,kDAAkD;AAClD,MAAM,gCAAgC,GAAG,EAAE,CAAC;AAgB5C,MAAM,sBAAsB,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACtE,MAAM,qBAAqB,GAAG,CAAC,WAAgB,EAAE,EAAE;IACjD,WAAW,qBAAQ,WAAW,C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,CAAC;IACtC,wCAAwC,GAAG,EAAE,CAAC;IAC9C,6BAA6B,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1C,kCAAkC,GAAG,EAAE,CAAC;IACxC,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,gCAAgC,GAAG,CAAC,CAAC;IACrC,gDAAgD,GAAG,EAAE,CAAC;IACtD,oBAAoB,GAAG,EAAE,CAAC;IAC1B,6BAA6B,GAAG,CAAC,CAAC;IAClC,4BAA4B,GAAG,EAAE,CAAC;IAClC,kBAAkB,GAAG,KAAK,CAAC;IAC3B,mDAAmD;IACnD,YAAY,CAAC,OAAO,EAAE,CAAC;IACvB,yBAAyB;IACzB,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IACrC,oBAAoB,CAAC,QAAQ,iCAAM,oBAAoB,CAAC,QAAQ,EAAE,KAAE,QAAQ,EAAE,EAAE,IAAG,CAAC;IACpF,uBAAuB,GAAG,KAAK,CAAC;AAClC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAS,EAAE;IACrD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,kCAAkC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC1F,MAAM,iBAAiB,EAAE,CAAC;AAC5B,CAAC,CAAA,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:stores\");\nimport {\n Feed,\n Feeds,\n Comment,\n Comments,\n Account,\n RepliesFeedOptions,\n RepliesFeedsOptions,\n RepliesPage,\n CommentsFilter,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport accountsStore from \"../accounts\";\nimport repliesCommentsStore from \"./replies-comments-store\";\nimport repliesPagesStore from \"../replies-pages\";\nimport {\n getFeedsCommentsFirstPageCids,\n getLoadedFeeds,\n getBufferedFeedsWithoutLoadedFeeds,\n getUpdatedFeeds,\n getFeedsReplyCounts,\n getFeedsHaveMore,\n feedsCommentsChanged,\n getFeedsComments,\n getFeedsCommentsLoadedCount,\n getFeedsCommentsRepliesPagesFirstUpdatedAts,\n getFilteredSortedFeeds,\n getSortTypeFromComment,\n addAccountsComments,\n} from \"./utils\";\n\n// reddit loads approximately 25 posts per page\n// while infinite scrolling\nexport const defaultRepliesPerPage = 25;\n\n// keep large buffer because fetching cids is slow\nconst commentRepliesLeftBeforeNextPage = 50;\n\nexport type RepliesState = {\n feedsOptions: RepliesFeedsOptions;\n bufferedFeeds: Feeds;\n loadedFeeds: Feeds;\n updatedFeeds: Feeds;\n bufferedFeedsReplyCounts: { [feedName: string]: number };\n feedsHaveMore: { [feedName: string]: boolean };\n addFeedsToStore: Function;\n addFeedToStoreOrUpdateComment: Function;\n incrementFeedPageNumber: Function;\n resetFeed: Function;\n updateFeeds: Function;\n};\n\nconst defaultAccountComments = { newerThan: Infinity, append: false };\nconst addDefaultFeedOptions = (feedOptions: any) => {\n feedOptions = { ...feedOptions };\n if (feedOptions.flat === undefined || feedOptions.flat === null) {\n feedOptions.flat = false;\n }\n feedOptions.onlyIfCached = feedOptions.onlyIfCached === true;\n if (feedOptions.accountComments === undefined || feedOptions.accountComments === null) {\n feedOptions.accountComments = defaultAccountComments;\n }\n feedOptions.repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n return feedOptions;\n};\n\nexport const feedOptionsToFeedName = (feedOptions: Partial<RepliesFeedOptions>) => {\n feedOptions = addDefaultFeedOptions(feedOptions);\n return `${feedOptions?.accountId}-${feedOptions?.commentCid}-${feedOptions?.postCid}-${feedOptions?.sortType}-${feedOptions?.flat}-${feedOptions?.onlyIfCached}-${feedOptions?.accountComments?.newerThan}-${feedOptions?.accountComments?.append}-${feedOptions?.repliesPerPage}-${feedOptions?.filter?.key}-${feedOptions?.streamPage}`;\n};\n\n// don't updateFeeds more than once per updateFeedsMinIntervalTime\nlet updateFeedsPending = false;\nlet updateFeedsAgain = false;\nconst updateFeedsMinIntervalTime = 100;\n\nconst repliesStore = createStore<RepliesState>((setState: Function, getState: Function) => ({\n feedsOptions: {},\n bufferedFeeds: {},\n loadedFeeds: {},\n updatedFeeds: {},\n bufferedFeedsReplyCounts: {},\n feedsHaveMore: {},\n\n addFeedsToStore(feedOptionsArray: RepliesFeedOptions[]) {\n if (!feedOptionsArray.length) {\n return;\n }\n const { feedsOptions: previousFeedsOptions } = getState();\n const newFeedsOptions: RepliesFeedsOptions = {};\n\n // get all newFeedsOptions\n for (let feedOptions of feedOptionsArray) {\n const feedName = feedOptionsToFeedName(feedOptions);\n // feed is in store already, do nothing\n // if the feed already exist but is at page 0, reset it to page 1\n if (previousFeedsOptions[feedName] && previousFeedsOptions[feedName].pageNumber !== 0) {\n continue;\n }\n\n feedOptions = addDefaultFeedOptions(feedOptions);\n\n // to add a buffered feed, add a feed with pageNumber 0\n feedOptions.pageNumber = 1;\n newFeedsOptions[feedName] = feedOptions;\n }\n\n // set new feedsOptions state (first loop already skips existing feeds)\n let feedsChanged = false;\n setState(({ feedsOptions }: RepliesState) => {\n if (!Object.keys(newFeedsOptions).length) return {};\n feedsChanged = true;\n return { feedsOptions: { ...feedsOptions, ...newFeedsOptions } };\n });\n if (feedsChanged) {\n log(\"repliesStore.addFeedsToStore\", newFeedsOptions);\n }\n return feedsChanged;\n },\n\n async addFeedToStoreOrUpdateComment(comment: Comment, feedOptions: RepliesFeedOptions) {\n // init here because must be called after async accounts store finished initializing\n initializeRepliesStore();\n\n // validate options\n assert(\n comment && comment.cid && typeof comment.cid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment comment.cid '${comment?.cid}' invalid`,\n );\n assert(\n feedOptions.commentCid && typeof feedOptions.commentCid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.commentCid '${feedOptions.commentCid}' invalid`,\n );\n assert(\n feedOptions.sortType && typeof feedOptions.sortType === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.sortType '${feedOptions.sortType}' invalid`,\n );\n const account = accountsStore.getState().accounts[feedOptions.accountId];\n assert(\n typeof account?.pkc?.createComment === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.accountId '${feedOptions.accountId}' invalid`,\n );\n assert(\n !feedOptions.repliesPerPage || typeof feedOptions.repliesPerPage === \"number\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.repliesPerPage '${feedOptions.repliesPerPage}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.filter === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.filter '${feedOptions.filter?.filter}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.key === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.key '${feedOptions.filter?.key}' invalid`,\n );\n\n // if replies feed aren't in store yet, add them recursively\n // TODO: optimize performance by only adding feeds that are in page 1, and add more on each page increase\n const commentsToAddToStoreOrUpdate: Comment[] = [];\n const feedsToAddToStore: RepliesFeedOptions[] = [];\n\n // use the sort type availabe on the comment when missing\n const sortType = getSortTypeFromComment(comment, feedOptions);\n\n const addRepliesFeedsToStoreRecursively = (comment: Comment) => {\n // NOTE: even a comment with no replies needs a feed, to know it has 0 replies and not displace the UI when a new replies appears\n commentsToAddToStoreOrUpdate.push(comment);\n feedsToAddToStore.push({\n ...feedOptions,\n commentCid: comment?.cid,\n commentDepth: comment?.depth,\n });\n\n // flat doesn't need nested feeds\n if (!feedOptions.flat) {\n for (const reply of comment.replies?.pages?.[sortType]?.comments || []) {\n addRepliesFeedsToStoreRecursively(reply);\n }\n }\n };\n addRepliesFeedsToStoreRecursively(comment);\n\n // add feeds to store and update feeds\n const { addFeedsToStore, updateFeeds } = getState();\n const feedsChanged = addFeedsToStore(feedsToAddToStore);\n // add comments to store (do it after addFeedsToStore because it can trigger updateFeeds)\n repliesCommentsStore\n .getState()\n .addCommentsToStoreOrUpdateComments(commentsToAddToStoreOrUpdate);\n if (feedsChanged) {\n log(\"repliesStore.addFeedToStoreOrUpdateComment\", {\n comment,\n feedOptions,\n sortType,\n feedsToAddToStore,\n commentsToAddToStoreOrUpdate,\n });\n updateFeeds();\n }\n },\n\n incrementFeedPageNumber(feedName: string) {\n const { feedsOptions, loadedFeeds, bufferedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`,\n );\n log(\"repliesStore.incrementFeedPageNumber\", { feedName });\n\n // TODO: fix design issue, pageNumber shouldnt be increased when loadMore is called and repliesPerPage not reached\n // assert(\n // feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <= loadedFeeds[feedName].length,\n // `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`\n // )\n if (\n feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <=\n loadedFeeds[feedName].length\n ) {\n assert(\n bufferedFeeds[feedName].length > 0,\n `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`,\n );\n }\n\n setState(({ feedsOptions, loadedFeeds }: any) => {\n // don't increment page number before the current page has loaded\n // if (feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage > loadedFeeds[feedName].length) {\n // return {}\n // }\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: feedsOptions[feedName].pageNumber + 1,\n };\n return { feedsOptions: { ...feedsOptions, [feedName]: feedOptions } };\n });\n\n // do not update feed at the same time as increment a page number or it might cause\n // a race condition, rather schedule a feed update\n updateFeeds();\n },\n\n resetFeed(feedName: string) {\n const { feedsOptions, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.resetFeed feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n feedsOptions[feedName].pageNumber >= 1,\n `repliesStore.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`,\n );\n log(\"repliesStore.resetFeed\", { feedName });\n\n setState(({ feedsOptions, loadedFeeds, updatedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: 1,\n };\n return {\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n loadedFeeds: { ...loadedFeeds, [feedName]: [] },\n updatedFeeds: { ...updatedFeeds, [feedName]: [] },\n };\n });\n\n updateFeeds();\n },\n\n // recalculate all feeds using new comments.replies.pages, repliesPagesStore and page numbers\n updateFeeds() {\n if (updateFeedsPending) {\n updateFeedsAgain = true;\n return;\n }\n updateFeedsPending = true;\n\n // don't update feeds more than once per updateFeedsMinIntervalTime\n const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;\n\n setTimeout(async () => {\n // get state from all stores\n const previousState = getState();\n const { feedsOptions, updateFeeds } = previousState;\n const { comments } = repliesCommentsStore.getState();\n const { repliesPages } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // calculate new feeds\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n filteredSortedFeeds,\n previousState.loadedFeeds,\n );\n const canonicalLoadedFeeds = await getLoadedFeeds(\n feedsOptions,\n previousState.loadedFeeds,\n bufferedFeedsWithoutPreviousLoadedFeeds,\n accounts,\n { addAccountComments: false },\n );\n const canonicalBufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n canonicalLoadedFeeds,\n );\n const canonicalFeedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n canonicalBufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n const loadedFeedsWithAccountComments = { ...canonicalLoadedFeeds };\n const accountCommentsChangedFeeds = addAccountsComments(\n feedsOptions,\n loadedFeedsWithAccountComments,\n canonicalFeedsHaveMore,\n );\n const loadedFeeds = accountCommentsChangedFeeds\n ? loadedFeedsWithAccountComments\n : canonicalLoadedFeeds;\n // after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds\n const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n loadedFeeds,\n );\n const bufferedFeedsReplyCounts = getFeedsReplyCounts(feedsOptions, bufferedFeeds);\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n const updatedFeeds = await getUpdatedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.updatedFeeds,\n loadedFeeds,\n accounts,\n );\n\n // set new feeds\n setState((state: any) => ({\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n }));\n log(\"repliesStore.updateFeeds\", {\n feedsOptions,\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n comments,\n repliesPages,\n });\n\n updateFeedsPending = false;\n\n // if updateFeeds was called while updateFeedsPending = true, call updateFeeds again\n if (updateFeedsAgain) {\n updateFeedsAgain = false;\n updateFeeds();\n }\n }, timeUntilNextUpdate);\n },\n}));\n\nlet repliesStoreInitialized = false;\nconst initializeRepliesStore = async () => {\n if (repliesStoreInitialized) {\n return;\n }\n repliesStoreInitialized = true;\n // TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommentsChange(comment)\n // subscribe to comments store changes\n repliesCommentsStore.subscribe(updateFeedsOnFeedsCommentsChange);\n // subscribe to bufferedFeedsReplyCounts change\n repliesStore.subscribe(addRepliesPagesOnLowBufferedFeedsReplyCounts);\n // subscribe to replies pages store changes\n repliesPagesStore.subscribe(updateFeedsOnFeedsRepliesPagesChange);\n // subscribe to accounts store changes\n accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);\n};\n\nlet previousRepliesPages: { [pageCid: string]: RepliesPage } = {};\nconst updateFeedsOnFeedsRepliesPagesChange = (repliesPagesStoreState: any) => {\n const { repliesPages } = repliesPagesStoreState;\n\n // no changes, do nothing\n if (repliesPages === previousRepliesPages) {\n return;\n }\n previousRepliesPages = repliesPages;\n\n // currently only the feeds use repliesPagesStore, so any change must\n // trigger a feed update, if in the future another hook uses the repliesPagesStore\n // we should check if the replies pages changed are actually used by the feeds before\n // triggering an update\n repliesStore.getState().updateFeeds();\n};\n\nlet previousBufferedFeedsReplyCountsPageCids: string[] = [];\nlet previousBufferedFeedsComments = new Map<string, Comments>();\nlet previousBufferedFeedsReplyCounts: { [feedName: string]: number } = {};\nconst addRepliesPagesOnLowBufferedFeedsReplyCounts = (repliesStoreState: any) => {\n const { bufferedFeedsReplyCounts, feedsOptions } = repliesStore.getState();\n const { comments } = repliesCommentsStore.getState();\n\n // if feeds comments have changed, we must try adding them even if buffered replies counts haven't changed\n const bufferedFeedsComments = getFeedsComments(feedsOptions, comments);\n const _feedsCommentsChanged = feedsCommentsChanged(\n previousBufferedFeedsComments,\n bufferedFeedsComments,\n );\n const bufferedFeedsReplyCountsChanged =\n previousBufferedFeedsReplyCounts !== bufferedFeedsReplyCounts;\n\n // if feeds comments havent changed and buffered replies counts also havent changed, do nothing\n if (!_feedsCommentsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsComments = bufferedFeedsComments;\n previousBufferedFeedsReplyCounts = bufferedFeedsReplyCounts;\n\n // in case feeds comments changed, but the first page cids haven't\n const bufferedFeedsReplyCountsPageCids = getFeedsCommentsFirstPageCids(bufferedFeedsComments);\n const bufferedFeedsReplyCountsPageCidsChanged =\n bufferedFeedsReplyCountsPageCids.toString() !==\n previousBufferedFeedsReplyCountsPageCids.toString();\n if (!bufferedFeedsReplyCountsPageCidsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsReplyCountsPageCids = bufferedFeedsReplyCountsPageCids;\n\n const { addNextRepliesPageToStore } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // bufferedFeedsReplyCounts have changed, check if any of them are low\n for (const feedName in bufferedFeedsReplyCounts) {\n if (feedsOptions[feedName].onlyIfCached) {\n continue;\n }\n const account = accounts[feedsOptions[feedName].accountId];\n const feedReplyCount = bufferedFeedsReplyCounts[feedName];\n let sortType = feedsOptions[feedName].sortType;\n const commentCid = feedsOptions[feedName].commentCid;\n\n // TODO: maybe skip if comment community address, comment cid or comment author is blocked?\n\n // comment hasn't loaded yet\n if (!comments[commentCid]) {\n continue;\n }\n\n sortType = getSortTypeFromComment(comments[commentCid], feedsOptions[feedName]);\n\n // comment replies count is low, fetch next replies page\n if (feedReplyCount <= commentRepliesLeftBeforeNextPage) {\n addNextRepliesPageToStore(comments[commentCid], sortType, account).catch((error: unknown) =>\n log.error(\"repliesStore repliesPagesStore.addNextRepliesPageToStore error\", {\n commentCid,\n comment: comments[commentCid],\n sortType,\n error,\n }),\n );\n }\n }\n};\n\nlet previousFeedsCommentsFirstPageCids: string[] = [];\nlet previousFeedsComments: Map<string, Comments> = new Map();\nlet previousFeedsCommentsLoadedCount = 0;\nlet previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\nconst updateFeedsOnFeedsCommentsChange = (repliesCommentsStoreState: any) => {\n const { comments } = repliesCommentsStoreState;\n const { feedsOptions, updateFeeds } = repliesStore.getState();\n\n // feeds comments haven't changed, do nothing\n const feedsComments = getFeedsComments(feedsOptions, comments);\n if (!feedsCommentsChanged(previousFeedsComments, feedsComments)) {\n return;\n }\n previousFeedsComments = feedsComments;\n\n // decide if feeds comments have changed by looking at all feeds comments page cids\n // (in case that a comment changed, but its first page cid didn't)\n const feedsCommentsFirstPageCids = getFeedsCommentsFirstPageCids(feedsComments);\n\n // first page cids haven't changed, do nothing\n if (feedsCommentsFirstPageCids.toString() === previousFeedsCommentsFirstPageCids.toString()) {\n // if no new feed comments have loaded, do nothing\n // in case a comment loads with no first page cid and first pages cids don't change, need to trigger hasMore update\n const feedsCommentsLoadedCount = getFeedsCommentsLoadedCount(feedsComments);\n if (feedsCommentsLoadedCount === previousFeedsCommentsLoadedCount) {\n // if comment.replies.pages haven't changed, do nothing\n const feedsCommentsRepliesPagesFirstUpdatedAts =\n getFeedsCommentsRepliesPagesFirstUpdatedAts(feedsComments);\n if (\n feedsCommentsRepliesPagesFirstUpdatedAts ===\n previousFeedsCommentsRepliesPagesFirstUpdatedAts\n ) {\n return;\n }\n\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = feedsCommentsRepliesPagesFirstUpdatedAts;\n }\n previousFeedsCommentsLoadedCount = feedsCommentsLoadedCount;\n }\n\n // feeds comments have changed, update feeds\n previousFeedsCommentsFirstPageCids = feedsCommentsFirstPageCids;\n updateFeeds();\n};\n\nlet previousAccountsCommentsCount = 0;\nlet previousAccountsCommentsCids = \"\";\nconst updateFeedsOnAccountsCommentsChange = (accountsStoreState: any) => {\n const { accountsComments } = accountsStoreState;\n const accountsCommentsCount = Object.values(accountsComments as Comment[][]).reduce(\n (count, accountComments) => count + accountComments.length,\n 0,\n );\n\n // no changes, do nothing\n if (accountsCommentsCount === previousAccountsCommentsCount) {\n // if cids haven't changed (account comments receive cids after pending), do nothing\n const accountsCommentsCids = Object.values(accountsComments as Comment[][]).reduce(\n (cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || \"\")),\n \"\",\n );\n if (accountsCommentsCids === previousAccountsCommentsCids) {\n return;\n }\n previousAccountsCommentsCids = accountsCommentsCids;\n }\n previousAccountsCommentsCount = accountsCommentsCount;\n\n // TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid\n repliesStore.getState().updateFeeds();\n};\n\n// needed to view replies instantly without waiting for zustant store react rerenders. must be synchronous\nexport const getRepliesFirstPageSkipValidation = (\n comment: Comment,\n feedOptions: Partial<RepliesFeedOptions>,\n) => {\n const feedName = `firstPageSkipValidation-${comment?.cid}`;\n const feedsOptions: any = { [feedName]: feedOptions };\n const { accounts } = accountsStore.getState();\n\n // don't use comments store, only use preloaded comment.replies.pages\n const comments = { [comment.cid]: comment };\n\n // don't use any reply pages, they can't provide instant loading like preloaded comment.replies.pages\n const repliesPages = {};\n\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n\n // only get first page and put next page in buffered\n const bufferedFeeds: Feeds = { [feedName]: [] };\n const repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n if (filteredSortedFeeds[feedName].length > repliesPerPage) {\n bufferedFeeds[feedName] = filteredSortedFeeds[feedName].splice(repliesPerPage);\n }\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore);\n return { replies: filteredSortedFeeds[feedName], hasMore: feedsHaveMore[feedName] };\n};\n\n// reset store in between tests\nconst originalState = repliesStore.getState();\n// async function because some stores have async init\nexport const resetRepliesStore = async () => {\n previousBufferedFeedsReplyCounts = {};\n previousBufferedFeedsReplyCountsPageCids = [];\n previousBufferedFeedsComments = new Map();\n previousFeedsCommentsFirstPageCids = [];\n previousFeedsComments = new Map();\n previousFeedsCommentsLoadedCount = 0;\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\n previousRepliesPages = {};\n previousAccountsCommentsCount = 0;\n previousAccountsCommentsCids = \"\";\n updateFeedsPending = false;\n // destroy all component subscriptions to the store\n repliesStore.destroy();\n // restore original state\n repliesStore.setState(originalState);\n repliesCommentsStore.setState({ ...repliesCommentsStore.getState(), comments: {} });\n repliesStoreInitialized = false;\n};\n\n// reset database and store in between tests\nexport const resetRepliesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-repliesPages\" }).clear();\n await resetRepliesStore();\n};\n\nexport default repliesStore;\n"]}
1
+ {"version":3,"file":"replies-store.js","sourceRoot":"","sources":["../../../src/stores/replies/replies-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC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,MAAM,iBAAiB,GAAG,GAAS,EAAE;IAC1C,gCAAgC,GAAG,EAAE,CAAC;IACtC,wCAAwC,GAAG,EAAE,CAAC;IAC9C,6BAA6B,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1C,kCAAkC,GAAG,EAAE,CAAC;IACxC,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,gCAAgC,GAAG,CAAC,CAAC;IACrC,gDAAgD,GAAG,EAAE,CAAC;IACtD,oBAAoB,GAAG,EAAE,CAAC;IAC1B,6BAA6B,GAAG,CAAC,CAAC;IAClC,4BAA4B,GAAG,EAAE,CAAC;IAClC,kBAAkB,GAAG,KAAK,CAAC;IAC3B,mDAAmD;IACnD,YAAY,CAAC,OAAO,EAAE,CAAC;IACvB,yBAAyB;IACzB,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IACrC,oBAAoB,CAAC,QAAQ,iCAAM,oBAAoB,CAAC,QAAQ,EAAE,KAAE,QAAQ,EAAE,EAAE,IAAG,CAAC;IACpF,uBAAuB,GAAG,KAAK,CAAC;AAClC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAS,EAAE;IACrD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,kCAAkC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC1F,MAAM,iBAAiB,EAAE,CAAC;AAC5B,CAAC,CAAA,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:stores\");\nimport {\n Feed,\n Feeds,\n Comment,\n Comments,\n Account,\n RepliesFeedOptions,\n RepliesFeedsOptions,\n RepliesPage,\n CommentsFilter,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport accountsStore from \"../accounts\";\nimport repliesCommentsStore from \"./replies-comments-store\";\nimport repliesPagesStore from \"../replies-pages\";\nimport {\n getFeedsCommentsFirstPageCids,\n getLoadedFeeds,\n getBufferedFeedsWithoutLoadedFeeds,\n getUpdatedFeeds,\n getFeedsReplyCounts,\n getFeedsHaveMore,\n feedsCommentsChanged,\n getFeedsComments,\n getFeedsCommentsLoadedCount,\n getFeedsCommentsRepliesPagesFirstUpdatedAts,\n getFilteredSortedFeeds,\n getSortTypeFromComment,\n addAccountsComments,\n} from \"./utils\";\n\n// reddit loads approximately 25 posts per page\n// while infinite scrolling\nexport const defaultRepliesPerPage = 25;\n\n// keep large buffer because fetching cids is slow\nconst commentRepliesLeftBeforeNextPage = 50;\n\nexport type RepliesState = {\n feedsOptions: RepliesFeedsOptions;\n bufferedFeeds: Feeds;\n loadedFeeds: Feeds;\n updatedFeeds: Feeds;\n bufferedFeedsReplyCounts: { [feedName: string]: number };\n feedsHaveMore: { [feedName: string]: boolean };\n addFeedsToStore: Function;\n addFeedToStoreOrUpdateComment: Function;\n incrementFeedPageNumber: Function;\n resetFeed: Function;\n updateFeeds: Function;\n};\n\nconst defaultAccountComments = { newerThan: Infinity, append: false };\nconst addDefaultFeedOptions = (feedOptions: any) => {\n feedOptions = { ...feedOptions };\n if (feedOptions.flat === undefined || feedOptions.flat === null) {\n feedOptions.flat = false;\n }\n feedOptions.onlyIfCached = feedOptions.onlyIfCached === true;\n if (feedOptions.accountComments === undefined || feedOptions.accountComments === null) {\n feedOptions.accountComments = defaultAccountComments;\n }\n feedOptions.repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n return feedOptions;\n};\n\nexport const feedOptionsToFeedName = (feedOptions: Partial<RepliesFeedOptions>) => {\n feedOptions = addDefaultFeedOptions(feedOptions);\n return `${feedOptions?.accountId}-${feedOptions?.commentCid}-${feedOptions?.postCid}-${feedOptions?.sortType}-${feedOptions?.flat}-${feedOptions?.onlyIfCached}-${feedOptions?.accountComments?.newerThan}-${feedOptions?.accountComments?.append}-${feedOptions?.repliesPerPage}-${feedOptions?.filter?.key}-${feedOptions?.streamPage}`;\n};\n\nconst getFeedsUpdatedAts = (feedsOptions: RepliesFeedsOptions, comments: Comments) => {\n const feedsUpdatedAts: { [feedName: string]: number | undefined } = {};\n for (const feedName in feedsOptions) {\n feedsUpdatedAts[feedName] = comments[feedsOptions[feedName].commentCid]?.updatedAt;\n }\n return feedsUpdatedAts;\n};\n\n// don't updateFeeds more than once per updateFeedsMinIntervalTime\nlet updateFeedsPending = false;\nlet updateFeedsAgain = false;\nconst updateFeedsMinIntervalTime = 100;\n\nconst repliesStore = createStore<RepliesState>((setState: Function, getState: Function) => ({\n feedsOptions: {},\n bufferedFeeds: {},\n loadedFeeds: {},\n updatedFeeds: {},\n bufferedFeedsReplyCounts: {},\n feedsHaveMore: {},\n\n addFeedsToStore(feedOptionsArray: RepliesFeedOptions[]) {\n if (!feedOptionsArray.length) {\n return;\n }\n const { feedsOptions: previousFeedsOptions } = getState();\n const newFeedsOptions: RepliesFeedsOptions = {};\n\n // get all newFeedsOptions\n for (let feedOptions of feedOptionsArray) {\n const feedName = feedOptionsToFeedName(feedOptions);\n // feed is in store already, do nothing\n // if the feed already exist but is at page 0, reset it to page 1\n if (previousFeedsOptions[feedName] && previousFeedsOptions[feedName].pageNumber !== 0) {\n continue;\n }\n\n feedOptions = addDefaultFeedOptions(feedOptions);\n\n // to add a buffered feed, add a feed with pageNumber 0\n feedOptions.pageNumber = 1;\n newFeedsOptions[feedName] = feedOptions;\n }\n\n // set new feedsOptions state (first loop already skips existing feeds)\n let feedsChanged = false;\n setState(({ feedsOptions }: RepliesState) => {\n if (!Object.keys(newFeedsOptions).length) return {};\n feedsChanged = true;\n return { feedsOptions: { ...feedsOptions, ...newFeedsOptions } };\n });\n if (feedsChanged) {\n log(\"repliesStore.addFeedsToStore\", newFeedsOptions);\n }\n return feedsChanged;\n },\n\n async addFeedToStoreOrUpdateComment(comment: Comment, feedOptions: RepliesFeedOptions) {\n // init here because must be called after async accounts store finished initializing\n initializeRepliesStore();\n\n // validate options\n assert(\n comment && comment.cid && typeof comment.cid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment comment.cid '${comment?.cid}' invalid`,\n );\n assert(\n feedOptions.commentCid && typeof feedOptions.commentCid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.commentCid '${feedOptions.commentCid}' invalid`,\n );\n assert(\n feedOptions.sortType && typeof feedOptions.sortType === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.sortType '${feedOptions.sortType}' invalid`,\n );\n const account = accountsStore.getState().accounts[feedOptions.accountId];\n assert(\n typeof account?.pkc?.createComment === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.accountId '${feedOptions.accountId}' invalid`,\n );\n assert(\n !feedOptions.repliesPerPage || typeof feedOptions.repliesPerPage === \"number\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.repliesPerPage '${feedOptions.repliesPerPage}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.filter === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.filter '${feedOptions.filter?.filter}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.key === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.key '${feedOptions.filter?.key}' invalid`,\n );\n\n // if replies feed aren't in store yet, add them recursively\n // TODO: optimize performance by only adding feeds that are in page 1, and add more on each page increase\n const commentsToAddToStoreOrUpdate: Comment[] = [];\n const feedsToAddToStore: RepliesFeedOptions[] = [];\n\n // use the sort type availabe on the comment when missing\n const sortType = getSortTypeFromComment(comment, feedOptions);\n\n const addRepliesFeedsToStoreRecursively = (comment: Comment) => {\n // NOTE: even a comment with no replies needs a feed, to know it has 0 replies and not displace the UI when a new replies appears\n commentsToAddToStoreOrUpdate.push(comment);\n feedsToAddToStore.push({\n ...feedOptions,\n commentCid: comment?.cid,\n commentDepth: comment?.depth,\n });\n\n // flat doesn't need nested feeds\n if (!feedOptions.flat) {\n for (const reply of comment.replies?.pages?.[sortType]?.comments || []) {\n addRepliesFeedsToStoreRecursively(reply);\n }\n }\n };\n addRepliesFeedsToStoreRecursively(comment);\n\n // add feeds to store and update feeds\n const { addFeedsToStore, updateFeeds } = getState();\n const feedsChanged = addFeedsToStore(feedsToAddToStore);\n // add comments to store (do it after addFeedsToStore because it can trigger updateFeeds)\n repliesCommentsStore\n .getState()\n .addCommentsToStoreOrUpdateComments(commentsToAddToStoreOrUpdate);\n if (feedsChanged) {\n log(\"repliesStore.addFeedToStoreOrUpdateComment\", {\n comment,\n feedOptions,\n sortType,\n feedsToAddToStore,\n commentsToAddToStoreOrUpdate,\n });\n updateFeeds();\n }\n },\n\n incrementFeedPageNumber(feedName: string) {\n const { feedsOptions, loadedFeeds, bufferedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`,\n );\n log(\"repliesStore.incrementFeedPageNumber\", { feedName });\n\n // TODO: fix design issue, pageNumber shouldnt be increased when loadMore is called and repliesPerPage not reached\n // assert(\n // feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <= loadedFeeds[feedName].length,\n // `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`\n // )\n if (\n feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <=\n loadedFeeds[feedName].length\n ) {\n assert(\n bufferedFeeds[feedName].length > 0,\n `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`,\n );\n }\n\n setState(({ feedsOptions, loadedFeeds }: any) => {\n // don't increment page number before the current page has loaded\n // if (feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage > loadedFeeds[feedName].length) {\n // return {}\n // }\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: feedsOptions[feedName].pageNumber + 1,\n };\n return { feedsOptions: { ...feedsOptions, [feedName]: feedOptions } };\n });\n\n // do not update feed at the same time as increment a page number or it might cause\n // a race condition, rather schedule a feed update\n updateFeeds();\n },\n\n resetFeed(feedName: string) {\n const { feedsOptions, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.resetFeed feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n feedsOptions[feedName].pageNumber >= 1,\n `repliesStore.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`,\n );\n log(\"repliesStore.resetFeed\", { feedName });\n\n setState(({ feedsOptions, loadedFeeds, updatedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: 1,\n };\n return {\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n loadedFeeds: { ...loadedFeeds, [feedName]: [] },\n updatedFeeds: { ...updatedFeeds, [feedName]: [] },\n };\n });\n\n updateFeeds();\n },\n\n // recalculate all feeds using new comments.replies.pages, repliesPagesStore and page numbers\n updateFeeds() {\n if (updateFeedsPending) {\n updateFeedsAgain = true;\n return;\n }\n updateFeedsPending = true;\n\n // don't update feeds more than once per updateFeedsMinIntervalTime\n const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;\n\n setTimeout(async () => {\n // get state from all stores\n const previousState = getState();\n const { feedsOptions, updateFeeds } = previousState;\n const { comments } = repliesCommentsStore.getState();\n const { repliesPages } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // calculate new feeds\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n filteredSortedFeeds,\n previousState.loadedFeeds,\n );\n const canonicalLoadedFeeds = await getLoadedFeeds(\n feedsOptions,\n previousState.loadedFeeds,\n bufferedFeedsWithoutPreviousLoadedFeeds,\n accounts,\n { addAccountComments: false },\n );\n const canonicalBufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n canonicalLoadedFeeds,\n );\n const canonicalFeedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n canonicalBufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n const canonicalFeedsUpdatedAts = getFeedsUpdatedAts(feedsOptions, comments);\n const loadedFeedsWithAccountComments = { ...canonicalLoadedFeeds };\n const accountCommentsChangedFeeds = addAccountsComments(\n feedsOptions,\n loadedFeedsWithAccountComments,\n canonicalFeedsHaveMore,\n canonicalFeedsUpdatedAts,\n );\n const loadedFeeds = accountCommentsChangedFeeds\n ? loadedFeedsWithAccountComments\n : canonicalLoadedFeeds;\n // after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds\n const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n loadedFeeds,\n );\n const bufferedFeedsReplyCounts = getFeedsReplyCounts(feedsOptions, bufferedFeeds);\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n const updatedFeeds = await getUpdatedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.updatedFeeds,\n loadedFeeds,\n accounts,\n );\n\n // set new feeds\n setState((state: any) => ({\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n }));\n log(\"repliesStore.updateFeeds\", {\n feedsOptions,\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n comments,\n repliesPages,\n });\n\n updateFeedsPending = false;\n\n // if updateFeeds was called while updateFeedsPending = true, call updateFeeds again\n if (updateFeedsAgain) {\n updateFeedsAgain = false;\n updateFeeds();\n }\n }, timeUntilNextUpdate);\n },\n}));\n\nlet repliesStoreInitialized = false;\nconst initializeRepliesStore = async () => {\n if (repliesStoreInitialized) {\n return;\n }\n repliesStoreInitialized = true;\n // TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommentsChange(comment)\n // subscribe to comments store changes\n repliesCommentsStore.subscribe(updateFeedsOnFeedsCommentsChange);\n // subscribe to bufferedFeedsReplyCounts change\n repliesStore.subscribe(addRepliesPagesOnLowBufferedFeedsReplyCounts);\n // subscribe to replies pages store changes\n repliesPagesStore.subscribe(updateFeedsOnFeedsRepliesPagesChange);\n // subscribe to accounts store changes\n accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);\n};\n\nlet previousRepliesPages: { [pageCid: string]: RepliesPage } = {};\nconst updateFeedsOnFeedsRepliesPagesChange = (repliesPagesStoreState: any) => {\n const { repliesPages } = repliesPagesStoreState;\n\n // no changes, do nothing\n if (repliesPages === previousRepliesPages) {\n return;\n }\n previousRepliesPages = repliesPages;\n\n // currently only the feeds use repliesPagesStore, so any change must\n // trigger a feed update, if in the future another hook uses the repliesPagesStore\n // we should check if the replies pages changed are actually used by the feeds before\n // triggering an update\n repliesStore.getState().updateFeeds();\n};\n\nlet previousBufferedFeedsReplyCountsPageCids: string[] = [];\nlet previousBufferedFeedsComments = new Map<string, Comments>();\nlet previousBufferedFeedsReplyCounts: { [feedName: string]: number } = {};\nconst addRepliesPagesOnLowBufferedFeedsReplyCounts = (repliesStoreState: any) => {\n const { bufferedFeedsReplyCounts, feedsOptions } = repliesStore.getState();\n const { comments } = repliesCommentsStore.getState();\n\n // if feeds comments have changed, we must try adding them even if buffered replies counts haven't changed\n const bufferedFeedsComments = getFeedsComments(feedsOptions, comments);\n const _feedsCommentsChanged = feedsCommentsChanged(\n previousBufferedFeedsComments,\n bufferedFeedsComments,\n );\n const bufferedFeedsReplyCountsChanged =\n previousBufferedFeedsReplyCounts !== bufferedFeedsReplyCounts;\n\n // if feeds comments havent changed and buffered replies counts also havent changed, do nothing\n if (!_feedsCommentsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsComments = bufferedFeedsComments;\n previousBufferedFeedsReplyCounts = bufferedFeedsReplyCounts;\n\n // in case feeds comments changed, but the first page cids haven't\n const bufferedFeedsReplyCountsPageCids = getFeedsCommentsFirstPageCids(bufferedFeedsComments);\n const bufferedFeedsReplyCountsPageCidsChanged =\n bufferedFeedsReplyCountsPageCids.toString() !==\n previousBufferedFeedsReplyCountsPageCids.toString();\n if (!bufferedFeedsReplyCountsPageCidsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsReplyCountsPageCids = bufferedFeedsReplyCountsPageCids;\n\n const { addNextRepliesPageToStore } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // bufferedFeedsReplyCounts have changed, check if any of them are low\n for (const feedName in bufferedFeedsReplyCounts) {\n if (feedsOptions[feedName].onlyIfCached) {\n continue;\n }\n const account = accounts[feedsOptions[feedName].accountId];\n const feedReplyCount = bufferedFeedsReplyCounts[feedName];\n let sortType = feedsOptions[feedName].sortType;\n const commentCid = feedsOptions[feedName].commentCid;\n\n // TODO: maybe skip if comment community address, comment cid or comment author is blocked?\n\n // comment hasn't loaded yet\n if (!comments[commentCid]) {\n continue;\n }\n\n sortType = getSortTypeFromComment(comments[commentCid], feedsOptions[feedName]);\n\n // comment replies count is low, fetch next replies page\n if (feedReplyCount <= commentRepliesLeftBeforeNextPage) {\n addNextRepliesPageToStore(comments[commentCid], sortType, account).catch((error: unknown) =>\n log.error(\"repliesStore repliesPagesStore.addNextRepliesPageToStore error\", {\n commentCid,\n comment: comments[commentCid],\n sortType,\n error,\n }),\n );\n }\n }\n};\n\nlet previousFeedsCommentsFirstPageCids: string[] = [];\nlet previousFeedsComments: Map<string, Comments> = new Map();\nlet previousFeedsCommentsLoadedCount = 0;\nlet previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\nconst updateFeedsOnFeedsCommentsChange = (repliesCommentsStoreState: any) => {\n const { comments } = repliesCommentsStoreState;\n const { feedsOptions, updateFeeds } = repliesStore.getState();\n\n // feeds comments haven't changed, do nothing\n const feedsComments = getFeedsComments(feedsOptions, comments);\n if (!feedsCommentsChanged(previousFeedsComments, feedsComments)) {\n return;\n }\n previousFeedsComments = feedsComments;\n\n // decide if feeds comments have changed by looking at all feeds comments page cids\n // (in case that a comment changed, but its first page cid didn't)\n const feedsCommentsFirstPageCids = getFeedsCommentsFirstPageCids(feedsComments);\n\n // first page cids haven't changed, do nothing\n if (feedsCommentsFirstPageCids.toString() === previousFeedsCommentsFirstPageCids.toString()) {\n // if no new feed comments have loaded, do nothing\n // in case a comment loads with no first page cid and first pages cids don't change, need to trigger hasMore update\n const feedsCommentsLoadedCount = getFeedsCommentsLoadedCount(feedsComments);\n if (feedsCommentsLoadedCount === previousFeedsCommentsLoadedCount) {\n // if comment.replies.pages haven't changed, do nothing\n const feedsCommentsRepliesPagesFirstUpdatedAts =\n getFeedsCommentsRepliesPagesFirstUpdatedAts(feedsComments);\n if (\n feedsCommentsRepliesPagesFirstUpdatedAts ===\n previousFeedsCommentsRepliesPagesFirstUpdatedAts\n ) {\n return;\n }\n\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = feedsCommentsRepliesPagesFirstUpdatedAts;\n }\n previousFeedsCommentsLoadedCount = feedsCommentsLoadedCount;\n }\n\n // feeds comments have changed, update feeds\n previousFeedsCommentsFirstPageCids = feedsCommentsFirstPageCids;\n updateFeeds();\n};\n\nlet previousAccountsCommentsCount = 0;\nlet previousAccountsCommentsCids = \"\";\nconst updateFeedsOnAccountsCommentsChange = (accountsStoreState: any) => {\n const { accountsComments } = accountsStoreState;\n const accountsCommentsCount = Object.values(accountsComments as Comment[][]).reduce(\n (count, accountComments) => count + accountComments.length,\n 0,\n );\n\n // no changes, do nothing\n if (accountsCommentsCount === previousAccountsCommentsCount) {\n // if cids haven't changed (account comments receive cids after pending), do nothing\n const accountsCommentsCids = Object.values(accountsComments as Comment[][]).reduce(\n (cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || \"\")),\n \"\",\n );\n if (accountsCommentsCids === previousAccountsCommentsCids) {\n return;\n }\n previousAccountsCommentsCids = accountsCommentsCids;\n }\n previousAccountsCommentsCount = accountsCommentsCount;\n\n // TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid\n repliesStore.getState().updateFeeds();\n};\n\n// needed to view replies instantly without waiting for zustant store react rerenders. must be synchronous\nexport const getRepliesFirstPageSkipValidation = (\n comment: Comment,\n feedOptions: Partial<RepliesFeedOptions>,\n) => {\n const feedName = `firstPageSkipValidation-${comment?.cid}`;\n const feedsOptions: any = { [feedName]: feedOptions };\n const { accounts } = accountsStore.getState();\n\n // don't use comments store, only use preloaded comment.replies.pages\n const comments = { [comment.cid]: comment };\n\n // don't use any reply pages, they can't provide instant loading like preloaded comment.replies.pages\n const repliesPages = {};\n\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n\n // only get first page and put next page in buffered\n const bufferedFeeds: Feeds = { [feedName]: [] };\n const repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n if (filteredSortedFeeds[feedName].length > repliesPerPage) {\n bufferedFeeds[feedName] = filteredSortedFeeds[feedName].splice(repliesPerPage);\n }\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore, {\n [feedName]: comment.updatedAt,\n });\n return { replies: filteredSortedFeeds[feedName], hasMore: feedsHaveMore[feedName] };\n};\n\n// reset store in between tests\nconst originalState = repliesStore.getState();\n// async function because some stores have async init\nexport const resetRepliesStore = async () => {\n previousBufferedFeedsReplyCounts = {};\n previousBufferedFeedsReplyCountsPageCids = [];\n previousBufferedFeedsComments = new Map();\n previousFeedsCommentsFirstPageCids = [];\n previousFeedsComments = new Map();\n previousFeedsCommentsLoadedCount = 0;\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\n previousRepliesPages = {};\n previousAccountsCommentsCount = 0;\n previousAccountsCommentsCids = \"\";\n updateFeedsPending = false;\n // destroy all component subscriptions to the store\n repliesStore.destroy();\n // restore original state\n repliesStore.setState(originalState);\n repliesCommentsStore.setState({ ...repliesCommentsStore.getState(), comments: {} });\n repliesStoreInitialized = false;\n};\n\n// reset database and store in between tests\nexport const resetRepliesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-repliesPages\" }).clear();\n await resetRepliesStore();\n};\n\nexport default repliesStore;\n"]}
@@ -8,10 +8,15 @@ type GetLoadedFeedsOptions = {
8
8
  feedsHaveMore?: {
9
9
  [feedName: string]: boolean;
10
10
  };
11
+ feedsUpdatedAts?: {
12
+ [feedName: string]: number | undefined;
13
+ };
11
14
  };
12
15
  export declare const getLoadedFeeds: (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds, bufferedFeeds: Feeds, accounts: Accounts, options?: GetLoadedFeedsOptions) => Promise<Feeds>;
13
16
  export declare const addAccountsComments: (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds, feedsHaveMore?: {
14
17
  [feedName: string]: boolean;
18
+ }, feedsUpdatedAts?: {
19
+ [feedName: string]: number | undefined;
15
20
  }) => boolean;
16
21
  export declare const getBufferedFeedsWithoutLoadedFeeds: (bufferedFeeds: Feeds, loadedFeeds: Feeds) => Feeds;
17
22
  export declare const getUpdatedFeeds: (feedsOptions: RepliesFeedsOptions, filteredSortedFeeds: Feeds, updatedFeeds: Feeds, loadedFeeds: Feeds, accounts: Accounts) => Promise<Feeds>;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/replies/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,EACL,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,QAAQ,EAER,QAAQ,EAER,YAAY,EACb,MAAM,aAAa,CAAC;AASrB;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,cAAc,mBAAmB,EACjC,UAAU,QAAQ,EAClB,cAAc,YAAY,EAC1B,UAAU,QAAQ,UAmEnB,CAAC;AAgFF,KAAK,qBAAqB,GA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,KAAK,EAAE,aAAa,KAAK,UAoC1F,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,cAAc,mBAAmB,EACjC,qBAAqB,KAAK,EAC1B,cAAc,KAAK,EACnB,aAAa,KAAK,EAClB,UAAU,QAAQ,mBAmEnB,CAAC;AAIF,eAAO,MAAM,mBAAmB,GAAI,cAAc,mBAAmB,EAAE,OAAO,KAAK;;CAMlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,cAAc,mBAAmB,EACjC,eAAe,KAAK,EACpB,UAAU,QAAQ,EAClB,cAAc,YAAY,EAC1B,UAAU,QAAQ;;CA+CnB,CAAC;AAGF,eAAO,MAAM,gBAAgB,GAAI,cAAc,mBAAmB,EAAE,UAAU,QAAQ,yBASrF,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,uBAAuB,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3C,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,YAYpC,CAAC;AAGF,eAAO,MAAM,6BAA6B,GAAI,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,EA4BzF,CAAC;AAGF,eAAO,MAAM,2CAA2C,GACtD,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAClC,MAWF,CAAC;AAGF,eAAO,MAAM,2BAA2B,GAAI,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAQjF,CAAC;AAGF,eAAO,MAAM,sBAAsB,GAAI,SAAS,OAAO,EAAE,aAAa,kBAAkB,WA0EvF,CAAC"}
@@ -140,6 +140,12 @@ const isPublishedAccountReply = (reply) => typeof (reply === null || reply === v
140
140
  !!reply.cid &&
141
141
  reply.pendingApproval !== true &&
142
142
  !isActivePublishingState(reply.publishingState);
143
+ const canonicalFeedRefreshedAfterReply = (reply, feedUpdatedAt) => typeof feedUpdatedAt !== "number" ||
144
+ typeof reply.timestamp !== "number" ||
145
+ feedUpdatedAt > reply.timestamp;
146
+ const shouldHidePublishedAccountReply = (reply, hidePublishedAccountReplies, feedUpdatedAt) => hidePublishedAccountReplies &&
147
+ isPublishedAccountReply(reply) &&
148
+ canonicalFeedRefreshedAfterReply(reply, feedUpdatedAt);
143
149
  export const getLoadedFeeds = (feedsOptions_1, loadedFeeds_1, bufferedFeeds_1, accounts_1, ...args_1) => __awaiter(void 0, [feedsOptions_1, loadedFeeds_1, bufferedFeeds_1, accounts_1, ...args_1], void 0, function* (feedsOptions, loadedFeeds, bufferedFeeds, accounts, options = {}) {
144
150
  var _a;
145
151
  const loadedFeedsMissingReplies = {};
@@ -187,14 +193,14 @@ export const getLoadedFeeds = (feedsOptions_1, loadedFeeds_1, bufferedFeeds_1, a
187
193
  newLoadedFeeds = Object.assign(Object.assign({}, loadedFeeds), newLoadedFeeds);
188
194
  const accountCommentsChangedFeeds = options.addAccountComments === false
189
195
  ? false
190
- : addAccountsComments(feedsOptions, newLoadedFeeds, options.feedsHaveMore);
196
+ : addAccountsComments(feedsOptions, newLoadedFeeds, options.feedsHaveMore, options.feedsUpdatedAts);
191
197
  // do nothing if there are no missing replies
192
198
  if (Object.keys(loadedFeedsMissingReplies).length === 0 && !accountCommentsChangedFeeds) {
193
199
  return loadedFeeds;
194
200
  }
195
201
  return newLoadedFeeds;
196
202
  });
197
- export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore) => {
203
+ export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore, feedsUpdatedAts) => {
198
204
  let loadedFeedsChanged = false;
199
205
  const accountsComments = accountsStore.getState().accountsComments || {};
200
206
  for (const feedName in feedsOptions) {
@@ -206,9 +212,10 @@ export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore) =>
206
212
  const newerThanTimestamp = newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;
207
213
  const isNewerThan = (reply) => reply.timestamp > newerThanTimestamp;
208
214
  const hidePublishedAccountReplies = (feedsHaveMore === null || feedsHaveMore === void 0 ? void 0 : feedsHaveMore[feedName]) === false;
215
+ const feedUpdatedAt = feedsUpdatedAts === null || feedsUpdatedAts === void 0 ? void 0 : feedsUpdatedAts[feedName];
209
216
  const accountComments = accountsComments[accountId] || [];
210
217
  const accountReplies = accountComments.filter((reply) => {
211
- if (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {
218
+ if (shouldHidePublishedAccountReply(reply, hidePublishedAccountReplies, feedUpdatedAt)) {
212
219
  return false;
213
220
  }
214
221
  if (!isNewerThan(reply)) {
@@ -237,7 +244,7 @@ export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore) =>
237
244
  prunedLoadedFeed.push(reply);
238
245
  continue;
239
246
  }
240
- if (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {
247
+ if (shouldHidePublishedAccountReply(reply, hidePublishedAccountReplies, feedUpdatedAt)) {
241
248
  loadedFeedsChanged = true;
242
249
  continue;
243
250
  }