@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 CHANGED
@@ -1,3 +1,21 @@
1
+ ## [0.1.60](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.59...v0.1.60) (2026-10-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **comments:** freeze autoUpdate false comments after the update requested on open ([b98e7a5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b98e7a59fb8b1e635943efe3a54801769e4c0ec9))
7
+
8
+
9
+
10
+ ## [0.1.59](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.58...v0.1.59) (2026-10-27)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **accounts-store:** link previousCommentCid to comments stored by hooks <= 0.1.51 ([#161](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/161)) ([8efb6b5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/8efb6b597ab14eb90285b398fd6df9e2a0fe3360))
16
+
17
+
18
+
1
19
  ## [0.1.58](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.57...v0.1.58) (2026-10-24)
2
20
 
3
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../src/hooks/comments.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAkBlB,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAGxE;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,OAAO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AE,kBAAkB,GAAG,iBAAiB,CAuL3E;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,CAMhC;AAED,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,wBAAwB,CAmDhG"}
@@ -115,6 +115,7 @@ export function useComment(options) {
115
115
  const communitiesPagesComment = useCommunitiesPagesStore((state) => state.comments[commentCid || ""]);
116
116
  const repliesPagesComment = useRepliesPagesStore((state) => state.comments[commentCid || ""]);
117
117
  const errors = useCommentsStore((state) => state.errors[commentCid || ""]);
118
+ const openingUpdatePending = useCommentsStore((state) => Boolean(state.openingUpdatesPending[commentCid || ""]));
118
119
  // get account comment of the cid if any
119
120
  const accountCommentInfo = useAccountsStore((state) => state.commentCidsToAccountsComments[commentCid || ""]);
120
121
  const accountComment = useAccountsStore((state) => {
@@ -187,6 +188,9 @@ export function useComment(options) {
187
188
  selectedComment = selectedCommentWithFallback;
188
189
  const selectedCommentShortAddress = (_a = selectedComment === null || selectedComment === void 0 ? void 0 : selectedComment.author) === null || _a === void 0 ? void 0 : _a.shortAddress;
189
190
  const initialCommentUpdatePending = Boolean(((_b = initialComment === null || initialComment === void 0 ? void 0 : initialComment.raw) === null || _b === void 0 ? void 0 : _b.comment) && !((_c = selectedComment === null || selectedComment === void 0 ? void 0 : selectedComment.raw) === null || _c === void 0 ? void 0 : _c.commentUpdate));
191
+ // A copy cached on an earlier visit loads before the network. Freeze only once the update this
192
+ // load requested has ended, so a returning visitor sees the current comment.
193
+ const openingUpdateEnded = onlyIfCached || (Boolean(commentFromStore) && !openingUpdatePending);
190
194
  const freezeSettledForCurrentCid = freezeSettledCid === commentCid;
191
195
  useEffect(() => {
192
196
  if (autoUpdate) {
@@ -233,7 +237,9 @@ export function useComment(options) {
233
237
  }
234
238
  setFrozenComment(selectedComment);
235
239
  // Recent immutable payloads report "succeeded" before moderation is available.
236
- if (typeof selectedComment.updatedAt === "number" && !initialCommentUpdatePending) {
240
+ if (typeof selectedComment.updatedAt === "number" &&
241
+ !initialCommentUpdatePending &&
242
+ openingUpdateEnded) {
237
243
  setFreezeSettledCid(commentCid);
238
244
  }
239
245
  }, [
@@ -241,6 +247,7 @@ export function useComment(options) {
241
247
  commentCid,
242
248
  selectedComment,
243
249
  initialCommentUpdatePending,
250
+ openingUpdateEnded,
244
251
  freezeSettledForCurrentCid,
245
252
  frozenComment,
246
253
  selectedCommentShortAddress,
@@ -323,6 +330,7 @@ export function useComments(options) {
323
330
  const accountVotes = useAccountsStore((state) => (account === null || account === void 0 ? void 0 : account.id) ? state.accountsVotes[account.id] : undefined);
324
331
  const commentsStoreComments = useCommentsStore((state) => commentCids.map((commentCid) => state.comments[commentCid || ""]), shallow);
325
332
  const communitiesPagesComments = useCommunitiesPagesStore((state) => commentCids.map((commentCid) => state.comments[commentCid || ""]), shallow);
333
+ const openingUpdatesPending = useCommentsStore((state) => commentCids.map((commentCid) => Boolean(state.openingUpdatesPending[commentCid || ""])), shallow);
326
334
  const addCommentToStore = useCommentsStore((state) => state.addCommentToStore);
327
335
  const startCommentAutoUpdate = useCommentsStore((state) => state.startCommentAutoUpdate);
328
336
  const stopCommentAutoUpdate = useCommentsStore((state) => state.stopCommentAutoUpdate);
@@ -380,7 +388,10 @@ export function useComments(options) {
380
388
  }
381
389
  return result;
382
390
  }, [commentsStoreComments, communitiesPagesComments]);
383
- const liveCommentsSettled = liveComments.every((comment) => typeof (comment === null || comment === void 0 ? void 0 : comment.updatedAt) === "number");
391
+ // like useComment, wait for each update requested on load before freezing over cached copies
392
+ const liveCommentsSettled = liveComments.every((comment) => typeof (comment === null || comment === void 0 ? void 0 : comment.updatedAt) === "number") &&
393
+ (Boolean(onlyIfCached) ||
394
+ commentsStoreComments.every((comment, index) => comment && !openingUpdatesPending[index]));
384
395
  const freezeSettledForCurrentKey = freezeSettledKey === commentsKey;
385
396
  use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AAQ,CAAC;IACnB,CAAC;IAED,kHAAkH;IAClH,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACvB,KAAK,GAAG,KAAK,CAAC;IAChB,CAAC;IACD,uEAAuE;IACvE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,KAAK,GAAG,KAAK,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,KAAK;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF,CAAC,KAAK,EAAE,KAAK,CAAC,CACf,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:comments:hooks\");\nimport assert from \"../lib/assert\";\nimport {\n Comment,\n UseCommentsOptions,\n UseCommentsResult,\n UseCommentOptions,\n UseCommentResult,\n UseCrosspostOptions,\n UseCrosspostResult,\n UseValidateCommentOptions,\n UseValidateCommentResult,\n ValidateCommentOptions,\n ValidateCommentResult,\n} from \"../types\";\nimport useCommentsStore from \"../stores/comments\";\nimport useAccountsStore from \"../stores/accounts\";\nimport utils, { commentIsValid } from \"../lib/utils\";\nimport { getOfflinePkc, validateCommentWithPkc } from \"../lib/validate-comment\";\nimport {\n addCommentModeration,\n addCommentModerationToComments,\n} from \"../lib/utils/comment-moderation\";\nimport useCommunitiesPagesStore from \"../stores/communities-pages\";\nimport useRepliesPagesStore from \"../stores/replies-pages\";\nimport shallow from \"zustand/shallow\";\nimport { assertCommunityRef } from \"../lib/community-ref\";\nimport {\n addOptimisticVoteCounts,\n addOptimisticVoteCountsToComments,\n} from \"../lib/utils/optimistic-vote-counts\";\n\nexport function getCommentFreshness(comment: Comment | undefined): number {\n if (!comment) return 0;\n return Math.max(comment.updatedAt ?? 0, comment.timestamp ?? 0, 0);\n}\n\nexport function preferFresher(\n current: Comment | undefined,\n candidate: Comment | undefined,\n): Comment | undefined {\n if (!candidate) return current;\n if (!current) return candidate;\n return getCommentFreshness(candidate) > getCommentFreshness(current) ? candidate : current;\n}\n\nconst getCommentStateAndReplyCount = (comment: Comment | undefined) => {\n let state = comment?.updatingState || \"initializing\";\n // force 'fetching-ipns' even if could be something else, so the frontend can use\n // the correct loading skeleton\n if (comment?.timestamp) {\n state = \"fetching-update-ipns\";\n }\n // force succeeded even if the comment is fecthing a new update\n if (comment?.updatedAt) {\n state = \"succeeded\";\n }\n\n // force succeeded if the comment is newer than 5 minutes, no need to display loading skeleton if comment was just created\n let replyCount = comment?.replyCount;\n if (\n comment?.replyCount === undefined &&\n comment?.timestamp &&\n comment?.timestamp > Date.now() / 1000 - 5 * 60\n ) {\n state = \"succeeded\";\n // set replyCount because some frontend are likely to check if replyCount === undefined to show a loading skeleton\n replyCount = 0;\n }\n\n return { state, replyCount };\n};\n\nconst getCommentsState = (comments: (Comment | undefined)[]) =>\n comments.every((comment) => getCommentStateAndReplyCount(comment).state === \"succeeded\")\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\nlet commentAutoUpdateSubscriptionCount = 0;\nlet commentsAutoUpdateSubscriptionCount = 0;\n\nconst getCommentCreateCommentData = (\n commentCid: string | undefined,\n community: UseCommentOptions[\"community\"] | undefined,\n initialComment: Comment | undefined,\n ...comments: (Comment | undefined)[]\n) => {\n if (!commentCid) {\n return undefined;\n }\n\n const createCommentData: Comment = initialComment\n ? { ...utils.clone(initialComment), cid: commentCid }\n : { cid: commentCid };\n let hasCreateCommentData = Boolean(initialComment);\n for (const comment of comments) {\n if (!comment) {\n continue;\n }\n if (!createCommentData.communityPublicKey && comment.communityPublicKey) {\n createCommentData.communityPublicKey = comment.communityPublicKey;\n hasCreateCommentData = true;\n }\n if (!createCommentData.communityName && comment.communityName) {\n createCommentData.communityName = comment.communityName;\n hasCreateCommentData = true;\n }\n }\n\n if (community?.publicKey) {\n createCommentData.communityPublicKey = community.publicKey;\n hasCreateCommentData = true;\n }\n if (community?.name) {\n createCommentData.communityName = community.name;\n hasCreateCommentData = true;\n }\n\n return hasCreateCommentData ? createCommentData : undefined;\n};\n\n/**\n * @param commentCid - The IPFS CID of the comment to get\n * @param community - The community identifier, e.g. {name: 'memes.eth', publicKey: '12D3KooW...'}.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useComment(options?: UseCommentOptions): UseCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useComment options argument '${options}' not an object`,\n );\n const {\n commentCid,\n community,\n initialComment,\n accountName,\n onlyIfCached,\n autoUpdate = true,\n } = options ?? {};\n if (community !== undefined) {\n assertCommunityRef(community, \"useComment community\");\n }\n const account = useAccount({ accountName });\n const commentFromStore = useCommentsStore((state: any) => state.comments[commentCid || \"\"]);\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const communitiesPagesComment = useCommunitiesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const repliesPagesComment = useRepliesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const errors = useCommentsStore((state: any) => state.errors[commentCid || \"\"]);\n\n // get account comment of the cid if any\n const accountCommentInfo = useAccountsStore(\n (state: any) => state.commentCidsToAccountsComments[commentCid || \"\"],\n );\n const accountComment = useAccountsStore(\n (state: any) =>\n state.accountsComments[accountCommentInfo?.accountId || \"\"]?.[\n Number(accountCommentInfo?.accountCommentIndex)\n ],\n );\n const accountVote = useAccountsStore((state: any) =>\n account?.id && commentCid ? state.accountsVotes[account.id]?.[commentCid] : undefined,\n );\n const createCommentData = useMemo(\n () =>\n getCommentCreateCommentData(\n commentCid,\n community,\n initialComment,\n communitiesPagesComment,\n repliesPagesComment,\n ),\n [\n commentCid,\n community?.name,\n community?.publicKey,\n initialComment,\n communitiesPagesComment?.communityName,\n communitiesPagesComment?.communityPublicKey,\n repliesPagesComment?.communityName,\n repliesPagesComment?.communityPublicKey,\n ],\n );\n const autoUpdateSubscriptionId = useRef(`useComment-${++commentAutoUpdateSubscriptionCount}`);\n const currentCommentCidRef = useRef<string | undefined>(commentCid);\n currentCommentCidRef.current = commentCid;\n const [frozenComment, setFrozenComment] = useState<Comment | undefined>();\n const [freezeSettledCid, setFreezeSettledCid] = useState<string>();\n\n useEffect(() => {\n if (!commentCid || !account) {\n return;\n }\n validator.validateUseCommentArguments(commentCid, account);\n if (!commentFromStore && !onlyIfCached) {\n // if comment isn't already in store, add it\n const addCommentPromise = createCommentData\n ? addCommentToStore(commentCid, account, createCommentData)\n : addCommentToStore(commentCid, account);\n addCommentPromise.catch((error: unknown) =>\n log.error(\"useComment addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCid, account?.id, onlyIfCached, createCommentData]);\n\n useEffect(() => {\n if (!commentCid || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const startAutoUpdatePromise = createCommentData\n ? startCommentAutoUpdate(\n commentCid,\n autoUpdateSubscriptionId.current,\n account,\n createCommentData,\n )\n : startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account);\n startAutoUpdatePromise.catch((error: unknown) =>\n log.error(\"useComment startCommentAutoUpdate error\", { commentCid, error }),\n );\n\n return () => {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch((error: unknown) =>\n log.error(\"useComment stopCommentAutoUpdate error\", { commentCid, error }),\n );\n };\n }, [commentCid, account?.id, onlyIfCached, autoUpdate, createCommentData]);\n\n let selectedComment = commentFromStore;\n\n if (commentCid && communitiesPagesComment) {\n selectedComment = preferFresher(selectedComment, communitiesPagesComment);\n }\n if (commentCid && repliesPagesComment) {\n selectedComment = preferFresher(selectedComment, repliesPagesComment);\n }\n\n // if comment is still not defined, but account comment is, use account comment\n // check `comment.timestamp` instead of `comment` in case comment exists but in a loading state\n const commentFromStoreNotLoaded = !selectedComment?.timestamp;\n if (commentCid && commentFromStoreNotLoaded && accountComment) {\n selectedComment = accountComment;\n }\n const selectedCommentWithFallback = useMemo(() => {\n if (!commentCid || !commentFromStoreNotLoaded || !initialComment) {\n return selectedComment;\n }\n const commentWithFallback = utils.merge(\n initialComment.raw?.comment || {},\n initialComment,\n { cid: commentCid },\n selectedComment || {},\n );\n commentWithFallback.raw = utils.merge(initialComment.raw || {}, selectedComment?.raw || {});\n return commentWithFallback;\n }, [commentCid, commentFromStoreNotLoaded, initialComment, selectedComment]);\n selectedComment = selectedCommentWithFallback;\n\n const selectedCommentShortAddress = selectedComment?.author?.shortAddress;\n const initialCommentUpdatePending = Boolean(\n initialComment?.raw?.comment && !selectedComment?.raw?.commentUpdate,\n );\n const freezeSettledForCurrentCid = freezeSettledCid === commentCid;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n }, [commentCid, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate) {\n return;\n }\n if (!commentCid) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n if (!selectedComment) {\n return;\n }\n if (freezeSettledForCurrentCid) {\n // Canonical number and author identity can arrive after the first community\n // update. Absorb only that immutable metadata while keeping later updates frozen.\n const frozenCommentForCurrentCid =\n frozenComment?.cid === commentCid ? frozenComment : undefined;\n const frozenCommentShortAddress = frozenCommentForCurrentCid?.author?.shortAddress;\n const hasReconciledPublicationMetadata =\n (selectedComment.number !== undefined &&\n selectedComment.number !== frozenCommentForCurrentCid?.number) ||\n (selectedComment.postNumber !== undefined &&\n selectedComment.postNumber !== frozenCommentForCurrentCid?.postNumber) ||\n (selectedCommentShortAddress && selectedCommentShortAddress !== frozenCommentShortAddress);\n if (hasReconciledPublicationMetadata && frozenCommentForCurrentCid) {\n setFrozenComment({\n ...frozenCommentForCurrentCid,\n ...(selectedComment.number !== undefined ? { number: selectedComment.number } : {}),\n ...(selectedComment.postNumber !== undefined\n ? { postNumber: selectedComment.postNumber }\n : {}),\n ...(selectedCommentShortAddress\n ? {\n author: {\n ...frozenCommentForCurrentCid.author,\n shortAddress: selectedCommentShortAddress,\n },\n }\n : {}),\n });\n }\n return;\n }\n\n setFrozenComment(selectedComment);\n // Recent immutable payloads report \"succeeded\" before moderation is available.\n if (typeof selectedComment.updatedAt === \"number\" && !initialCommentUpdatePending) {\n setFreezeSettledCid(commentCid);\n }\n }, [\n autoUpdate,\n commentCid,\n selectedComment,\n initialCommentUpdatePending,\n freezeSettledForCurrentCid,\n frozenComment,\n selectedCommentShortAddress,\n ]);\n\n const frozenCommentForCurrentCid = frozenComment?.cid === commentCid ? frozenComment : undefined;\n let comment = autoUpdate\n ? selectedComment\n : freezeSettledForCurrentCid\n ? frozenCommentForCurrentCid\n : frozenCommentForCurrentCid || selectedComment;\n comment = addCommentModeration(comment);\n comment = addOptimisticVoteCounts(comment, accountVote);\n\n const { state, replyCount } = getCommentStateAndReplyCount(comment);\n\n if (account && commentCid) {\n log(\"useComment\", {\n commentCid,\n comment,\n replyCount,\n state,\n commentFromStore,\n communitiesPagesComment,\n repliesPagesComment,\n accountComment,\n commentsStore: useCommentsStore.getState().comments,\n account,\n onlyIfCached,\n autoUpdate,\n });\n }\n\n const refresh = useCallback(async () => {\n if (!commentCid || !account) {\n throw Error(\"useComment cannot refresh comment not initialized yet\");\n }\n\n const refreshCommentCid = commentCid;\n const refreshedComment = createCommentData\n ? await refreshCommentInStore(refreshCommentCid, account, createCommentData)\n : await refreshCommentInStore(refreshCommentCid, account);\n if (!autoUpdate && refreshedComment && currentCommentCidRef.current === refreshCommentCid) {\n setFrozenComment(refreshedComment);\n setFreezeSettledCid(refreshCommentCid);\n }\n }, [account, autoUpdate, commentCid, createCommentData, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n ...comment,\n replyCount,\n state,\n refresh,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [comment, commentCid, errors, refresh, state, replyCount],\n );\n}\n\n/**\n * Read a crosspost from its embedded signed record immediately, then use the normal comment store\n * to load the referenced community's current CommentUpdate when it is available.\n */\nexport function useCrosspost(options?: UseCrosspostOptions): UseCrosspostResult {\n assert(\n !options || typeof options === \"object\",\n `useCrosspost options argument '${options}' not an object`,\n );\n const { crosspost, accountName, autoUpdate = true } = options ?? {};\n const initialComment = useMemo(\n () =>\n crosspost\n ? {\n cid: crosspost.cid,\n raw: { comment: crosspost.comment },\n }\n : undefined,\n [crosspost],\n );\n const comment = useComment({\n accountName,\n autoUpdate,\n commentCid: crosspost?.cid,\n initialComment,\n });\n\n return useMemo(\n () => ({\n ...comment,\n isCommunityVerified: Boolean(comment.raw?.commentUpdate),\n }),\n [comment],\n );\n}\n\n/**\n * @param commentCids - The IPFS CIDs of the comments to get\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useComments(options?: UseCommentsOptions): UseCommentsResult {\n assert(\n !options || typeof options === \"object\",\n `useComments options argument '${options}' not an object`,\n );\n const { commentCids = [], accountName, onlyIfCached, autoUpdate = true } = options ?? {};\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const commentsStoreComments: (Comment | undefined)[] = useCommentsStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n const communitiesPagesComments: (Comment | undefined)[] = useCommunitiesPagesStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const autoUpdateSubscriptionId = useRef(`useComments-${++commentsAutoUpdateSubscriptionCount}`);\n const commentCidsKey = JSON.stringify(commentCids);\n const commentsKey = `${account?.id || \"\"}:${commentCidsKey}`;\n const currentCommentsKeyRef = useRef(commentsKey);\n currentCommentsKeyRef.current = commentsKey;\n const [frozenComments, setFrozenComments] = useState<(Comment | undefined)[]>([]);\n const [frozenCommentsKey, setFrozenCommentsKey] = useState<string>();\n const [freezeSettledKey, setFreezeSettledKey] = useState<string>();\n\n useEffect(() => {\n if (!commentCids || !account) {\n return;\n }\n validator.validateUseCommentsArguments(commentCids, account);\n if (onlyIfCached) {\n return;\n }\n const uniqueCommentCids = new Set(commentCids);\n for (const commentCid of uniqueCommentCids) {\n addCommentToStore(commentCid, account).catch((error: unknown) =>\n log.error(\"useComments addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCidsKey, account?.id, onlyIfCached]);\n\n useEffect(() => {\n if (!commentCids || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const uniqueCommentCids = [...new Set(commentCids)];\n for (const commentCid of uniqueCommentCids) {\n startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account).catch(\n (error: unknown) =>\n log.error(\"useComments startCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n\n return () => {\n for (const commentCid of uniqueCommentCids) {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch(\n (error: unknown) =>\n log.error(\"useComments stopCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n };\n }, [commentCidsKey, account?.id, onlyIfCached, autoUpdate]);\n\n if (account && commentCids?.length) {\n log(\"useComments\", {\n commentCids,\n commentsStoreComments,\n commentsStore: useCommentsStore.getState().comments,\n account,\n });\n }\n\n // if comment from community pages exists and is fresher (or current missing), use it instead\n const liveComments = useMemo(() => {\n const result = [...commentsStoreComments];\n for (const i in result) {\n const candidate = communitiesPagesComments[i];\n if (candidate) result[i] = preferFresher(result[i], candidate);\n }\n return result;\n }, [commentsStoreComments, communitiesPagesComments]);\n\n const liveCommentsSettled = liveComments.every(\n (comment) => typeof comment?.updatedAt === \"number\",\n );\n const freezeSettledForCurrentKey = freezeSettledKey === commentsKey;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n return;\n }\n\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n }, [commentsKey, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate || freezeSettledForCurrentKey) {\n return;\n }\n\n setFrozenComments(liveComments);\n setFrozenCommentsKey(commentsKey);\n if (liveCommentsSettled) {\n setFreezeSettledKey(commentsKey);\n }\n }, [autoUpdate, commentsKey, freezeSettledForCurrentKey, liveComments, liveCommentsSettled]);\n\n const frozenCommentsForCurrentSelection =\n frozenCommentsKey === commentsKey ? frozenComments : undefined;\n const comments = autoUpdate ? liveComments : frozenCommentsForCurrentSelection || liveComments;\n const normalizedComments = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(comments), accountVotes),\n [comments, accountVotes],\n );\n\n // succeed if no comments are undefined\n const state = getCommentsState(normalizedComments);\n\n const refresh = useCallback(async () => {\n if (!account) {\n throw Error(\"useComments cannot refresh comments not initialized yet\");\n }\n const uniqueCommentCids = [...new Set(commentCids)];\n const refreshedComments = await Promise.all(\n uniqueCommentCids.map((commentCid) => refreshCommentInStore(commentCid, account)),\n );\n\n if (!autoUpdate && currentCommentsKeyRef.current === commentsKey) {\n const latestCommunitiesPagesComments = useCommunitiesPagesStore.getState().comments;\n const refreshedCommentsByCid = uniqueCommentCids.reduce(\n (\n refreshedCommentsMap: { [commentCid: string]: Comment | undefined },\n commentCid,\n index,\n ) => {\n refreshedCommentsMap[commentCid] = refreshedComments[index];\n return refreshedCommentsMap;\n },\n {},\n );\n setFrozenComments(\n commentCids.map((commentCid) =>\n preferFresher(\n refreshedCommentsByCid[commentCid || \"\"],\n latestCommunitiesPagesComments[commentCid || \"\"],\n ),\n ),\n );\n setFrozenCommentsKey(commentsKey);\n setFreezeSettledKey(commentsKey);\n }\n }, [account, autoUpdate, commentCids, commentsKey, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n comments: normalizedComments,\n state,\n refresh,\n error: undefined,\n errors: [],\n }),\n [normalizedComments, commentsKey, refresh, state],\n );\n}\n\n/**\n * Validate a comment from an untrusted source outside React, e.g. `{ cid, raw: { comment,\n * commentUpdate } }` from a third-party provider: the author's signature, the community's\n * signature of the commentUpdate for this cid, and that raw.comment hashes to cid. It needs no\n * network or account, so it doesn't wait for accounts to initialize.\n */\nexport async function validateComment(\n comment: Comment,\n options?: ValidateCommentOptions,\n): Promise<ValidateCommentResult> {\n assert(\n !options || typeof options === \"object\",\n `validateComment options argument '${options}' not an object`,\n );\n return validateCommentWithPkc(comment, options ?? {}, await getOfflinePkc());\n}\n\nexport function useValidateComment(options?: UseValidateCommentOptions): UseValidateCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useValidateComment options argument '${options}' not an object`,\n );\n let { comment, validateReplies, accountName } = options ?? {};\n validateReplies = validateReplies ?? true;\n const [validated, setValidated] = useState<boolean | undefined>();\n const [errors] = useState([]);\n const account = useAccount({ accountName });\n\n useEffect(() => {\n if (!comment || !account?.pkc) {\n setValidated(undefined);\n return;\n }\n // don't automatically block community because what community it comes from\n // a malicious community could try to block other communities, etc\n const blockCommunity = false;\n commentIsValid(comment, { validateReplies, blockCommunity }, account.pkc).then((validated) =>\n setValidated(validated),\n );\n }, [comment, validateReplies, account?.pkc]);\n\n let state = \"initializing\";\n if (validated === true) {\n state = \"succeeded\";\n }\n if (validated === false) {\n state = \"failed\";\n }\n\n // start valid at true always because most of the time the value will be true and we dont want to cause a rerender\n let valid = true;\n if (validated == false) {\n valid = false;\n }\n // if comment isn't defined, it would be confusing for valid to be true\n if (!comment) {\n valid = false;\n }\n\n return useMemo(\n () => ({\n valid,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [valid, state],\n );\n}\n"]}
1
+ {"version":3,"file":"comments.js","sourceRoot":"","sources":["../../src/hooks/comments.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAC3D,OAAO,MAAM,MAAM,eAAe,CAAC;AAcnC,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,oBAAoB,EACpB,8BAA8B,GAC/B,MAAM,iCAAiC,CAAC;AACzC,OAAO,wBAAwB,MAAM,6BAA6B,CAAC;AACnE,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,uBAAuB,EACvB,iCAAiC,GAClC,MAAM,qCAAqC,CAAC;AAE7C,MAAM,UAAU,mBAAmB,CAAC,OAA4B;;IAC9D,IAAI,CAAC,OAAO;QAAE,OAAO,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC,GAAG,CAAC,MAAA,OAAO,CAAC,SAAS,mCAAI,CAAC,EAAE,MAAA,OAAO,CAAC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,KAAK,CAAC,CACf,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:comments:hooks\");\nimport assert from \"../lib/assert\";\nimport {\n Comment,\n UseCommentsOptions,\n UseCommentsResult,\n UseCommentOptions,\n UseCommentResult,\n UseCrosspostOptions,\n UseCrosspostResult,\n UseValidateCommentOptions,\n UseValidateCommentResult,\n ValidateCommentOptions,\n ValidateCommentResult,\n} from \"../types\";\nimport useCommentsStore from \"../stores/comments\";\nimport useAccountsStore from \"../stores/accounts\";\nimport utils, { commentIsValid } from \"../lib/utils\";\nimport { getOfflinePkc, validateCommentWithPkc } from \"../lib/validate-comment\";\nimport {\n addCommentModeration,\n addCommentModerationToComments,\n} from \"../lib/utils/comment-moderation\";\nimport useCommunitiesPagesStore from \"../stores/communities-pages\";\nimport useRepliesPagesStore from \"../stores/replies-pages\";\nimport shallow from \"zustand/shallow\";\nimport { assertCommunityRef } from \"../lib/community-ref\";\nimport {\n addOptimisticVoteCounts,\n addOptimisticVoteCountsToComments,\n} from \"../lib/utils/optimistic-vote-counts\";\n\nexport function getCommentFreshness(comment: Comment | undefined): number {\n if (!comment) return 0;\n return Math.max(comment.updatedAt ?? 0, comment.timestamp ?? 0, 0);\n}\n\nexport function preferFresher(\n current: Comment | undefined,\n candidate: Comment | undefined,\n): Comment | undefined {\n if (!candidate) return current;\n if (!current) return candidate;\n return getCommentFreshness(candidate) > getCommentFreshness(current) ? candidate : current;\n}\n\nconst getCommentStateAndReplyCount = (comment: Comment | undefined) => {\n let state = comment?.updatingState || \"initializing\";\n // force 'fetching-ipns' even if could be something else, so the frontend can use\n // the correct loading skeleton\n if (comment?.timestamp) {\n state = \"fetching-update-ipns\";\n }\n // force succeeded even if the comment is fecthing a new update\n if (comment?.updatedAt) {\n state = \"succeeded\";\n }\n\n // force succeeded if the comment is newer than 5 minutes, no need to display loading skeleton if comment was just created\n let replyCount = comment?.replyCount;\n if (\n comment?.replyCount === undefined &&\n comment?.timestamp &&\n comment?.timestamp > Date.now() / 1000 - 5 * 60\n ) {\n state = \"succeeded\";\n // set replyCount because some frontend are likely to check if replyCount === undefined to show a loading skeleton\n replyCount = 0;\n }\n\n return { state, replyCount };\n};\n\nconst getCommentsState = (comments: (Comment | undefined)[]) =>\n comments.every((comment) => getCommentStateAndReplyCount(comment).state === \"succeeded\")\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\nlet commentAutoUpdateSubscriptionCount = 0;\nlet commentsAutoUpdateSubscriptionCount = 0;\n\nconst getCommentCreateCommentData = (\n commentCid: string | undefined,\n community: UseCommentOptions[\"community\"] | undefined,\n initialComment: Comment | undefined,\n ...comments: (Comment | undefined)[]\n) => {\n if (!commentCid) {\n return undefined;\n }\n\n const createCommentData: Comment = initialComment\n ? { ...utils.clone(initialComment), cid: commentCid }\n : { cid: commentCid };\n let hasCreateCommentData = Boolean(initialComment);\n for (const comment of comments) {\n if (!comment) {\n continue;\n }\n if (!createCommentData.communityPublicKey && comment.communityPublicKey) {\n createCommentData.communityPublicKey = comment.communityPublicKey;\n hasCreateCommentData = true;\n }\n if (!createCommentData.communityName && comment.communityName) {\n createCommentData.communityName = comment.communityName;\n hasCreateCommentData = true;\n }\n }\n\n if (community?.publicKey) {\n createCommentData.communityPublicKey = community.publicKey;\n hasCreateCommentData = true;\n }\n if (community?.name) {\n createCommentData.communityName = community.name;\n hasCreateCommentData = true;\n }\n\n return hasCreateCommentData ? createCommentData : undefined;\n};\n\n/**\n * @param commentCid - The IPFS CID of the comment to get\n * @param community - The community identifier, e.g. {name: 'memes.eth', publicKey: '12D3KooW...'}.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useComment(options?: UseCommentOptions): UseCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useComment options argument '${options}' not an object`,\n );\n const {\n commentCid,\n community,\n initialComment,\n accountName,\n onlyIfCached,\n autoUpdate = true,\n } = options ?? {};\n if (community !== undefined) {\n assertCommunityRef(community, \"useComment community\");\n }\n const account = useAccount({ accountName });\n const commentFromStore = useCommentsStore((state: any) => state.comments[commentCid || \"\"]);\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const communitiesPagesComment = useCommunitiesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const repliesPagesComment = useRepliesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const errors = useCommentsStore((state: any) => state.errors[commentCid || \"\"]);\n const openingUpdatePending = useCommentsStore((state: any) =>\n Boolean(state.openingUpdatesPending[commentCid || \"\"]),\n );\n\n // get account comment of the cid if any\n const accountCommentInfo = useAccountsStore(\n (state: any) => state.commentCidsToAccountsComments[commentCid || \"\"],\n );\n const accountComment = useAccountsStore(\n (state: any) =>\n state.accountsComments[accountCommentInfo?.accountId || \"\"]?.[\n Number(accountCommentInfo?.accountCommentIndex)\n ],\n );\n const accountVote = useAccountsStore((state: any) =>\n account?.id && commentCid ? state.accountsVotes[account.id]?.[commentCid] : undefined,\n );\n const createCommentData = useMemo(\n () =>\n getCommentCreateCommentData(\n commentCid,\n community,\n initialComment,\n communitiesPagesComment,\n repliesPagesComment,\n ),\n [\n commentCid,\n community?.name,\n community?.publicKey,\n initialComment,\n communitiesPagesComment?.communityName,\n communitiesPagesComment?.communityPublicKey,\n repliesPagesComment?.communityName,\n repliesPagesComment?.communityPublicKey,\n ],\n );\n const autoUpdateSubscriptionId = useRef(`useComment-${++commentAutoUpdateSubscriptionCount}`);\n const currentCommentCidRef = useRef<string | undefined>(commentCid);\n currentCommentCidRef.current = commentCid;\n const [frozenComment, setFrozenComment] = useState<Comment | undefined>();\n const [freezeSettledCid, setFreezeSettledCid] = useState<string>();\n\n useEffect(() => {\n if (!commentCid || !account) {\n return;\n }\n validator.validateUseCommentArguments(commentCid, account);\n if (!commentFromStore && !onlyIfCached) {\n // if comment isn't already in store, add it\n const addCommentPromise = createCommentData\n ? addCommentToStore(commentCid, account, createCommentData)\n : addCommentToStore(commentCid, account);\n addCommentPromise.catch((error: unknown) =>\n log.error(\"useComment addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCid, account?.id, onlyIfCached, createCommentData]);\n\n useEffect(() => {\n if (!commentCid || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const startAutoUpdatePromise = createCommentData\n ? startCommentAutoUpdate(\n commentCid,\n autoUpdateSubscriptionId.current,\n account,\n createCommentData,\n )\n : startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account);\n startAutoUpdatePromise.catch((error: unknown) =>\n log.error(\"useComment startCommentAutoUpdate error\", { commentCid, error }),\n );\n\n return () => {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch((error: unknown) =>\n log.error(\"useComment stopCommentAutoUpdate error\", { commentCid, error }),\n );\n };\n }, [commentCid, account?.id, onlyIfCached, autoUpdate, createCommentData]);\n\n let selectedComment = commentFromStore;\n\n if (commentCid && communitiesPagesComment) {\n selectedComment = preferFresher(selectedComment, communitiesPagesComment);\n }\n if (commentCid && repliesPagesComment) {\n selectedComment = preferFresher(selectedComment, repliesPagesComment);\n }\n\n // if comment is still not defined, but account comment is, use account comment\n // check `comment.timestamp` instead of `comment` in case comment exists but in a loading state\n const commentFromStoreNotLoaded = !selectedComment?.timestamp;\n if (commentCid && commentFromStoreNotLoaded && accountComment) {\n selectedComment = accountComment;\n }\n const selectedCommentWithFallback = useMemo(() => {\n if (!commentCid || !commentFromStoreNotLoaded || !initialComment) {\n return selectedComment;\n }\n const commentWithFallback = utils.merge(\n initialComment.raw?.comment || {},\n initialComment,\n { cid: commentCid },\n selectedComment || {},\n );\n commentWithFallback.raw = utils.merge(initialComment.raw || {}, selectedComment?.raw || {});\n return commentWithFallback;\n }, [commentCid, commentFromStoreNotLoaded, initialComment, selectedComment]);\n selectedComment = selectedCommentWithFallback;\n\n const selectedCommentShortAddress = selectedComment?.author?.shortAddress;\n const initialCommentUpdatePending = Boolean(\n initialComment?.raw?.comment && !selectedComment?.raw?.commentUpdate,\n );\n // A copy cached on an earlier visit loads before the network. Freeze only once the update this\n // load requested has ended, so a returning visitor sees the current comment.\n const openingUpdateEnded = onlyIfCached || (Boolean(commentFromStore) && !openingUpdatePending);\n const freezeSettledForCurrentCid = freezeSettledCid === commentCid;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n }, [commentCid, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate) {\n return;\n }\n if (!commentCid) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n if (!selectedComment) {\n return;\n }\n if (freezeSettledForCurrentCid) {\n // Canonical number and author identity can arrive after the first community\n // update. Absorb only that immutable metadata while keeping later updates frozen.\n const frozenCommentForCurrentCid =\n frozenComment?.cid === commentCid ? frozenComment : undefined;\n const frozenCommentShortAddress = frozenCommentForCurrentCid?.author?.shortAddress;\n const hasReconciledPublicationMetadata =\n (selectedComment.number !== undefined &&\n selectedComment.number !== frozenCommentForCurrentCid?.number) ||\n (selectedComment.postNumber !== undefined &&\n selectedComment.postNumber !== frozenCommentForCurrentCid?.postNumber) ||\n (selectedCommentShortAddress && selectedCommentShortAddress !== frozenCommentShortAddress);\n if (hasReconciledPublicationMetadata && frozenCommentForCurrentCid) {\n setFrozenComment({\n ...frozenCommentForCurrentCid,\n ...(selectedComment.number !== undefined ? { number: selectedComment.number } : {}),\n ...(selectedComment.postNumber !== undefined\n ? { postNumber: selectedComment.postNumber }\n : {}),\n ...(selectedCommentShortAddress\n ? {\n author: {\n ...frozenCommentForCurrentCid.author,\n shortAddress: selectedCommentShortAddress,\n },\n }\n : {}),\n });\n }\n return;\n }\n\n setFrozenComment(selectedComment);\n // Recent immutable payloads report \"succeeded\" before moderation is available.\n if (\n typeof selectedComment.updatedAt === \"number\" &&\n !initialCommentUpdatePending &&\n openingUpdateEnded\n ) {\n setFreezeSettledCid(commentCid);\n }\n }, [\n autoUpdate,\n commentCid,\n selectedComment,\n initialCommentUpdatePending,\n openingUpdateEnded,\n freezeSettledForCurrentCid,\n frozenComment,\n selectedCommentShortAddress,\n ]);\n\n const frozenCommentForCurrentCid = frozenComment?.cid === commentCid ? frozenComment : undefined;\n let comment = autoUpdate\n ? selectedComment\n : freezeSettledForCurrentCid\n ? frozenCommentForCurrentCid\n : frozenCommentForCurrentCid || selectedComment;\n comment = addCommentModeration(comment);\n comment = addOptimisticVoteCounts(comment, accountVote);\n\n const { state, replyCount } = getCommentStateAndReplyCount(comment);\n\n if (account && commentCid) {\n log(\"useComment\", {\n commentCid,\n comment,\n replyCount,\n state,\n commentFromStore,\n communitiesPagesComment,\n repliesPagesComment,\n accountComment,\n commentsStore: useCommentsStore.getState().comments,\n account,\n onlyIfCached,\n autoUpdate,\n });\n }\n\n const refresh = useCallback(async () => {\n if (!commentCid || !account) {\n throw Error(\"useComment cannot refresh comment not initialized yet\");\n }\n\n const refreshCommentCid = commentCid;\n const refreshedComment = createCommentData\n ? await refreshCommentInStore(refreshCommentCid, account, createCommentData)\n : await refreshCommentInStore(refreshCommentCid, account);\n if (!autoUpdate && refreshedComment && currentCommentCidRef.current === refreshCommentCid) {\n setFrozenComment(refreshedComment);\n setFreezeSettledCid(refreshCommentCid);\n }\n }, [account, autoUpdate, commentCid, createCommentData, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n ...comment,\n replyCount,\n state,\n refresh,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [comment, commentCid, errors, refresh, state, replyCount],\n );\n}\n\n/**\n * Read a crosspost from its embedded signed record immediately, then use the normal comment store\n * to load the referenced community's current CommentUpdate when it is available.\n */\nexport function useCrosspost(options?: UseCrosspostOptions): UseCrosspostResult {\n assert(\n !options || typeof options === \"object\",\n `useCrosspost options argument '${options}' not an object`,\n );\n const { crosspost, accountName, autoUpdate = true } = options ?? {};\n const initialComment = useMemo(\n () =>\n crosspost\n ? {\n cid: crosspost.cid,\n raw: { comment: crosspost.comment },\n }\n : undefined,\n [crosspost],\n );\n const comment = useComment({\n accountName,\n autoUpdate,\n commentCid: crosspost?.cid,\n initialComment,\n });\n\n return useMemo(\n () => ({\n ...comment,\n isCommunityVerified: Boolean(comment.raw?.commentUpdate),\n }),\n [comment],\n );\n}\n\n/**\n * @param commentCids - The IPFS CIDs of the comments to get\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useComments(options?: UseCommentsOptions): UseCommentsResult {\n assert(\n !options || typeof options === \"object\",\n `useComments options argument '${options}' not an object`,\n );\n const { commentCids = [], accountName, onlyIfCached, autoUpdate = true } = options ?? {};\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const commentsStoreComments: (Comment | undefined)[] = useCommentsStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n const communitiesPagesComments: (Comment | undefined)[] = useCommunitiesPagesStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n const openingUpdatesPending: boolean[] = useCommentsStore(\n (state: any) =>\n commentCids.map((commentCid) => Boolean(state.openingUpdatesPending[commentCid || \"\"])),\n shallow,\n );\n\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const autoUpdateSubscriptionId = useRef(`useComments-${++commentsAutoUpdateSubscriptionCount}`);\n const commentCidsKey = JSON.stringify(commentCids);\n const commentsKey = `${account?.id || \"\"}:${commentCidsKey}`;\n const currentCommentsKeyRef = useRef(commentsKey);\n currentCommentsKeyRef.current = commentsKey;\n const [frozenComments, setFrozenComments] = useState<(Comment | undefined)[]>([]);\n const [frozenCommentsKey, setFrozenCommentsKey] = useState<string>();\n const [freezeSettledKey, setFreezeSettledKey] = useState<string>();\n\n useEffect(() => {\n if (!commentCids || !account) {\n return;\n }\n validator.validateUseCommentsArguments(commentCids, account);\n if (onlyIfCached) {\n return;\n }\n const uniqueCommentCids = new Set(commentCids);\n for (const commentCid of uniqueCommentCids) {\n addCommentToStore(commentCid, account).catch((error: unknown) =>\n log.error(\"useComments addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCidsKey, account?.id, onlyIfCached]);\n\n useEffect(() => {\n if (!commentCids || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const uniqueCommentCids = [...new Set(commentCids)];\n for (const commentCid of uniqueCommentCids) {\n startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account).catch(\n (error: unknown) =>\n log.error(\"useComments startCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n\n return () => {\n for (const commentCid of uniqueCommentCids) {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch(\n (error: unknown) =>\n log.error(\"useComments stopCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n };\n }, [commentCidsKey, account?.id, onlyIfCached, autoUpdate]);\n\n if (account && commentCids?.length) {\n log(\"useComments\", {\n commentCids,\n commentsStoreComments,\n commentsStore: useCommentsStore.getState().comments,\n account,\n });\n }\n\n // if comment from community pages exists and is fresher (or current missing), use it instead\n const liveComments = useMemo(() => {\n const result = [...commentsStoreComments];\n for (const i in result) {\n const candidate = communitiesPagesComments[i];\n if (candidate) result[i] = preferFresher(result[i], candidate);\n }\n return result;\n }, [commentsStoreComments, communitiesPagesComments]);\n\n // like useComment, wait for each update requested on load before freezing over cached copies\n const liveCommentsSettled =\n liveComments.every((comment) => typeof comment?.updatedAt === \"number\") &&\n (Boolean(onlyIfCached) ||\n commentsStoreComments.every((comment, index) => comment && !openingUpdatesPending[index]));\n const freezeSettledForCurrentKey = freezeSettledKey === commentsKey;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n return;\n }\n\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n }, [commentsKey, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate || freezeSettledForCurrentKey) {\n return;\n }\n\n setFrozenComments(liveComments);\n setFrozenCommentsKey(commentsKey);\n if (liveCommentsSettled) {\n setFreezeSettledKey(commentsKey);\n }\n }, [autoUpdate, commentsKey, freezeSettledForCurrentKey, liveComments, liveCommentsSettled]);\n\n const frozenCommentsForCurrentSelection =\n frozenCommentsKey === commentsKey ? frozenComments : undefined;\n const comments = autoUpdate ? liveComments : frozenCommentsForCurrentSelection || liveComments;\n const normalizedComments = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(comments), accountVotes),\n [comments, accountVotes],\n );\n\n // succeed if no comments are undefined\n const state = getCommentsState(normalizedComments);\n\n const refresh = useCallback(async () => {\n if (!account) {\n throw Error(\"useComments cannot refresh comments not initialized yet\");\n }\n const uniqueCommentCids = [...new Set(commentCids)];\n const refreshedComments = await Promise.all(\n uniqueCommentCids.map((commentCid) => refreshCommentInStore(commentCid, account)),\n );\n\n if (!autoUpdate && currentCommentsKeyRef.current === commentsKey) {\n const latestCommunitiesPagesComments = useCommunitiesPagesStore.getState().comments;\n const refreshedCommentsByCid = uniqueCommentCids.reduce(\n (\n refreshedCommentsMap: { [commentCid: string]: Comment | undefined },\n commentCid,\n index,\n ) => {\n refreshedCommentsMap[commentCid] = refreshedComments[index];\n return refreshedCommentsMap;\n },\n {},\n );\n setFrozenComments(\n commentCids.map((commentCid) =>\n preferFresher(\n refreshedCommentsByCid[commentCid || \"\"],\n latestCommunitiesPagesComments[commentCid || \"\"],\n ),\n ),\n );\n setFrozenCommentsKey(commentsKey);\n setFreezeSettledKey(commentsKey);\n }\n }, [account, autoUpdate, commentCids, commentsKey, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n comments: normalizedComments,\n state,\n refresh,\n error: undefined,\n errors: [],\n }),\n [normalizedComments, commentsKey, refresh, state],\n );\n}\n\n/**\n * Validate a comment from an untrusted source outside React, e.g. `{ cid, raw: { comment,\n * commentUpdate } }` from a third-party provider: the author's signature, the community's\n * signature of the commentUpdate for this cid, and that raw.comment hashes to cid. It needs no\n * network or account, so it doesn't wait for accounts to initialize.\n */\nexport async function validateComment(\n comment: Comment,\n options?: ValidateCommentOptions,\n): Promise<ValidateCommentResult> {\n assert(\n !options || typeof options === \"object\",\n `validateComment options argument '${options}' not an object`,\n );\n return validateCommentWithPkc(comment, options ?? {}, await getOfflinePkc());\n}\n\nexport function useValidateComment(options?: UseValidateCommentOptions): UseValidateCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useValidateComment options argument '${options}' not an object`,\n );\n let { comment, validateReplies, accountName } = options ?? {};\n validateReplies = validateReplies ?? true;\n const [validated, setValidated] = useState<boolean | undefined>();\n const [errors] = useState([]);\n const account = useAccount({ accountName });\n\n useEffect(() => {\n if (!comment || !account?.pkc) {\n setValidated(undefined);\n return;\n }\n // don't automatically block community because what community it comes from\n // a malicious community could try to block other communities, etc\n const blockCommunity = false;\n commentIsValid(comment, { validateReplies, blockCommunity }, account.pkc).then((validated) =>\n setValidated(validated),\n );\n }, [comment, validateReplies, account?.pkc]);\n\n let state = \"initializing\";\n if (validated === true) {\n state = \"succeeded\";\n }\n if (validated === false) {\n state = \"failed\";\n }\n\n // start valid at true always because most of the time the value will be true and we dont want to cause a rerender\n let valid = true;\n if (validated == false) {\n valid = false;\n }\n // if comment isn't defined, it would be confusing for valid to be true\n if (!comment) {\n valid = false;\n }\n\n return useMemo(\n () => ({\n valid,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [valid, state],\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"accounts-actions.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/accounts-actions.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,OAAO,EAEP,qBAAqB,EAGrB,kBAAkB,EAClB,yBAAyB,EACzB,+BAA+B,EAC/B,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAIhB,MAAM,aAAa,CAAC;AA2TrB,sGAAsG;AACtG,eAAO,MAAM,yBAAyB,GACpC,kBAAkB,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EACvC,WAAW,MAAM,EACjB,OAAO,MAAM,EACb,SAAS,CAAC,eAAe,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,GAAG,KAAK,IAAI;;;;;;CAO/D,CAAC;AA2BF,eAAO,MAAM,0BAA0B,GAAI,mBAAmB,GAAG,EAAE,yBAAyB,GAAG,YAGtC,CAAC;AAE1D,eAAO,MAAM,yBAAyB,GAAI,mBAAmB,GAAG,QAK/D,CAAC;AAuCF,eAAO,MAAM,kCAAkC,GAC7C,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC3D,WAAW,MAAM,EACjB,mBAAmB,GAAG;;CAsCvB,CAAC;AAEF,eAAO,MAAM,uCAAuC,GAClD,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC3D,eAAe,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EACpD,WAAW,MAAM,EACjB,mBAAmB,GAAG;;CA6BvB,CAAC;AAEF,eAAO,MAAM,qCAAqC,GAAI,uBAAuB,GAAG,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cAAc,GACzB,uBAAuB,qBAAqB,EAC5C,cAAc,MAAM,iBA6crB,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,iCAAiC,MAAM,GAAG,MAAM,EAChD,cAAc,MAAM,kBA2DrB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,oBAAoB,kBAAkB,EAAE,cAAc,MAAM,kBA4I7F,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAU,YAAY,MAAM,EAAE,cAAc,MAAM,kBAmCzE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,2BAA2B,yBAAyB,EACpD,cAAc,MAAM,kBA4IrB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,iCAAiC,+BAA+B,EAChE,cAAc,MAAM,kBAyJrB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,kBAAkB,MAAM,EACxB,6BAA6B,2BAA2B,EACxD,cAAc,MAAM,kBA+JrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,wBAAwB,sBAAsB,EAC9C,cAAc,MAAM,iBAmBrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,kBAAkB,MAAM,EAAE,cAAc,MAAM,kBAcnF,CAAC"}
@@ -37,6 +37,7 @@ import utils from "../../lib/utils/index.js";
37
37
  import { addOptimisticVoteMetadata } from "../../lib/utils/optimistic-vote-counts.js";
38
38
  import { applyCommunityWordfilters } from "../../lib/wordfilters.js";
39
39
  const PUBLICATION_COMMUNITY_LOAD_TIMEOUT_MS = 30000;
40
+ const COMMENT_AUTHOR_LOAD_TIMEOUT_MS = 10000;
40
41
  const communityHasPublicationConfig = (community) => community &&
41
42
  (typeof community.updatedAt === "number" ||
42
43
  Object.prototype.hasOwnProperty.call(community, "challenges"));
@@ -96,6 +97,24 @@ const loadPublicationCommunity = (communityAddress, account) => __awaiter(void 0
96
97
  yield ((_a = community.stop) === null || _a === void 0 ? void 0 : _a.call(community));
97
98
  }
98
99
  });
100
+ const loadCommentAuthorAddress = (account, commentCid) => __awaiter(void 0, void 0, void 0, function* () {
101
+ var _a;
102
+ const abortController = new AbortController();
103
+ const timeout = setTimeout(() => abortController.abort(), COMMENT_AUTHOR_LOAD_TIMEOUT_MS);
104
+ try {
105
+ const comment = yield account.pkc.getComment({
106
+ cid: commentCid,
107
+ abortSignal: abortController.signal,
108
+ });
109
+ return (_a = comment === null || comment === void 0 ? void 0 : comment.author) === null || _a === void 0 ? void 0 : _a.address;
110
+ }
111
+ catch (error) {
112
+ log.error("accountsActions.loadCommentAuthorAddress error", { commentCid, error });
113
+ }
114
+ finally {
115
+ clearTimeout(timeout);
116
+ }
117
+ });
99
118
  const applyPublicationWordfilters = (publicationType, options, account) => __awaiter(void 0, void 0, void 0, function* () {
100
119
  const communityAddress = options.communityAddress;
101
120
  if (typeof communityAddress !== "string" || !communityAddress)
@@ -885,7 +904,7 @@ export const unsaveComment = (commentCid, accountName) => __awaiter(void 0, void
885
904
  yield updateSavedComments(commentCid, accountName, false);
886
905
  });
887
906
  export const publishComment = (publishCommentOptions, accountName) => __awaiter(void 0, void 0, void 0, function* () {
888
- var _a, _b, _c, _d, _e;
907
+ var _a, _b, _c, _d, _e, _f, _g;
889
908
  const { accounts, accountsComments, accountNamesToAccountIds, activeAccountId } = accountsStore.getState();
890
909
  assert(accounts && accountNamesToAccountIds && activeAccountId, `can't use accountsStore.accountActions before initialized`);
891
910
  let account = accounts[activeAccountId];
@@ -901,18 +920,41 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
901
920
  // find author.previousCommentCid if any
902
921
  const accountCommentsWithCids = accountsComments[account.id]
903
922
  .filter((comment) => comment.cid)
904
- // author can change his address, his previousCommentCid becomes invalid
905
- .filter((comment) => { var _a, _b; return ((_a = comment.author) === null || _a === void 0 ? void 0 : _a.address) === ((_b = account.author) === null || _b === void 0 ? void 0 : _b.address); });
906
- const previousCommentCid = (_a = accountCommentsWithCids[accountCommentsWithCids.length - 1]) === null || _a === void 0 ? void 0 : _a.cid;
923
+ // a pseudonymous community published the comment under an alias, linking it would reveal the account
924
+ .filter((comment) => !comment.pseudonymityMode)
925
+ // author can change his address, his previousCommentCid becomes invalid. hooks <= 0.1.51 replaced
926
+ // the stored author with commentUpdate.author, so those comments have no author.address at all
927
+ .filter((comment) => { var _a, _b; return !((_a = comment.author) === null || _a === void 0 ? void 0 : _a.address) || comment.author.address === ((_b = account.author) === null || _b === void 0 ? void 0 : _b.address); });
928
+ const previousComment = accountCommentsWithCids[accountCommentsWithCids.length - 1];
907
929
  const author = Object.assign({}, account.author);
908
- if (previousCommentCid) {
909
- author.previousCommentCid = previousCommentCid;
930
+ if (previousComment) {
931
+ author.previousCommentCid = previousComment.cid;
910
932
  }
911
933
  const publicationAuthor = Object.assign(Object.assign({}, author), publishCommentOptions.author);
912
- if (publicationAuthor.address !== ((_b = account.author) === null || _b === void 0 ? void 0 : _b.address) &&
913
- ((_c = publishCommentOptions.author) === null || _c === void 0 ? void 0 : _c.previousCommentCid) === undefined) {
934
+ if (publicationAuthor.address !== ((_a = account.author) === null || _a === void 0 ? void 0 : _a.address) &&
935
+ ((_b = publishCommentOptions.author) === null || _b === void 0 ? void 0 : _b.previousCommentCid) === undefined) {
914
936
  delete publicationAuthor.previousCommentCid;
915
937
  }
938
+ // a comment without author.address may have been published under an alternate author passed to
939
+ // publishComment, so only link it once its immutable author, loaded from its cid, is the account's
940
+ if (previousComment &&
941
+ !((_c = previousComment.author) === null || _c === void 0 ? void 0 : _c.address) &&
942
+ ((_d = publishCommentOptions.author) === null || _d === void 0 ? void 0 : _d.previousCommentCid) === undefined &&
943
+ publicationAuthor.previousCommentCid === previousComment.cid) {
944
+ const previousCommentAuthorAddress = yield loadCommentAuthorAddress(account, previousComment.cid);
945
+ if (!previousCommentAuthorAddress || previousCommentAuthorAddress !== ((_e = account.author) === null || _e === void 0 ? void 0 : _e.address)) {
946
+ // fall back to the newest stored comment that kept the account author address
947
+ const previousAccountAuthorComment = accountCommentsWithCids
948
+ .filter((comment) => { var _a; return (_a = comment.author) === null || _a === void 0 ? void 0 : _a.address; })
949
+ .pop();
950
+ if (previousAccountAuthorComment) {
951
+ publicationAuthor.previousCommentCid = previousAccountAuthorComment.cid;
952
+ }
953
+ else {
954
+ delete publicationAuthor.previousCommentCid;
955
+ }
956
+ }
957
+ }
916
958
  let createCommentOptions = normalizePublicationOptionsForPkc(account.pkc, Object.assign(Object.assign({ timestamp: Math.floor(Date.now() / 1000), signer: account.signer }, publishCommentOptions), { author: publicationAuthor }));
917
959
  delete createCommentOptions.onChallenge;
918
960
  delete createCommentOptions.onChallengeVerification;
@@ -929,7 +971,7 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
929
971
  // set fetching link dimensions state
930
972
  let fetchingLinkDimensionsStates;
931
973
  if (publishCommentOptions.link) {
932
- (_d = publishCommentOptions.onPublishingStateChange) === null || _d === void 0 ? void 0 : _d.call(publishCommentOptions, "fetching-link-dimensions");
974
+ (_f = publishCommentOptions.onPublishingStateChange) === null || _f === void 0 ? void 0 : _f.call(publishCommentOptions, "fetching-link-dimensions");
933
975
  fetchingLinkDimensionsStates = {
934
976
  state: "publishing",
935
977
  publishingState: "fetching-link-dimensions",
@@ -1001,7 +1043,7 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
1001
1043
  if (pendingCommentIndex !== accountCommentIndex) {
1002
1044
  notifyPendingComment(pendingCommentIndex, createdAccountComment);
1003
1045
  }
1004
- (_e = publishCommentOptions._onPendingCommentIndex) === null || _e === void 0 ? void 0 : _e.call(publishCommentOptions, pendingCommentIndex, createdAccountComment);
1046
+ (_g = publishCommentOptions._onPendingCommentIndex) === null || _g === void 0 ? void 0 : _g.call(publishCommentOptions, pendingCommentIndex, createdAccountComment);
1005
1047
  let comment;
1006
1048
  (() => __awaiter(void 0, void 0, void 0, function* () {
1007
1049
  // fetch comment.link dimensions