@bitsocial/bitsocial-react-hooks 0.1.53 → 0.1.55
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 +23 -0
- package/dist/hooks/accounts/accounts.js +2 -2
- package/dist/hooks/accounts/accounts.js.map +1 -1
- package/dist/hooks/accounts/utils.d.ts.map +1 -1
- package/dist/hooks/accounts/utils.js +3 -12
- package/dist/hooks/accounts/utils.js.map +1 -1
- package/dist/hooks/actions/actions.js +1 -1
- package/dist/hooks/actions/actions.js.map +1 -1
- package/dist/hooks/authors/author-avatars.js +1 -1
- package/dist/hooks/authors/author-avatars.js.map +1 -1
- package/dist/hooks/authors/authors.js +1 -1
- package/dist/hooks/authors/authors.js.map +1 -1
- package/dist/hooks/authors/utils.d.ts.map +1 -1
- package/dist/hooks/authors/utils.js +1 -13
- package/dist/hooks/authors/utils.js.map +1 -1
- package/dist/hooks/comments.d.ts +7 -1
- package/dist/hooks/comments.d.ts.map +1 -1
- package/dist/hooks/comments.js +31 -1
- package/dist/hooks/comments.js.map +1 -1
- package/dist/hooks/communities.js +1 -1
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.js +1 -1
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/hooks/pkc-rpc.js +1 -1
- package/dist/hooks/pkc-rpc.js.map +1 -1
- package/dist/hooks/replies.js +1 -1
- package/dist/hooks/replies.js.map +1 -1
- package/dist/hooks/states.js +1 -1
- package/dist/hooks/states.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/assert.d.ts +6 -0
- package/dist/lib/assert.d.ts.map +1 -0
- package/dist/lib/assert.js +17 -0
- package/dist/lib/assert.js.map +1 -0
- package/dist/lib/chain/chain.js +1 -1
- package/dist/lib/chain/chain.js.map +1 -1
- package/dist/lib/community-ref.js +1 -1
- package/dist/lib/community-ref.js.map +1 -1
- package/dist/lib/crosspost.js +1 -1
- package/dist/lib/crosspost.js.map +1 -1
- package/dist/lib/is-equal.d.ts +6 -0
- package/dist/lib/is-equal.d.ts.map +1 -0
- package/dist/lib/is-equal.js +100 -0
- package/dist/lib/is-equal.js.map +1 -0
- package/dist/lib/memoize.d.ts +9 -0
- package/dist/lib/memoize.d.ts.map +1 -0
- package/dist/lib/memoize.js +24 -0
- package/dist/lib/memoize.js.map +1 -0
- package/dist/lib/pkc-address.d.ts +2 -0
- package/dist/lib/pkc-address.d.ts.map +1 -0
- package/dist/lib/pkc-address.js +16 -0
- package/dist/lib/pkc-address.js.map +1 -0
- package/dist/lib/pkc-compat.js +1 -1
- package/dist/lib/pkc-compat.js.map +1 -1
- package/dist/lib/pkc-js/index.d.ts.map +1 -1
- package/dist/lib/pkc-js/index.js +23 -12
- package/dist/lib/pkc-js/index.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
- package/dist/lib/protocol-compat.js +1 -1
- package/dist/lib/protocol-compat.js.map +1 -1
- package/dist/lib/utils/utils.js +1 -1
- package/dist/lib/utils/utils.js.map +1 -1
- package/dist/lib/validate-comment.d.ts +11 -0
- package/dist/lib/validate-comment.d.ts.map +1 -0
- package/dist/lib/validate-comment.js +133 -0
- package/dist/lib/validate-comment.js.map +1 -0
- package/dist/lib/validator.js +1 -1
- package/dist/lib/validator.js.map +1 -1
- package/dist/stores/accounts/accounts-actions-internal.js +2 -2
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +2 -2
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/accounts-database.js +2 -2
- package/dist/stores/accounts/accounts-database.js.map +1 -1
- package/dist/stores/accounts/accounts-store.js +1 -1
- package/dist/stores/accounts/accounts-store.js.map +1 -1
- package/dist/stores/accounts/utils.js +1 -1
- package/dist/stores/accounts/utils.js.map +1 -1
- package/dist/stores/authors-comments/authors-comments-store.js +1 -1
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
- package/dist/stores/authors-comments/utils.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +53 -11
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
- package/dist/stores/feeds/feeds-store.js +1 -1
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/stores/replies/replies-store.js +1 -1
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.js.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -6
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
|
|
4
|
-
import { create as createMultihash } from "multiformats/hashes/digest";
|
|
2
|
+
import { getPkcAddressFromPublicKey } from "../../lib/pkc-address.js";
|
|
5
3
|
export const useAuthorCommentsName = (accountId, authorAddress, filter) => {
|
|
6
4
|
return useMemo(() => accountId + "-" + authorAddress + "-" + (filter === null || filter === void 0 ? void 0 : filter.key), [accountId, authorAddress, filter === null || filter === void 0 ? void 0 : filter.key]);
|
|
7
5
|
};
|
|
8
|
-
const protobufPublicKeyPrefix = new Uint8Array([8, 1, 18, 32]);
|
|
9
|
-
const multihashIdentityCode = 0;
|
|
10
|
-
const getPkcAddressFromPublicKey = (publicKeyBase64) => {
|
|
11
|
-
const publicKeyBuffer = uint8ArrayFromString(publicKeyBase64, "base64");
|
|
12
|
-
const publicKeyBufferWithPrefix = new Uint8Array(protobufPublicKeyPrefix.length + publicKeyBuffer.length);
|
|
13
|
-
publicKeyBufferWithPrefix.set(protobufPublicKeyPrefix, 0);
|
|
14
|
-
publicKeyBufferWithPrefix.set(publicKeyBuffer, protobufPublicKeyPrefix.length);
|
|
15
|
-
const multihash = createMultihash(multihashIdentityCode, publicKeyBufferWithPrefix).bytes;
|
|
16
|
-
return uint8ArrayToString(multihash, "base58btc");
|
|
17
|
-
};
|
|
18
6
|
export const usePkcAddress = (publicKeyBase64) => {
|
|
19
7
|
return useMemo(() => (publicKeyBase64 ? getPkcAddressFromPublicKey(publicKeyBase64) : undefined), [publicKeyBase64]);
|
|
20
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/hooks/authors/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/hooks/authors/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,OAAO,EAAE,MAAM,OAAO,CAAC;AAMrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAEnE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,SAAkB,EAClB,aAAsB,EACtB,MAAmC,EACnC,EAAE;IACF,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,SAAS,GAAG,GAAG,GAAG,aAAa,GAAG,GAAG,IAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAA,EACzD,CAAC,SAAS,EAAE,aAAa,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAC,CACxC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,eAAwB,EAAE,EAAE;IACxD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,0BAA0B,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EACjF,CAAC,eAAe,CAAC,CAClB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { Comment, CommentsFilter } from \"../../types\";\nimport { useComments } from \"../comments\";\nimport utils from \"../../lib/utils\";\nimport PeerId from \"peer-id\";\nimport assert from \"../../lib/assert\";\nimport { getPkcAddressFromPublicKey } from \"../../lib/pkc-address\";\n\nexport const useAuthorCommentsName = (\n accountId?: string,\n authorAddress?: string,\n filter?: CommentsFilter | undefined,\n) => {\n return useMemo(\n () => accountId + \"-\" + authorAddress + \"-\" + filter?.key,\n [accountId, authorAddress, filter?.key],\n );\n};\n\nexport const usePkcAddress = (publicKeyBase64?: string) => {\n return useMemo(\n () => (publicKeyBase64 ? getPkcAddressFromPublicKey(publicKeyBase64) : undefined),\n [publicKeyBase64],\n );\n};\n"]}
|
package/dist/hooks/comments.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Comment, UseCommentsOptions, UseCommentsResult, UseCommentOptions, UseCommentResult, UseCrosspostOptions, UseCrosspostResult, UseValidateCommentOptions, UseValidateCommentResult } from "../types.js";
|
|
1
|
+
import { Comment, UseCommentsOptions, UseCommentsResult, UseCommentOptions, UseCommentResult, UseCrosspostOptions, UseCrosspostResult, UseValidateCommentOptions, UseValidateCommentResult, ValidateCommentOptions, ValidateCommentResult } from "../types.js";
|
|
2
2
|
export declare function getCommentFreshness(comment: Comment | undefined): number;
|
|
3
3
|
export declare function preferFresher(current: Comment | undefined, candidate: Comment | undefined): Comment | undefined;
|
|
4
4
|
/**
|
|
@@ -19,5 +19,11 @@ export declare function useCrosspost(options?: UseCrosspostOptions): UseCrosspos
|
|
|
19
19
|
* the active account.
|
|
20
20
|
*/
|
|
21
21
|
export declare function useComments(options?: UseCommentsOptions): UseCommentsResult;
|
|
22
|
+
/**
|
|
23
|
+
* Validate a comment from an untrusted source outside React, e.g. `{ cid, raw: { comment,
|
|
24
|
+
* commentUpdate } }` from a third-party provider: the author's signature, the community's
|
|
25
|
+
* signature of the commentUpdate for this cid, and that raw.comment hashes to cid.
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateComment(comment: Comment, options?: ValidateCommentOptions): Promise<ValidateCommentResult>;
|
|
22
28
|
export declare function useValidateComment(options?: UseValidateCommentOptions): UseValidateCommentResult;
|
|
23
29
|
//# sourceMappingURL=comments.d.ts.map
|
|
@@ -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,
|
|
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,GAAG,SAAS,GAC7B,OAAO,GAAG,SAAS,CAIrB;AA6ED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CA6QxE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,kBAAkB,CA8B9E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,iBAAiB,CAgL3E;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,qBAAqB,CAAC,CAehC;AAED,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,wBAAwB,CAmDhG"}
|
package/dist/hooks/comments.js
CHANGED
|
@@ -7,15 +7,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
10
21
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
11
22
|
import { useAccount } from "./accounts/index.js";
|
|
12
23
|
import validator from "../lib/validator.js";
|
|
13
24
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
14
25
|
const log = Logger("bitsocial-react-hooks:comments:hooks");
|
|
15
|
-
import assert from "assert";
|
|
26
|
+
import assert from "../lib/assert.js";
|
|
16
27
|
import useCommentsStore from "../stores/comments/index.js";
|
|
17
28
|
import useAccountsStore from "../stores/accounts/index.js";
|
|
18
29
|
import utils, { commentIsValid } from "../lib/utils/index.js";
|
|
30
|
+
import { validateCommentWithPkc } from "../lib/validate-comment.js";
|
|
19
31
|
import { addCommentModeration, addCommentModerationToComments, } from "../lib/utils/comment-moderation.js";
|
|
20
32
|
import useCommunitiesPagesStore from "../stores/communities-pages/index.js";
|
|
21
33
|
import useRepliesPagesStore from "../stores/replies-pages/index.js";
|
|
@@ -432,6 +444,24 @@ export function useComments(options) {
|
|
|
432
444
|
errors: [],
|
|
433
445
|
}), [normalizedComments, commentsKey, refresh, state]);
|
|
434
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Validate a comment from an untrusted source outside React, e.g. `{ cid, raw: { comment,
|
|
449
|
+
* commentUpdate } }` from a third-party provider: the author's signature, the community's
|
|
450
|
+
* signature of the commentUpdate for this cid, and that raw.comment hashes to cid.
|
|
451
|
+
*/
|
|
452
|
+
export function validateComment(comment, options) {
|
|
453
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
var _a;
|
|
455
|
+
assert(!options || typeof options === "object", `validateComment options argument '${options}' not an object`);
|
|
456
|
+
const _b = options !== null && options !== void 0 ? options : {}, { accountName } = _b, validateOptions = __rest(_b, ["accountName"]);
|
|
457
|
+
const { accounts, accountNamesToAccountIds, activeAccountId } = useAccountsStore.getState();
|
|
458
|
+
assert(accounts && accountNamesToAccountIds && activeAccountId, `can't use validateComment before accounts are initialized`);
|
|
459
|
+
const accountId = accountName ? accountNamesToAccountIds[accountName] : activeAccountId;
|
|
460
|
+
const pkc = (_a = accounts[accountId]) === null || _a === void 0 ? void 0 : _a.pkc;
|
|
461
|
+
assert(pkc, `validateComment account '${accountName !== null && accountName !== void 0 ? accountName : activeAccountId}' not found`);
|
|
462
|
+
return validateCommentWithPkc(comment, validateOptions, pkc);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
435
465
|
export function useValidateComment(options) {
|
|
436
466
|
assert(!options || typeof options === "object", `useValidateComment options argument '${options}' not an object`);
|
|
437
467
|
let { comment, validateReplies, accountName } = options !== null && options !== void 0 ? options : {};
|
|
@@ -1 +1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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 \"assert\";\nimport {\n Comment,\n UseCommentsOptions,\n UseCommentsResult,\n UseCommentOptions,\n UseCommentResult,\n UseCrosspostOptions,\n UseCrosspostResult,\n UseValidateCommentOptions,\n UseValidateCommentResult,\n} from \"../types\";\nimport useCommentsStore from \"../stores/comments\";\nimport useAccountsStore from \"../stores/accounts\";\nimport utils, { commentIsValid } from \"../lib/utils\";\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\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,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EACL,oBAAoB,EACpB,8BAA8B,GAC/B,MAAM,iCAAiC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ACvE,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 { 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.\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 const { accountName, ...validateOptions } = options ?? {};\n const { accounts, accountNamesToAccountIds, activeAccountId } = useAccountsStore.getState();\n assert(\n accounts && accountNamesToAccountIds && activeAccountId,\n `can't use validateComment before accounts are initialized`,\n );\n const accountId = accountName ? accountNamesToAccountIds[accountName] : activeAccountId;\n const pkc = accounts[accountId]?.pkc;\n assert(pkc, `validateComment account '${accountName ?? activeAccountId}' not found`);\n return validateCommentWithPkc(comment, validateOptions, pkc);\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"]}
|
|
@@ -12,7 +12,7 @@ import { useAccount } from "./accounts/index.js";
|
|
|
12
12
|
import validator from "../lib/validator.js";
|
|
13
13
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
14
14
|
const log = Logger("bitsocial-react-hooks:communities:hooks");
|
|
15
|
-
import assert from "assert";
|
|
15
|
+
import assert from "../lib/assert.js";
|
|
16
16
|
import useInterval from "./utils/use-interval.js";
|
|
17
17
|
import createStore from "zustand";
|
|
18
18
|
import { resolveEnsTxtRecord } from "../lib/chain/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities.js","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,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,yCAAyC,CAAC,CAAC;AAC9D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAc5B,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,4BAA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AC,CAAC;QAChC,MAAM;KACP,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,gBAAwB,EACxB,cAA8B,EAC9B,EAAE;;IACF,IAAI,wBAAwB,CAAC;IAC7B,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,wBAAwB,GAAG,MAAM,mBAAmB,CAClD,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,EACL,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,IAAI,0CAAG,CAAC,CAAC,EAClC,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,OAAO,CACjC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,CAAC,qDAAqD,gBAAgB,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:hooks\");\nimport assert from \"assert\";\nimport {\n Community,\n CommunityStats,\n ChainProviders,\n UseResolvedCommunityAddressOptions,\n UseResolvedCommunityAddressResult,\n UseCommunityOptions,\n UseCommunityResult,\n UseCommunitiesOptions,\n UseCommunitiesResult,\n UseCommunityStatsOptions,\n UseCommunityStatsResult,\n} from \"../types\";\nimport useInterval from \"./utils/use-interval\";\nimport createStore from \"zustand\";\nimport { resolveEnsTxtRecord } from \"../lib/chain\";\nimport useCommunitiesStore from \"../stores/communities\";\nimport useAccountsStore from \"../stores/accounts\";\nimport shallow from \"zustand/shallow\";\nimport { getChainProviders, getPkcCommunityAddresses } from \"../lib/pkc-compat\";\nimport { getCommunityRefKey, getUniqueSortedCommunityRefs } from \"../lib/community-ref\";\n\nconst parseMaybeJson = (value: unknown) => (typeof value === \"string\" ? JSON.parse(value) : value);\n\nconst tryParseMaybeJson = (value: unknown) => {\n try {\n return parseMaybeJson(value);\n } catch {\n return value;\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === \"object\";\n\nconst isCommunityStatsPayload = (value: unknown): value is CommunityStats =>\n isRecord(value) &&\n (\"hourActiveUserCount\" in value || \"weekActiveUserCount\" in value || \"allPostCount\" in value);\n\nconst parseFetchedCommunityStats = (fetchedCid: unknown): CommunityStats => {\n const parsedCid = parseMaybeJson(fetchedCid);\n if (isCommunityStatsPayload(parsedCid)) {\n return parsedCid;\n }\n if (isRecord(parsedCid) && \"content\" in parsedCid) {\n const parsedContent = tryParseMaybeJson(parsedCid.content);\n if (isCommunityStatsPayload(parsedContent)) {\n return parsedContent;\n }\n }\n return parsedCid as CommunityStats;\n};\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {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 useCommunity(options?: UseCommunityOptions): UseCommunityResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunity options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community: communityInput, accountName, onlyIfCached } = opts;\n const account = useAccount({ accountName });\n const accountId = account?.id || \"\";\n validator.validateUseCommunityArguments({\n community: communityInput,\n communityAddress: (opts as any).communityAddress,\n account,\n });\n const communityKey = communityInput ? getCommunityRefKey(communityInput) : \"\";\n const storedCommunity = useCommunitiesStore((state: any) => state.communities[communityKey]);\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const errors = useCommunitiesStore((state: any) => state.errors[communityKey]);\n const syncStatus = useCommunitiesStore((state: any) => state.syncStatuses[communityKey]);\n const communityEditSummary = useAccountsStore((state: any) => {\n const accountEditsSummaries = state.accountsEditsSummaries[accountId] || {};\n const candidateCommunityKeys = [\n storedCommunity?.address,\n storedCommunity?.name,\n storedCommunity?.publicKey,\n communityInput?.name,\n communityInput?.publicKey,\n ];\n for (const candidateCommunityKey of candidateCommunityKeys) {\n if (\n typeof candidateCommunityKey === \"string\" &&\n accountEditsSummaries[candidateCommunityKey]\n ) {\n return accountEditsSummaries[candidateCommunityKey];\n }\n }\n });\n\n useEffect(() => {\n if (!communityInput || !account) {\n return;\n }\n if (!storedCommunity && !onlyIfCached) {\n // if community isn't already in store, add it\n addCommunityToStore(communityInput, account).catch((error: unknown) =>\n log.error(\"useCommunity addCommunityToStore error\", { communityInput, error }),\n );\n }\n }, [communityKey, account?.id]);\n\n if (account && communityInput) {\n log(\"useCommunity\", {\n community: communityInput,\n communityKey,\n storedCommunity,\n account,\n });\n }\n\n const mergedCommunity = useMemo(() => {\n if (!communityEditSummary) {\n return storedCommunity;\n }\n const localCommunityAddresses = getPkcCommunityAddresses(account?.pkc);\n const editedCommunityAddress = communityEditSummary.address?.value;\n const inputCommunityIdentifiers = [communityInput?.name, communityInput?.publicKey].filter(\n (communityIdentifier): communityIdentifier is string =>\n typeof communityIdentifier === \"string\",\n );\n if (\n !storedCommunity &&\n editedCommunityAddress &&\n !inputCommunityIdentifiers.some((communityIdentifier) =>\n localCommunityAddresses.includes(communityIdentifier),\n ) &&\n !localCommunityAddresses.includes(editedCommunityAddress)\n ) {\n return storedCommunity;\n }\n if (\n storedCommunity?.address &&\n editedCommunityAddress &&\n storedCommunity.address !== editedCommunityAddress\n ) {\n return storedCommunity;\n }\n const summaryValues = Object.fromEntries(\n Object.entries(communityEditSummary).map(([propertyName, propertySummary]: [string, any]) => [\n propertyName,\n propertySummary?.value,\n ]),\n );\n return {\n ...(storedCommunity || { address: communityInput?.name || communityInput?.publicKey }),\n ...summaryValues,\n };\n }, [account?.pkc, storedCommunity, communityInput, communityEditSummary]);\n\n let state = mergedCommunity?.updatingState || \"initializing\";\n // force succeeded even if the community is fecthing a new update\n if (mergedCommunity?.updatedAt) {\n state = \"succeeded\";\n }\n\n return useMemo(\n () => ({\n ...mergedCommunity,\n state,\n syncState: syncStatus?.syncState || (onlyIfCached ? \"stopped\" : \"initializing\"),\n hasCachedData: typeof mergedCommunity?.updatedAt === \"number\",\n lastFetchAttemptAt: syncStatus?.lastFetchAttemptAt,\n lastSuccessfulFetchAt: syncStatus?.lastSuccessfulFetchAt,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [mergedCommunity, communityKey, errors, onlyIfCached, syncStatus],\n );\n}\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {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 useCommunityStats(options?: UseCommunityStatsOptions): UseCommunityStatsResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunityStats options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community, accountName, onlyIfCached } = opts;\n validator.validateUseCommunityStatsArguments({\n community,\n communityAddress: (opts as any).communityAddress,\n });\n const account = useAccount({ accountName });\n const communityKey = community ? getCommunityRefKey(community) : \"\";\n const fetchedCommunity = useCommunity({ community, onlyIfCached });\n const communityStatsCid = fetchedCommunity?.statsCid;\n const communityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.communitiesStats[communityKey],\n );\n const setCommunityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.setCommunityStats,\n );\n const [fetchError, setFetchError] = useState<Error | undefined>();\n\n useEffect(() => {\n setFetchError(undefined);\n if (!communityKey || !communityStatsCid || !account) {\n return;\n }\n let cancelled = false;\n (async () => {\n let fetchedCid;\n try {\n fetchedCid = await account.pkc.fetchCid({ cid: communityStatsCid });\n fetchedCid = parseFetchedCommunityStats(fetchedCid);\n if (cancelled) {\n return;\n }\n setCommunityStats(communityKey, fetchedCid);\n } catch (error) {\n const normalizedError =\n error instanceof Error ? error : new Error(typeof error === \"string\" ? error : \"error\");\n if (cancelled) {\n return;\n }\n setFetchError(normalizedError);\n log.error(\"useCommunityStats pkc.fetchCid error\", {\n community,\n communityKey,\n communityStatsCid,\n fetchedCommunity,\n fetchedCid,\n error: normalizedError,\n });\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [communityStatsCid, account?.id, communityKey, setCommunityStats]);\n\n if (account && communityStatsCid) {\n log(\"useCommunityStats\", {\n community,\n communityKey,\n communityStatsCid,\n communityStats,\n fetchedCommunity,\n account,\n });\n }\n\n const state =\n !communityKey || !account || !communityStatsCid\n ? \"uninitialized\"\n : fetchError\n ? \"failed\"\n : communityStats\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\n return useMemo(\n () => ({\n ...communityStats,\n state,\n error: fetchError,\n errors: fetchError ? [fetchError] : [],\n }),\n [communityStats, state, fetchError],\n );\n}\n\ntype CommunitiesStatsState = {\n communitiesStats: { [communityAddress: string]: CommunityStats };\n setCommunityStats: Function;\n};\n\nconst useCommunitiesStatsStore = createStore<CommunitiesStatsState>((setState: Function) => ({\n communitiesStats: {},\n setCommunityStats: (communityAddress: string, communityStats: CommunityStats) =>\n setState((state: CommunitiesStatsState) => ({\n communitiesStats: { ...state.communitiesStats, [communityAddress]: communityStats },\n })),\n}));\n\n/**\n * @param communities - The communities to fetch, 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 useCommunities(options?: UseCommunitiesOptions): UseCommunitiesResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunities options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { communities: communitiesInput, accountName, onlyIfCached } = opts;\n const account = useAccount({ accountName });\n validator.validateUseCommunitiesArguments({\n communities: communitiesInput,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n account,\n });\n const normalizedCommunityRefs = useMemo(() => communitiesInput || [], [communitiesInput]);\n const communityKeys = useMemo(\n () => normalizedCommunityRefs.map(getCommunityRefKey),\n [normalizedCommunityRefs],\n );\n const communities: (Community | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.communities[communityKey || \"\"]),\n shallow,\n );\n const communitiesErrors: (Error[] | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.errors[communityKey || \"\"]),\n shallow,\n );\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n\n useEffect(() => {\n if (!normalizedCommunityRefs.length || !account) {\n return;\n }\n if (onlyIfCached) {\n return;\n }\n const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);\n for (const communityRef of uniqueCommunityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"useCommunities addCommunityToStore error\", { communityRef, error }),\n );\n }\n }, [account?.id, communityKeys.toString(), onlyIfCached, normalizedCommunityRefs]);\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useCommunities\", {\n requestedCommunities: normalizedCommunityRefs,\n communityKeys,\n communities,\n account,\n });\n }\n\n const errors = useMemo(\n () => communitiesErrors.flatMap((communityErrors) => communityErrors || []),\n [communitiesErrors],\n );\n const hasFailedCommunity = communities.some(\n (community, index) => !community && Boolean(communitiesErrors[index]?.length),\n );\n const state = hasFailedCommunity\n ? \"failed\"\n : communities.indexOf(undefined) === -1\n ? \"succeeded\"\n : \"fetching-ipns\";\n\n return useMemo(\n () => ({\n communities,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [communities, state, errors, communityKeys.toString()],\n );\n}\n\n// TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling\n/**\n * Returns all the owner communities created by pkc-js by calling pkc.listCommunities()\n */\nexport function useListCommunities(accountName?: string) {\n const account = useAccount({ accountName });\n const [communityAddresses, setCommunityAddresses] = useState<string[]>([]);\n\n const delay = 1000;\n const immediate = true;\n useInterval(\n () => {\n const pkc = account?.pkc;\n if (!pkc) return;\n const newAddrs = getPkcCommunityAddresses(pkc);\n if (newAddrs.toString() !== communityAddresses.toString()) {\n log(\"useListCommunities\", { communityAddresses });\n setCommunityAddresses(newAddrs);\n }\n },\n delay,\n immediate,\n );\n\n return communityAddresses;\n}\n\n/**\n * @param communityAddress - The community address to resolve to a public key, e.g. 'news.eth' resolves to '12D3KooW...'.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useResolvedCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport function useResolvedCommunityAddress(\n options?: UseResolvedCommunityAddressOptions,\n): UseResolvedCommunityAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useResolvedCommunityAddress options argument '${options}' not an object`,\n );\n let { communityAddress, accountName, cache } = options ?? {};\n\n // cache by default\n if (typeof cache !== \"boolean\") {\n cache = true;\n }\n\n // poll every 15 seconds, about the duration of an eth block\n let interval = 15000;\n // no point in polling often if caching is on\n if (cache) {\n interval = 1000 * 60 * 60 * 25;\n }\n\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [resolvedAddress, setResolvedAddress] = useState<string>();\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n\n let initialState = \"initializing\";\n // before those defined, nothing can happen\n if (options && account && communityAddress) {\n initialState = \"ready\";\n }\n\n useInterval(\n () => {\n if (!account || !communityAddress) {\n setResolvedAddress(undefined);\n setState(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n return;\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!communityAddress?.includes(\".\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"not a crypto domain\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n // only support resolving '.eth' for now\n if (!communityAddress?.endsWith(\".eth\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n setState(\"resolving\");\n const res = await resolveCommunityAddress(communityAddress, chainProviders);\n setState(\"succeeded\");\n if (res !== resolvedAddress) {\n setResolvedAddress(res);\n }\n } catch (error: any) {\n setErrors([...errors, error]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n log.error(\"useResolvedCommunityAddress resolveCommunityAddress error\", {\n communityAddress,\n chainProviders,\n error,\n });\n }\n })();\n },\n interval,\n true,\n [communityAddress, chainProviders],\n );\n\n // only support ENS at the moment\n const chainProvider = chainProviders?.[\"eth\"];\n\n // log('useResolvedCommunityAddress', {communityAddress, state, errors, resolvedAddress, chainProviders})\n return {\n resolvedAddress,\n chainProvider,\n state: state || initialState,\n error: errors[errors.length - 1],\n errors,\n };\n}\n\n// NOTE: resolveCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport const resolveCommunityAddress = async (\n communityAddress: string,\n chainProviders: ChainProviders,\n) => {\n let resolvedCommunityAddress;\n if (communityAddress.endsWith(\".eth\")) {\n resolvedCommunityAddress = await resolveEnsTxtRecord(\n communityAddress,\n \"community-address\",\n \"eth\",\n chainProviders?.[\"eth\"]?.urls?.[0],\n chainProviders?.[\"eth\"]?.chainId,\n );\n } else {\n throw Error(`resolveCommunityAddress invalid communityAddress '${communityAddress}'`);\n }\n return resolvedCommunityAddress;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"communities.js","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,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,yCAAyC,CAAC,CAAC;AAC9D,OAAO,MAAM,MAAM,eAAe,CAAC;AAcnC,OAAO,WAAW,MAAM,sBAAsB,CAAC;AA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,EACD,QAAQ,EACR,IAAI,EACJ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CACnC,CAAC;IAEF,iCAAiC;IACjC,MAAM,aAAa,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,CAAC;IAE9C,yGAAyG;IACzG,OAAO;QACL,eAAe;QACf,aAAa;QACb,KAAK,EAAE,KAAK,IAAI,YAAY;QAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,gBAAwB,EACxB,cAA8B,EAC9B,EAAE;;IACF,IAAI,wBAAwB,CAAC;IAC7B,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,wBAAwB,GAAG,MAAM,mBAAmB,CAClD,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,EACL,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,IAAI,0CAAG,CAAC,CAAC,EAClC,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,OAAO,CACjC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,CAAC,qDAAqD,gBAAgB,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:hooks\");\nimport assert from \"../lib/assert\";\nimport {\n Community,\n CommunityStats,\n ChainProviders,\n UseResolvedCommunityAddressOptions,\n UseResolvedCommunityAddressResult,\n UseCommunityOptions,\n UseCommunityResult,\n UseCommunitiesOptions,\n UseCommunitiesResult,\n UseCommunityStatsOptions,\n UseCommunityStatsResult,\n} from \"../types\";\nimport useInterval from \"./utils/use-interval\";\nimport createStore from \"zustand\";\nimport { resolveEnsTxtRecord } from \"../lib/chain\";\nimport useCommunitiesStore from \"../stores/communities\";\nimport useAccountsStore from \"../stores/accounts\";\nimport shallow from \"zustand/shallow\";\nimport { getChainProviders, getPkcCommunityAddresses } from \"../lib/pkc-compat\";\nimport { getCommunityRefKey, getUniqueSortedCommunityRefs } from \"../lib/community-ref\";\n\nconst parseMaybeJson = (value: unknown) => (typeof value === \"string\" ? JSON.parse(value) : value);\n\nconst tryParseMaybeJson = (value: unknown) => {\n try {\n return parseMaybeJson(value);\n } catch {\n return value;\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === \"object\";\n\nconst isCommunityStatsPayload = (value: unknown): value is CommunityStats =>\n isRecord(value) &&\n (\"hourActiveUserCount\" in value || \"weekActiveUserCount\" in value || \"allPostCount\" in value);\n\nconst parseFetchedCommunityStats = (fetchedCid: unknown): CommunityStats => {\n const parsedCid = parseMaybeJson(fetchedCid);\n if (isCommunityStatsPayload(parsedCid)) {\n return parsedCid;\n }\n if (isRecord(parsedCid) && \"content\" in parsedCid) {\n const parsedContent = tryParseMaybeJson(parsedCid.content);\n if (isCommunityStatsPayload(parsedContent)) {\n return parsedContent;\n }\n }\n return parsedCid as CommunityStats;\n};\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {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 useCommunity(options?: UseCommunityOptions): UseCommunityResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunity options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community: communityInput, accountName, onlyIfCached } = opts;\n const account = useAccount({ accountName });\n const accountId = account?.id || \"\";\n validator.validateUseCommunityArguments({\n community: communityInput,\n communityAddress: (opts as any).communityAddress,\n account,\n });\n const communityKey = communityInput ? getCommunityRefKey(communityInput) : \"\";\n const storedCommunity = useCommunitiesStore((state: any) => state.communities[communityKey]);\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const errors = useCommunitiesStore((state: any) => state.errors[communityKey]);\n const syncStatus = useCommunitiesStore((state: any) => state.syncStatuses[communityKey]);\n const communityEditSummary = useAccountsStore((state: any) => {\n const accountEditsSummaries = state.accountsEditsSummaries[accountId] || {};\n const candidateCommunityKeys = [\n storedCommunity?.address,\n storedCommunity?.name,\n storedCommunity?.publicKey,\n communityInput?.name,\n communityInput?.publicKey,\n ];\n for (const candidateCommunityKey of candidateCommunityKeys) {\n if (\n typeof candidateCommunityKey === \"string\" &&\n accountEditsSummaries[candidateCommunityKey]\n ) {\n return accountEditsSummaries[candidateCommunityKey];\n }\n }\n });\n\n useEffect(() => {\n if (!communityInput || !account) {\n return;\n }\n if (!storedCommunity && !onlyIfCached) {\n // if community isn't already in store, add it\n addCommunityToStore(communityInput, account).catch((error: unknown) =>\n log.error(\"useCommunity addCommunityToStore error\", { communityInput, error }),\n );\n }\n }, [communityKey, account?.id]);\n\n if (account && communityInput) {\n log(\"useCommunity\", {\n community: communityInput,\n communityKey,\n storedCommunity,\n account,\n });\n }\n\n const mergedCommunity = useMemo(() => {\n if (!communityEditSummary) {\n return storedCommunity;\n }\n const localCommunityAddresses = getPkcCommunityAddresses(account?.pkc);\n const editedCommunityAddress = communityEditSummary.address?.value;\n const inputCommunityIdentifiers = [communityInput?.name, communityInput?.publicKey].filter(\n (communityIdentifier): communityIdentifier is string =>\n typeof communityIdentifier === \"string\",\n );\n if (\n !storedCommunity &&\n editedCommunityAddress &&\n !inputCommunityIdentifiers.some((communityIdentifier) =>\n localCommunityAddresses.includes(communityIdentifier),\n ) &&\n !localCommunityAddresses.includes(editedCommunityAddress)\n ) {\n return storedCommunity;\n }\n if (\n storedCommunity?.address &&\n editedCommunityAddress &&\n storedCommunity.address !== editedCommunityAddress\n ) {\n return storedCommunity;\n }\n const summaryValues = Object.fromEntries(\n Object.entries(communityEditSummary).map(([propertyName, propertySummary]: [string, any]) => [\n propertyName,\n propertySummary?.value,\n ]),\n );\n return {\n ...(storedCommunity || { address: communityInput?.name || communityInput?.publicKey }),\n ...summaryValues,\n };\n }, [account?.pkc, storedCommunity, communityInput, communityEditSummary]);\n\n let state = mergedCommunity?.updatingState || \"initializing\";\n // force succeeded even if the community is fecthing a new update\n if (mergedCommunity?.updatedAt) {\n state = \"succeeded\";\n }\n\n return useMemo(\n () => ({\n ...mergedCommunity,\n state,\n syncState: syncStatus?.syncState || (onlyIfCached ? \"stopped\" : \"initializing\"),\n hasCachedData: typeof mergedCommunity?.updatedAt === \"number\",\n lastFetchAttemptAt: syncStatus?.lastFetchAttemptAt,\n lastSuccessfulFetchAt: syncStatus?.lastSuccessfulFetchAt,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [mergedCommunity, communityKey, errors, onlyIfCached, syncStatus],\n );\n}\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {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 useCommunityStats(options?: UseCommunityStatsOptions): UseCommunityStatsResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunityStats options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community, accountName, onlyIfCached } = opts;\n validator.validateUseCommunityStatsArguments({\n community,\n communityAddress: (opts as any).communityAddress,\n });\n const account = useAccount({ accountName });\n const communityKey = community ? getCommunityRefKey(community) : \"\";\n const fetchedCommunity = useCommunity({ community, onlyIfCached });\n const communityStatsCid = fetchedCommunity?.statsCid;\n const communityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.communitiesStats[communityKey],\n );\n const setCommunityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.setCommunityStats,\n );\n const [fetchError, setFetchError] = useState<Error | undefined>();\n\n useEffect(() => {\n setFetchError(undefined);\n if (!communityKey || !communityStatsCid || !account) {\n return;\n }\n let cancelled = false;\n (async () => {\n let fetchedCid;\n try {\n fetchedCid = await account.pkc.fetchCid({ cid: communityStatsCid });\n fetchedCid = parseFetchedCommunityStats(fetchedCid);\n if (cancelled) {\n return;\n }\n setCommunityStats(communityKey, fetchedCid);\n } catch (error) {\n const normalizedError =\n error instanceof Error ? error : new Error(typeof error === \"string\" ? error : \"error\");\n if (cancelled) {\n return;\n }\n setFetchError(normalizedError);\n log.error(\"useCommunityStats pkc.fetchCid error\", {\n community,\n communityKey,\n communityStatsCid,\n fetchedCommunity,\n fetchedCid,\n error: normalizedError,\n });\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [communityStatsCid, account?.id, communityKey, setCommunityStats]);\n\n if (account && communityStatsCid) {\n log(\"useCommunityStats\", {\n community,\n communityKey,\n communityStatsCid,\n communityStats,\n fetchedCommunity,\n account,\n });\n }\n\n const state =\n !communityKey || !account || !communityStatsCid\n ? \"uninitialized\"\n : fetchError\n ? \"failed\"\n : communityStats\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\n return useMemo(\n () => ({\n ...communityStats,\n state,\n error: fetchError,\n errors: fetchError ? [fetchError] : [],\n }),\n [communityStats, state, fetchError],\n );\n}\n\ntype CommunitiesStatsState = {\n communitiesStats: { [communityAddress: string]: CommunityStats };\n setCommunityStats: Function;\n};\n\nconst useCommunitiesStatsStore = createStore<CommunitiesStatsState>((setState: Function) => ({\n communitiesStats: {},\n setCommunityStats: (communityAddress: string, communityStats: CommunityStats) =>\n setState((state: CommunitiesStatsState) => ({\n communitiesStats: { ...state.communitiesStats, [communityAddress]: communityStats },\n })),\n}));\n\n/**\n * @param communities - The communities to fetch, 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 useCommunities(options?: UseCommunitiesOptions): UseCommunitiesResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunities options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { communities: communitiesInput, accountName, onlyIfCached } = opts;\n const account = useAccount({ accountName });\n validator.validateUseCommunitiesArguments({\n communities: communitiesInput,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n account,\n });\n const normalizedCommunityRefs = useMemo(() => communitiesInput || [], [communitiesInput]);\n const communityKeys = useMemo(\n () => normalizedCommunityRefs.map(getCommunityRefKey),\n [normalizedCommunityRefs],\n );\n const communities: (Community | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.communities[communityKey || \"\"]),\n shallow,\n );\n const communitiesErrors: (Error[] | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.errors[communityKey || \"\"]),\n shallow,\n );\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n\n useEffect(() => {\n if (!normalizedCommunityRefs.length || !account) {\n return;\n }\n if (onlyIfCached) {\n return;\n }\n const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);\n for (const communityRef of uniqueCommunityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"useCommunities addCommunityToStore error\", { communityRef, error }),\n );\n }\n }, [account?.id, communityKeys.toString(), onlyIfCached, normalizedCommunityRefs]);\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useCommunities\", {\n requestedCommunities: normalizedCommunityRefs,\n communityKeys,\n communities,\n account,\n });\n }\n\n const errors = useMemo(\n () => communitiesErrors.flatMap((communityErrors) => communityErrors || []),\n [communitiesErrors],\n );\n const hasFailedCommunity = communities.some(\n (community, index) => !community && Boolean(communitiesErrors[index]?.length),\n );\n const state = hasFailedCommunity\n ? \"failed\"\n : communities.indexOf(undefined) === -1\n ? \"succeeded\"\n : \"fetching-ipns\";\n\n return useMemo(\n () => ({\n communities,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [communities, state, errors, communityKeys.toString()],\n );\n}\n\n// TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling\n/**\n * Returns all the owner communities created by pkc-js by calling pkc.listCommunities()\n */\nexport function useListCommunities(accountName?: string) {\n const account = useAccount({ accountName });\n const [communityAddresses, setCommunityAddresses] = useState<string[]>([]);\n\n const delay = 1000;\n const immediate = true;\n useInterval(\n () => {\n const pkc = account?.pkc;\n if (!pkc) return;\n const newAddrs = getPkcCommunityAddresses(pkc);\n if (newAddrs.toString() !== communityAddresses.toString()) {\n log(\"useListCommunities\", { communityAddresses });\n setCommunityAddresses(newAddrs);\n }\n },\n delay,\n immediate,\n );\n\n return communityAddresses;\n}\n\n/**\n * @param communityAddress - The community address to resolve to a public key, e.g. 'news.eth' resolves to '12D3KooW...'.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useResolvedCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport function useResolvedCommunityAddress(\n options?: UseResolvedCommunityAddressOptions,\n): UseResolvedCommunityAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useResolvedCommunityAddress options argument '${options}' not an object`,\n );\n let { communityAddress, accountName, cache } = options ?? {};\n\n // cache by default\n if (typeof cache !== \"boolean\") {\n cache = true;\n }\n\n // poll every 15 seconds, about the duration of an eth block\n let interval = 15000;\n // no point in polling often if caching is on\n if (cache) {\n interval = 1000 * 60 * 60 * 25;\n }\n\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [resolvedAddress, setResolvedAddress] = useState<string>();\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n\n let initialState = \"initializing\";\n // before those defined, nothing can happen\n if (options && account && communityAddress) {\n initialState = \"ready\";\n }\n\n useInterval(\n () => {\n if (!account || !communityAddress) {\n setResolvedAddress(undefined);\n setState(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n return;\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!communityAddress?.includes(\".\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"not a crypto domain\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n // only support resolving '.eth' for now\n if (!communityAddress?.endsWith(\".eth\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n setState(\"resolving\");\n const res = await resolveCommunityAddress(communityAddress, chainProviders);\n setState(\"succeeded\");\n if (res !== resolvedAddress) {\n setResolvedAddress(res);\n }\n } catch (error: any) {\n setErrors([...errors, error]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n log.error(\"useResolvedCommunityAddress resolveCommunityAddress error\", {\n communityAddress,\n chainProviders,\n error,\n });\n }\n })();\n },\n interval,\n true,\n [communityAddress, chainProviders],\n );\n\n // only support ENS at the moment\n const chainProvider = chainProviders?.[\"eth\"];\n\n // log('useResolvedCommunityAddress', {communityAddress, state, errors, resolvedAddress, chainProviders})\n return {\n resolvedAddress,\n chainProvider,\n state: state || initialState,\n error: errors[errors.length - 1],\n errors,\n };\n}\n\n// NOTE: resolveCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport const resolveCommunityAddress = async (\n communityAddress: string,\n chainProviders: ChainProviders,\n) => {\n let resolvedCommunityAddress;\n if (communityAddress.endsWith(\".eth\")) {\n resolvedCommunityAddress = await resolveEnsTxtRecord(\n communityAddress,\n \"community-address\",\n \"eth\",\n chainProviders?.[\"eth\"]?.urls?.[0],\n chainProviders?.[\"eth\"]?.chainId,\n );\n } else {\n throw Error(`resolveCommunityAddress invalid communityAddress '${communityAddress}'`);\n }\n return resolvedCommunityAddress;\n};\n"]}
|
|
@@ -12,7 +12,7 @@ import { useAccount } from "../accounts/index.js";
|
|
|
12
12
|
import validator from "../../lib/validator.js";
|
|
13
13
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
14
14
|
const log = Logger("bitsocial-react-hooks:feeds:hooks");
|
|
15
|
-
import assert from "assert";
|
|
15
|
+
import assert from "../../lib/assert.js";
|
|
16
16
|
import useFeedsStore from "../../stores/feeds/index.js";
|
|
17
17
|
import useAccountsStore from "../../stores/accounts/index.js";
|
|
18
18
|
import { addCommentModerationToComments } from "../../lib/utils/comment-moderation.js";
|