@bitsocial/bitsocial-react-hooks 0.1.52 → 0.1.54
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 +30 -0
- package/README.md +52 -1507
- 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.js.map +1 -1
- package/dist/hooks/comments.js +1 -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.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +9 -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/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-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/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.js +1 -1
- 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/feed-sorter.d.ts +4 -0
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
- package/dist/stores/feeds/feed-sorter.js +35 -1
- package/dist/stores/feeds/feed-sorter.js.map +1 -1
- package/dist/stores/feeds/feeds-store.d.ts +3 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
- package/dist/stores/feeds/feeds-store.js +27 -4
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/stores/feeds/utils.d.ts +9 -0
- package/dist/stores/feeds/utils.d.ts.map +1 -1
- package/dist/stores/feeds/utils.js +81 -66
- 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 +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -6
|
@@ -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,kBAAkB,CAAC;AACjD,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AAErF,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,GAAG,MAAA,MAAA,WAAW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;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,wBAAwB;IACxB,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 repliesCommentsStore from \"../replies/replies-comments-store\";\nimport PkcJs from \"../../lib/pkc-js\";\nimport { getCommentVoteCountsVersion } from \"../../lib/utils/optimistic-vote-counts\";\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 getFreshestLoadedComment = (\n commentCid: string,\n ...additionalCandidates: (Comment | undefined)[]\n): Comment | undefined => {\n const candidates = [\n commentsStore.getState().comments[commentCid],\n repliesPagesStore.getState().comments[commentCid],\n communitiesPagesStore.getState().comments[commentCid],\n repliesCommentsStore.getState().comments[commentCid],\n ...additionalCandidates,\n ];\n return candidates.reduce<Comment | undefined>(\n (freshest, candidate) =>\n getCommentVoteCountsVersion(candidate) > getCommentVoteCountsVersion(freshest)\n ? candidate\n : freshest,\n undefined,\n );\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 getFreshestLoadedComment,\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,kBAAkB,CAAC;AACtC,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,s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QAC5E,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,QAAQ,EACd,SAAS,CACV,CAAC;AACJ,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,wBAAwB;IACxB,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 \"../../lib/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 repliesCommentsStore from \"../replies/replies-comments-store\";\nimport PkcJs from \"../../lib/pkc-js\";\nimport { getCommentVoteCountsVersion } from \"../../lib/utils/optimistic-vote-counts\";\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 getFreshestLoadedComment = (\n commentCid: string,\n ...additionalCandidates: (Comment | undefined)[]\n): Comment | undefined => {\n const candidates = [\n commentsStore.getState().comments[commentCid],\n repliesPagesStore.getState().comments[commentCid],\n communitiesPagesStore.getState().comments[commentCid],\n repliesCommentsStore.getState().comments[commentCid],\n ...additionalCandidates,\n ];\n return candidates.reduce<Comment | undefined>(\n (freshest, candidate) =>\n getCommentVoteCountsVersion(candidate) > getCommentVoteCountsVersion(freshest)\n ? candidate\n : freshest,\n undefined,\n );\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 getFreshestLoadedComment,\n addShortAddressesToAccountComment,\n promiseAny,\n};\n\nexport default utils;\n"]}
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
11
11
|
const log = Logger("bitsocial-react-hooks:authors:stores");
|
|
12
12
|
import createStore from "zustand";
|
|
13
|
-
import assert from "assert";
|
|
13
|
+
import assert from "../../lib/assert.js";
|
|
14
14
|
import commentsStore from "../comments/index.js";
|
|
15
15
|
import QuickLru from "quick-lru";
|
|
16
16
|
import { getUpdatedLoadedAndBufferedComments, getNextCommentCidToFetchNotFetched, } from "./utils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authors-comments-store.js","sourceRoot":"","sources":["../../../src/stores/authors-comments/authors-comments-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAC3D,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAQ5B,OAAO,aAAgC,MAAM,aAAa,CAAC;AAC3D,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAEL,mCAAmC,EACnC,kCAAkC,GACnC,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,aAAa,CAAC;AAExC,wEAAwE;AACxE,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,kDAAkD;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAmBpC,MAAM,oBAAoB,GAAG,WAAW,CACtC,CAAC,QAAkB,EAAE,QAAkB,EAAE,EAAE,CAAC,CAAC;IAC3C,OAAO,EAAE,EAAE;IACX,cAAc,EAAE,EAAE;IAClB,uBAAuB,EAAE,EAAE;IAC3B,mBAAmB,EAAE,EAAE;IACvB,eAAe,EAAE,EAAE;IACnB,sBAAsB,EAAE,EAAE;IAC1B,sBAAs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E,kBAAkB,EAAE,CAAC;QACvC,yBAAyB,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC,CAAC;AAEJ,+BAA+B;AAC/B,MAAM,aAAa,GAAG,oBAAoB,CAAC,QAAQ,EAAE,CAAC;AACtD,qDAAqD;AACrD,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAS,EAAE;IAClD,gCAAgC,GAAG,EAAE,CAAC;IACtC,gBAAgB,GAAG,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACpD,yBAAyB,GAAG,EAAE,CAAC;IAC/B,oBAAoB,GAAG,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAExD,mDAAmD;IACnD,oBAAoB,CAAC,OAAO,EAAE,CAAC;IAC/B,yBAAyB;IACzB,oBAAoB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC/C,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAS,EAAE;IAC7D,MAAM,yBAAyB,EAAE,CAAC;AACpC,CAAC,CAAA,CAAC;AAEF,eAAe,oBAAoB,CAAC","sourcesContent":["import Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:authors:stores\");\nimport createStore from \"zustand\";\nimport assert from \"assert\";\nimport {\n CommentsFilter,\n AuthorCommentsOptions,\n AuthorsComments,\n Account,\n Comment,\n} from \"../../types\";\nimport commentsStore, { CommentsState } from \"../comments\";\nimport QuickLru from \"quick-lru\";\nimport {\n toSizes,\n getUpdatedLoadedAndBufferedComments,\n getNextCommentCidToFetchNotFetched,\n} from \"./utils\";\nimport accountsStore from \"../accounts\";\n\n// reddit loads approximately 25 posts per page while infinite scrolling\nexport const commentsPerPage = 25;\n// keep large buffer because fetching cids is slow\nexport const commentBufferSize = 50;\n\ntype AuthorsCommentsState = {\n // authorCommentsName is a string used a key to represent authorAddress + filter + accountId\n options: { [authorCommentsName: string]: AuthorCommentsOptions };\n loadedComments: { [authorCommentsName: string]: Comment[] };\n hasMoreBufferedComments: { [authorCommentsName: string]: boolean };\n bufferedCommentCids: { [authorAddress: string]: Set<string> };\n nextCommentCidsToFetch: { [authorAddress: string]: string | undefined };\n shouldFetchNextComment: { [authorAddress: string]: boolean };\n lastCommentCids: { [authorAddress: string]: string | undefined };\n addAuthorCommentsToStore: Function;\n setNextCommentCidsToFetch: Function;\n incrementPageNumber: Function;\n addBufferedCommentCid: Function;\n updateLoadedComments: Function;\n setLastCommentCid: Function;\n};\n\nconst authorsCommentsStore = createStore<AuthorsCommentsState>(\n (setState: Function, getState: Function) => ({\n options: {},\n loadedComments: {},\n hasMoreBufferedComments: {},\n bufferedCommentCids: {},\n lastCommentCids: {},\n nextCommentCidsToFetch: {},\n shouldFetchNextComment: {},\n\n addAuthorCommentsToStore: (\n authorCommentsName: string,\n authorAddress: string,\n commentCid: string,\n filter: CommentsFilter | undefined,\n account: Account,\n ) => {\n assert(\n authorCommentsName && typeof authorCommentsName === \"string\",\n `addAuthorCommentsToStore.incrementPageNumber invalid argument authorCommentsName '${authorCommentsName}'`,\n );\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n commentCid && typeof commentCid === \"string\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument commentCid '${commentCid}'`,\n );\n assert(\n !filter || typeof filter?.filter === \"function\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument filter.filter '${filter?.filter}'`,\n );\n assert(\n !filter || typeof filter?.key === \"string\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument filter.key '${filter?.key}'`,\n );\n assert(\n typeof account?.pkc?.getComment === \"function\",\n `authorsCommentsStore.addAuthorCommentsToStore account '${account}' invalid`,\n );\n\n const { options, updateLoadedComments } = getState();\n // in store already, do nothing\n if (options[authorCommentsName]) {\n return;\n }\n const authorCommentsOptions = { authorAddress, pageNumber: 1, filter, accountId: account.id };\n\n // subscribe to nextCommentCidsToFetch and shouldFetchNextComment to fetch the comments\n authorsCommentsStore.subscribe(\n fetchCommentOnShouldFetchOrNextCidChange(authorCommentsOptions),\n );\n\n log(\"authorsCommentsActions.addAuthorCommentsToStore\", {\n authorCommentsName,\n authorCommentsOptions,\n commentCid,\n previousAuthorsCommentsOptions: options,\n });\n setState((state: AuthorsCommentsState) => ({\n options: { ...state.options, [authorCommentsName]: authorCommentsOptions },\n loadedComments: { ...state.loadedComments, [authorCommentsName]: [] },\n hasMoreBufferedComments: { ...state.hasMoreBufferedComments, [authorCommentsName]: true },\n bufferedCommentCids: {\n ...state.bufferedCommentCids,\n [authorAddress]: state.bufferedCommentCids[authorAddress] || new Set(),\n },\n lastCommentCids: {\n ...state.lastCommentCids,\n [authorAddress]: state.lastCommentCids[authorAddress] || undefined,\n },\n nextCommentCidsToFetch: {\n ...state.nextCommentCidsToFetch,\n [authorAddress]: state.nextCommentCidsToFetch[authorAddress] || commentCid,\n },\n shouldFetchNextComment: {\n ...state.shouldFetchNextComment,\n [authorAddress]: state.shouldFetchNextComment[authorAddress] || true,\n },\n }));\n\n // update loadedComments in case the author already has bufferedCommentCids\n updateLoadedComments();\n },\n\n setNextCommentCidsToFetch: (authorAddress: string, authorComment: Comment) => {\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsActions.setNextCommentCidsToFetch invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n typeof authorComment?.timestamp === \"number\",\n `authorsCommentsActions.setNextCommentCidsToFetch invalid argument authorComment '${authorComment}'`,\n );\n const { nextCommentCidsToFetch, shouldFetchNextComment, lastCommentCids } = getState();\n if (typeof shouldFetchNextComment[authorAddress] !== \"boolean\") {\n throw Error(\n `authorsCommentsActions.setNextCommentCidsToFetch can't set nextCommentCidToFetch '${authorAddress}' not in store`,\n );\n }\n const nextCommentCidToFetch = authorComment?.author?.previousCommentCid;\n if (nextCommentCidToFetch === nextCommentCidsToFetch[authorAddress]) {\n throw Error(\n `authorsCommentsActions.setNextCommentCidsToFetch can't set nextCommentCidToFetch '${authorAddress}' to '${nextCommentCidToFetch}' same value`,\n );\n }\n const nextCommentCidToFetchNotFetched =\n getNextCommentCidToFetchNotFetched(nextCommentCidToFetch);\n\n // log.trace('authorsCommentsActions.setNextCommentCidsToFetch', {\n // authorAddress,\n // authorComment,\n // previousNextCommentCidToFetch: nextCommentCidsToFetch[authorAddress],\n // nextCommentCidToFetch,\n // nextCommentCidToFetchNotFetched,\n // lastCommentCid: lastCommentCids[authorAddress],\n // shouldFetchNextComment: shouldFetchNextComment[authorAddress],\n // })\n setState((state: AuthorsCommentsState) => ({\n nextCommentCidsToFetch: {\n ...state.nextCommentCidsToFetch,\n [authorAddress]: nextCommentCidToFetchNotFetched,\n },\n }));\n },\n\n incrementPageNumber: (authorCommentsName: string) => {\n assert(\n authorCommentsName && typeof authorCommentsName === \"string\",\n `authorsCommentsActions.incrementPageNumber invalid argument authorCommentsName '${authorCommentsName}'`,\n );\n const { options, updateLoadedComments, loadedComments, nextCommentCidsToFetch } = getState();\n if (!options[authorCommentsName]) {\n throw Error(\n `authorsCommentsActions.incrementPageNumber can't increment page number of options '${authorCommentsName}' not in store`,\n );\n }\n assert(\n options[authorCommentsName].pageNumber * commentsPerPage <=\n loadedComments[authorCommentsName].length,\n `authorsCommentsActions.incrementPageNumber cannot increment page number before current page has loaded`,\n );\n\n log(\"authorsCommentsActions.incrementPageNumber\", {\n authorCommentsName,\n pageNumber: options[authorCommentsName].pageNumber + 1,\n nextCommentCidsToFetch: nextCommentCidsToFetch[options[authorCommentsName].authorAddress],\n });\n setState(({ options }: AuthorsCommentsState) => {\n const authorCommentOptions = { ...options[authorCommentsName] };\n authorCommentOptions.pageNumber++;\n return { options: { ...options, [authorCommentsName]: authorCommentOptions } };\n });\n\n // must update loadedComments to reflect the new added page\n updateLoadedComments();\n },\n\n addBufferedCommentCid: (authorAddress: string, commentCid: string) => {\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsActions.addBufferedCommentCid invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n commentCid && typeof commentCid === \"string\",\n `authorsCommentsActions.addBufferedCommentCid invalid argument commentCid '${commentCid}'`,\n );\n\n const { bufferedCommentCids } = getState();\n if (!bufferedCommentCids[authorAddress]) {\n throw Error(\n `authorsCommentsActions.addBufferedCommentCid can't add commentCid '${authorAddress}' not in store`,\n );\n }\n if (bufferedCommentCids[authorAddress].has(commentCid)) {\n throw Error(\n `authorsCommentsActions.addBufferedCommentCid can't add commentCid '${authorAddress}' '${commentCid}' already added`,\n );\n }\n\n // log.trace('authorsCommentsActions.addBufferedCommentCid', {authorAddress, commentCid, previousBufferedCommentCidsSize: bufferedCommentCids[authorAddress].size})\n setState((state: AuthorsCommentsState) => ({\n bufferedCommentCids: {\n ...state.bufferedCommentCids,\n [authorAddress]: new Set([...bufferedCommentCids[authorAddress], commentCid]),\n },\n }));\n },\n\n updateLoadedComments() {\n const { comments } = commentsStore.getState();\n let {\n loadedComments: previousAuthorsLoadedComments,\n bufferedCommentCids,\n options,\n nextCommentCidsToFetch,\n lastCommentCids,\n } = getState();\n\n const newAuthorsLoadedComments: AuthorsComments = {};\n const newShouldFetchNextComment: { [authorAddress: string]: boolean } = {};\n const newHasMoreBufferedComments: { [authorCommentsName: string]: boolean } = {};\n const authorCommentsNames = Object.keys(options);\n for (const name of authorCommentsNames) {\n const { authorAddress, pageNumber, filter } = options[name];\n const previousLoadedComments = previousAuthorsLoadedComments[name];\n const unfilteredBufferedComments: Comment[] = [...bufferedCommentCids[authorAddress]].map(\n (commentCid: string) => comments[commentCid],\n );\n\n const { loadedComments, bufferedComments: filteredBufferedComments } =\n getUpdatedLoadedAndBufferedComments(\n previousLoadedComments,\n unfilteredBufferedComments,\n pageNumber,\n filter,\n comments,\n );\n newAuthorsLoadedComments[name] = loadedComments;\n newHasMoreBufferedComments[name] = filteredBufferedComments.length > loadedComments.length;\n\n // if another authorCommentOptions should fetch, don't change it\n if (newShouldFetchNextComment[authorAddress] !== true) {\n // fetch if less comments than full page + buffer size\n newShouldFetchNextComment[authorAddress] =\n filteredBufferedComments.length < pageNumber * commentsPerPage + commentBufferSize;\n }\n }\n\n // log.trace('authorsCommentsActions.updateLoadedComments', {\n // bufferedCommentCids,\n // bufferedCommentCidsSizes: toSizes(bufferedCommentCids),\n // previousAuthorsLoadedComments,\n // newAuthorsLoadedComments,\n // previousAuthorsLoadedCommentsSizes: toSizes(previousAuthorsLoadedComments),\n // newAuthorsLoadedCommentsSizes: toSizes(newAuthorsLoadedComments),\n // newShouldFetchNextComment,\n // lastCommentCids\n // })\n setState(() => ({\n loadedComments: newAuthorsLoadedComments,\n shouldFetchNextComment: newShouldFetchNextComment,\n hasMoreBufferedComments: newHasMoreBufferedComments,\n }));\n },\n\n setLastCommentCid: (authorAddress: string, lastCommentCid: string) => {\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsActions.setLastCommentCid invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n lastCommentCid && typeof lastCommentCid === \"string\",\n `authorsCommentsActions.setLastCommentCid invalid argument lastCommentCid '${lastCommentCid}'`,\n );\n const { lastCommentCids, shouldFetchNextComment, nextCommentCidsToFetch } = getState();\n if (typeof shouldFetchNextComment[authorAddress] !== \"boolean\") {\n throw Error(\n `authorsCommentsActions.setLastCommentCid can't set lastCommentCid '${authorAddress}' not in store`,\n );\n }\n if (lastCommentCid === lastCommentCids[authorAddress]) {\n throw Error(\n `authorsCommentsActions.setLastCommentCid can't set setLastCommentCid '${authorAddress}' to '${lastCommentCid}' same value`,\n );\n }\n\n log(\"authorsCommentsActions.setLastCommentCid\", {\n authorAddress,\n lastCommentCid,\n previousLastCommentCid: lastCommentCids[authorAddress],\n shouldFetchNextComment: shouldFetchNextComment[authorAddress],\n nextCommentCidsToFetch: nextCommentCidsToFetch[authorAddress],\n });\n setState((state: AuthorsCommentsState) => ({\n lastCommentCids: { ...state.lastCommentCids, [authorAddress]: lastCommentCid },\n }));\n },\n }),\n);\n\n// if nextCommentCidsToFetch or shouldFetchNextComment changed, fetch the next comment\nconst fetchCommentOnShouldFetchOrNextCidChange =\n (options: AuthorCommentsOptions) => (state: AuthorsCommentsState) => {\n const nextCommentCidToFetch = state.nextCommentCidsToFetch[options.authorAddress];\n if (!nextCommentCidToFetch) {\n return;\n }\n\n // the buffered comments are already full, not need to fetch next comment\n const shouldFetchNextComment = state.shouldFetchNextComment[options.authorAddress];\n if (!shouldFetchNextComment) {\n return;\n }\n\n // when comment has fetched, update loadedComments, bufferedComments and shouldFetchNextComment\n if (!authorCommentCidsFetching[nextCommentCidToFetch]) {\n authorCommentCidsFetching[nextCommentCidToFetch] = true;\n commentsStore.subscribe(updateCommentsOnCommentsChange(options, nextCommentCidToFetch));\n }\n\n // start fetching comment\n const account = accountsStore.getState().accounts[options.accountId];\n const addCommentToStore = commentsStore.getState().addCommentToStore;\n addCommentToStore(nextCommentCidToFetch, account).catch((error: unknown) =>\n log.error(\n \"authorsCommentsStore fetchCommentOnShouldFetchOrNextCidChange addCommentToStore error\",\n { error, nextCommentCidToFetch, account },\n ),\n );\n };\n\n// if commentStore changed, update loadedComments, bufferedCommentCids, shouldFetchNextComment and nextCommentCidsToFetch\nlet previousComments = new QuickLru({ maxSize: 10000 });\nlet authorCommentCidsFetching: { [commentCid: string]: boolean } = {};\nlet communityLastCommentCidsFetching: { [commentCid: string]: boolean } = {};\nconst updateCommentsOnCommentsChange =\n (options: AuthorCommentsOptions, commentCid: string) => (state: CommentsState) => {\n // not a next cid, do nothing\n if (!authorCommentCidsFetching[commentCid]) {\n return;\n }\n const comment = state.comments[commentCid];\n // comment hasn't changed, do nothing\n if (!comment?.timestamp || comment === previousComments.get(commentCid)) {\n return;\n }\n // comment author address is incorrect, do nothing\n if (comment.author?.address !== options.authorAddress) {\n return;\n }\n previousComments.set(commentCid, comment);\n\n const {\n addBufferedCommentCid,\n bufferedCommentCids,\n updateLoadedComments,\n setNextCommentCidsToFetch,\n nextCommentCidsToFetch,\n } = authorsCommentsStore.getState();\n\n // the comment is a new comment, add it to buffered comment cids\n if (!bufferedCommentCids[options.authorAddress].has(commentCid)) {\n addBufferedCommentCid(options.authorAddress, commentCid);\n }\n\n // the comment was the last cid to fetch, set the next cid to fetch as the author previous cid\n const nextCidToFetch = nextCommentCidsToFetch[options.authorAddress];\n if (commentCid === nextCidToFetch) {\n setNextCommentCidsToFetch(options.authorAddress, comment);\n }\n\n // one of the comment changed, must update loaded comments\n updateLoadedComments();\n\n // the changed comment might have a new author.community.lastCommentCid, try to fetch it\n const communityLastCommentCid = comment.author?.community?.lastCommentCid;\n if (communityLastCommentCid) {\n // when last comment has fetched, update lastCommentCid\n if (!communityLastCommentCidsFetching[communityLastCommentCid]) {\n communityLastCommentCidsFetching[communityLastCommentCid] = true;\n commentsStore.subscribe(\n setLastCommentCidOnCommentsChange(options, communityLastCommentCid),\n );\n }\n\n // start fetching lastCommentCid\n const account = accountsStore.getState().accounts[options.accountId];\n state.addCommentToStore(communityLastCommentCid, account).catch((error: unknown) =>\n log.error(\"authorsCommentsStore updateCommentsOnCommentsChange addCommentToStore error\", {\n error,\n communityLastCommentCid,\n account,\n }),\n );\n }\n };\n\nlet previousLastComments = new QuickLru({ maxSize: 10000 });\nconst setLastCommentCidOnCommentsChange =\n (options: AuthorCommentsOptions, commentCid: string) => (state: CommentsState) => {\n // not a last cid candidate, do nothing\n if (!communityLastCommentCidsFetching[commentCid]) {\n return;\n }\n const { comments } = state;\n\n const comment = comments[commentCid];\n // comment hasn't changed, do nothing\n if (!comment?.timestamp || comment === previousLastComments.get(commentCid)) {\n return;\n }\n // comment author address is incorrect, do nothing\n if (comment.author?.address !== options.authorAddress) {\n return;\n }\n previousLastComments.set(commentCid, comment);\n\n const {\n addBufferedCommentCid,\n lastCommentCids,\n bufferedCommentCids,\n setLastCommentCid,\n setNextCommentCidsToFetch,\n updateLoadedComments,\n } = authorsCommentsStore.getState();\n\n // if the comment is a new comment, add it to buffered comment cids\n if (!bufferedCommentCids[options.authorAddress].has(commentCid)) {\n addBufferedCommentCid(options.authorAddress, commentCid);\n }\n\n // already last comment cid, no need to set it\n if (commentCid === lastCommentCids[options.authorAddress]) {\n return;\n }\n\n // if comment is newer than current lastCommentCid and all bufferedComments, is lastCommentCid\n const currentLastCommentCid = lastCommentCids[options.authorAddress];\n const currentLastComment = comments[currentLastCommentCid || \"\"];\n // comment is older or equal to current lastCommentCid, do nothing\n if (comment.timestamp <= (currentLastComment?.timestamp || 0)) {\n log.trace(\n `authorsCommentsStore setLastCommentCidOnCommentsChange don't set lastCommentCid older than current lastCommentCid`,\n { comment, currentLastComment },\n );\n return;\n }\n\n // make sure lastComment is newer than all comments already in bufferedComments\n const bufferedComments: Comment[] = [...bufferedCommentCids[options.authorAddress]].map(\n (commentCid: string) => comments[commentCid],\n );\n for (const bufferedComment of bufferedComments) {\n const bufferedTs =\n bufferedComment == null || bufferedComment.timestamp == null\n ? 0\n : bufferedComment.timestamp;\n if (bufferedTs > comment.timestamp) {\n log.trace(\n `authorsCommentsStore setLastCommentCidOnCommentsChange don't set lastCommentCid older than buffered comments`,\n {\n comment,\n currentLastComment,\n bufferedComments,\n },\n );\n return;\n }\n }\n\n // is last comment cid, set it\n log(`authorsCommentsStore setLastCommentCidOnCommentsChange`, {\n lastCommentCid: comment.cid,\n lastComment: comment,\n currentLastComment,\n bufferedComments,\n });\n setLastCommentCid(options.authorAddress, commentCid);\n // add the last comment to loadedComments\n updateLoadedComments();\n // start a new linked list of comments to fetch using the lastComment.author.previousCommentCid\n if (comment.author?.previousCommentCid) {\n setNextCommentCidsToFetch(options.authorAddress, comment);\n }\n };\n\n// reset store in between tests\nconst originalState = authorsCommentsStore.getState();\n// async function because some stores have async init\nexport const resetAuthorsCommentsStore = async () => {\n communityLastCommentCidsFetching = {};\n previousComments = new QuickLru({ maxSize: 10000 });\n authorCommentCidsFetching = {};\n previousLastComments = new QuickLru({ maxSize: 10000 });\n\n // destroy all component subscriptions to the store\n authorsCommentsStore.destroy();\n // restore original state\n authorsCommentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetAuthorsCommentsDatabaseAndStore = async () => {\n await resetAuthorsCommentsStore();\n};\n\nexport default authorsCommentsStore;\n"]}
|
|
1
|
+
{"version":3,"file":"authors-comments-store.js","sourceRoot":"","sources":["../../../src/stores/authors-comments/authors-comments-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAC3D,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAQtC,OAAO,aAAgC,MAAM,aAAa,CAAC;AAC3D,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAEL,mCAAmC,EACnC,kCAAkC,GACnC,MAAM,SAAS,CAAC;AACjB,OAAO,aAAa,MAAM,aAAa,CAAC;AAExC,wEAAwE;AACxE,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,kDAAkD;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAmBpC,MAAM,oBAAoB,GAAG,WAAW,CACtC,CAAC,QAAkB,EAAE,QAAkB,EAAE,EAAE,CAAC,CAAC;IAC3C,OAAO,EAAE,EAAE;IACX,cAAc,EAAE,EAAE;IAClB,uBAAuB,EAAE,EAAE;IAC3B,mBAAmB,EAAE,EAAE;IACvB,eAAe,EAAE,EAAE;IACnB,sBAAsB,EAAE,EAAE;IAC1B,sBAAsB,EAAE,EAAE;IAE1B,wBAAwB,EAAE,CACxB,kBAA0B,EAC1B,aAAqB,EACrB,UAAkB,EAClB,MAAkC,EAClC,OAAgB,EAChB,EAAE;;QACF,MAAM,CACJ,kBAAkB,IAAI,OAAO,kBAAkB,K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CAAC,QAAQ,EAAE,CAAC;AACtD,qDAAqD;AACrD,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAS,EAAE;IAClD,gCAAgC,GAAG,EAAE,CAAC;IACtC,gBAAgB,GAAG,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACpD,yBAAyB,GAAG,EAAE,CAAC;IAC/B,oBAAoB,GAAG,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAExD,mDAAmD;IACnD,oBAAoB,CAAC,OAAO,EAAE,CAAC;IAC/B,yBAAyB;IACzB,oBAAoB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC/C,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,oCAAoC,GAAG,GAAS,EAAE;IAC7D,MAAM,yBAAyB,EAAE,CAAC;AACpC,CAAC,CAAA,CAAC;AAEF,eAAe,oBAAoB,CAAC","sourcesContent":["import Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:authors:stores\");\nimport createStore from \"zustand\";\nimport assert from \"../../lib/assert\";\nimport {\n CommentsFilter,\n AuthorCommentsOptions,\n AuthorsComments,\n Account,\n Comment,\n} from \"../../types\";\nimport commentsStore, { CommentsState } from \"../comments\";\nimport QuickLru from \"quick-lru\";\nimport {\n toSizes,\n getUpdatedLoadedAndBufferedComments,\n getNextCommentCidToFetchNotFetched,\n} from \"./utils\";\nimport accountsStore from \"../accounts\";\n\n// reddit loads approximately 25 posts per page while infinite scrolling\nexport const commentsPerPage = 25;\n// keep large buffer because fetching cids is slow\nexport const commentBufferSize = 50;\n\ntype AuthorsCommentsState = {\n // authorCommentsName is a string used a key to represent authorAddress + filter + accountId\n options: { [authorCommentsName: string]: AuthorCommentsOptions };\n loadedComments: { [authorCommentsName: string]: Comment[] };\n hasMoreBufferedComments: { [authorCommentsName: string]: boolean };\n bufferedCommentCids: { [authorAddress: string]: Set<string> };\n nextCommentCidsToFetch: { [authorAddress: string]: string | undefined };\n shouldFetchNextComment: { [authorAddress: string]: boolean };\n lastCommentCids: { [authorAddress: string]: string | undefined };\n addAuthorCommentsToStore: Function;\n setNextCommentCidsToFetch: Function;\n incrementPageNumber: Function;\n addBufferedCommentCid: Function;\n updateLoadedComments: Function;\n setLastCommentCid: Function;\n};\n\nconst authorsCommentsStore = createStore<AuthorsCommentsState>(\n (setState: Function, getState: Function) => ({\n options: {},\n loadedComments: {},\n hasMoreBufferedComments: {},\n bufferedCommentCids: {},\n lastCommentCids: {},\n nextCommentCidsToFetch: {},\n shouldFetchNextComment: {},\n\n addAuthorCommentsToStore: (\n authorCommentsName: string,\n authorAddress: string,\n commentCid: string,\n filter: CommentsFilter | undefined,\n account: Account,\n ) => {\n assert(\n authorCommentsName && typeof authorCommentsName === \"string\",\n `addAuthorCommentsToStore.incrementPageNumber invalid argument authorCommentsName '${authorCommentsName}'`,\n );\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n commentCid && typeof commentCid === \"string\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument commentCid '${commentCid}'`,\n );\n assert(\n !filter || typeof filter?.filter === \"function\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument filter.filter '${filter?.filter}'`,\n );\n assert(\n !filter || typeof filter?.key === \"string\",\n `authorsCommentsStore.addAuthorCommentsToStore invalid argument filter.key '${filter?.key}'`,\n );\n assert(\n typeof account?.pkc?.getComment === \"function\",\n `authorsCommentsStore.addAuthorCommentsToStore account '${account}' invalid`,\n );\n\n const { options, updateLoadedComments } = getState();\n // in store already, do nothing\n if (options[authorCommentsName]) {\n return;\n }\n const authorCommentsOptions = { authorAddress, pageNumber: 1, filter, accountId: account.id };\n\n // subscribe to nextCommentCidsToFetch and shouldFetchNextComment to fetch the comments\n authorsCommentsStore.subscribe(\n fetchCommentOnShouldFetchOrNextCidChange(authorCommentsOptions),\n );\n\n log(\"authorsCommentsActions.addAuthorCommentsToStore\", {\n authorCommentsName,\n authorCommentsOptions,\n commentCid,\n previousAuthorsCommentsOptions: options,\n });\n setState((state: AuthorsCommentsState) => ({\n options: { ...state.options, [authorCommentsName]: authorCommentsOptions },\n loadedComments: { ...state.loadedComments, [authorCommentsName]: [] },\n hasMoreBufferedComments: { ...state.hasMoreBufferedComments, [authorCommentsName]: true },\n bufferedCommentCids: {\n ...state.bufferedCommentCids,\n [authorAddress]: state.bufferedCommentCids[authorAddress] || new Set(),\n },\n lastCommentCids: {\n ...state.lastCommentCids,\n [authorAddress]: state.lastCommentCids[authorAddress] || undefined,\n },\n nextCommentCidsToFetch: {\n ...state.nextCommentCidsToFetch,\n [authorAddress]: state.nextCommentCidsToFetch[authorAddress] || commentCid,\n },\n shouldFetchNextComment: {\n ...state.shouldFetchNextComment,\n [authorAddress]: state.shouldFetchNextComment[authorAddress] || true,\n },\n }));\n\n // update loadedComments in case the author already has bufferedCommentCids\n updateLoadedComments();\n },\n\n setNextCommentCidsToFetch: (authorAddress: string, authorComment: Comment) => {\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsActions.setNextCommentCidsToFetch invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n typeof authorComment?.timestamp === \"number\",\n `authorsCommentsActions.setNextCommentCidsToFetch invalid argument authorComment '${authorComment}'`,\n );\n const { nextCommentCidsToFetch, shouldFetchNextComment, lastCommentCids } = getState();\n if (typeof shouldFetchNextComment[authorAddress] !== \"boolean\") {\n throw Error(\n `authorsCommentsActions.setNextCommentCidsToFetch can't set nextCommentCidToFetch '${authorAddress}' not in store`,\n );\n }\n const nextCommentCidToFetch = authorComment?.author?.previousCommentCid;\n if (nextCommentCidToFetch === nextCommentCidsToFetch[authorAddress]) {\n throw Error(\n `authorsCommentsActions.setNextCommentCidsToFetch can't set nextCommentCidToFetch '${authorAddress}' to '${nextCommentCidToFetch}' same value`,\n );\n }\n const nextCommentCidToFetchNotFetched =\n getNextCommentCidToFetchNotFetched(nextCommentCidToFetch);\n\n // log.trace('authorsCommentsActions.setNextCommentCidsToFetch', {\n // authorAddress,\n // authorComment,\n // previousNextCommentCidToFetch: nextCommentCidsToFetch[authorAddress],\n // nextCommentCidToFetch,\n // nextCommentCidToFetchNotFetched,\n // lastCommentCid: lastCommentCids[authorAddress],\n // shouldFetchNextComment: shouldFetchNextComment[authorAddress],\n // })\n setState((state: AuthorsCommentsState) => ({\n nextCommentCidsToFetch: {\n ...state.nextCommentCidsToFetch,\n [authorAddress]: nextCommentCidToFetchNotFetched,\n },\n }));\n },\n\n incrementPageNumber: (authorCommentsName: string) => {\n assert(\n authorCommentsName && typeof authorCommentsName === \"string\",\n `authorsCommentsActions.incrementPageNumber invalid argument authorCommentsName '${authorCommentsName}'`,\n );\n const { options, updateLoadedComments, loadedComments, nextCommentCidsToFetch } = getState();\n if (!options[authorCommentsName]) {\n throw Error(\n `authorsCommentsActions.incrementPageNumber can't increment page number of options '${authorCommentsName}' not in store`,\n );\n }\n assert(\n options[authorCommentsName].pageNumber * commentsPerPage <=\n loadedComments[authorCommentsName].length,\n `authorsCommentsActions.incrementPageNumber cannot increment page number before current page has loaded`,\n );\n\n log(\"authorsCommentsActions.incrementPageNumber\", {\n authorCommentsName,\n pageNumber: options[authorCommentsName].pageNumber + 1,\n nextCommentCidsToFetch: nextCommentCidsToFetch[options[authorCommentsName].authorAddress],\n });\n setState(({ options }: AuthorsCommentsState) => {\n const authorCommentOptions = { ...options[authorCommentsName] };\n authorCommentOptions.pageNumber++;\n return { options: { ...options, [authorCommentsName]: authorCommentOptions } };\n });\n\n // must update loadedComments to reflect the new added page\n updateLoadedComments();\n },\n\n addBufferedCommentCid: (authorAddress: string, commentCid: string) => {\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsActions.addBufferedCommentCid invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n commentCid && typeof commentCid === \"string\",\n `authorsCommentsActions.addBufferedCommentCid invalid argument commentCid '${commentCid}'`,\n );\n\n const { bufferedCommentCids } = getState();\n if (!bufferedCommentCids[authorAddress]) {\n throw Error(\n `authorsCommentsActions.addBufferedCommentCid can't add commentCid '${authorAddress}' not in store`,\n );\n }\n if (bufferedCommentCids[authorAddress].has(commentCid)) {\n throw Error(\n `authorsCommentsActions.addBufferedCommentCid can't add commentCid '${authorAddress}' '${commentCid}' already added`,\n );\n }\n\n // log.trace('authorsCommentsActions.addBufferedCommentCid', {authorAddress, commentCid, previousBufferedCommentCidsSize: bufferedCommentCids[authorAddress].size})\n setState((state: AuthorsCommentsState) => ({\n bufferedCommentCids: {\n ...state.bufferedCommentCids,\n [authorAddress]: new Set([...bufferedCommentCids[authorAddress], commentCid]),\n },\n }));\n },\n\n updateLoadedComments() {\n const { comments } = commentsStore.getState();\n let {\n loadedComments: previousAuthorsLoadedComments,\n bufferedCommentCids,\n options,\n nextCommentCidsToFetch,\n lastCommentCids,\n } = getState();\n\n const newAuthorsLoadedComments: AuthorsComments = {};\n const newShouldFetchNextComment: { [authorAddress: string]: boolean } = {};\n const newHasMoreBufferedComments: { [authorCommentsName: string]: boolean } = {};\n const authorCommentsNames = Object.keys(options);\n for (const name of authorCommentsNames) {\n const { authorAddress, pageNumber, filter } = options[name];\n const previousLoadedComments = previousAuthorsLoadedComments[name];\n const unfilteredBufferedComments: Comment[] = [...bufferedCommentCids[authorAddress]].map(\n (commentCid: string) => comments[commentCid],\n );\n\n const { loadedComments, bufferedComments: filteredBufferedComments } =\n getUpdatedLoadedAndBufferedComments(\n previousLoadedComments,\n unfilteredBufferedComments,\n pageNumber,\n filter,\n comments,\n );\n newAuthorsLoadedComments[name] = loadedComments;\n newHasMoreBufferedComments[name] = filteredBufferedComments.length > loadedComments.length;\n\n // if another authorCommentOptions should fetch, don't change it\n if (newShouldFetchNextComment[authorAddress] !== true) {\n // fetch if less comments than full page + buffer size\n newShouldFetchNextComment[authorAddress] =\n filteredBufferedComments.length < pageNumber * commentsPerPage + commentBufferSize;\n }\n }\n\n // log.trace('authorsCommentsActions.updateLoadedComments', {\n // bufferedCommentCids,\n // bufferedCommentCidsSizes: toSizes(bufferedCommentCids),\n // previousAuthorsLoadedComments,\n // newAuthorsLoadedComments,\n // previousAuthorsLoadedCommentsSizes: toSizes(previousAuthorsLoadedComments),\n // newAuthorsLoadedCommentsSizes: toSizes(newAuthorsLoadedComments),\n // newShouldFetchNextComment,\n // lastCommentCids\n // })\n setState(() => ({\n loadedComments: newAuthorsLoadedComments,\n shouldFetchNextComment: newShouldFetchNextComment,\n hasMoreBufferedComments: newHasMoreBufferedComments,\n }));\n },\n\n setLastCommentCid: (authorAddress: string, lastCommentCid: string) => {\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `authorsCommentsActions.setLastCommentCid invalid argument authorAddress '${authorAddress}'`,\n );\n assert(\n lastCommentCid && typeof lastCommentCid === \"string\",\n `authorsCommentsActions.setLastCommentCid invalid argument lastCommentCid '${lastCommentCid}'`,\n );\n const { lastCommentCids, shouldFetchNextComment, nextCommentCidsToFetch } = getState();\n if (typeof shouldFetchNextComment[authorAddress] !== \"boolean\") {\n throw Error(\n `authorsCommentsActions.setLastCommentCid can't set lastCommentCid '${authorAddress}' not in store`,\n );\n }\n if (lastCommentCid === lastCommentCids[authorAddress]) {\n throw Error(\n `authorsCommentsActions.setLastCommentCid can't set setLastCommentCid '${authorAddress}' to '${lastCommentCid}' same value`,\n );\n }\n\n log(\"authorsCommentsActions.setLastCommentCid\", {\n authorAddress,\n lastCommentCid,\n previousLastCommentCid: lastCommentCids[authorAddress],\n shouldFetchNextComment: shouldFetchNextComment[authorAddress],\n nextCommentCidsToFetch: nextCommentCidsToFetch[authorAddress],\n });\n setState((state: AuthorsCommentsState) => ({\n lastCommentCids: { ...state.lastCommentCids, [authorAddress]: lastCommentCid },\n }));\n },\n }),\n);\n\n// if nextCommentCidsToFetch or shouldFetchNextComment changed, fetch the next comment\nconst fetchCommentOnShouldFetchOrNextCidChange =\n (options: AuthorCommentsOptions) => (state: AuthorsCommentsState) => {\n const nextCommentCidToFetch = state.nextCommentCidsToFetch[options.authorAddress];\n if (!nextCommentCidToFetch) {\n return;\n }\n\n // the buffered comments are already full, not need to fetch next comment\n const shouldFetchNextComment = state.shouldFetchNextComment[options.authorAddress];\n if (!shouldFetchNextComment) {\n return;\n }\n\n // when comment has fetched, update loadedComments, bufferedComments and shouldFetchNextComment\n if (!authorCommentCidsFetching[nextCommentCidToFetch]) {\n authorCommentCidsFetching[nextCommentCidToFetch] = true;\n commentsStore.subscribe(updateCommentsOnCommentsChange(options, nextCommentCidToFetch));\n }\n\n // start fetching comment\n const account = accountsStore.getState().accounts[options.accountId];\n const addCommentToStore = commentsStore.getState().addCommentToStore;\n addCommentToStore(nextCommentCidToFetch, account).catch((error: unknown) =>\n log.error(\n \"authorsCommentsStore fetchCommentOnShouldFetchOrNextCidChange addCommentToStore error\",\n { error, nextCommentCidToFetch, account },\n ),\n );\n };\n\n// if commentStore changed, update loadedComments, bufferedCommentCids, shouldFetchNextComment and nextCommentCidsToFetch\nlet previousComments = new QuickLru({ maxSize: 10000 });\nlet authorCommentCidsFetching: { [commentCid: string]: boolean } = {};\nlet communityLastCommentCidsFetching: { [commentCid: string]: boolean } = {};\nconst updateCommentsOnCommentsChange =\n (options: AuthorCommentsOptions, commentCid: string) => (state: CommentsState) => {\n // not a next cid, do nothing\n if (!authorCommentCidsFetching[commentCid]) {\n return;\n }\n const comment = state.comments[commentCid];\n // comment hasn't changed, do nothing\n if (!comment?.timestamp || comment === previousComments.get(commentCid)) {\n return;\n }\n // comment author address is incorrect, do nothing\n if (comment.author?.address !== options.authorAddress) {\n return;\n }\n previousComments.set(commentCid, comment);\n\n const {\n addBufferedCommentCid,\n bufferedCommentCids,\n updateLoadedComments,\n setNextCommentCidsToFetch,\n nextCommentCidsToFetch,\n } = authorsCommentsStore.getState();\n\n // the comment is a new comment, add it to buffered comment cids\n if (!bufferedCommentCids[options.authorAddress].has(commentCid)) {\n addBufferedCommentCid(options.authorAddress, commentCid);\n }\n\n // the comment was the last cid to fetch, set the next cid to fetch as the author previous cid\n const nextCidToFetch = nextCommentCidsToFetch[options.authorAddress];\n if (commentCid === nextCidToFetch) {\n setNextCommentCidsToFetch(options.authorAddress, comment);\n }\n\n // one of the comment changed, must update loaded comments\n updateLoadedComments();\n\n // the changed comment might have a new author.community.lastCommentCid, try to fetch it\n const communityLastCommentCid = comment.author?.community?.lastCommentCid;\n if (communityLastCommentCid) {\n // when last comment has fetched, update lastCommentCid\n if (!communityLastCommentCidsFetching[communityLastCommentCid]) {\n communityLastCommentCidsFetching[communityLastCommentCid] = true;\n commentsStore.subscribe(\n setLastCommentCidOnCommentsChange(options, communityLastCommentCid),\n );\n }\n\n // start fetching lastCommentCid\n const account = accountsStore.getState().accounts[options.accountId];\n state.addCommentToStore(communityLastCommentCid, account).catch((error: unknown) =>\n log.error(\"authorsCommentsStore updateCommentsOnCommentsChange addCommentToStore error\", {\n error,\n communityLastCommentCid,\n account,\n }),\n );\n }\n };\n\nlet previousLastComments = new QuickLru({ maxSize: 10000 });\nconst setLastCommentCidOnCommentsChange =\n (options: AuthorCommentsOptions, commentCid: string) => (state: CommentsState) => {\n // not a last cid candidate, do nothing\n if (!communityLastCommentCidsFetching[commentCid]) {\n return;\n }\n const { comments } = state;\n\n const comment = comments[commentCid];\n // comment hasn't changed, do nothing\n if (!comment?.timestamp || comment === previousLastComments.get(commentCid)) {\n return;\n }\n // comment author address is incorrect, do nothing\n if (comment.author?.address !== options.authorAddress) {\n return;\n }\n previousLastComments.set(commentCid, comment);\n\n const {\n addBufferedCommentCid,\n lastCommentCids,\n bufferedCommentCids,\n setLastCommentCid,\n setNextCommentCidsToFetch,\n updateLoadedComments,\n } = authorsCommentsStore.getState();\n\n // if the comment is a new comment, add it to buffered comment cids\n if (!bufferedCommentCids[options.authorAddress].has(commentCid)) {\n addBufferedCommentCid(options.authorAddress, commentCid);\n }\n\n // already last comment cid, no need to set it\n if (commentCid === lastCommentCids[options.authorAddress]) {\n return;\n }\n\n // if comment is newer than current lastCommentCid and all bufferedComments, is lastCommentCid\n const currentLastCommentCid = lastCommentCids[options.authorAddress];\n const currentLastComment = comments[currentLastCommentCid || \"\"];\n // comment is older or equal to current lastCommentCid, do nothing\n if (comment.timestamp <= (currentLastComment?.timestamp || 0)) {\n log.trace(\n `authorsCommentsStore setLastCommentCidOnCommentsChange don't set lastCommentCid older than current lastCommentCid`,\n { comment, currentLastComment },\n );\n return;\n }\n\n // make sure lastComment is newer than all comments already in bufferedComments\n const bufferedComments: Comment[] = [...bufferedCommentCids[options.authorAddress]].map(\n (commentCid: string) => comments[commentCid],\n );\n for (const bufferedComment of bufferedComments) {\n const bufferedTs =\n bufferedComment == null || bufferedComment.timestamp == null\n ? 0\n : bufferedComment.timestamp;\n if (bufferedTs > comment.timestamp) {\n log.trace(\n `authorsCommentsStore setLastCommentCidOnCommentsChange don't set lastCommentCid older than buffered comments`,\n {\n comment,\n currentLastComment,\n bufferedComments,\n },\n );\n return;\n }\n }\n\n // is last comment cid, set it\n log(`authorsCommentsStore setLastCommentCidOnCommentsChange`, {\n lastCommentCid: comment.cid,\n lastComment: comment,\n currentLastComment,\n bufferedComments,\n });\n setLastCommentCid(options.authorAddress, commentCid);\n // add the last comment to loadedComments\n updateLoadedComments();\n // start a new linked list of comments to fetch using the lastComment.author.previousCommentCid\n if (comment.author?.previousCommentCid) {\n setNextCommentCidsToFetch(options.authorAddress, comment);\n }\n };\n\n// reset store in between tests\nconst originalState = authorsCommentsStore.getState();\n// async function because some stores have async init\nexport const resetAuthorsCommentsStore = async () => {\n communityLastCommentCidsFetching = {};\n previousComments = new QuickLru({ maxSize: 10000 });\n authorCommentCidsFetching = {};\n previousLastComments = new QuickLru({ maxSize: 10000 });\n\n // destroy all component subscriptions to the store\n authorsCommentsStore.destroy();\n // restore original state\n authorsCommentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetAuthorsCommentsDatabaseAndStore = async () => {\n await resetAuthorsCommentsStore();\n};\n\nexport default authorsCommentsStore;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/authors-comments/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,aAAa,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,cAAyB,EACzB,gBAA2B,EAC3B,UAAkB,EAClB,MAAkC,EAClC,QAAkB,EAClB,EAAE;IACF,MAAM,mBAAmB,GAAG,0BAA0B,CACpD,cAAc,EACd,gBAAgB,EAChB,MAAM,EACN,QAAQ,CACT,CAAC;IAEF,yEAAyE;IACzE,IAAI,iBAAiB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,eAAe,CAAC,CAAC;IAEnF,uCAAuC;IACvC,oEAAoE;IACpE,IAAI,CAAC,mBAAmB,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE,CAAC;QAC5D,iBAAiB,GAAG,cAAc,CAAC;IACrC,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC;AACtF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,cAAyB,EACzB,gBAA2B,EAC3B,MAAkC,EAClC,QAAkB,EAClB,EAAE;IACF,mCAAmC;IACnC,MAAM,yBAAyB,GAAsC,EAAE,CAAC;IACxE,KAAK,MAAM,OAAO,IAAI,cAAc,EAAE,CAAC;QACrC,yBAAyB,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAChD,CAAC;IAED,4CAA4C;IAC5C,IAAI,mBAAmB,GAAG,gBAAgB,CAAC,MAAM,CAC/C,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,yBAAyB,CAAC,OAAO,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Aa,CAAC,QAAQ,EAAE,CAAC;IAC9C,IAAI,+BAA+B,GAAG,qBAAqB,CAAC;IAC5D,+FAA+F;IAC/F,IAAI,UAAU,GAAG,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,QAAQ,CAAC;IAC/C,OAAO,IAAI,EAAE,CAAC;QACZ,yEAAyE;QACzE,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YAClB,MAAM,KAAK,CAAC,uCAAuC,qBAAqB,iBAAiB,CAAC,CAAC;QAC7F,CAAC;QACD,MAAM,OAAO,GAAG,QAAQ,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAA,EAAE,CAAC;YACxB,MAAM;QACR,CAAC;QACD,+BAA+B,GAAG,MAAA,OAAO,CAAC,MAAM,0CAAE,kBAAkB,CAAC;IACvE,CAAC;IACD,OAAO,+BAA+B,CAAC;AACzC,CAAC,CAAC;AAEF,oDAAoD;AACpD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAA2B,EAAE,EAAE;;IACrD,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC;QACpB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAA,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,mCAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { Comment, Comments, CommentsFilter } from \"../../types\";\nimport { commentsPerPage } from \"./authors-comments-store\";\nimport assert from \"assert\";\nimport commentsStore from \"../comments\";\n\nexport const getUpdatedLoadedAndBufferedComments = (\n loadedComments: Comment[],\n bufferedComments: Comment[],\n pageNumber: number,\n filter: CommentsFilter | undefined,\n comments: Comments,\n) => {\n const newBufferedComments = getUpdatedBufferedComments(\n loadedComments,\n bufferedComments,\n filter,\n comments,\n );\n\n // create new loaded comments using the page number and buffered comments\n let newLoadedComments = newBufferedComments.slice(0, pageNumber * commentsPerPage);\n\n // check if loadedComments have changed\n // don't return a new object if there's no change, to avoid rerender\n if (!commentsHaveChanged(loadedComments, newLoadedComments)) {\n newLoadedComments = loadedComments;\n }\n\n return { loadedComments: newLoadedComments, bufferedComments: newBufferedComments };\n};\n\nexport const getUpdatedBufferedComments = (\n loadedComments: Comment[],\n bufferedComments: Comment[],\n filter: CommentsFilter | undefined,\n comments: Comments,\n) => {\n // get previous loaded comment cids\n const previousLoadedCommentCids: { [commentCid: string]: boolean } = {};\n for (const comment of loadedComments) {\n previousLoadedCommentCids[comment.cid] = true;\n }\n\n // get buffered comments without loaded cids\n let newBufferedComments = bufferedComments.filter(\n (comment) => !previousLoadedCommentCids[comment.cid],\n );\n\n // filter buffered comments\n if (filter) {\n newBufferedComments = newBufferedComments.filter(filter.filter);\n }\n\n // sort buffered comments by timestamp (newest first)\n newBufferedComments.sort((a, b) => b.timestamp - a.timestamp);\n\n // append the (new updated) loaded comments to buffered comments\n for (const comment of [...loadedComments].reverse()) {\n const updatedComment = comments[comment.cid];\n newBufferedComments.unshift(updatedComment);\n }\n\n // no need to check if comments have changed because getUpdatedBufferedComments\n // is not used anywhere outside of tests\n\n return newBufferedComments;\n};\n\nexport const commentsHaveChanged = (comments1: Comment[], comments2: Comment[]) => {\n if (comments1 === comments2) {\n return false;\n }\n if (comments1.length !== comments2.length) {\n return true;\n }\n for (const i in comments1) {\n if (comments1[i] !== comments2[i]) {\n return true;\n }\n }\n return false;\n};\n\n// if comment already exist, find the actual nextCidToFetch\n// can happen if a more recent lastCommentCid becomes nextCommentCidToFetch\nexport const getNextCommentCidToFetchNotFetched = (\n nextCommentCidToFetch: string | undefined,\n maxAttemptForTest?: number,\n) => {\n const { comments } = commentsStore.getState();\n let nextCommentCidToFetchNotFetched = nextCommentCidToFetch;\n // scroll through comments until the comment doesn't exist, which means hasn't been fetched yet\n let maxAttempt = maxAttemptForTest ?? 99999999;\n while (true) {\n // can't happen in production because of hashing, but can happen in tests\n if (!maxAttempt--) {\n throw Error(`getNextCommentCidToFetchNotFetched '${nextCommentCidToFetch}' infinite loop`);\n }\n const comment = comments[nextCommentCidToFetchNotFetched || \"\"];\n if (!comment?.timestamp) {\n break;\n }\n nextCommentCidToFetchNotFetched = comment.author?.previousCommentCid;\n }\n return nextCommentCidToFetchNotFetched;\n};\n\n// util for debugging sizes of object of arrays/sets\nexport const toSizes = (obj: { [key: string]: any }) => {\n const newObj: { [key: string]: number } = {};\n for (const i in obj) {\n newObj[i] = obj[i].length ?? obj[i].size;\n }\n return newObj;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/authors-comments/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,aAAa,MAAM,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,cAAyB,EACzB,gBAA2B,EAC3B,UAAkB,EAClB,MAAkC,EAClC,QAAkB,EAClB,EAAE;IACF,MAAM,mBAAmB,GAAG,0BAA0B,CACpD,cAAc,EACd,gBAAgB,EAChB,MAAM,EACN,QAAQ,CACT,CAAC;IAEF,yEAAyE;IACzE,IAAI,iBAAiB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,eAAe,CAAC,CAAC;IAEnF,uCAAuC;IACvC,oEAAoE;IACpE,IAAI,CAAC,mBAAmB,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE,CAAC;QAC5D,iBAAiB,GAAG,cAAc,CAAC;IACrC,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC;AACtF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,cAAyB,EACzB,gBA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AAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { Comment, Comments, CommentsFilter } from \"../../types\";\nimport { commentsPerPage } from \"./authors-comments-store\";\nimport assert from \"../../lib/assert\";\nimport commentsStore from \"../comments\";\n\nexport const getUpdatedLoadedAndBufferedComments = (\n loadedComments: Comment[],\n bufferedComments: Comment[],\n pageNumber: number,\n filter: CommentsFilter | undefined,\n comments: Comments,\n) => {\n const newBufferedComments = getUpdatedBufferedComments(\n loadedComments,\n bufferedComments,\n filter,\n comments,\n );\n\n // create new loaded comments using the page number and buffered comments\n let newLoadedComments = newBufferedComments.slice(0, pageNumber * commentsPerPage);\n\n // check if loadedComments have changed\n // don't return a new object if there's no change, to avoid rerender\n if (!commentsHaveChanged(loadedComments, newLoadedComments)) {\n newLoadedComments = loadedComments;\n }\n\n return { loadedComments: newLoadedComments, bufferedComments: newBufferedComments };\n};\n\nexport const getUpdatedBufferedComments = (\n loadedComments: Comment[],\n bufferedComments: Comment[],\n filter: CommentsFilter | undefined,\n comments: Comments,\n) => {\n // get previous loaded comment cids\n const previousLoadedCommentCids: { [commentCid: string]: boolean } = {};\n for (const comment of loadedComments) {\n previousLoadedCommentCids[comment.cid] = true;\n }\n\n // get buffered comments without loaded cids\n let newBufferedComments = bufferedComments.filter(\n (comment) => !previousLoadedCommentCids[comment.cid],\n );\n\n // filter buffered comments\n if (filter) {\n newBufferedComments = newBufferedComments.filter(filter.filter);\n }\n\n // sort buffered comments by timestamp (newest first)\n newBufferedComments.sort((a, b) => b.timestamp - a.timestamp);\n\n // append the (new updated) loaded comments to buffered comments\n for (const comment of [...loadedComments].reverse()) {\n const updatedComment = comments[comment.cid];\n newBufferedComments.unshift(updatedComment);\n }\n\n // no need to check if comments have changed because getUpdatedBufferedComments\n // is not used anywhere outside of tests\n\n return newBufferedComments;\n};\n\nexport const commentsHaveChanged = (comments1: Comment[], comments2: Comment[]) => {\n if (comments1 === comments2) {\n return false;\n }\n if (comments1.length !== comments2.length) {\n return true;\n }\n for (const i in comments1) {\n if (comments1[i] !== comments2[i]) {\n return true;\n }\n }\n return false;\n};\n\n// if comment already exist, find the actual nextCidToFetch\n// can happen if a more recent lastCommentCid becomes nextCommentCidToFetch\nexport const getNextCommentCidToFetchNotFetched = (\n nextCommentCidToFetch: string | undefined,\n maxAttemptForTest?: number,\n) => {\n const { comments } = commentsStore.getState();\n let nextCommentCidToFetchNotFetched = nextCommentCidToFetch;\n // scroll through comments until the comment doesn't exist, which means hasn't been fetched yet\n let maxAttempt = maxAttemptForTest ?? 99999999;\n while (true) {\n // can't happen in production because of hashing, but can happen in tests\n if (!maxAttempt--) {\n throw Error(`getNextCommentCidToFetchNotFetched '${nextCommentCidToFetch}' infinite loop`);\n }\n const comment = comments[nextCommentCidToFetchNotFetched || \"\"];\n if (!comment?.timestamp) {\n break;\n }\n nextCommentCidToFetchNotFetched = comment.author?.previousCommentCid;\n }\n return nextCommentCidToFetchNotFetched;\n};\n\n// util for debugging sizes of object of arrays/sets\nexport const toSizes = (obj: { [key: string]: any }) => {\n const newObj: { [key: string]: number } = {};\n for (const i in obj) {\n newObj[i] = obj[i].length ?? obj[i].size;\n }\n return newObj;\n};\n"]}
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import assert from "assert";
|
|
10
|
+
import assert from "../../lib/assert.js";
|
|
11
11
|
import localForageLru from "../../lib/localforage-lru/index.js";
|
|
12
12
|
const communitiesDatabase = localForageLru.createInstance({
|
|
13
13
|
name: "bitsocialReactHooks-communities",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities-store.js","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,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AAO,CAAC,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACxE,mDAAmD;IACnD,gBAAgB,CAAC,OAAO,EAAE,CAAC;IAC3B,yBAAyB;IACzB,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC3C,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAS,EAAE;IACzD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACzF,MAAM,qBAAqB,EAAE,CAAC;AAChC,CAAC,CAAA,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import assert from \"assert\";\nimport localForageLru from \"../../lib/localforage-lru\";\nconst communitiesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communities\",\n size: 500,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:stores\");\nimport {\n Community,\n Communities,\n Account,\n CommunityIdentifier,\n CommunitySyncState,\n CreateCommunityOptions,\n} from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport { getCommunityLookupOptions, getCommunityRefKey } from \"../../lib/community-ref\";\nimport {\n createPkcCommunity,\n getPkcCommunity,\n getPkcCommunityAddresses,\n getPkcCreateCommunity,\n getPkcGetCommunity,\n} from \"../../lib/pkc-compat\";\n\nexport const COMMUNITY_UPDATE_INTERVAL_MS = 15 * 60 * 1000;\n\nlet pkcGetCommunityPending: { [key: string]: boolean } = {};\n// Key pollers by community so delete/reset can stop the matching live instance.\nconst communityUpdatePollers: {\n [communityKey: string]: {\n community: any;\n updateInterval: ReturnType<typeof setInterval>;\n };\n} = {};\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\nconst COMMUNITY_ERROR_UPDATE_GRACE_MS = 1000;\nconst pendingCommunityErrorTimers: {\n [communityKey: string]: ReturnType<typeof setTimeout>[];\n} = {};\n\ninterface CommunitySyncStatus {\n syncState: CommunitySyncState;\n lastFetchAttemptAt?: number;\n lastSuccessfulFetchAt?: number;\n}\n\nconst getNowSeconds = () => Math.floor(Date.now() / 1000);\n\nconst normalizeCommunitySyncState = (updatingState: string): CommunitySyncState => {\n if (updatingState === \"waiting-retry\") {\n return \"retrying\";\n }\n if (updatingState === \"succeeded\" || updatingState === \"failed\" || updatingState === \"stopped\") {\n return updatingState;\n }\n return \"loading\";\n};\n\nconst updateCommunitySyncStatus = (\n setState: Function,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n setState((state: CommunitiesState) => {\n const previousStatus = state.syncStatuses[communityKey];\n const timestamp = getNowSeconds();\n const shouldRecordAttempt = syncState === \"loading\" && previousStatus?.syncState !== \"loading\";\n return {\n ...state,\n syncStatuses: {\n ...state.syncStatuses,\n [communityKey]: {\n ...previousStatus,\n syncState,\n ...(shouldRecordAttempt ? { lastFetchAttemptAt: timestamp } : undefined),\n ...(syncState === \"succeeded\" ? { lastSuccessfulFetchAt: timestamp } : undefined),\n },\n },\n };\n });\n};\n\nconst createCommunityWithLookupFallback = async (\n pkc: any,\n communityLookupOptions: { address?: string; name?: string; publicKey?: string },\n communityKey: string,\n) => {\n const supportsAddressLookup = \"address\" in communityLookupOptions;\n const community = await createPkcCommunity(pkc, communityLookupOptions);\n if (community?.address || supportsAddressLookup) {\n return community;\n }\n throw Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`);\n};\n\nconst updateCommunity = (\n community: Community,\n {\n communityAddressOrRef,\n communityKey,\n }: { communityAddressOrRef: string | CommunityIdentifier; communityKey: string },\n) => {\n community.update().catch((error: unknown) =>\n log.trace(\"community.update error\", {\n communityAddressOrRef,\n communityKey,\n community,\n error,\n }),\n );\n};\n\nconst startCommunityUpdatePolling = (\n community: Community,\n {\n communityAddressOrRef,\n communityKey,\n }: { communityAddressOrRef: string | CommunityIdentifier; communityKey: string },\n) => {\n stopCommunityUpdatePolling(communityKey);\n updateCommunity(community, { communityAddressOrRef, communityKey });\n communityUpdatePollers[communityKey] = {\n community,\n updateInterval: setInterval(\n () => updateCommunity(community, { communityAddressOrRef, communityKey }),\n COMMUNITY_UPDATE_INTERVAL_MS,\n ),\n };\n};\n\nconst stopCommunityUpdatePolling = (communityKey: string) => {\n const polling = communityUpdatePollers[communityKey];\n if (!polling) {\n return;\n }\n\n clearPendingCommunityErrors(communityKey);\n clearInterval(polling.updateInterval);\n polling.community.removeAllListeners();\n const listenerIndex = listeners.indexOf(polling.community);\n if (listenerIndex >= 0) {\n listeners.splice(listenerIndex, 1);\n }\n delete communityUpdatePollers[communityKey];\n};\n\nconst clearPendingCommunityErrors = (communityKey: string) => {\n pendingCommunityErrorTimers[communityKey]?.forEach((timeout) => clearTimeout(timeout));\n delete pendingCommunityErrorTimers[communityKey];\n};\n\nconst clearStoredCommunityErrors = (state: CommunitiesState, communityKey: string) => {\n if (!state.errors[communityKey]) {\n return state.errors;\n }\n const nextErrors = { ...state.errors };\n delete nextErrors[communityKey];\n return nextErrors;\n};\n\nexport const isRetriableCommunityLoadError = (error: Error) => {\n const details = (error as Error & { details?: unknown }).details;\n return Boolean(\n details &&\n typeof details === \"object\" &&\n \"retriableError\" in details &&\n (details as { retriableError?: unknown }).retriableError === true,\n );\n};\n\nconst scheduleCommunityError = (setState: Function, communityKey: string, error: Error) => {\n if (isRetriableCommunityLoadError(error)) {\n return;\n }\n\n const timeout = setTimeout(() => {\n const pendingTimeouts = pendingCommunityErrorTimers[communityKey];\n if (!pendingTimeouts?.includes(timeout)) {\n return;\n }\n\n const remainingTimeouts = pendingTimeouts.filter(\n (pendingTimeout) => pendingTimeout !== timeout,\n );\n if (remainingTimeouts.length === 0) {\n delete pendingCommunityErrorTimers[communityKey];\n } else {\n pendingCommunityErrorTimers[communityKey] = remainingTimeouts;\n }\n setState((state: CommunitiesState) => {\n const communityErrors = state.errors[communityKey] || [];\n return {\n ...state,\n errors: { ...state.errors, [communityKey]: [...communityErrors, error] },\n };\n });\n }, COMMUNITY_ERROR_UPDATE_GRACE_MS);\n\n pendingCommunityErrorTimers[communityKey] = [\n ...(pendingCommunityErrorTimers[communityKey] || []),\n timeout,\n ];\n};\n\nexport type CommunitiesState = {\n communities: Communities;\n errors: { [communityAddress: string]: Error[] };\n syncStatuses: { [communityAddress: string]: CommunitySyncStatus };\n addCommunityToStore: Function;\n refreshCommunity: Function;\n editCommunity: Function;\n createCommunity: Function;\n deleteCommunity: Function;\n};\n\nconst communitiesStore = createStore<CommunitiesState>(\n (setState: Function, getState: Function) => ({\n communities: {},\n errors: {},\n syncStatuses: {},\n\n async addCommunityToStore(\n communityAddressOrRef: string | CommunityIdentifier,\n account: Account,\n ) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.addCommunityToStore invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.addCommunityToStore invalid account argument '${account}'`,\n );\n\n // community is in store already, do nothing\n const { communities } = getState();\n let community: Community | undefined = communities[communityKey];\n const pendingKey = communityKey + account.id;\n if (community || pkcGetCommunityPending[pendingKey]) {\n return;\n }\n\n // start trying to get community\n pkcGetCommunityPending[pendingKey] = true;\n updateCommunitySyncStatus(setState, communityKey, \"initializing\");\n let errorGettingCommunity: any;\n try {\n // try to find community in owner communities\n if (getPkcCommunityAddresses(account.pkc).includes(communityKey)) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // try to find community in database\n let fetchedAt: number | undefined;\n if (!community) {\n const communityData: any = await communitiesDatabase.getItem(communityKey);\n const lookupName =\n \"name\" in communityLookupOptions ? communityLookupOptions.name : undefined;\n const lookupPublicKey =\n \"publicKey\" in communityLookupOptions ? communityLookupOptions.publicKey : undefined;\n const lookupAddress =\n \"address\" in communityLookupOptions ? communityLookupOptions.address : undefined;\n const hasCachedPosts =\n Object.keys(communityData?.posts?.pageCids || {}).length > 0 ||\n Object.keys(communityData?.posts?.pages || {}).length > 0;\n const isUnresolvedNameCache =\n communityData &&\n lookupName &&\n !lookupPublicKey &&\n !lookupAddress &&\n !communityData.publicKey &&\n !communityData.updatedAt &&\n !communityData.updateCid &&\n !communityData.title &&\n !communityData.description &&\n !hasCachedPosts;\n if (communityData && !isUnresolvedNameCache) {\n fetchedAt = communityData.fetchedAt;\n delete communityData.fetchedAt; // not part of pkc-js schema\n try {\n community = await createPkcCommunity(account.pkc, communityData);\n } catch (e) {\n fetchedAt = undefined;\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createCommunity(cachedCommunity)\", {\n cachedCommunity: communityData,\n error: e,\n });\n }\n }\n if (community) {\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(community);\n }\n }\n\n // community not in database, try to fetch from pkc-js\n if (!community) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // failure getting community\n if (!community) {\n if (errorGettingCommunity) {\n setState((state: CommunitiesState) => {\n let communityErrors = state.errors[communityKey] || [];\n communityErrors = [...communityErrors, errorGettingCommunity];\n return { ...state, errors: { ...state.errors, [communityKey]: communityErrors } };\n });\n }\n\n throw (\n errorGettingCommunity ||\n Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`)\n );\n }\n\n // success getting community\n const firstCommunityState = utils.clone({\n ...community,\n ...(fetchedAt !== undefined ? { fetchedAt } : undefined),\n });\n await communitiesDatabase.setItem(communityKey, firstCommunityState);\n log(\"communitiesStore.addCommunityToStore\", {\n communityAddressOrRef,\n communityKey,\n community,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: firstCommunityState },\n }));\n\n // the community has published new posts\n community.on(\"update\", async (updatedCommunity: Community) => {\n clearPendingCommunityErrors(communityKey);\n setState((state: CommunitiesState) => ({\n ...state,\n errors: clearStoredCommunityErrors(state, communityKey),\n }));\n updatedCommunity = utils.clone(updatedCommunity);\n\n // add fetchedAt to be able to expire the cache\n // NOTE: fetchedAt is undefined on owner communities because never stale\n updatedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, updatedCommunity);\n log(\"communitiesStore community update\", {\n communityAddressOrRef,\n communityKey,\n updatedCommunity,\n account,\n });\n setState((state: any) => ({\n ...state,\n communities: { ...state.communities, [communityKey]: updatedCommunity },\n }));\n\n // if a community has a role with an account's address add it to the account.communities\n accountsStore\n .getState()\n .accountsActionsInternal.addCommunityRoleToAccountsCommunities(updatedCommunity);\n\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(updatedCommunity);\n });\n\n community.on(\"updatingstatechange\", (updatingState: string) => {\n updateCommunitySyncStatus(\n setState,\n communityKey,\n normalizeCommunitySyncState(updatingState),\n );\n setState((state: CommunitiesState) => ({\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], updatingState },\n },\n }));\n });\n\n community.on(\"error\", (error: Error) => {\n scheduleCommunityError(setState, communityKey, error);\n });\n\n // set clients on community so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n community?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityKey]) {\n return {};\n }\n const clients = { ...state.communities[communityKey]?.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 communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], clients },\n },\n };\n });\n },\n );\n\n listeners.push(community);\n startCommunityUpdatePolling(community, { communityAddressOrRef, communityKey });\n } catch (error) {\n updateCommunitySyncStatus(setState, communityKey, \"failed\");\n throw error;\n } finally {\n pkcGetCommunityPending[pendingKey] = false;\n }\n },\n\n async refreshCommunity(communityAddressOrRef: string | CommunityIdentifier, account: Account) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.refreshCommunity invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `communitiesStore.refreshCommunity invalid account argument '${account}'`,\n );\n\n const refreshedCommunity = utils.clone(\n await getPkcCommunity(account.pkc, communityLookupOptions),\n );\n refreshedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, refreshedCommunity);\n log(\"communitiesStore.refreshCommunity\", {\n communityAddressOrRef,\n communityKey,\n refreshedCommunity,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: refreshedCommunity },\n }));\n\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(refreshedCommunity);\n\n return refreshedCommunity;\n },\n\n // user is the owner of the community and can edit it locally\n async editCommunity(communityAddress: string, communityEditOptions: any, account: Account) {\n assert(\n communityAddress !== \"\" && typeof communityAddress === \"string\",\n `communitiesStore.editCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n communityEditOptions && typeof communityEditOptions === \"object\",\n `communitiesStore.editCommunity invalid communityEditOptions argument '${communityEditOptions}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.editCommunity invalid account argument '${account}'`,\n );\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(communityAddress, account);\n\n // `communityAddress` is different from `communityEditOptions.address` when editing the community address\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.edit(communityEditOptions);\n\n const updatedCommunity = utils.clone(community);\n // edit db of both old and new community address to not break the UI\n await communitiesDatabase.setItem(communityAddress, updatedCommunity);\n await communitiesDatabase.setItem(community.address, updatedCommunity);\n log(\"communitiesStore.editCommunity\", {\n communityAddress,\n communityEditOptions,\n community,\n account,\n });\n setState((state: any) => ({\n communities: {\n ...state.communities,\n // edit react state of both old and new community address to not break the UI\n [communityAddress]: updatedCommunity,\n [community.address]: updatedCommunity,\n },\n }));\n },\n\n // internal action called by accountsActions.createCommunity\n async createCommunity(createCommunityOptions: CreateCommunityOptions, account: Account) {\n assert(\n !createCommunityOptions || typeof createCommunityOptions === \"object\",\n `communitiesStore.createCommunity invalid createCommunityOptions argument '${createCommunityOptions}'`,\n );\n if (!createCommunityOptions?.signer) {\n assert(\n !createCommunityOptions?.address,\n `communitiesStore.createCommunity createCommunityOptions.address '${createCommunityOptions?.address}' must be undefined to create a community`,\n );\n }\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.createCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, createCommunityOptions);\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(community.address, account);\n\n await communitiesDatabase.setItem(community.address, utils.clone(community));\n log(\"communitiesStore.createCommunity\", { createCommunityOptions, community, account });\n setState((state: any) => ({\n communities: { ...state.communities, [community.address]: utils.clone(community) },\n }));\n return community;\n },\n\n // internal action called by accountsActions.deleteCommunity\n async deleteCommunity(communityAddress: string, account: Account) {\n assert(\n communityAddress && typeof communityAddress === \"string\",\n `communitiesStore.deleteCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.deleteCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.delete();\n stopCommunityUpdatePolling(communityAddress);\n await communitiesDatabase.removeItem(communityAddress);\n log(\"communitiesStore.deleteCommunity\", { communityAddress, community, account });\n setState((state: CommunitiesState) => {\n const syncStatuses = { ...state.syncStatuses };\n delete syncStatuses[communityAddress];\n const errors = { ...state.errors };\n delete errors[communityAddress];\n return {\n communities: { ...state.communities, [communityAddress]: undefined },\n errors,\n syncStatuses,\n };\n });\n },\n }),\n);\n\n// reset store in between tests\nconst originalState = communitiesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesStore = async () => {\n pkcGetCommunityPending = {};\n Object.keys(pendingCommunityErrorTimers).forEach(clearPendingCommunityErrors);\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n Object.keys(communityUpdatePollers).forEach(stopCommunityUpdatePolling);\n // destroy all component subscriptions to the store\n communitiesStore.destroy();\n // restore original state\n communitiesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communities\" }).clear();\n await resetCommunitiesStore();\n};\n\nexport default communitiesStore;\n"]}
|
|
1
|
+
{"version":3,"file":"communities-store.js","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OA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EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACxE,mDAAmD;IACnD,gBAAgB,CAAC,OAAO,EAAE,CAAC;IAC3B,yBAAyB;IACzB,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC3C,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAS,EAAE;IACzD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACzF,MAAM,qBAAqB,EAAE,CAAC;AAChC,CAAC,CAAA,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import assert from \"../../lib/assert\";\nimport localForageLru from \"../../lib/localforage-lru\";\nconst communitiesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communities\",\n size: 500,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:stores\");\nimport {\n Community,\n Communities,\n Account,\n CommunityIdentifier,\n CommunitySyncState,\n CreateCommunityOptions,\n} from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport { getCommunityLookupOptions, getCommunityRefKey } from \"../../lib/community-ref\";\nimport {\n createPkcCommunity,\n getPkcCommunity,\n getPkcCommunityAddresses,\n getPkcCreateCommunity,\n getPkcGetCommunity,\n} from \"../../lib/pkc-compat\";\n\nexport const COMMUNITY_UPDATE_INTERVAL_MS = 15 * 60 * 1000;\n\nlet pkcGetCommunityPending: { [key: string]: boolean } = {};\n// Key pollers by community so delete/reset can stop the matching live instance.\nconst communityUpdatePollers: {\n [communityKey: string]: {\n community: any;\n updateInterval: ReturnType<typeof setInterval>;\n };\n} = {};\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\nconst COMMUNITY_ERROR_UPDATE_GRACE_MS = 1000;\nconst pendingCommunityErrorTimers: {\n [communityKey: string]: ReturnType<typeof setTimeout>[];\n} = {};\n\ninterface CommunitySyncStatus {\n syncState: CommunitySyncState;\n lastFetchAttemptAt?: number;\n lastSuccessfulFetchAt?: number;\n}\n\nconst getNowSeconds = () => Math.floor(Date.now() / 1000);\n\nconst normalizeCommunitySyncState = (updatingState: string): CommunitySyncState => {\n if (updatingState === \"waiting-retry\") {\n return \"retrying\";\n }\n if (updatingState === \"succeeded\" || updatingState === \"failed\" || updatingState === \"stopped\") {\n return updatingState;\n }\n return \"loading\";\n};\n\nconst updateCommunitySyncStatus = (\n setState: Function,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n setState((state: CommunitiesState) => {\n const previousStatus = state.syncStatuses[communityKey];\n const timestamp = getNowSeconds();\n const shouldRecordAttempt = syncState === \"loading\" && previousStatus?.syncState !== \"loading\";\n return {\n ...state,\n syncStatuses: {\n ...state.syncStatuses,\n [communityKey]: {\n ...previousStatus,\n syncState,\n ...(shouldRecordAttempt ? { lastFetchAttemptAt: timestamp } : undefined),\n ...(syncState === \"succeeded\" ? { lastSuccessfulFetchAt: timestamp } : undefined),\n },\n },\n };\n });\n};\n\nconst createCommunityWithLookupFallback = async (\n pkc: any,\n communityLookupOptions: { address?: string; name?: string; publicKey?: string },\n communityKey: string,\n) => {\n const supportsAddressLookup = \"address\" in communityLookupOptions;\n const community = await createPkcCommunity(pkc, communityLookupOptions);\n if (community?.address || supportsAddressLookup) {\n return community;\n }\n throw Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`);\n};\n\nconst updateCommunity = (\n community: Community,\n {\n communityAddressOrRef,\n communityKey,\n }: { communityAddressOrRef: string | CommunityIdentifier; communityKey: string },\n) => {\n community.update().catch((error: unknown) =>\n log.trace(\"community.update error\", {\n communityAddressOrRef,\n communityKey,\n community,\n error,\n }),\n );\n};\n\nconst startCommunityUpdatePolling = (\n community: Community,\n {\n communityAddressOrRef,\n communityKey,\n }: { communityAddressOrRef: string | CommunityIdentifier; communityKey: string },\n) => {\n stopCommunityUpdatePolling(communityKey);\n updateCommunity(community, { communityAddressOrRef, communityKey });\n communityUpdatePollers[communityKey] = {\n community,\n updateInterval: setInterval(\n () => updateCommunity(community, { communityAddressOrRef, communityKey }),\n COMMUNITY_UPDATE_INTERVAL_MS,\n ),\n };\n};\n\nconst stopCommunityUpdatePolling = (communityKey: string) => {\n const polling = communityUpdatePollers[communityKey];\n if (!polling) {\n return;\n }\n\n clearPendingCommunityErrors(communityKey);\n clearInterval(polling.updateInterval);\n polling.community.removeAllListeners();\n const listenerIndex = listeners.indexOf(polling.community);\n if (listenerIndex >= 0) {\n listeners.splice(listenerIndex, 1);\n }\n delete communityUpdatePollers[communityKey];\n};\n\nconst clearPendingCommunityErrors = (communityKey: string) => {\n pendingCommunityErrorTimers[communityKey]?.forEach((timeout) => clearTimeout(timeout));\n delete pendingCommunityErrorTimers[communityKey];\n};\n\nconst clearStoredCommunityErrors = (state: CommunitiesState, communityKey: string) => {\n if (!state.errors[communityKey]) {\n return state.errors;\n }\n const nextErrors = { ...state.errors };\n delete nextErrors[communityKey];\n return nextErrors;\n};\n\nexport const isRetriableCommunityLoadError = (error: Error) => {\n const details = (error as Error & { details?: unknown }).details;\n return Boolean(\n details &&\n typeof details === \"object\" &&\n \"retriableError\" in details &&\n (details as { retriableError?: unknown }).retriableError === true,\n );\n};\n\nconst scheduleCommunityError = (setState: Function, communityKey: string, error: Error) => {\n if (isRetriableCommunityLoadError(error)) {\n return;\n }\n\n const timeout = setTimeout(() => {\n const pendingTimeouts = pendingCommunityErrorTimers[communityKey];\n if (!pendingTimeouts?.includes(timeout)) {\n return;\n }\n\n const remainingTimeouts = pendingTimeouts.filter(\n (pendingTimeout) => pendingTimeout !== timeout,\n );\n if (remainingTimeouts.length === 0) {\n delete pendingCommunityErrorTimers[communityKey];\n } else {\n pendingCommunityErrorTimers[communityKey] = remainingTimeouts;\n }\n setState((state: CommunitiesState) => {\n const communityErrors = state.errors[communityKey] || [];\n return {\n ...state,\n errors: { ...state.errors, [communityKey]: [...communityErrors, error] },\n };\n });\n }, COMMUNITY_ERROR_UPDATE_GRACE_MS);\n\n pendingCommunityErrorTimers[communityKey] = [\n ...(pendingCommunityErrorTimers[communityKey] || []),\n timeout,\n ];\n};\n\nexport type CommunitiesState = {\n communities: Communities;\n errors: { [communityAddress: string]: Error[] };\n syncStatuses: { [communityAddress: string]: CommunitySyncStatus };\n addCommunityToStore: Function;\n refreshCommunity: Function;\n editCommunity: Function;\n createCommunity: Function;\n deleteCommunity: Function;\n};\n\nconst communitiesStore = createStore<CommunitiesState>(\n (setState: Function, getState: Function) => ({\n communities: {},\n errors: {},\n syncStatuses: {},\n\n async addCommunityToStore(\n communityAddressOrRef: string | CommunityIdentifier,\n account: Account,\n ) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.addCommunityToStore invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.addCommunityToStore invalid account argument '${account}'`,\n );\n\n // community is in store already, do nothing\n const { communities } = getState();\n let community: Community | undefined = communities[communityKey];\n const pendingKey = communityKey + account.id;\n if (community || pkcGetCommunityPending[pendingKey]) {\n return;\n }\n\n // start trying to get community\n pkcGetCommunityPending[pendingKey] = true;\n updateCommunitySyncStatus(setState, communityKey, \"initializing\");\n let errorGettingCommunity: any;\n try {\n // try to find community in owner communities\n if (getPkcCommunityAddresses(account.pkc).includes(communityKey)) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // try to find community in database\n let fetchedAt: number | undefined;\n if (!community) {\n const communityData: any = await communitiesDatabase.getItem(communityKey);\n const lookupName =\n \"name\" in communityLookupOptions ? communityLookupOptions.name : undefined;\n const lookupPublicKey =\n \"publicKey\" in communityLookupOptions ? communityLookupOptions.publicKey : undefined;\n const lookupAddress =\n \"address\" in communityLookupOptions ? communityLookupOptions.address : undefined;\n const hasCachedPosts =\n Object.keys(communityData?.posts?.pageCids || {}).length > 0 ||\n Object.keys(communityData?.posts?.pages || {}).length > 0;\n const isUnresolvedNameCache =\n communityData &&\n lookupName &&\n !lookupPublicKey &&\n !lookupAddress &&\n !communityData.publicKey &&\n !communityData.updatedAt &&\n !communityData.updateCid &&\n !communityData.title &&\n !communityData.description &&\n !hasCachedPosts;\n if (communityData && !isUnresolvedNameCache) {\n fetchedAt = communityData.fetchedAt;\n delete communityData.fetchedAt; // not part of pkc-js schema\n try {\n community = await createPkcCommunity(account.pkc, communityData);\n } catch (e) {\n fetchedAt = undefined;\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createCommunity(cachedCommunity)\", {\n cachedCommunity: communityData,\n error: e,\n });\n }\n }\n if (community) {\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(community);\n }\n }\n\n // community not in database, try to fetch from pkc-js\n if (!community) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // failure getting community\n if (!community) {\n if (errorGettingCommunity) {\n setState((state: CommunitiesState) => {\n let communityErrors = state.errors[communityKey] || [];\n communityErrors = [...communityErrors, errorGettingCommunity];\n return { ...state, errors: { ...state.errors, [communityKey]: communityErrors } };\n });\n }\n\n throw (\n errorGettingCommunity ||\n Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`)\n );\n }\n\n // success getting community\n const firstCommunityState = utils.clone({\n ...community,\n ...(fetchedAt !== undefined ? { fetchedAt } : undefined),\n });\n await communitiesDatabase.setItem(communityKey, firstCommunityState);\n log(\"communitiesStore.addCommunityToStore\", {\n communityAddressOrRef,\n communityKey,\n community,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: firstCommunityState },\n }));\n\n // the community has published new posts\n community.on(\"update\", async (updatedCommunity: Community) => {\n clearPendingCommunityErrors(communityKey);\n setState((state: CommunitiesState) => ({\n ...state,\n errors: clearStoredCommunityErrors(state, communityKey),\n }));\n updatedCommunity = utils.clone(updatedCommunity);\n\n // add fetchedAt to be able to expire the cache\n // NOTE: fetchedAt is undefined on owner communities because never stale\n updatedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, updatedCommunity);\n log(\"communitiesStore community update\", {\n communityAddressOrRef,\n communityKey,\n updatedCommunity,\n account,\n });\n setState((state: any) => ({\n ...state,\n communities: { ...state.communities, [communityKey]: updatedCommunity },\n }));\n\n // if a community has a role with an account's address add it to the account.communities\n accountsStore\n .getState()\n .accountsActionsInternal.addCommunityRoleToAccountsCommunities(updatedCommunity);\n\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(updatedCommunity);\n });\n\n community.on(\"updatingstatechange\", (updatingState: string) => {\n updateCommunitySyncStatus(\n setState,\n communityKey,\n normalizeCommunitySyncState(updatingState),\n );\n setState((state: CommunitiesState) => ({\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], updatingState },\n },\n }));\n });\n\n community.on(\"error\", (error: Error) => {\n scheduleCommunityError(setState, communityKey, error);\n });\n\n // set clients on community so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n community?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityKey]) {\n return {};\n }\n const clients = { ...state.communities[communityKey]?.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 communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], clients },\n },\n };\n });\n },\n );\n\n listeners.push(community);\n startCommunityUpdatePolling(community, { communityAddressOrRef, communityKey });\n } catch (error) {\n updateCommunitySyncStatus(setState, communityKey, \"failed\");\n throw error;\n } finally {\n pkcGetCommunityPending[pendingKey] = false;\n }\n },\n\n async refreshCommunity(communityAddressOrRef: string | CommunityIdentifier, account: Account) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.refreshCommunity invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `communitiesStore.refreshCommunity invalid account argument '${account}'`,\n );\n\n const refreshedCommunity = utils.clone(\n await getPkcCommunity(account.pkc, communityLookupOptions),\n );\n refreshedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, refreshedCommunity);\n log(\"communitiesStore.refreshCommunity\", {\n communityAddressOrRef,\n communityKey,\n refreshedCommunity,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: refreshedCommunity },\n }));\n\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(refreshedCommunity);\n\n return refreshedCommunity;\n },\n\n // user is the owner of the community and can edit it locally\n async editCommunity(communityAddress: string, communityEditOptions: any, account: Account) {\n assert(\n communityAddress !== \"\" && typeof communityAddress === \"string\",\n `communitiesStore.editCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n communityEditOptions && typeof communityEditOptions === \"object\",\n `communitiesStore.editCommunity invalid communityEditOptions argument '${communityEditOptions}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.editCommunity invalid account argument '${account}'`,\n );\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(communityAddress, account);\n\n // `communityAddress` is different from `communityEditOptions.address` when editing the community address\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.edit(communityEditOptions);\n\n const updatedCommunity = utils.clone(community);\n // edit db of both old and new community address to not break the UI\n await communitiesDatabase.setItem(communityAddress, updatedCommunity);\n await communitiesDatabase.setItem(community.address, updatedCommunity);\n log(\"communitiesStore.editCommunity\", {\n communityAddress,\n communityEditOptions,\n community,\n account,\n });\n setState((state: any) => ({\n communities: {\n ...state.communities,\n // edit react state of both old and new community address to not break the UI\n [communityAddress]: updatedCommunity,\n [community.address]: updatedCommunity,\n },\n }));\n },\n\n // internal action called by accountsActions.createCommunity\n async createCommunity(createCommunityOptions: CreateCommunityOptions, account: Account) {\n assert(\n !createCommunityOptions || typeof createCommunityOptions === \"object\",\n `communitiesStore.createCommunity invalid createCommunityOptions argument '${createCommunityOptions}'`,\n );\n if (!createCommunityOptions?.signer) {\n assert(\n !createCommunityOptions?.address,\n `communitiesStore.createCommunity createCommunityOptions.address '${createCommunityOptions?.address}' must be undefined to create a community`,\n );\n }\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.createCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, createCommunityOptions);\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(community.address, account);\n\n await communitiesDatabase.setItem(community.address, utils.clone(community));\n log(\"communitiesStore.createCommunity\", { createCommunityOptions, community, account });\n setState((state: any) => ({\n communities: { ...state.communities, [community.address]: utils.clone(community) },\n }));\n return community;\n },\n\n // internal action called by accountsActions.deleteCommunity\n async deleteCommunity(communityAddress: string, account: Account) {\n assert(\n communityAddress && typeof communityAddress === \"string\",\n `communitiesStore.deleteCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.deleteCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.delete();\n stopCommunityUpdatePolling(communityAddress);\n await communitiesDatabase.removeItem(communityAddress);\n log(\"communitiesStore.deleteCommunity\", { communityAddress, community, account });\n setState((state: CommunitiesState) => {\n const syncStatuses = { ...state.syncStatuses };\n delete syncStatuses[communityAddress];\n const errors = { ...state.errors };\n delete errors[communityAddress];\n return {\n communities: { ...state.communities, [communityAddress]: undefined },\n errors,\n syncStatuses,\n };\n });\n },\n }),\n);\n\n// reset store in between tests\nconst originalState = communitiesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesStore = async () => {\n pkcGetCommunityPending = {};\n Object.keys(pendingCommunityErrorTimers).forEach(clearPendingCommunityErrors);\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n Object.keys(communityUpdatePollers).forEach(stopCommunityUpdatePolling);\n // destroy all component subscriptions to the store\n communitiesStore.destroy();\n // restore original state\n communitiesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communities\" }).clear();\n await resetCommunitiesStore();\n};\n\nexport default communitiesStore;\n"]}
|