@bitsocial/bitsocial-react-hooks 0.1.14 → 0.1.16
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 +24 -0
- package/README.md +34 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -1
- package/dist/hooks/accounts/accounts.js +41 -5
- package/dist/hooks/accounts/accounts.js.map +1 -1
- package/dist/hooks/actions/actions.d.ts +2 -1
- package/dist/hooks/actions/actions.d.ts.map +1 -1
- package/dist/hooks/actions/actions.js +54 -0
- package/dist/hooks/actions/actions.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/pkc-js/pkc-js-mock.d.ts +6 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.js +23 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts +2 -1
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +62 -5
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/utils.d.ts +1 -0
- package/dist/stores/accounts/utils.d.ts.map +1 -1
- package/dist/stores/accounts/utils.js +21 -3
- package/dist/stores/accounts/utils.js.map +1 -1
- package/dist/stores/comments/comments-store.d.ts.map +1 -1
- package/dist/stores/comments/comments-store.js +65 -1
- package/dist/stores/comments/comments-store.js.map +1 -1
- package/dist/types.d.ts +27 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +16 -10
|
@@ -5,6 +5,7 @@ export declare const sanitizeAccountCommentForState: (comment: Comment) => any;
|
|
|
5
5
|
export declare const sanitizeStoredAccountComment: (comment: Comment) => any;
|
|
6
6
|
export declare const getAccountCommentsIndex: (accountComments: AccountComment[] | undefined) => AccountCommentsIndex;
|
|
7
7
|
export declare const getAccountsCommentsIndexes: (accountsComments: AccountsComments) => AccountsCommentsIndexes;
|
|
8
|
+
export declare const COMMENT_MODERATION_AUTHOR_SUMMARY_KEY = "commentModeration.author";
|
|
8
9
|
export declare const getAccountEditPropertySummary: (accountEdits: AccountEdit[] | undefined) => {
|
|
9
10
|
[propertyName: string]: import("../../types.js").AccountEditPropertySummary;
|
|
10
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,6BAA6B,EAC7B,OAAO,EACP,WAAW,EACX,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAoBrB,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,aAAa,WAAW,QAiB/E,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAAI,kBAAkB,gBAAgB,kCAalF,CAAC;AA0FF,eAAO,MAAM,8BAA8B,GAAI,SAAS,OAAO,QAuB9D,CAAC;AAEF,eAAO,MAAM,4BAA4B,GAAI,SAAS,OAAO,QAoB5D,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,iBAAiB,cAAc,EAAE,GAAG,SAAS,KAC5C,oBAoBF,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,kBAAkB,gBAAgB,4BAM5E,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,6BAA6B,EAC7B,OAAO,EACP,WAAW,EACX,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAoBrB,eAAO,MAAM,qBAAqB,GAA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AO;kDAsFD,WAAW,EAAE,GAAG,SAAS;;;4CAwB/B;QACpD,CAAC,4BAA4B,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;KACvD;uCA4BsD,MAAM,KAAG,OAAO,CAAC,qBAAqB,CAAC;uDA8H7B,gBAAgB;wBAC9B,cAAc;mBAAa,MAAM;;sCAoBpC,OAAO;iDAoBI,OAAO;iBApL9C,CAAC,YAAY,OAAO,CAAC,CAAC,CAAC,EAAE,KAAG,OAAO,CAAC,CAAC,CAAC;CAkNzD,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
|
@@ -7,6 +7,17 @@ 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 assert from "assert";
|
|
11
22
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
12
23
|
const log = Logger("bitsocial-react-hooks:accounts:stores");
|
|
@@ -190,11 +201,17 @@ const accountEditNonPropertyNames = new Set([
|
|
|
190
201
|
"communityAddress",
|
|
191
202
|
"timestamp",
|
|
192
203
|
]);
|
|
204
|
+
export const COMMENT_MODERATION_AUTHOR_SUMMARY_KEY = "commentModeration.author";
|
|
193
205
|
const normalizeAccountEditForSummary = (accountEdit) => {
|
|
194
206
|
var _a;
|
|
195
207
|
const normalizedAccountEdit = Object.assign({}, accountEdit);
|
|
196
|
-
|
|
197
|
-
|
|
208
|
+
const commentModeration = normalizedAccountEdit.commentModeration;
|
|
209
|
+
if (commentModeration && typeof commentModeration === "object") {
|
|
210
|
+
const { author } = commentModeration, commentModerationProperties = __rest(commentModeration, ["author"]);
|
|
211
|
+
Object.assign(normalizedAccountEdit, commentModerationProperties);
|
|
212
|
+
if (Object.prototype.hasOwnProperty.call(commentModeration, "author")) {
|
|
213
|
+
normalizedAccountEdit[COMMENT_MODERATION_AUTHOR_SUMMARY_KEY] = author;
|
|
214
|
+
}
|
|
198
215
|
delete normalizedAccountEdit.commentModeration;
|
|
199
216
|
}
|
|
200
217
|
const communityEdit = (_a = normalizedAccountEdit.communityEdit) !== null && _a !== void 0 ? _a : normalizedAccountEdit.communityEdit;
|
|
@@ -211,7 +228,8 @@ export const getAccountEditPropertySummary = (accountEdits) => {
|
|
|
211
228
|
for (const accountEdit of accountEdits || []) {
|
|
212
229
|
const normalizedAccountEdit = normalizeAccountEditForSummary(accountEdit);
|
|
213
230
|
for (const propertyName in normalizedAccountEdit) {
|
|
214
|
-
if (normalizedAccountEdit[propertyName] === undefined
|
|
231
|
+
if ((normalizedAccountEdit[propertyName] === undefined &&
|
|
232
|
+
propertyName !== COMMENT_MODERATION_AUTHOR_SUMMARY_KEY) ||
|
|
215
233
|
accountEditNonPropertyNames.has(propertyName)) {
|
|
216
234
|
continue;
|
|
217
235
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAC5D,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kB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AQ,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,0CAAE,KAAK,CAAC;IACzF,IAAI,OAAO,kBAAkB,KAAK,QAAQ,EAAE,CAAC;QAC3C,OAAO,kBAAkB,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,6FAA6F;IAC7F,yEAAyE;AAC3E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,OAAgB,EAAE,EAAE;IACpE,OAAO,qBAAQ,OAAO,CAAE,CAAC;IACzB,IAAI,CAAC;QACH,OAAO,CAAC,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;YACxD,OAAO,EAAE,OAAO,CAAC,gBAAgB;SAClC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IACd,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,qBAAQ,OAAO,CAAC,MAAM,CAAE,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;YACtD,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO;SAChC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IACd,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG;IACZ,qBAAqB;IACrB,gCAAgC;IAChC,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,4BAA4B;IAC5B,6BAA6B;IAC7B,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,sBAAsB;IACtB,iCAAiC;IACjC,UAAU;CACX,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import {\n Account,\n Role,\n Communities,\n AccountComment,\n AccountsComments,\n AccountsCommentsIndexes,\n AccountCommentsIndex,\n CommentCidsToAccountsComments,\n Comment,\n AccountEdit,\n AccountEditsSummary,\n} from \"../../types\";\nimport assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport commentsStore from \"../comments\";\nimport repliesPagesStore from \"../replies-pages\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport PkcJs from \"../../lib/pkc-js\";\n\nconst getAuthorAddressRolesFromCommunities = (authorAddress: string, communities: Communities) => {\n const roles: { [communityAddress: string]: Role } = {};\n for (const communityAddress in communities) {\n const role = communities[communityAddress]?.roles?.[authorAddress];\n if (role) {\n roles[communityAddress] = role;\n }\n }\n return roles;\n};\n\nexport const getAccountCommunities = (account: Account, communities: Communities) => {\n assert(\n account?.author?.address && typeof account?.author?.address === \"string\",\n `accountsStore utils getAccountCommunities invalid account.author.address '${account?.author?.address}'`,\n );\n assert(\n communities && typeof communities === \"object\",\n `accountsStore utils getAccountCommunities invalid communities '${communities}'`,\n );\n\n const roles = getAuthorAddressRolesFromCommunities(account.author.address, communities);\n const accountCommunities = { ...account.communities };\n for (const communityAddress in roles) {\n accountCommunities[communityAddress] = { ...accountCommunities[communityAddress] };\n accountCommunities[communityAddress].role = roles[communityAddress];\n }\n return accountCommunities;\n};\n\nexport const getCommentCidsToAccountsComments = (accountsComments: AccountsComments) => {\n const commentCidsToAccountsComments: CommentCidsToAccountsComments = {};\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n if (accountComment.cid) {\n commentCidsToAccountsComments[accountComment.cid] = {\n accountId,\n accountCommentIndex: accountComment.index,\n };\n }\n }\n }\n return commentCidsToAccountsComments;\n};\n\nconst cloneWithoutFunctions = (value: any): any => {\n if (Array.isArray(value)) {\n return value\n .map((entry) => cloneWithoutFunctions(entry))\n .filter((entry) => entry !== undefined);\n }\n if (!value || typeof value !== \"object\") {\n return typeof value === \"function\" ? undefined : value;\n }\n\n const clonedValue: Record<string, any> = {};\n for (const key in value) {\n if (typeof value[key] === \"function\") {\n continue;\n }\n const clonedChild = cloneWithoutFunctions(value[key]);\n if (clonedChild !== undefined) {\n clonedValue[key] = clonedChild;\n }\n }\n return clonedValue;\n};\n\nconst compactStoredCommentAuthor = (author: any) => {\n if (!author || typeof author !== \"object\") {\n return undefined;\n }\n\n const compactAuthor = cloneWithoutFunctions({\n address: author.address,\n shortAddress: author.shortAddress,\n displayName: author.displayName,\n avatar: author.avatar,\n flair: author.flair,\n });\n\n return compactAuthor && Object.keys(compactAuthor).length > 0 ? compactAuthor : undefined;\n};\n\nconst compactStoredOriginalComment = (originalComment: any) => {\n if (!originalComment || typeof originalComment !== \"object\") {\n return undefined;\n }\n\n const compactOriginalComment = cloneWithoutFunctions({\n cid: originalComment.cid,\n content: originalComment.content,\n title: originalComment.title,\n link: originalComment.link,\n linkWidth: originalComment.linkWidth,\n linkHeight: originalComment.linkHeight,\n linkHtmlTagName: originalComment.linkHtmlTagName,\n thumbnailUrl: originalComment.thumbnailUrl,\n media: originalComment.media,\n spoiler: originalComment.spoiler,\n nsfw: originalComment.nsfw,\n deleted: originalComment.deleted,\n removed: originalComment.removed,\n reason: originalComment.reason,\n quotedCids: originalComment.quotedCids,\n parentCid: originalComment.parentCid,\n postCid: originalComment.postCid,\n communityAddress: originalComment.communityAddress,\n timestamp: originalComment.timestamp,\n author: compactStoredCommentAuthor(originalComment.author),\n });\n\n return compactOriginalComment && Object.keys(compactOriginalComment).length > 0\n ? compactOriginalComment\n : undefined;\n};\n\nconst compactStoredReplies = (replies: any) => {\n if (!replies || typeof replies !== \"object\") {\n return undefined;\n }\n\n const compactReplies = cloneWithoutFunctions(\n Object.fromEntries(\n Object.entries(replies).filter(\n ([replyKey]) => replyKey !== \"pages\" && replyKey !== \"clients\",\n ),\n ),\n );\n\n return compactReplies && Object.keys(compactReplies).length > 0 ? compactReplies : undefined;\n};\n\nexport const sanitizeAccountCommentForState = (comment: Comment) => {\n const sanitizedComment = cloneWithoutFunctions({\n ...comment,\n signer: undefined,\n raw: undefined,\n replies: comment?.replies\n ? Object.fromEntries(\n Object.entries(comment.replies).filter(([replyKey]) => replyKey !== \"pages\"),\n )\n : comment?.replies,\n });\n\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies?.pages) {\n sanitizedComment.replies = { ...sanitizedComment.replies };\n delete sanitizedComment.replies.pages;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n return sanitizedComment;\n};\n\nexport const sanitizeStoredAccountComment = (comment: Comment) => {\n const preprocessedComment = {\n ...comment,\n signer: undefined,\n clients: undefined,\n raw: undefined,\n replies: compactStoredReplies(comment?.replies),\n original: comment?.edit ? compactStoredOriginalComment(comment.original) : undefined,\n };\n const sanitizedComment = cloneWithoutFunctions(preprocessedComment);\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n if (sanitizedComment?.original && Object.keys(sanitizedComment.original).length === 0) {\n delete sanitizedComment.original;\n }\n return sanitizedComment;\n};\n\nexport const getAccountCommentsIndex = (\n accountComments: AccountComment[] | undefined,\n): AccountCommentsIndex => {\n const index: AccountCommentsIndex = {\n byCommunityAddress: {},\n byParentCid: {},\n };\n for (const accountComment of accountComments || []) {\n if (accountComment.communityAddress) {\n if (!index.byCommunityAddress[accountComment.communityAddress]) {\n index.byCommunityAddress[accountComment.communityAddress] = [];\n }\n index.byCommunityAddress[accountComment.communityAddress].push(accountComment.index);\n }\n if (accountComment.parentCid) {\n if (!index.byParentCid[accountComment.parentCid]) {\n index.byParentCid[accountComment.parentCid] = [];\n }\n index.byParentCid[accountComment.parentCid].push(accountComment.index);\n }\n }\n return index;\n};\n\nexport const getAccountsCommentsIndexes = (accountsComments: AccountsComments) => {\n const indexes: AccountsCommentsIndexes = {};\n for (const accountId in accountsComments) {\n indexes[accountId] = getAccountCommentsIndex(accountsComments[accountId]);\n }\n return indexes;\n};\n\nconst accountEditNonPropertyNames = new Set([\n \"author\",\n \"signer\",\n \"clientId\",\n \"commentCid\",\n \"communityAddress\",\n \"communityAddress\",\n \"timestamp\",\n]);\n\nconst normalizeAccountEditForSummary = (accountEdit: AccountEdit) => {\n const normalizedAccountEdit = { ...accountEdit };\n if (normalizedAccountEdit.commentModeration) {\n Object.assign(normalizedAccountEdit, normalizedAccountEdit.commentModeration);\n delete normalizedAccountEdit.commentModeration;\n }\n const communityEdit = normalizedAccountEdit.communityEdit ?? normalizedAccountEdit.communityEdit;\n if (communityEdit && typeof communityEdit === \"object\") {\n Object.assign(normalizedAccountEdit, communityEdit);\n }\n delete normalizedAccountEdit.communityEdit;\n delete normalizedAccountEdit.communityEdit;\n return normalizedAccountEdit;\n};\n\nexport const getAccountEditPropertySummary = (accountEdits: AccountEdit[] | undefined) => {\n const accountEditPropertySummary: AccountEditsSummary[string] = {};\n for (const accountEdit of accountEdits || []) {\n const normalizedAccountEdit = normalizeAccountEditForSummary(accountEdit);\n for (const propertyName in normalizedAccountEdit) {\n if (\n normalizedAccountEdit[propertyName] === undefined ||\n accountEditNonPropertyNames.has(propertyName)\n ) {\n continue;\n }\n const previousTimestamp = accountEditPropertySummary[propertyName]?.timestamp || 0;\n if ((normalizedAccountEdit.timestamp || 0) >= previousTimestamp) {\n accountEditPropertySummary[propertyName] = {\n timestamp: normalizedAccountEdit.timestamp,\n value: normalizedAccountEdit[propertyName],\n };\n }\n }\n }\n return accountEditPropertySummary;\n};\n\nexport const getAccountsEditsSummary = (accountEdits: {\n [commentCidOrCommunityAddress: string]: AccountEdit[];\n}) => {\n const summary: AccountEditsSummary = {};\n for (const target in accountEdits || {}) {\n summary[target] = getAccountEditPropertySummary(accountEdits[target]);\n }\n return summary;\n};\n\ninterface CommentLinkDimensions {\n linkWidth?: number;\n linkHeight?: number;\n linkHtmlTagName?: \"img\" | \"video\" | \"audio\";\n}\n\n// polyfill Promise.any, exported for test coverage of empty-array branch\nconst promiseAny = <T>(promises: Promise<T>[]): Promise<T> =>\n new Promise((res, rej) => {\n let count = promises.length;\n if (count === 0) return rej(Error(\"all promises rejected\"));\n promises.forEach((p) =>\n Promise.resolve(p)\n .then(res)\n .catch((e) => {\n if (--count === 0) rej(Error(\"all promises rejected\"));\n }),\n );\n });\n\nexport const fetchCommentLinkDimensions = async (link: string): Promise<CommentLinkDimensions> => {\n if (!link) {\n return {};\n }\n\n const fetchImageDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const image = new Image();\n image.onload = () => {\n // don't accept 0px value\n if (!image.width || !image.height) {\n return reject(Error(`failed fetching image dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: image.width,\n linkHeight: image.height,\n linkHtmlTagName: \"img\",\n });\n\n // remove image from memory\n try {\n image.src = \"\";\n } catch (e) {}\n };\n image.onerror = (error) => {\n reject(Error(`failed fetching image dimensions for url '${url}'`));\n };\n\n // max loading time\n const timeout = 10000;\n setTimeout(\n () =>\n reject(Error(`failed fetching image dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n image.src = url;\n });\n\n const fetchVideoDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const video = document.createElement(\"video\");\n video.muted = true;\n video.loop = false;\n video.addEventListener(\"loadeddata\", () => {\n // don't accept 0px value\n if (!video.videoWidth || !video.videoHeight) {\n return reject(Error(`failed fetching video dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: video.videoWidth,\n linkHeight: video.videoHeight,\n linkHtmlTagName: \"video\",\n });\n // prevent video from playing\n try {\n video.pause();\n } catch (e) {}\n // prevent video from loading\n try {\n video.src = \"\";\n } catch (e) {}\n });\n video.addEventListener(\"error\", (error) => {\n reject(Error(`failed fetching video dimensions for url '${url}'`));\n });\n\n // max loading time\n const timeout = 30000;\n setTimeout(\n () =>\n reject(Error(`failed fetching video dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n video.src = url;\n });\n\n const fetchAudio = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const audio = document.createElement(\"audio\");\n audio.addEventListener(\"loadeddata\", () => {\n resolve({\n linkHtmlTagName: \"audio\",\n });\n try {\n audio.pause();\n } catch {}\n try {\n audio.src = \"\";\n } catch {}\n });\n audio.addEventListener(\"error\", () =>\n reject(Error(`failed fetching audio html tag name for url '${url}'`)),\n );\n\n const timeout = 20000;\n setTimeout(\n () =>\n reject(\n Error(`failed fetching audio html tag name for url '${url}' timeout '${timeout}'`),\n ),\n timeout,\n );\n\n audio.src = url;\n });\n\n try {\n if (new URL(link).protocol !== \"https:\") {\n throw Error(`failed fetching comment.link dimensions for link '${link}' not https protocol`);\n }\n const dimensions = await promiseAny([\n fetchImageDimensions(link),\n fetchVideoDimensions(link),\n fetchAudio(link),\n ]);\n return dimensions;\n } catch (error: any) {\n log.error(\"fetchCommentLinkDimensions error\", { error, link });\n return {};\n }\n};\n\nexport const getInitAccountCommentsToUpdate = (accountsComments: AccountsComments) => {\n const accountCommentsToUpdate: { accountComment: AccountComment; accountId: string }[] = [];\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n accountCommentsToUpdate.push({ accountComment, accountId });\n }\n }\n\n // update newer comments first, more likely to have notifications\n accountCommentsToUpdate.sort((a, b) => b.accountComment.timestamp - a.accountComment.timestamp);\n\n // updating too many comments during init slows down fetching comments/subs\n if (accountCommentsToUpdate.length > 10) {\n accountCommentsToUpdate.length = 10;\n }\n\n // TODO: add some algo to fetch all notifications (even old), but not on init\n // during downtimes when we're not fetching anything else\n return accountCommentsToUpdate;\n};\n\nexport const getAccountCommentDepth = (comment: Comment) => {\n if (!comment.parentCid) {\n return 0;\n }\n let parentCommentDepth = commentsStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = repliesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = communitiesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n // if can't find the parent comment depth anywhere, don't include it with the account comment\n // it will be added automatically when challenge verification is received\n};\n\nexport const addShortAddressesToAccountComment = (comment: Comment) => {\n comment = { ...comment };\n try {\n comment.shortCommunityAddress = PkcJs.PKC.getShortAddress({\n address: comment.communityAddress,\n });\n } catch (e) {}\n try {\n comment.author = { ...comment.author };\n comment.author.shortAddress = PkcJs.PKC.getShortAddress({\n address: comment.author.address,\n });\n } catch (e) {}\n return comment;\n};\n\nconst utils = {\n getAccountCommunities,\n getCommentCidsToAccountsComments,\n getAccountCommentsIndex,\n getAccountsCommentsIndexes,\n sanitizeAccountCommentForState,\n sanitizeStoredAccountComment,\n getAccountEditPropertySummary,\n getAccountsEditsSummary,\n fetchCommentLinkDimensions,\n getInitAccountCommentsToUpdate,\n getAccountCommentDepth,\n addShortAddressesToAccountComment,\n promiseAny,\n};\n\nexport default utils;\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAaA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAC5D,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,MAAM,kBAAkB,CAAC;AAErC,MAAM,oCAAoC,GAAG,CAAC,aAAqB,EAAE,WAAwB,EAAE,EAAE;;IAC/F,MAAM,KAAK,GAAyC,EAAE,CAAC;IACvD,KAAK,MAAM,gBAAgB,IAAI,WAAW,EAAE,CAAC;QAC3C,MAAM,IAAI,GA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AC","sourcesContent":["import {\n Account,\n Role,\n Communities,\n AccountComment,\n AccountsComments,\n AccountsCommentsIndexes,\n AccountCommentsIndex,\n CommentCidsToAccountsComments,\n Comment,\n AccountEdit,\n AccountEditsSummary,\n} from \"../../types\";\nimport assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport commentsStore from \"../comments\";\nimport repliesPagesStore from \"../replies-pages\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport PkcJs from \"../../lib/pkc-js\";\n\nconst getAuthorAddressRolesFromCommunities = (authorAddress: string, communities: Communities) => {\n const roles: { [communityAddress: string]: Role } = {};\n for (const communityAddress in communities) {\n const role = communities[communityAddress]?.roles?.[authorAddress];\n if (role) {\n roles[communityAddress] = role;\n }\n }\n return roles;\n};\n\nexport const getAccountCommunities = (account: Account, communities: Communities) => {\n assert(\n account?.author?.address && typeof account?.author?.address === \"string\",\n `accountsStore utils getAccountCommunities invalid account.author.address '${account?.author?.address}'`,\n );\n assert(\n communities && typeof communities === \"object\",\n `accountsStore utils getAccountCommunities invalid communities '${communities}'`,\n );\n\n const roles = getAuthorAddressRolesFromCommunities(account.author.address, communities);\n const accountCommunities = { ...account.communities };\n for (const communityAddress in roles) {\n accountCommunities[communityAddress] = { ...accountCommunities[communityAddress] };\n accountCommunities[communityAddress].role = roles[communityAddress];\n }\n return accountCommunities;\n};\n\nexport const getCommentCidsToAccountsComments = (accountsComments: AccountsComments) => {\n const commentCidsToAccountsComments: CommentCidsToAccountsComments = {};\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n if (accountComment.cid) {\n commentCidsToAccountsComments[accountComment.cid] = {\n accountId,\n accountCommentIndex: accountComment.index,\n };\n }\n }\n }\n return commentCidsToAccountsComments;\n};\n\nconst cloneWithoutFunctions = (value: any): any => {\n if (Array.isArray(value)) {\n return value\n .map((entry) => cloneWithoutFunctions(entry))\n .filter((entry) => entry !== undefined);\n }\n if (!value || typeof value !== \"object\") {\n return typeof value === \"function\" ? undefined : value;\n }\n\n const clonedValue: Record<string, any> = {};\n for (const key in value) {\n if (typeof value[key] === \"function\") {\n continue;\n }\n const clonedChild = cloneWithoutFunctions(value[key]);\n if (clonedChild !== undefined) {\n clonedValue[key] = clonedChild;\n }\n }\n return clonedValue;\n};\n\nconst compactStoredCommentAuthor = (author: any) => {\n if (!author || typeof author !== \"object\") {\n return undefined;\n }\n\n const compactAuthor = cloneWithoutFunctions({\n address: author.address,\n shortAddress: author.shortAddress,\n displayName: author.displayName,\n avatar: author.avatar,\n flair: author.flair,\n });\n\n return compactAuthor && Object.keys(compactAuthor).length > 0 ? compactAuthor : undefined;\n};\n\nconst compactStoredOriginalComment = (originalComment: any) => {\n if (!originalComment || typeof originalComment !== \"object\") {\n return undefined;\n }\n\n const compactOriginalComment = cloneWithoutFunctions({\n cid: originalComment.cid,\n content: originalComment.content,\n title: originalComment.title,\n link: originalComment.link,\n linkWidth: originalComment.linkWidth,\n linkHeight: originalComment.linkHeight,\n linkHtmlTagName: originalComment.linkHtmlTagName,\n thumbnailUrl: originalComment.thumbnailUrl,\n media: originalComment.media,\n spoiler: originalComment.spoiler,\n nsfw: originalComment.nsfw,\n deleted: originalComment.deleted,\n removed: originalComment.removed,\n reason: originalComment.reason,\n quotedCids: originalComment.quotedCids,\n parentCid: originalComment.parentCid,\n postCid: originalComment.postCid,\n communityAddress: originalComment.communityAddress,\n timestamp: originalComment.timestamp,\n author: compactStoredCommentAuthor(originalComment.author),\n });\n\n return compactOriginalComment && Object.keys(compactOriginalComment).length > 0\n ? compactOriginalComment\n : undefined;\n};\n\nconst compactStoredReplies = (replies: any) => {\n if (!replies || typeof replies !== \"object\") {\n return undefined;\n }\n\n const compactReplies = cloneWithoutFunctions(\n Object.fromEntries(\n Object.entries(replies).filter(\n ([replyKey]) => replyKey !== \"pages\" && replyKey !== \"clients\",\n ),\n ),\n );\n\n return compactReplies && Object.keys(compactReplies).length > 0 ? compactReplies : undefined;\n};\n\nexport const sanitizeAccountCommentForState = (comment: Comment) => {\n const sanitizedComment = cloneWithoutFunctions({\n ...comment,\n signer: undefined,\n raw: undefined,\n replies: comment?.replies\n ? Object.fromEntries(\n Object.entries(comment.replies).filter(([replyKey]) => replyKey !== \"pages\"),\n )\n : comment?.replies,\n });\n\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies?.pages) {\n sanitizedComment.replies = { ...sanitizedComment.replies };\n delete sanitizedComment.replies.pages;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n return sanitizedComment;\n};\n\nexport const sanitizeStoredAccountComment = (comment: Comment) => {\n const preprocessedComment = {\n ...comment,\n signer: undefined,\n clients: undefined,\n raw: undefined,\n replies: compactStoredReplies(comment?.replies),\n original: comment?.edit ? compactStoredOriginalComment(comment.original) : undefined,\n };\n const sanitizedComment = cloneWithoutFunctions(preprocessedComment);\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n if (sanitizedComment?.original && Object.keys(sanitizedComment.original).length === 0) {\n delete sanitizedComment.original;\n }\n return sanitizedComment;\n};\n\nexport const getAccountCommentsIndex = (\n accountComments: AccountComment[] | undefined,\n): AccountCommentsIndex => {\n const index: AccountCommentsIndex = {\n byCommunityAddress: {},\n byParentCid: {},\n };\n for (const accountComment of accountComments || []) {\n if (accountComment.communityAddress) {\n if (!index.byCommunityAddress[accountComment.communityAddress]) {\n index.byCommunityAddress[accountComment.communityAddress] = [];\n }\n index.byCommunityAddress[accountComment.communityAddress].push(accountComment.index);\n }\n if (accountComment.parentCid) {\n if (!index.byParentCid[accountComment.parentCid]) {\n index.byParentCid[accountComment.parentCid] = [];\n }\n index.byParentCid[accountComment.parentCid].push(accountComment.index);\n }\n }\n return index;\n};\n\nexport const getAccountsCommentsIndexes = (accountsComments: AccountsComments) => {\n const indexes: AccountsCommentsIndexes = {};\n for (const accountId in accountsComments) {\n indexes[accountId] = getAccountCommentsIndex(accountsComments[accountId]);\n }\n return indexes;\n};\n\nconst accountEditNonPropertyNames = new Set([\n \"author\",\n \"signer\",\n \"clientId\",\n \"commentCid\",\n \"communityAddress\",\n \"communityAddress\",\n \"timestamp\",\n]);\n\nexport const COMMENT_MODERATION_AUTHOR_SUMMARY_KEY = \"commentModeration.author\";\n\nconst normalizeAccountEditForSummary = (accountEdit: AccountEdit) => {\n const normalizedAccountEdit = { ...accountEdit };\n const commentModeration = normalizedAccountEdit.commentModeration;\n if (commentModeration && typeof commentModeration === \"object\") {\n const { author, ...commentModerationProperties } = commentModeration;\n Object.assign(normalizedAccountEdit, commentModerationProperties);\n if (Object.prototype.hasOwnProperty.call(commentModeration, \"author\")) {\n normalizedAccountEdit[COMMENT_MODERATION_AUTHOR_SUMMARY_KEY] = author;\n }\n delete normalizedAccountEdit.commentModeration;\n }\n const communityEdit = normalizedAccountEdit.communityEdit ?? normalizedAccountEdit.communityEdit;\n if (communityEdit && typeof communityEdit === \"object\") {\n Object.assign(normalizedAccountEdit, communityEdit);\n }\n delete normalizedAccountEdit.communityEdit;\n delete normalizedAccountEdit.communityEdit;\n return normalizedAccountEdit;\n};\n\nexport const getAccountEditPropertySummary = (accountEdits: AccountEdit[] | undefined) => {\n const accountEditPropertySummary: AccountEditsSummary[string] = {};\n for (const accountEdit of accountEdits || []) {\n const normalizedAccountEdit = normalizeAccountEditForSummary(accountEdit);\n for (const propertyName in normalizedAccountEdit) {\n if (\n (normalizedAccountEdit[propertyName] === undefined &&\n propertyName !== COMMENT_MODERATION_AUTHOR_SUMMARY_KEY) ||\n accountEditNonPropertyNames.has(propertyName)\n ) {\n continue;\n }\n const previousTimestamp = accountEditPropertySummary[propertyName]?.timestamp || 0;\n if ((normalizedAccountEdit.timestamp || 0) >= previousTimestamp) {\n accountEditPropertySummary[propertyName] = {\n timestamp: normalizedAccountEdit.timestamp,\n value: normalizedAccountEdit[propertyName],\n };\n }\n }\n }\n return accountEditPropertySummary;\n};\n\nexport const getAccountsEditsSummary = (accountEdits: {\n [commentCidOrCommunityAddress: string]: AccountEdit[];\n}) => {\n const summary: AccountEditsSummary = {};\n for (const target in accountEdits || {}) {\n summary[target] = getAccountEditPropertySummary(accountEdits[target]);\n }\n return summary;\n};\n\ninterface CommentLinkDimensions {\n linkWidth?: number;\n linkHeight?: number;\n linkHtmlTagName?: \"img\" | \"video\" | \"audio\";\n}\n\n// polyfill Promise.any, exported for test coverage of empty-array branch\nconst promiseAny = <T>(promises: Promise<T>[]): Promise<T> =>\n new Promise((res, rej) => {\n let count = promises.length;\n if (count === 0) return rej(Error(\"all promises rejected\"));\n promises.forEach((p) =>\n Promise.resolve(p)\n .then(res)\n .catch((e) => {\n if (--count === 0) rej(Error(\"all promises rejected\"));\n }),\n );\n });\n\nexport const fetchCommentLinkDimensions = async (link: string): Promise<CommentLinkDimensions> => {\n if (!link) {\n return {};\n }\n\n const fetchImageDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const image = new Image();\n image.onload = () => {\n // don't accept 0px value\n if (!image.width || !image.height) {\n return reject(Error(`failed fetching image dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: image.width,\n linkHeight: image.height,\n linkHtmlTagName: \"img\",\n });\n\n // remove image from memory\n try {\n image.src = \"\";\n } catch (e) {}\n };\n image.onerror = (error) => {\n reject(Error(`failed fetching image dimensions for url '${url}'`));\n };\n\n // max loading time\n const timeout = 10000;\n setTimeout(\n () =>\n reject(Error(`failed fetching image dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n image.src = url;\n });\n\n const fetchVideoDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const video = document.createElement(\"video\");\n video.muted = true;\n video.loop = false;\n video.addEventListener(\"loadeddata\", () => {\n // don't accept 0px value\n if (!video.videoWidth || !video.videoHeight) {\n return reject(Error(`failed fetching video dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: video.videoWidth,\n linkHeight: video.videoHeight,\n linkHtmlTagName: \"video\",\n });\n // prevent video from playing\n try {\n video.pause();\n } catch (e) {}\n // prevent video from loading\n try {\n video.src = \"\";\n } catch (e) {}\n });\n video.addEventListener(\"error\", (error) => {\n reject(Error(`failed fetching video dimensions for url '${url}'`));\n });\n\n // max loading time\n const timeout = 30000;\n setTimeout(\n () =>\n reject(Error(`failed fetching video dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n video.src = url;\n });\n\n const fetchAudio = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const audio = document.createElement(\"audio\");\n audio.addEventListener(\"loadeddata\", () => {\n resolve({\n linkHtmlTagName: \"audio\",\n });\n try {\n audio.pause();\n } catch {}\n try {\n audio.src = \"\";\n } catch {}\n });\n audio.addEventListener(\"error\", () =>\n reject(Error(`failed fetching audio html tag name for url '${url}'`)),\n );\n\n const timeout = 20000;\n setTimeout(\n () =>\n reject(\n Error(`failed fetching audio html tag name for url '${url}' timeout '${timeout}'`),\n ),\n timeout,\n );\n\n audio.src = url;\n });\n\n try {\n if (new URL(link).protocol !== \"https:\") {\n throw Error(`failed fetching comment.link dimensions for link '${link}' not https protocol`);\n }\n const dimensions = await promiseAny([\n fetchImageDimensions(link),\n fetchVideoDimensions(link),\n fetchAudio(link),\n ]);\n return dimensions;\n } catch (error: any) {\n log.error(\"fetchCommentLinkDimensions error\", { error, link });\n return {};\n }\n};\n\nexport const getInitAccountCommentsToUpdate = (accountsComments: AccountsComments) => {\n const accountCommentsToUpdate: { accountComment: AccountComment; accountId: string }[] = [];\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n accountCommentsToUpdate.push({ accountComment, accountId });\n }\n }\n\n // update newer comments first, more likely to have notifications\n accountCommentsToUpdate.sort((a, b) => b.accountComment.timestamp - a.accountComment.timestamp);\n\n // updating too many comments during init slows down fetching comments/subs\n if (accountCommentsToUpdate.length > 10) {\n accountCommentsToUpdate.length = 10;\n }\n\n // TODO: add some algo to fetch all notifications (even old), but not on init\n // during downtimes when we're not fetching anything else\n return accountCommentsToUpdate;\n};\n\nexport const getAccountCommentDepth = (comment: Comment) => {\n if (!comment.parentCid) {\n return 0;\n }\n let parentCommentDepth = commentsStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = repliesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = communitiesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n // if can't find the parent comment depth anywhere, don't include it with the account comment\n // it will be added automatically when challenge verification is received\n};\n\nexport const addShortAddressesToAccountComment = (comment: Comment) => {\n comment = { ...comment };\n try {\n comment.shortCommunityAddress = PkcJs.PKC.getShortAddress({\n address: comment.communityAddress,\n });\n } catch (e) {}\n try {\n comment.author = { ...comment.author };\n comment.author.shortAddress = PkcJs.PKC.getShortAddress({\n address: comment.author.address,\n });\n } catch (e) {}\n return comment;\n};\n\nconst utils = {\n getAccountCommunities,\n getCommentCidsToAccountsComments,\n getAccountCommentsIndex,\n getAccountsCommentsIndexes,\n sanitizeAccountCommentForState,\n sanitizeStoredAccountComment,\n getAccountEditPropertySummary,\n getAccountsEditsSummary,\n fetchCommentLinkDimensions,\n getInitAccountCommentsToUpdate,\n getAccountCommentDepth,\n addShortAddressesToAccountComment,\n promiseAny,\n};\n\nexport default utils;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,eAAO,MAAM,GAAG,QAAkD,CAAC;AACnE,OAAO,EAAW,QAAQ,EAAW,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,eAAO,MAAM,GAAG,QAAkD,CAAC;AACnE,OAAO,EAAW,QAAQ,EAAW,MAAM,aAAa,CAAC;AAmBzD,eAAO,MAAM,SAAS,EAAE,GAAQ,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAC1C,iBAAiB,EAAE,QAAQ,CAAC;IAC5B,sBAAsB,EAAE,QAAQ,CAAC;IACjC,qBAAqB,EAAE,QAAQ,CAAC;IAChC,cAAc,EAAE,QAAQ,CAAC;CAC1B,CAAC;AAuDF,QAAA,MAAM,aAAa,4EAqZjB,CAAC;AA8BH,eAAO,MAAM,kBAAkB,qBAmC9B,CAAC;AAGF,eAAO,MAAM,6BAA6B,qBAGzC,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -24,6 +24,7 @@ const liveComments = {};
|
|
|
24
24
|
const liveCommentPromises = {};
|
|
25
25
|
const commentAutoUpdateSubscribers = {};
|
|
26
26
|
const stopCommentAfterNextUpdate = {};
|
|
27
|
+
const sparseCommentFollowupRequested = {};
|
|
27
28
|
const initializedComments = new WeakSet();
|
|
28
29
|
const trackedListeners = new WeakSet();
|
|
29
30
|
// reset all event listeners in between tests
|
|
@@ -89,7 +90,11 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
89
90
|
repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);
|
|
90
91
|
return normalizedComment;
|
|
91
92
|
});
|
|
93
|
+
const clearCommentUpdateFollowup = (commentCid) => {
|
|
94
|
+
delete sparseCommentFollowupRequested[commentCid];
|
|
95
|
+
};
|
|
92
96
|
const stopLiveComment = (commentCid, comment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
clearCommentUpdateFollowup(commentCid);
|
|
93
98
|
const liveComment = comment || liveComments[commentCid];
|
|
94
99
|
if (typeof (liveComment === null || liveComment === void 0 ? void 0 : liveComment.stop) !== "function") {
|
|
95
100
|
return;
|
|
@@ -113,6 +118,41 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
113
118
|
maybeReleaseStoppedLiveComment(commentCid, comment);
|
|
114
119
|
});
|
|
115
120
|
};
|
|
121
|
+
const toCommentUpdateError = (error) => error instanceof Error ? error : Error("comment update failed");
|
|
122
|
+
const emitCommentError = (comment, error) => {
|
|
123
|
+
const emit = comment === null || comment === void 0 ? void 0 : comment.emit;
|
|
124
|
+
if (typeof emit !== "function") {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
emit.call(comment, "error", error);
|
|
129
|
+
}
|
|
130
|
+
catch (emitError) {
|
|
131
|
+
if (emitError !== error) {
|
|
132
|
+
log.trace("comment.update error event error", { comment, error: emitError });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const handleCommentUpdateError = (commentCid, comment, error) => {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
const updateError = toCommentUpdateError(error);
|
|
139
|
+
clearCommentUpdateFollowup(commentCid);
|
|
140
|
+
if (!((_a = getState().errors[commentCid]) === null || _a === void 0 ? void 0 : _a.includes(updateError))) {
|
|
141
|
+
emitCommentError(comment, updateError);
|
|
142
|
+
if (!((_b = getState().errors[commentCid]) === null || _b === void 0 ? void 0 : _b.includes(updateError))) {
|
|
143
|
+
addCommentError(commentCid, updateError);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
maybeStopCommentAfterOneShotUpdate(commentCid, comment);
|
|
147
|
+
return updateError;
|
|
148
|
+
};
|
|
149
|
+
const isSparseCommentUpdate = (comment) => !!(comment === null || comment === void 0 ? void 0 : comment.timestamp) && !(comment === null || comment === void 0 ? void 0 : comment.updatedAt);
|
|
150
|
+
// A CID-only comment update can settle after immutable IPFS data; one follow-up
|
|
151
|
+
// update gives PKC a chance to load mutable community data such as replies.
|
|
152
|
+
const shouldRequestSparseCommentFollowup = (commentCid, comment) => !sparseCommentFollowupRequested[commentCid] &&
|
|
153
|
+
(stopCommentAfterNextUpdate[commentCid] || hasCommentAutoUpdateSubscribers(commentCid)) &&
|
|
154
|
+
isSparseCommentUpdate(comment);
|
|
155
|
+
const shouldWaitForSparseCommentFollowup = (commentCid, comment) => sparseCommentFollowupRequested[commentCid] && isSparseCommentUpdate(comment);
|
|
116
156
|
const initializeComment = (commentCid, comment, account) => {
|
|
117
157
|
var _a, _b, _c, _d;
|
|
118
158
|
if (initializedComments.has(comment)) {
|
|
@@ -129,6 +169,21 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
129
169
|
setState((state) => ({
|
|
130
170
|
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: Object.assign(Object.assign({}, state.comments[commentCid]), { updatingState }) }),
|
|
131
171
|
}));
|
|
172
|
+
if (updatingState === "succeeded" &&
|
|
173
|
+
shouldRequestSparseCommentFollowup(commentCid, comment)) {
|
|
174
|
+
sparseCommentFollowupRequested[commentCid] = true;
|
|
175
|
+
requestCommentUpdate(commentCid, comment, {
|
|
176
|
+
stopAfterNextUpdate: !!stopCommentAfterNextUpdate[commentCid],
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (updatingState === "succeeded" &&
|
|
181
|
+
(comment.updatedAt || sparseCommentFollowupRequested[commentCid])) {
|
|
182
|
+
clearCommentUpdateFollowup(commentCid);
|
|
183
|
+
}
|
|
184
|
+
if (updatingState === "failed") {
|
|
185
|
+
clearCommentUpdateFollowup(commentCid);
|
|
186
|
+
}
|
|
132
187
|
if (updatingState === "succeeded" || updatingState === "failed") {
|
|
133
188
|
maybeStopCommentAfterOneShotUpdate(commentCid, comment);
|
|
134
189
|
}
|
|
@@ -205,13 +260,19 @@ const commentsStore = createStore((setState, getState) => {
|
|
|
205
260
|
else {
|
|
206
261
|
delete stopCommentAfterNextUpdate[commentCid];
|
|
207
262
|
}
|
|
208
|
-
(_a = comment === null || comment === void 0 ? void 0 : comment.update) === null || _a === void 0 ? void 0 : _a.call(comment).catch((error) =>
|
|
263
|
+
(_a = comment === null || comment === void 0 ? void 0 : comment.update) === null || _a === void 0 ? void 0 : _a.call(comment).catch((error) => {
|
|
264
|
+
const updateError = handleCommentUpdateError(commentCid, comment, error);
|
|
265
|
+
log.trace("comment.update error", { commentCid, comment, error: updateError });
|
|
266
|
+
});
|
|
209
267
|
};
|
|
210
268
|
const waitForCommentUpdateCycle = (commentCid, comment) => new Promise((resolve, reject) => {
|
|
211
269
|
var _a, _b;
|
|
212
270
|
const onUpdatingStateChange = (updatingState) => {
|
|
213
271
|
var _a;
|
|
214
272
|
if (updatingState === "succeeded") {
|
|
273
|
+
if (shouldWaitForSparseCommentFollowup(commentCid, comment)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
215
276
|
cleanup();
|
|
216
277
|
resolve(normalizeCommentCommunityAddress(utils.clone(comment)));
|
|
217
278
|
return;
|
|
@@ -362,6 +423,9 @@ export const resetCommentsStore = () => __awaiter(void 0, void 0, void 0, functi
|
|
|
362
423
|
for (const commentCid in stopCommentAfterNextUpdate) {
|
|
363
424
|
delete stopCommentAfterNextUpdate[commentCid];
|
|
364
425
|
}
|
|
426
|
+
for (const commentCid in sparseCommentFollowupRequested) {
|
|
427
|
+
delete sparseCommentFollowupRequested[commentCid];
|
|
428
|
+
}
|
|
365
429
|
for (const commentCid in liveCommentPromises) {
|
|
366
430
|
delete liveCommentPromises[commentCid];
|
|
367
431
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments-store.js","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mapp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IAAI,CAAC;YACH,IAAI,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAA,KAAK,UAAU,EAAE,CAAC;gBACzC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxB,CAAC;QACH,CAAC;QAAC,WAAM,CAAC,CAAA,CAAC;QACV,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,kBAAkB,wDAAI,CAAC;IACnC,CAAC,CAAA,CAAC,CACH,CAAC;IACF,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IAErB,mDAAmD;IACnD,aAAa,CAAC,OAAO,EAAE,CAAC;IACxB,yBAAyB;IACzB,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAS,EAAE;IACtD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACtF,MAAM,kBAAkB,EAAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import localForageLru from \"../../lib/localforage-lru\";\nconst commentsDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-comments\",\n size: 5000,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nexport const log = Logger(\"bitsocial-react-hooks:comments:stores\");\nimport { Comment, Comments, Account } from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport repliesPagesStore from \"../replies-pages\";\nimport { normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\n\nlet pkcGetCommentPending: { [key: string]: boolean } = {};\nconst liveComments: { [commentCid: string]: Comment } = {};\nconst liveCommentPromises: { [commentCid: string]: Promise<Comment> | undefined } = {};\nconst commentAutoUpdateSubscribers: {\n [commentCid: string]: { [subscriberId: string]: true };\n} = {};\nconst stopCommentAfterNextUpdate: { [commentCid: string]: boolean } = {};\nconst initializedComments = new WeakSet<object>();\nconst trackedListeners = new WeakSet<object>();\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\nexport type CommentsState = {\n comments: Comments;\n errors: { [commentCid: string]: Error[] };\n addCommentToStore: Function;\n startCommentAutoUpdate: Function;\n stopCommentAutoUpdate: Function;\n refreshComment: Function;\n};\n\nconst removeCommentListener = (comment: any, event: string, listener: (...args: any[]) => void) => {\n if (typeof comment?.off === \"function\") {\n comment.off(event, listener);\n return;\n }\n if (typeof comment?.removeListener === \"function\") {\n comment.removeListener(event, listener);\n }\n};\n\nconst getCommentAutoUpdateSubscribersCount = (commentCid: string) =>\n Object.keys(commentAutoUpdateSubscribers[commentCid] || {}).length;\n\nconst hasCommentAutoUpdateSubscribers = (commentCid: string) =>\n getCommentAutoUpdateSubscribersCount(commentCid) > 0;\n\nconst mergeCommentData = (\n commentCid: string,\n ...commentDataList: (Comment | undefined)[]\n): Comment => {\n const mergedCommentData: Comment = { cid: commentCid };\n for (const commentData of commentDataList) {\n if (commentData && typeof commentData === \"object\") {\n Object.assign(mergedCommentData, utils.clone(commentData));\n }\n }\n mergedCommentData.cid = commentCid;\n return mergedCommentData;\n};\n\nconst releaseLiveComment = (commentCid: string, comment?: Comment) => {\n const liveComment = comment || liveComments[commentCid];\n if (liveComment) {\n const listenerIndex = listeners.indexOf(liveComment);\n if (listenerIndex !== -1) {\n listeners.splice(listenerIndex, 1);\n }\n }\n if (!comment || liveComments[commentCid] === liveComment) {\n delete liveComments[commentCid];\n }\n};\n\nconst maybeReleaseStoppedLiveComment = (commentCid: string, comment?: Comment) => {\n if (!comment || hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n if (liveComments[commentCid] !== comment) {\n return;\n }\n releaseLiveComment(commentCid, comment);\n};\n\nconst commentsStore = createStore<CommentsState>((setState: Function, getState: Function) => {\n const addCommentError = (commentCid: string, error: Error) => {\n setState((state: CommentsState) => {\n let commentErrors = state.errors[commentCid] || [];\n commentErrors = [...commentErrors, error];\n return { ...state, errors: { ...state.errors, [commentCid]: commentErrors } };\n });\n };\n\n const persistComment = async (commentCid: string, nextComment: Comment) => {\n const normalizedComment = normalizeCommentCommunityAddress(utils.clone(nextComment)) as Comment;\n await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: normalizedComment },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);\n\n return normalizedComment;\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\n const liveComment = comment || liveComments[commentCid];\n if (typeof liveComment?.stop !== \"function\") {\n return;\n }\n try {\n await liveComment.stop();\n } catch (error) {\n log.trace(\"comment.stop error\", { commentCid, comment: liveComment, error });\n }\n };\n\n const maybeStopCommentAfterOneShotUpdate = (commentCid: string, comment: Comment) => {\n if (!stopCommentAfterNextUpdate[commentCid]) {\n return;\n }\n delete stopCommentAfterNextUpdate[commentCid];\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n void stopLiveComment(commentCid, comment).finally(() => {\n maybeReleaseStoppedLiveComment(commentCid, comment);\n });\n };\n\n const initializeComment = (commentCid: string, comment: Comment, account: Account) => {\n if (initializedComments.has(comment as object)) {\n liveComments[commentCid] = comment;\n return;\n }\n initializedComments.add(comment as object);\n liveComments[commentCid] = comment;\n\n comment?.on?.(\"update\", async (updatedComment: Comment) => {\n updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment)) as Comment;\n await persistComment(commentCid, updatedComment);\n });\n\n comment?.on?.(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommentsState) => ({\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], updatingState },\n },\n }));\n\n if (updatingState === \"succeeded\" || updatingState === \"failed\") {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\n addCommentError(commentCid, error);\n });\n\n // set clients on comment so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n comment?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommentsState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.comments[commentCid]) {\n return {};\n }\n const clients = { ...state.comments[commentCid]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], clients },\n },\n };\n });\n },\n );\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n // if comment.timestamp isn't defined, it means the next update will contain the timestamp and author\n // which is used in addCidToAccountComment\n if (!comment?.timestamp) {\n comment?.once?.(\"update\", () =>\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(comment)\n .catch((error: any) =>\n log.error(\"accountsActionsInternal.addCidToAccountComment error\", { comment, error }),\n ),\n );\n }\n\n if (!trackedListeners.has(comment as object)) {\n trackedListeners.add(comment as object);\n listeners.push(comment);\n }\n };\n\n const ensureLiveComment = async (commentCid: string, account: Account, commentData?: Comment) => {\n if (liveComments[commentCid]) {\n return liveComments[commentCid];\n }\n if (liveCommentPromises[commentCid]) {\n return liveCommentPromises[commentCid] as Promise<Comment>;\n }\n\n const liveCommentPromise = (async () => {\n const initialComment = normalizeCommentCommunityAddress(\n mergeCommentData(commentCid, commentData),\n );\n const liveComment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(initialComment),\n ) as Comment;\n initializeComment(commentCid, liveComment, account);\n return liveComment;\n })();\n liveCommentPromises[commentCid] = liveCommentPromise;\n\n try {\n return await liveCommentPromise;\n } finally {\n if (liveCommentPromises[commentCid] === liveCommentPromise) {\n delete liveCommentPromises[commentCid];\n }\n }\n };\n\n const requestCommentUpdate = (\n commentCid: string,\n comment: Comment,\n options?: { stopAfterNextUpdate?: boolean },\n ) => {\n if (options?.stopAfterNextUpdate) {\n stopCommentAfterNextUpdate[commentCid] = true;\n } else {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n\n comment\n ?.update?.()\n .catch((error: unknown) => log.trace(\"comment.update error\", { commentCid, comment, error }));\n };\n\n const waitForCommentUpdateCycle = (commentCid: string, comment: Comment) =>\n new Promise<Comment>((resolve, reject) => {\n const onUpdatingStateChange = (updatingState: string) => {\n if (updatingState === \"succeeded\") {\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n return;\n }\n if (updatingState === \"failed\") {\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const cleanup = () => {\n removeCommentListener(comment, \"updatingstatechange\", onUpdatingStateChange);\n removeCommentListener(comment, \"error\", onError);\n };\n\n comment?.on?.(\"updatingstatechange\", onUpdatingStateChange);\n comment?.on?.(\"error\", onError);\n });\n\n return {\n comments: {},\n errors: {},\n\n async addCommentToStore(commentCid: string, account: Account, commentData?: Comment) {\n const { comments } = getState();\n const pendingKey = commentCid + account.id;\n\n // comment is in store already, do nothing\n let comment: Comment | undefined = comments[commentCid];\n if (comment || pkcGetCommentPending[pendingKey]) {\n return;\n }\n pkcGetCommentPending[pendingKey] = true;\n\n try {\n // try to find comment in database\n comment = await getCommentFromDatabase(commentCid, account, commentData);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, commentData);\n comment = normalizeCommentCommunityAddress(comment);\n log(\"commentsStore.addCommentToStore\", { commentCid, comment, account });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n } else {\n comment = normalizeCommentCommunityAddress(comment);\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);\n\n comment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, comment, commentData),\n );\n }\n\n if (comment) {\n requestCommentUpdate(commentCid, comment, { stopAfterNextUpdate: true });\n }\n } catch (e: any) {\n addCommentError(commentCid, e);\n throw e;\n } finally {\n pkcGetCommentPending[pendingKey] = false;\n }\n },\n\n async startCommentAutoUpdate(\n commentCid: string,\n subscriberId: string,\n account: Account,\n commentData?: Comment,\n ) {\n const hadAutoUpdateSubscribers = hasCommentAutoUpdateSubscribers(commentCid);\n commentAutoUpdateSubscribers[commentCid] = {\n ...(commentAutoUpdateSubscribers[commentCid] || {}),\n [subscriberId]: true,\n };\n\n if (hadAutoUpdateSubscribers && liveComments[commentCid]) {\n return;\n }\n\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (!storedComment) {\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(liveComment) },\n }));\n }\n\n if (!hasCommentAutoUpdateSubscribers(commentCid)) {\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n return;\n }\n\n requestCommentUpdate(commentCid, liveComment);\n },\n\n async stopCommentAutoUpdate(commentCid: string, subscriberId: string) {\n if (commentAutoUpdateSubscribers[commentCid]) {\n delete commentAutoUpdateSubscribers[commentCid][subscriberId];\n if (Object.keys(commentAutoUpdateSubscribers[commentCid]).length === 0) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n }\n\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n\n delete stopCommentAfterNextUpdate[commentCid];\n const liveComment = liveComments[commentCid];\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n },\n\n async refreshComment(commentCid: string, account: Account, commentData?: Comment) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n const waitForUpdate = waitForCommentUpdateCycle(commentCid, liveComment);\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n });\n return waitForUpdate;\n },\n };\n});\n\nconst getCommentFromDatabase = async (\n commentCid: string,\n account: Account,\n initialCommentData?: Comment,\n) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(\n mergeCommentData(commentCid, commentData, initialCommentData),\n ),\n );\n return comment;\n } catch (e) {\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createComment(cachedComment)\", {\n cachedComment: commentData,\n error: e,\n });\n }\n};\n\n// reset store in between tests\nconst originalState = commentsStore.getState();\n// async function because some stores have async init\nexport const resetCommentsStore = async () => {\n pkcGetCommentPending = {};\n for (const commentCid in commentAutoUpdateSubscribers) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n for (const commentCid in stopCommentAfterNextUpdate) {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n for (const commentCid in liveCommentPromises) {\n delete liveCommentPromises[commentCid];\n }\n for (const commentCid in liveComments) {\n delete liveComments[commentCid];\n }\n\n // remove all event listeners\n await Promise.all(\n listeners.map(async (listener: any) => {\n try {\n if (typeof listener?.stop === \"function\") {\n await listener.stop();\n }\n } catch {}\n listener?.removeAllListeners?.();\n }),\n );\n listeners.length = 0;\n\n // destroy all component subscriptions to the store\n commentsStore.destroy();\n // restore original state\n commentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommentsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear();\n await resetCommentsStore();\n};\n\nexport default commentsStore;\n"]}
|
|
1
|
+
{"version":3,"file":"comments-store.js","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,MAAM,gBAAgB,GAAG,cAAc,CAAC,cAAc,CAAC;IACrD,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AACH,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAEnE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAExE,IAAI,oBAAoB,GAA+B,EAAE,CAAC;AAC1D,MAAM,YAAY,GAAsC,EAAE,CAAC;AAC3D,MAAM,mBAAmB,GAA2D,EAAE,CAAC;AACvF,MAAM,4BAA4B,GAE9B,EAAE,CAAC;AACP,MAAM,0BAA0B,GAAsC,EAAE,CAAC;AACzE,MAAM,8BAA8B,GAAsC,EAAE,CAAC;AAC7E,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAU,CAAC;AAClD,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAU,CAAC;AAE/C,6CAA6C;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAQ,EAAE,CAAC;AAWjC,MAAM,qBAAqB,GAAG,CAAC,OAAY,EAAE,KAAa,EAAE,QAAkC,EAAE,EAAE;IAChG,I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,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAS,EAAE;IACtD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACtF,MAAM,kBAAkB,EAAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import localForageLru from \"../../lib/localforage-lru\";\nconst commentsDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-comments\",\n size: 5000,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nexport const log = Logger(\"bitsocial-react-hooks:comments:stores\");\nimport { Comment, Comments, Account } from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport repliesPagesStore from \"../replies-pages\";\nimport { normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\n\nlet pkcGetCommentPending: { [key: string]: boolean } = {};\nconst liveComments: { [commentCid: string]: Comment } = {};\nconst liveCommentPromises: { [commentCid: string]: Promise<Comment> | undefined } = {};\nconst commentAutoUpdateSubscribers: {\n [commentCid: string]: { [subscriberId: string]: true };\n} = {};\nconst stopCommentAfterNextUpdate: { [commentCid: string]: boolean } = {};\nconst sparseCommentFollowupRequested: { [commentCid: string]: boolean } = {};\nconst initializedComments = new WeakSet<object>();\nconst trackedListeners = new WeakSet<object>();\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\nexport type CommentsState = {\n comments: Comments;\n errors: { [commentCid: string]: Error[] };\n addCommentToStore: Function;\n startCommentAutoUpdate: Function;\n stopCommentAutoUpdate: Function;\n refreshComment: Function;\n};\n\nconst removeCommentListener = (comment: any, event: string, listener: (...args: any[]) => void) => {\n if (typeof comment?.off === \"function\") {\n comment.off(event, listener);\n return;\n }\n if (typeof comment?.removeListener === \"function\") {\n comment.removeListener(event, listener);\n }\n};\n\nconst getCommentAutoUpdateSubscribersCount = (commentCid: string) =>\n Object.keys(commentAutoUpdateSubscribers[commentCid] || {}).length;\n\nconst hasCommentAutoUpdateSubscribers = (commentCid: string) =>\n getCommentAutoUpdateSubscribersCount(commentCid) > 0;\n\nconst mergeCommentData = (\n commentCid: string,\n ...commentDataList: (Comment | undefined)[]\n): Comment => {\n const mergedCommentData: Comment = { cid: commentCid };\n for (const commentData of commentDataList) {\n if (commentData && typeof commentData === \"object\") {\n Object.assign(mergedCommentData, utils.clone(commentData));\n }\n }\n mergedCommentData.cid = commentCid;\n return mergedCommentData;\n};\n\nconst releaseLiveComment = (commentCid: string, comment?: Comment) => {\n const liveComment = comment || liveComments[commentCid];\n if (liveComment) {\n const listenerIndex = listeners.indexOf(liveComment);\n if (listenerIndex !== -1) {\n listeners.splice(listenerIndex, 1);\n }\n }\n if (!comment || liveComments[commentCid] === liveComment) {\n delete liveComments[commentCid];\n }\n};\n\nconst maybeReleaseStoppedLiveComment = (commentCid: string, comment?: Comment) => {\n if (!comment || hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n if (liveComments[commentCid] !== comment) {\n return;\n }\n releaseLiveComment(commentCid, comment);\n};\n\nconst commentsStore = createStore<CommentsState>((setState: Function, getState: Function) => {\n const addCommentError = (commentCid: string, error: Error) => {\n setState((state: CommentsState) => {\n let commentErrors = state.errors[commentCid] || [];\n commentErrors = [...commentErrors, error];\n return { ...state, errors: { ...state.errors, [commentCid]: commentErrors } };\n });\n };\n\n const persistComment = async (commentCid: string, nextComment: Comment) => {\n const normalizedComment = normalizeCommentCommunityAddress(utils.clone(nextComment)) as Comment;\n await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: normalizedComment },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);\n\n return normalizedComment;\n };\n\n const clearCommentUpdateFollowup = (commentCid: string) => {\n delete sparseCommentFollowupRequested[commentCid];\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\n clearCommentUpdateFollowup(commentCid);\n const liveComment = comment || liveComments[commentCid];\n if (typeof liveComment?.stop !== \"function\") {\n return;\n }\n try {\n await liveComment.stop();\n } catch (error) {\n log.trace(\"comment.stop error\", { commentCid, comment: liveComment, error });\n }\n };\n\n const maybeStopCommentAfterOneShotUpdate = (commentCid: string, comment: Comment) => {\n if (!stopCommentAfterNextUpdate[commentCid]) {\n return;\n }\n delete stopCommentAfterNextUpdate[commentCid];\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n void stopLiveComment(commentCid, comment).finally(() => {\n maybeReleaseStoppedLiveComment(commentCid, comment);\n });\n };\n\n const toCommentUpdateError = (error: unknown) =>\n error instanceof Error ? error : Error(\"comment update failed\");\n\n const emitCommentError = (comment: Comment, error: Error) => {\n const emit = (comment as any)?.emit;\n if (typeof emit !== \"function\") {\n return;\n }\n try {\n emit.call(comment, \"error\", error);\n } catch (emitError) {\n if (emitError !== error) {\n log.trace(\"comment.update error event error\", { comment, error: emitError });\n }\n }\n };\n\n const handleCommentUpdateError = (commentCid: string, comment: Comment, error: unknown) => {\n const updateError = toCommentUpdateError(error);\n clearCommentUpdateFollowup(commentCid);\n\n if (!getState().errors[commentCid]?.includes(updateError)) {\n emitCommentError(comment, updateError);\n if (!getState().errors[commentCid]?.includes(updateError)) {\n addCommentError(commentCid, updateError);\n }\n }\n\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n return updateError;\n };\n\n const isSparseCommentUpdate = (comment: Comment) => !!comment?.timestamp && !comment?.updatedAt;\n\n // A CID-only comment update can settle after immutable IPFS data; one follow-up\n // update gives PKC a chance to load mutable community data such as replies.\n const shouldRequestSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n !sparseCommentFollowupRequested[commentCid] &&\n (stopCommentAfterNextUpdate[commentCid] || hasCommentAutoUpdateSubscribers(commentCid)) &&\n isSparseCommentUpdate(comment);\n\n const shouldWaitForSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n sparseCommentFollowupRequested[commentCid] && isSparseCommentUpdate(comment);\n\n const initializeComment = (commentCid: string, comment: Comment, account: Account) => {\n if (initializedComments.has(comment as object)) {\n liveComments[commentCid] = comment;\n return;\n }\n initializedComments.add(comment as object);\n liveComments[commentCid] = comment;\n\n comment?.on?.(\"update\", async (updatedComment: Comment) => {\n updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment)) as Comment;\n await persistComment(commentCid, updatedComment);\n });\n\n comment?.on?.(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommentsState) => ({\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], updatingState },\n },\n }));\n\n if (\n updatingState === \"succeeded\" &&\n shouldRequestSparseCommentFollowup(commentCid, comment)\n ) {\n sparseCommentFollowupRequested[commentCid] = true;\n requestCommentUpdate(commentCid, comment, {\n stopAfterNextUpdate: !!stopCommentAfterNextUpdate[commentCid],\n });\n return;\n }\n\n if (\n updatingState === \"succeeded\" &&\n (comment.updatedAt || sparseCommentFollowupRequested[commentCid])\n ) {\n clearCommentUpdateFollowup(commentCid);\n }\n if (updatingState === \"failed\") {\n clearCommentUpdateFollowup(commentCid);\n }\n\n if (updatingState === \"succeeded\" || updatingState === \"failed\") {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\n addCommentError(commentCid, error);\n });\n\n // set clients on comment so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n comment?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommentsState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.comments[commentCid]) {\n return {};\n }\n const clients = { ...state.comments[commentCid]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], clients },\n },\n };\n });\n },\n );\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n // if comment.timestamp isn't defined, it means the next update will contain the timestamp and author\n // which is used in addCidToAccountComment\n if (!comment?.timestamp) {\n comment?.once?.(\"update\", () =>\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(comment)\n .catch((error: any) =>\n log.error(\"accountsActionsInternal.addCidToAccountComment error\", { comment, error }),\n ),\n );\n }\n\n if (!trackedListeners.has(comment as object)) {\n trackedListeners.add(comment as object);\n listeners.push(comment);\n }\n };\n\n const ensureLiveComment = async (commentCid: string, account: Account, commentData?: Comment) => {\n if (liveComments[commentCid]) {\n return liveComments[commentCid];\n }\n if (liveCommentPromises[commentCid]) {\n return liveCommentPromises[commentCid] as Promise<Comment>;\n }\n\n const liveCommentPromise = (async () => {\n const initialComment = normalizeCommentCommunityAddress(\n mergeCommentData(commentCid, commentData),\n );\n const liveComment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(initialComment),\n ) as Comment;\n initializeComment(commentCid, liveComment, account);\n return liveComment;\n })();\n liveCommentPromises[commentCid] = liveCommentPromise;\n\n try {\n return await liveCommentPromise;\n } finally {\n if (liveCommentPromises[commentCid] === liveCommentPromise) {\n delete liveCommentPromises[commentCid];\n }\n }\n };\n\n const requestCommentUpdate = (\n commentCid: string,\n comment: Comment,\n options?: { stopAfterNextUpdate?: boolean },\n ) => {\n if (options?.stopAfterNextUpdate) {\n stopCommentAfterNextUpdate[commentCid] = true;\n } else {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n\n comment?.update?.().catch((error: unknown) => {\n const updateError = handleCommentUpdateError(commentCid, comment, error);\n log.trace(\"comment.update error\", { commentCid, comment, error: updateError });\n });\n };\n\n const waitForCommentUpdateCycle = (commentCid: string, comment: Comment) =>\n new Promise<Comment>((resolve, reject) => {\n const onUpdatingStateChange = (updatingState: string) => {\n if (updatingState === \"succeeded\") {\n if (shouldWaitForSparseCommentFollowup(commentCid, comment)) {\n return;\n }\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n return;\n }\n if (updatingState === \"failed\") {\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\n cleanup();\n reject(error);\n };\n\n const cleanup = () => {\n removeCommentListener(comment, \"updatingstatechange\", onUpdatingStateChange);\n removeCommentListener(comment, \"error\", onError);\n };\n\n comment?.on?.(\"updatingstatechange\", onUpdatingStateChange);\n comment?.on?.(\"error\", onError);\n });\n\n return {\n comments: {},\n errors: {},\n\n async addCommentToStore(commentCid: string, account: Account, commentData?: Comment) {\n const { comments } = getState();\n const pendingKey = commentCid + account.id;\n\n // comment is in store already, do nothing\n let comment: Comment | undefined = comments[commentCid];\n if (comment || pkcGetCommentPending[pendingKey]) {\n return;\n }\n pkcGetCommentPending[pendingKey] = true;\n\n try {\n // try to find comment in database\n comment = await getCommentFromDatabase(commentCid, account, commentData);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, commentData);\n comment = normalizeCommentCommunityAddress(comment);\n log(\"commentsStore.addCommentToStore\", { commentCid, comment, account });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n } else {\n comment = normalizeCommentCommunityAddress(comment);\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);\n\n comment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, comment, commentData),\n );\n }\n\n if (comment) {\n requestCommentUpdate(commentCid, comment, { stopAfterNextUpdate: true });\n }\n } catch (e: any) {\n addCommentError(commentCid, e);\n throw e;\n } finally {\n pkcGetCommentPending[pendingKey] = false;\n }\n },\n\n async startCommentAutoUpdate(\n commentCid: string,\n subscriberId: string,\n account: Account,\n commentData?: Comment,\n ) {\n const hadAutoUpdateSubscribers = hasCommentAutoUpdateSubscribers(commentCid);\n commentAutoUpdateSubscribers[commentCid] = {\n ...(commentAutoUpdateSubscribers[commentCid] || {}),\n [subscriberId]: true,\n };\n\n if (hadAutoUpdateSubscribers && liveComments[commentCid]) {\n return;\n }\n\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (!storedComment) {\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(liveComment) },\n }));\n }\n\n if (!hasCommentAutoUpdateSubscribers(commentCid)) {\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n return;\n }\n\n requestCommentUpdate(commentCid, liveComment);\n },\n\n async stopCommentAutoUpdate(commentCid: string, subscriberId: string) {\n if (commentAutoUpdateSubscribers[commentCid]) {\n delete commentAutoUpdateSubscribers[commentCid][subscriberId];\n if (Object.keys(commentAutoUpdateSubscribers[commentCid]).length === 0) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n }\n\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n\n delete stopCommentAfterNextUpdate[commentCid];\n const liveComment = liveComments[commentCid];\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n },\n\n async refreshComment(commentCid: string, account: Account, commentData?: Comment) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n const waitForUpdate = waitForCommentUpdateCycle(commentCid, liveComment);\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n });\n return waitForUpdate;\n },\n };\n});\n\nconst getCommentFromDatabase = async (\n commentCid: string,\n account: Account,\n initialCommentData?: Comment,\n) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(\n mergeCommentData(commentCid, commentData, initialCommentData),\n ),\n );\n return comment;\n } catch (e) {\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createComment(cachedComment)\", {\n cachedComment: commentData,\n error: e,\n });\n }\n};\n\n// reset store in between tests\nconst originalState = commentsStore.getState();\n// async function because some stores have async init\nexport const resetCommentsStore = async () => {\n pkcGetCommentPending = {};\n for (const commentCid in commentAutoUpdateSubscribers) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n for (const commentCid in stopCommentAfterNextUpdate) {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n for (const commentCid in sparseCommentFollowupRequested) {\n delete sparseCommentFollowupRequested[commentCid];\n }\n for (const commentCid in liveCommentPromises) {\n delete liveCommentPromises[commentCid];\n }\n for (const commentCid in liveComments) {\n delete liveComments[commentCid];\n }\n\n // remove all event listeners\n await Promise.all(\n listeners.map(async (listener: any) => {\n try {\n if (typeof listener?.stop === \"function\") {\n await listener.stop();\n }\n } catch {}\n listener?.removeAllListeners?.();\n }),\n );\n listeners.length = 0;\n\n // destroy all component subscriptions to the store\n commentsStore.destroy();\n // restore original state\n commentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommentsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear();\n await resetCommentsStore();\n};\n\nexport default commentsStore;\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -320,6 +320,17 @@ export interface UseCreateCommunityResult extends Result {
|
|
|
320
320
|
createdCommunity: Community | undefined;
|
|
321
321
|
createCommunity(): Promise<void>;
|
|
322
322
|
}
|
|
323
|
+
export interface UseExportCommunityOptions extends Options {
|
|
324
|
+
communityAddress?: string;
|
|
325
|
+
communityAddresses?: string[];
|
|
326
|
+
includePrivateKey?: boolean;
|
|
327
|
+
exportPath?: string;
|
|
328
|
+
signal?: AbortSignal;
|
|
329
|
+
}
|
|
330
|
+
export interface UseExportCommunityResult extends Result {
|
|
331
|
+
communityExports: CommunityExport[];
|
|
332
|
+
exportCommunity(): Promise<void>;
|
|
333
|
+
}
|
|
323
334
|
export interface UseSubscribeOptions extends Options {
|
|
324
335
|
communityAddress?: string;
|
|
325
336
|
multisubAddress?: string;
|
|
@@ -402,6 +413,12 @@ export type PublishCommentModerationOptions = {
|
|
|
402
413
|
export type PublishCommunityEditOptions = {
|
|
403
414
|
[key: string]: any;
|
|
404
415
|
};
|
|
416
|
+
export interface ExportCommunityOptions {
|
|
417
|
+
includePrivateKey?: boolean;
|
|
418
|
+
exportPath?: string;
|
|
419
|
+
signal?: AbortSignal;
|
|
420
|
+
[key: string]: unknown;
|
|
421
|
+
}
|
|
405
422
|
export type Challenge = {
|
|
406
423
|
[key: string]: any;
|
|
407
424
|
};
|
|
@@ -435,6 +452,16 @@ export type CommunityEdit = {
|
|
|
435
452
|
export type Community = {
|
|
436
453
|
[key: string]: any;
|
|
437
454
|
};
|
|
455
|
+
export type CommunityExport = {
|
|
456
|
+
communityAddress: string;
|
|
457
|
+
exportId: string;
|
|
458
|
+
name?: string;
|
|
459
|
+
publicKey?: string;
|
|
460
|
+
includePrivateKey?: boolean;
|
|
461
|
+
progress?: number;
|
|
462
|
+
url?: string;
|
|
463
|
+
[key: string]: unknown;
|
|
464
|
+
};
|
|
438
465
|
export type CommunityStats = {
|
|
439
466
|
[key: string]: any;
|
|
440
467
|
};
|