@bitsocial/bitsocial-react-hooks 0.2.2 → 0.2.3
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 +22 -0
- package/README.md +2 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -1
- package/dist/hooks/accounts/accounts.js +35 -10
- package/dist/hooks/accounts/accounts.js.map +1 -1
- package/dist/hooks/actions/actions.d.ts.map +1 -1
- package/dist/hooks/actions/actions.js +166 -93
- package/dist/hooks/actions/actions.js.map +1 -1
- package/dist/hooks/authors/author-avatars.d.ts +2 -2
- package/dist/hooks/authors/author-avatars.d.ts.map +1 -1
- package/dist/hooks/authors/author-avatars.js +48 -20
- package/dist/hooks/authors/author-avatars.js.map +1 -1
- package/dist/hooks/authors/authors.d.ts.map +1 -1
- package/dist/hooks/authors/authors.js +68 -22
- package/dist/hooks/authors/authors.js.map +1 -1
- package/dist/hooks/comments.d.ts.map +1 -1
- package/dist/hooks/comments.js +54 -3
- package/dist/hooks/comments.js.map +1 -1
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +41 -12
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +47 -11
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/hooks/pkc-rpc.d.ts.map +1 -1
- package/dist/hooks/pkc-rpc.js +33 -20
- package/dist/hooks/pkc-rpc.js.map +1 -1
- package/dist/hooks/replies.d.ts.map +1 -1
- package/dist/hooks/replies.js +30 -4
- package/dist/hooks/replies.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/debug-utils.d.ts +4 -4
- package/dist/lib/debug-utils.d.ts.map +1 -1
- package/dist/lib/debug-utils.js +56 -11
- package/dist/lib/debug-utils.js.map +1 -1
- package/dist/lib/localforage-lru/localforage-lru.d.ts +1 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -1
- package/dist/lib/localforage-lru/localforage-lru.js +48 -10
- package/dist/lib/localforage-lru/localforage-lru.js.map +1 -1
- package/dist/lib/page-sorts.d.ts +6 -0
- package/dist/lib/page-sorts.d.ts.map +1 -1
- package/dist/lib/page-sorts.js +45 -9
- package/dist/lib/page-sorts.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js +5 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
- package/dist/lib/utils/utils.d.ts.map +1 -1
- package/dist/lib/utils/utils.js +24 -16
- package/dist/lib/utils/utils.js.map +1 -1
- package/dist/lib/validator.d.ts +1 -1
- package/dist/lib/validator.d.ts.map +1 -1
- package/dist/lib/validator.js +7 -1
- package/dist/lib/validator.js.map +1 -1
- package/dist/stores/accounts/account-generator.d.ts +1 -0
- package/dist/stores/accounts/account-generator.d.ts.map +1 -1
- package/dist/stores/accounts/account-generator.js +12 -4
- package/dist/stores/accounts/account-generator.js.map +1 -1
- package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions-internal.js +24 -6
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +339 -98
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/accounts-database.d.ts +1 -0
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-database.js +82 -15
- package/dist/stores/accounts/accounts-database.js.map +1 -1
- package/dist/stores/accounts/accounts-store.d.ts +1 -1
- package/dist/stores/accounts/accounts-store.d.ts.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.d.ts +5 -1
- package/dist/stores/accounts/utils.d.ts.map +1 -1
- package/dist/stores/accounts/utils.js +58 -0
- package/dist/stores/accounts/utils.js.map +1 -1
- package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -1
- package/dist/stores/authors-comments/authors-comments-store.js +39 -12
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
- package/dist/stores/comments/comments-store.d.ts +2 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -1
- package/dist/stores/comments/comments-store.js +170 -21
- package/dist/stores/comments/comments-store.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +27 -7
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js +60 -8
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
- package/dist/stores/feeds/feed-sorter.d.ts +5 -2
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
- package/dist/stores/feeds/feed-sorter.js +15 -4
- 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 +36 -26
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/stores/feeds/utils.d.ts +16 -0
- package/dist/stores/feeds/utils.d.ts.map +1 -1
- package/dist/stores/feeds/utils.js +82 -26
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/stores/replies/replies-store.d.ts.map +1 -1
- package/dist/stores/replies/replies-store.js +32 -6
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.d.ts +3 -2
- package/dist/stores/replies/utils.d.ts.map +1 -1
- package/dist/stores/replies/utils.js +38 -5
- package/dist/stores/replies/utils.js.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js +68 -13
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
- package/dist/types.d.ts +11 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities-pages-store.js","sourceRoot":"","sources":["../../../src/stores/communities-pages/communities-pages-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,2DAA2D;AAC3D,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAShE,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,gBAAsC,MAAM,gBAAgB,CAAC;AACpE,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,wBAAwB,GAAG,cAAc,CAAC,cAAc,CAAC;IAC7D,IAAI,EAAE,sCAAsC;IAC5C,IAAI,EAAE,GAAG;CACV,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,OAAe,EAAE,QAAgB,EAAE,SAAkB,EAAE,EAAE;IACzF,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC5B,MAAM,CACJ,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,EAC1C,uCAAuC,SAAS,wBAAwB,CACzE,CAAC;QACF,OAAO,GAAG,SAAS,IAAI,OAAO,EAAE,CAAC;IACnC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,4HAA4H;AAC5H,MAAM,CAAC,MAAM,mBA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kB,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACrB,mDAAmD;IACnD,qBAAqB,CAAC,OAAO,EAAE,CAAC;IAChC,yBAAyB;IACzB,qBAAqB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAChD,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,qCAAqC,GAAG,GAAS,EAAE;IAC9D,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC9F,MAAM,0BAA0B,EAAE,CAAC;AACrC,CAAC,CAAA,CAAC;AAEF,eAAe,qBAAqB,CAAC","sourcesContent":["import utils from \"../../lib/utils\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\n// include communities pages store with feeds for debugging\nexport const log = Logger(\"bitsocial-react-hooks:feeds:stores\");\nimport {\n Community,\n CommunityPage,\n CommunitiesPages,\n Account,\n Comment,\n Comments,\n} from \"../../types\";\nimport accountsStore from \"../accounts\";\nimport communitiesStore, { CommunitiesState } from \"../communities\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport createStore from \"zustand\";\nimport assert from \"../../lib/assert\";\nimport {\n createPkcCommunity,\n getPkcCreateCommunity,\n normalizeCommentCommunityAddress,\n} from \"../../lib/pkc-compat\";\nimport { getPostPageSortType } from \"../../lib/page-sorts\";\n\nconst communitiesPagesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communitiesPages\",\n size: 500,\n});\n\nconst getCommunityPageStoreKey = (pageCid: string, pageType: string, accountId?: string) => {\n if (pageType === \"modQueue\") {\n assert(\n accountId && typeof accountId === \"string\",\n `getCommunityPageStoreKey accountId '${accountId}' invalid for modQueue`,\n );\n return `${accountId}:${pageCid}`;\n }\n return pageCid;\n};\n\n/** Freshness for comparison: max(updatedAt, timestamp, 0). Used to decide add vs replace per CID. Exported for coverage. */\nexport const getCommentFreshness = (comment: Comment | undefined): number =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\n// the page keys stored for each community address, with the page type and account each was\n// fetched for, to find the pages a community no longer links to\ntype StoredCommunityPage = { pageType: string; accountId: string };\nlet storedCommunityPageKeys: {\n [communityAddress: string]: { [pageStoreKey: string]: StoredCommunityPage };\n} = {};\n\n// The page keys community records link to: the first page cids of every sort, followed through the\n// stored pages' nextCid. A superset of the chain getCommunityPages walks for one sort.\nconst getLinkedCommunityPageKeys = (\n communityRecords: Community[],\n communitiesPages: CommunitiesPages,\n pageType: string,\n accountId: string,\n) => {\n const linkedPageKeys = new Set<string>();\n for (const communityRecord of communityRecords) {\n const pages = communityRecord?.[pageType];\n const firstPageCids = [\n ...Object.values(pages?.pageCids || {}),\n ...Object.values(pages?.pages || {}).map((page: any) => page?.nextCid),\n ];\n for (let pageCid of firstPageCids) {\n while (typeof pageCid === \"string\" && pageCid) {\n const pageKey = getCommunityPageStoreKey(pageCid, pageType, accountId);\n if (linkedPageKeys.has(pageKey)) {\n break;\n }\n linkedPageKeys.add(pageKey);\n pageCid = communitiesPages[pageKey]?.nextCid;\n }\n }\n }\n return linkedPageKeys;\n};\n\n// A community update replaces its page cids, and getCommunityPages only walks from the current ones,\n// so the previous page chains are never read again. Without dropping them, a feed left open keeps a\n// copy of its communities' pages for every update it fetched pages after. Only pages of this\n// community are checked, against its stored records and the record the caller fetched with, so a\n// page fetched with a record that was replaced meanwhile doesn't drop the current chain. A later\n// page shared by the old and new chains is dropped until the new chain reaches it again, and is then\n// read back from the pages database.\nconst removeUnlinkedCommunityPages = (communitiesPages: CommunitiesPages, community: Community) => {\n const storedPageKeys = storedCommunityPageKeys[community.address];\n if (!storedPageKeys) {\n return;\n }\n const communityRecords = [\n community,\n ...Object.values(communitiesStore.getState()?.communities || {}).filter(\n (communityRecord: any) => communityRecord?.address === community.address,\n ),\n ];\n const linkedPageKeys: { [pageTypeAndAccount: string]: Set<string> } = {};\n const unlinkedPageKeys: string[] = [];\n for (const pageKey in storedPageKeys) {\n if (!communitiesPages[pageKey]) {\n // already removed, e.g. by invalidateCommunityPages\n delete storedPageKeys[pageKey];\n continue;\n }\n const { pageType, accountId } = storedPageKeys[pageKey];\n const pageTypeAndAccount = `${pageType}:${accountId}`;\n if (!linkedPageKeys[pageTypeAndAccount]) {\n linkedPageKeys[pageTypeAndAccount] = getLinkedCommunityPageKeys(\n communityRecords,\n communitiesPages,\n pageType,\n accountId,\n );\n }\n if (!linkedPageKeys[pageTypeAndAccount].has(pageKey)) {\n unlinkedPageKeys.push(pageKey);\n }\n }\n for (const pageKey of unlinkedPageKeys) {\n delete communitiesPages[pageKey];\n delete storedPageKeys[pageKey];\n }\n};\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\ntype CommunitiesPagesState = {\n communitiesPages: CommunitiesPages;\n comments: Comments;\n addNextCommunityPageToStore: Function;\n invalidateCommunityPages: Function;\n addCommunityPageCommentsToStore: Function;\n};\n\nconst communitiesPagesStore = createStore<CommunitiesPagesState>(\n (setState: Function, getState: Function) => ({\n // pages a community no longer links to are dropped when one of its pages is added\n // TODO: eventually clear old comments from memory\n communitiesPages: {},\n comments: {},\n\n addNextCommunityPageToStore: async (\n community: Community,\n sortType: string | undefined,\n account: Account,\n modQueue?: string[],\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.addNextCommunityPageToStore community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `communitiesPagesStore.addNextCommunityPageToStore sortType '${sortType}' invalid`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesPagesStore.addNextCommunityPageToStore account '${account}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.addNextCommunityPageToStore modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // check the preloaded posts on community.posts.pages first, then the community.posts.pageCids\n const communityFirstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!communityFirstPageCid) {\n log(\n `communitiesPagesStore.addNextCommunityPageToStore community '${community?.address}' sortType '${sortType}' no communityFirstPageCid`,\n );\n return;\n }\n\n // all communities pages in store\n const { communitiesPages } = getState();\n // only specific pages of the community+sortType\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n account.id,\n );\n\n // if no pages exist yet, add the first page\n let pageCidToAdd: string;\n if (!communityPages.length) {\n pageCidToAdd = communityFirstPageCid;\n } else {\n const nextCid = communityPages[communityPages.length - 1]?.nextCid;\n // if last nextCid is undefined, reached end of pages\n if (!nextCid) {\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore no more pages\", {\n communityAddress: community.address,\n sortType,\n account,\n });\n return;\n }\n\n pageCidToAdd = nextCid;\n }\n\n // page is already added or pending\n const pageStoreKeyToAdd = getCommunityPageStoreKey(pageCidToAdd, pageType, account.id);\n if (communitiesPages[pageStoreKeyToAdd] || fetchPagePending[pageStoreKeyToAdd]) {\n return;\n }\n\n fetchPagePending[pageStoreKeyToAdd] = true;\n let page: CommunityPage;\n try {\n page = await fetchPage(pageCidToAdd, community.address, account, pageType);\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore community.posts.getPage\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n account,\n });\n } catch (e) {\n throw e;\n } finally {\n fetchPagePending[pageStoreKeyToAdd] = false;\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(page);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n if (pageType !== \"modQueue\") {\n for (const comment of flattenedComments) {\n const normalizedComment = normalizeCommentCommunityAddress(comment) as Comment;\n const existing = comments[normalizedComment.cid];\n if (\n normalizedComment.cid &&\n (!existing || getCommentFreshness(normalizedComment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[normalizedComment.cid] = normalizedComment;\n hasNewComments = true;\n }\n }\n }\n\n storedCommunityPageKeys[community.address] = {\n ...storedCommunityPageKeys[community.address],\n [pageStoreKeyToAdd]: { pageType, accountId: account.id },\n };\n setState(({ communitiesPages, comments }: any) => {\n const nextCommunitiesPages = { ...communitiesPages, [pageStoreKeyToAdd]: page };\n removeUnlinkedCommunityPages(nextCommunitiesPages, community);\n const newState: any = { communitiesPages: nextCommunitiesPages };\n if (hasNewComments) {\n newState.comments = { ...comments, ...newComments };\n }\n return newState;\n });\n log(\"communitiesPagesStore.addNextCommunityPageToStore\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n sortType,\n page,\n account,\n });\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n for (const comment of flattenedComments) {\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(\n normalizeCommentCommunityAddress(comment) as Comment,\n )\n .catch((error: unknown) =>\n log.error(\n \"communitiesPagesStore.addNextCommunityPageToStore addCidToAccountComment error\",\n { comment, error },\n ),\n );\n }\n },\n\n invalidateCommunityPages: async (\n community: Community,\n sortType: string | undefined,\n modQueue?: string[],\n accountId?: string,\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.invalidateCommunityPages community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `communitiesPagesStore.invalidateCommunityPages sortType '${sortType}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.invalidateCommunityPages modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, for now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!firstPageCid) {\n return;\n }\n\n const { communitiesPages } = getState();\n const firstPageKey = getCommunityPageStoreKey(firstPageCid, pageType, accountId);\n const pageKeysToInvalidate = new Set<string>([firstPageKey]);\n let nextPageCid = communitiesPages[firstPageKey]?.nextCid;\n while (nextPageCid) {\n const nextPageKey = getCommunityPageStoreKey(nextPageCid, pageType, accountId);\n pageKeysToInvalidate.add(nextPageKey);\n nextPageCid = communitiesPages[nextPageKey]?.nextCid;\n }\n\n await Promise.all(\n [...pageKeysToInvalidate].map((pageKey) => communitiesPagesDatabase.removeItem(pageKey)),\n );\n\n setState(({ communitiesPages }: any) => {\n const nextCommunitiesPages = { ...communitiesPages };\n for (const pageKey of pageKeysToInvalidate) {\n delete nextCommunitiesPages[pageKey];\n }\n return { communitiesPages: nextCommunitiesPages };\n });\n },\n\n // communities contain preloaded pages, those page comments must be added separately\n addCommunityPageCommentsToStore: (community: Community) => {\n if (!community.posts?.pages) {\n return;\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(community.posts.pages);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n for (const comment of flattenedComments) {\n const existing = comments[comment.cid];\n if (\n comment.cid &&\n (!existing || getCommentFreshness(comment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[comment.cid] = comment;\n hasNewComments = true;\n }\n }\n\n if (!hasNewComments) {\n return;\n }\n\n setState(({ comments }: any) => {\n return { comments: { ...comments, ...newComments } };\n });\n log(\"communitiesPagesStore.addCommunityPageCommentsToStore\", { community, newComments });\n },\n }),\n);\n\n// set clients states on communities store so the frontend can display it, dont persist in db because a reload cancels updating\nconst onCommunityPostsClientsStateChange =\n (communityAddress: string) =>\n (clientState: string, clientType: string, sortType: string, clientUrl: string) => {\n communitiesStore.setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityAddress]) {\n return {};\n }\n const client = { state: clientState };\n const community = { ...state.communities[communityAddress] };\n community.posts = { ...community.posts };\n community.posts.clients = { ...community.posts.clients };\n community.posts.clients[clientType] = { ...community.posts.clients[clientType] };\n community.posts.clients[clientType][sortType] = {\n ...community.posts.clients[clientType][sortType],\n };\n community.posts.clients[clientType][sortType][clientUrl] = client;\n return { communities: { ...state.communities, [community.address]: community } };\n });\n };\n\nconst fetchPageCommunities: {\n [accountId: string]: { pkc: any; communities: { [communityAddress: string]: any } };\n} = {}; // cache created community clients per account because creating them can be slow\nlet fetchPagePending: { [key: string]: boolean } = {};\nconst fetchPage = async (\n pageCid: string,\n communityAddress: string,\n account: Account,\n pageType: string,\n) => {\n // community page is cached\n const pageStoreKey = getCommunityPageStoreKey(pageCid, pageType, account.id);\n const cachedCommunityPage = await communitiesPagesDatabase.getItem(pageStoreKey);\n if (cachedCommunityPage) {\n return cachedCommunityPage;\n }\n if (!fetchPageCommunities[account.id] || fetchPageCommunities[account.id].pkc !== account.pkc) {\n fetchPageCommunities[account.id] = { pkc: account.pkc, communities: {} };\n }\n const accountCommunities = fetchPageCommunities[account.id].communities;\n if (!accountCommunities[communityAddress]) {\n accountCommunities[communityAddress] = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n listeners.push(accountCommunities[communityAddress]);\n\n // set clients states on communities store so the frontend can display it\n utils.pageClientsOnStateChange(\n accountCommunities[communityAddress][pageType]?.clients,\n onCommunityPostsClientsStateChange(communityAddress),\n );\n }\n\n const onError = (error: any) =>\n log.error(\n `communitiesPagesStore community '${communityAddress}' failed community.posts.getPage page cid '${pageCid}':`,\n error,\n );\n const fetchedCommunityPage = await utils.retryInfinity(\n () => accountCommunities[communityAddress][pageType].getPage({ cid: pageCid }),\n { onError },\n );\n await communitiesPagesDatabase.setItem(pageStoreKey, utils.clone(fetchedCommunityPage));\n return fetchedCommunityPage;\n};\n\n/**\n * Util function to get all pages in the store for a\n * specific community+sortType using `CommunityPage.nextCid`\n */\nexport const getCommunityPages = (\n community: Community,\n sortType: string | undefined,\n communitiesPages: CommunitiesPages,\n pageType: string,\n accountId?: string,\n) => {\n assert(\n communitiesPages && typeof communitiesPages === \"object\",\n `getCommunityPages communitiesPages '${communitiesPages}' invalid`,\n );\n const pages: CommunityPage[] = [];\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n // community has no pages\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n // 'return pages' to ignore it for now\n if (!firstPageCid) {\n return pages;\n }\n const firstPage = communitiesPages[getCommunityPageStoreKey(firstPageCid, pageType, accountId)];\n if (!firstPage) {\n return pages;\n }\n pages.push(firstPage);\n while (true) {\n const nextCid = pages[pages.length - 1]?.nextCid;\n const nextPageKey = nextCid && getCommunityPageStoreKey(nextCid, pageType, accountId);\n const communityPage = nextPageKey && communitiesPages[nextPageKey];\n if (!communityPage) {\n return pages;\n }\n pages.push(communityPage);\n }\n};\n\nexport const getCommunityFirstPageCid = (\n community: Community,\n sortType: string | undefined,\n pageType = \"posts\",\n) => {\n assert(\n community && typeof community === \"object\",\n `getCommunityFirstPageCid community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `getCommunityFirstPageCid sortType '${sortType}' invalid`,\n );\n // posts served client-side from a complete preloaded page read that page instead of their own\n const pageSortType = pageType === \"posts\" ? getPostPageSortType(community, sortType) : sortType;\n if (!pageSortType) {\n return;\n }\n // community has preloaded posts for sort type\n if (community[pageType]?.pages?.[pageSortType]?.comments) {\n return community[pageType]?.pages?.[pageSortType]?.nextCid;\n }\n return community[pageType]?.pageCids?.[pageSortType];\n\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n};\n\n// reset store in between tests\nconst originalState = communitiesPagesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesPagesStore = async () => {\n fetchPagePending = {};\n storedCommunityPageKeys = {};\n for (const accountId in fetchPageCommunities) {\n delete fetchPageCommunities[accountId];\n }\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n // destroy all component subscriptions to the store\n communitiesPagesStore.destroy();\n // restore original state\n communitiesPagesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesPagesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear();\n await resetCommunitiesPagesStore();\n};\n\nexport default communitiesPagesStore;\n"]}
|
|
1
|
+
{"version":3,"file":"communities-pages-store.js","sourceRoot":"","sources":["../../../src/stores/communities-pages/communities-pages-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,2DAA2D;AAC3D,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAShE,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,gBAAsC,MAAM,gBAAgB,CAAC;AACpE,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,wBAAwB,GAAG,cAAc,CAAC,cAAc,CAAC;IAC7D,IAAI,EAAE,sCAAsC;IAC5C,IAAI,EAAE,GAAG;CACV,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,OAAe,EAAE,QAAgB,EAAE,SAAkB,EAAE,EAAE;IACzF,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC5B,MAAM,CACJ,SAAS,IAAI,OAAO,SAAS,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AAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACrB,mDAAmD;IACnD,qBAAqB,CAAC,OAAO,EAAE,CAAC;IAChC,yBAAyB;IACzB,qBAAqB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAChD,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,qCAAqC,GAAG,GAAS,EAAE;IAC9D,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC9F,MAAM,0BAA0B,EAAE,CAAC;AACrC,CAAC,CAAA,CAAC;AAEF,eAAe,qBAAqB,CAAC","sourcesContent":["import utils from \"../../lib/utils\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\n// include communities pages store with feeds for debugging\nexport const log = Logger(\"bitsocial-react-hooks:feeds:stores\");\nimport {\n Community,\n CommunityPage,\n CommunitiesPages,\n Account,\n Comment,\n Comments,\n} from \"../../types\";\nimport accountsStore from \"../accounts\";\nimport communitiesStore, { CommunitiesState } from \"../communities\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport createStore from \"zustand\";\nimport assert from \"../../lib/assert\";\nimport {\n createPkcCommunity,\n getPkcCreateCommunity,\n normalizeCommentCommunityAddress,\n} from \"../../lib/pkc-compat\";\nimport { getPostPageSortType } from \"../../lib/page-sorts\";\n\nconst communitiesPagesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communitiesPages\",\n size: 500,\n});\n\nconst getCommunityPageStoreKey = (pageCid: string, pageType: string, accountId?: string) => {\n if (pageType === \"modQueue\") {\n assert(\n accountId && typeof accountId === \"string\",\n `getCommunityPageStoreKey accountId '${accountId}' invalid for modQueue`,\n );\n return `${accountId}:${pageCid}`;\n }\n return pageCid;\n};\n\n/** Freshness for comparison: max(updatedAt, timestamp, 0). Used to decide add vs replace per CID. Exported for coverage. */\nexport const getCommentFreshness = (comment: Comment | undefined): number =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\n// the page keys stored for each community address, with the page type and account each was\n// fetched for, to find the pages a community no longer links to\ntype StoredCommunityPage = { pageType: string; accountId: string };\nlet storedCommunityPageKeys: {\n [communityAddress: string]: { [pageStoreKey: string]: StoredCommunityPage };\n} = {};\n\n// The page keys community records link to: the first page cids of every sort, followed through the\n// stored pages' nextCid. A superset of the chain getCommunityPages walks for one sort.\nconst getLinkedCommunityPageKeys = (\n communityRecords: Community[],\n communitiesPages: CommunitiesPages,\n pageType: string,\n accountId: string,\n) => {\n const linkedPageKeys = new Set<string>();\n for (const communityRecord of communityRecords) {\n const pages = communityRecord?.[pageType];\n const firstPageCids = [\n ...Object.values(pages?.pageCids || {}),\n ...Object.values(pages?.pages || {}).map((page: any) => page?.nextCid),\n ];\n for (let pageCid of firstPageCids) {\n while (typeof pageCid === \"string\" && pageCid) {\n const pageKey = getCommunityPageStoreKey(pageCid, pageType, accountId);\n if (linkedPageKeys.has(pageKey)) {\n break;\n }\n linkedPageKeys.add(pageKey);\n pageCid = communitiesPages[pageKey]?.nextCid;\n }\n }\n }\n return linkedPageKeys;\n};\n\n// A community update replaces its page cids, and getCommunityPages only walks from the current ones,\n// so the previous page chains are never read again. Without dropping them, a feed left open keeps a\n// copy of its communities' pages for every update it fetched pages after. Only pages of this\n// community are checked, against its stored records and the record the caller fetched with, so a\n// page fetched with a record that was replaced meanwhile doesn't drop the current chain. A later\n// page shared by the old and new chains is dropped until the new chain reaches it again, and is then\n// read back from the pages database.\nconst removeUnlinkedCommunityPages = (communitiesPages: CommunitiesPages, community: Community) => {\n const storedPageKeys = storedCommunityPageKeys[community.address];\n if (!storedPageKeys) {\n return;\n }\n const communityRecords = [\n community,\n ...Object.values(communitiesStore.getState()?.communities || {}).filter(\n (communityRecord: any) => communityRecord?.address === community.address,\n ),\n ];\n const linkedPageKeys: { [pageTypeAndAccount: string]: Set<string> } = {};\n const unlinkedPageKeys: string[] = [];\n for (const pageKey in storedPageKeys) {\n if (!communitiesPages[pageKey]) {\n // already removed, e.g. by invalidateCommunityPages\n delete storedPageKeys[pageKey];\n continue;\n }\n const { pageType, accountId } = storedPageKeys[pageKey];\n const pageTypeAndAccount = `${pageType}:${accountId}`;\n if (!linkedPageKeys[pageTypeAndAccount]) {\n linkedPageKeys[pageTypeAndAccount] = getLinkedCommunityPageKeys(\n communityRecords,\n communitiesPages,\n pageType,\n accountId,\n );\n }\n if (!linkedPageKeys[pageTypeAndAccount].has(pageKey)) {\n unlinkedPageKeys.push(pageKey);\n }\n }\n for (const pageKey of unlinkedPageKeys) {\n delete communitiesPages[pageKey];\n delete storedPageKeys[pageKey];\n }\n};\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\ntype CommunitiesPagesState = {\n communitiesPages: CommunitiesPages;\n comments: Comments;\n addNextCommunityPageToStore: Function;\n invalidateCommunityPages: Function;\n addCommunityPageCommentsToStore: Function;\n};\n\nconst communitiesPagesStore = createStore<CommunitiesPagesState>(\n (setState: Function, getState: Function) => ({\n // pages a community no longer links to are dropped when one of its pages is added\n // TODO: eventually clear old comments from memory\n communitiesPages: {},\n comments: {},\n\n addNextCommunityPageToStore: async (\n community: Community,\n sortType: string | undefined,\n account: Account,\n modQueue?: string[],\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.addNextCommunityPageToStore community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `communitiesPagesStore.addNextCommunityPageToStore sortType '${sortType}' invalid`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesPagesStore.addNextCommunityPageToStore account '${account}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.addNextCommunityPageToStore modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // check the preloaded posts on community.posts.pages first, then the community.posts.pageCids\n const communityFirstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!communityFirstPageCid) {\n log(\n `communitiesPagesStore.addNextCommunityPageToStore community '${community?.address}' sortType '${sortType}' no communityFirstPageCid`,\n );\n return;\n }\n\n // all communities pages in store\n const { communitiesPages } = getState();\n // only specific pages of the community+sortType\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n account.id,\n );\n\n // if no pages exist yet, add the first page\n let pageCidToAdd: string;\n if (!communityPages.length) {\n pageCidToAdd = communityFirstPageCid;\n } else {\n const nextCid = communityPages[communityPages.length - 1]?.nextCid;\n // if last nextCid is undefined, reached end of pages\n if (!nextCid) {\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore no more pages\", {\n communityAddress: community.address,\n sortType,\n account,\n });\n return;\n }\n\n pageCidToAdd = nextCid;\n }\n\n // page is already added or pending\n const pageStoreKeyToAdd = getCommunityPageStoreKey(pageCidToAdd, pageType, account.id);\n if (\n communitiesPages[pageStoreKeyToAdd] ||\n pageFetchIsPending(pageStoreKeyToAdd, account.pkc)\n ) {\n return;\n }\n\n const pendingFetch: PendingPageFetch = { pkc: account.pkc, failed: false };\n fetchPagePending[pageStoreKeyToAdd] = [\n ...(fetchPagePending[pageStoreKeyToAdd] || []),\n pendingFetch,\n ];\n let page: CommunityPage;\n try {\n page = await fetchPage(pageCidToAdd, community.address, account, pageType, pendingFetch);\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore community.posts.getPage\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n account,\n });\n } catch (e) {\n throw e;\n } finally {\n fetchPagePending[pageStoreKeyToAdd] = fetchPagePending[pageStoreKeyToAdd]?.filter(\n (fetch) => fetch !== pendingFetch,\n );\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(page);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n if (pageType !== \"modQueue\") {\n for (const comment of flattenedComments) {\n const normalizedComment = normalizeCommentCommunityAddress(comment) as Comment;\n const existing = comments[normalizedComment.cid];\n if (\n normalizedComment.cid &&\n (!existing || getCommentFreshness(normalizedComment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[normalizedComment.cid] = normalizedComment;\n hasNewComments = true;\n }\n }\n }\n\n storedCommunityPageKeys[community.address] = {\n ...storedCommunityPageKeys[community.address],\n [pageStoreKeyToAdd]: { pageType, accountId: account.id },\n };\n setState(({ communitiesPages, comments }: any) => {\n const nextCommunitiesPages = { ...communitiesPages, [pageStoreKeyToAdd]: page };\n removeUnlinkedCommunityPages(nextCommunitiesPages, community);\n const newState: any = { communitiesPages: nextCommunitiesPages };\n if (hasNewComments) {\n newState.comments = { ...comments, ...newComments };\n }\n return newState;\n });\n log(\"communitiesPagesStore.addNextCommunityPageToStore\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n sortType,\n page,\n account,\n });\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n for (const comment of flattenedComments) {\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(\n normalizeCommentCommunityAddress(comment) as Comment,\n )\n .catch((error: unknown) =>\n log.error(\n \"communitiesPagesStore.addNextCommunityPageToStore addCidToAccountComment error\",\n { comment, error },\n ),\n );\n }\n },\n\n invalidateCommunityPages: async (\n community: Community,\n sortType: string | undefined,\n modQueue?: string[],\n accountId?: string,\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.invalidateCommunityPages community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `communitiesPagesStore.invalidateCommunityPages sortType '${sortType}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.invalidateCommunityPages modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, for now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!firstPageCid) {\n return;\n }\n\n const { communitiesPages } = getState();\n const firstPageKey = getCommunityPageStoreKey(firstPageCid, pageType, accountId);\n const pageKeysToInvalidate = new Set<string>([firstPageKey]);\n let nextPageCid = communitiesPages[firstPageKey]?.nextCid;\n while (nextPageCid) {\n const nextPageKey = getCommunityPageStoreKey(nextPageCid, pageType, accountId);\n pageKeysToInvalidate.add(nextPageKey);\n nextPageCid = communitiesPages[nextPageKey]?.nextCid;\n }\n\n await Promise.all(\n [...pageKeysToInvalidate].map((pageKey) => communitiesPagesDatabase.removeItem(pageKey)),\n );\n\n setState(({ communitiesPages }: any) => {\n const nextCommunitiesPages = { ...communitiesPages };\n for (const pageKey of pageKeysToInvalidate) {\n delete nextCommunitiesPages[pageKey];\n }\n return { communitiesPages: nextCommunitiesPages };\n });\n },\n\n // communities contain preloaded pages, those page comments must be added separately\n addCommunityPageCommentsToStore: (community: Community) => {\n if (!community.posts?.pages) {\n return;\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(community.posts.pages);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n for (const comment of flattenedComments) {\n const existing = comments[comment.cid];\n if (\n comment.cid &&\n (!existing || getCommentFreshness(comment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[comment.cid] = comment;\n hasNewComments = true;\n }\n }\n\n if (!hasNewComments) {\n return;\n }\n\n setState(({ comments }: any) => {\n return { comments: { ...comments, ...newComments } };\n });\n log(\"communitiesPagesStore.addCommunityPageCommentsToStore\", { community, newComments });\n },\n }),\n);\n\n// set clients states on communities store so the frontend can display it, dont persist in db because a reload cancels updating\nconst onCommunityPostsClientsStateChange =\n (communityAddress: string) =>\n (clientState: string, clientType: string, sortType: string, clientUrl: string) => {\n communitiesStore.setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityAddress]) {\n return {};\n }\n const client = { state: clientState };\n const community = { ...state.communities[communityAddress] };\n community.posts = { ...community.posts };\n community.posts.clients = { ...community.posts.clients };\n community.posts.clients[clientType] = { ...community.posts.clients[clientType] };\n community.posts.clients[clientType][sortType] = {\n ...community.posts.clients[clientType][sortType],\n };\n community.posts.clients[clientType][sortType][clientUrl] = client;\n return { communities: { ...state.communities, [community.address]: community } };\n });\n };\n\nconst fetchPageCommunities: {\n [accountId: string]: { pkc: any; communities: { [communityAddress: string]: any } };\n} = {}; // cache created community clients per account because creating them can be slow\n// the page fetches in progress per page store key, with the pkc client each uses. A new fetch waits\n// for one with the same client, or with another client until that one fails, so an account's\n// failing or replaced client doesn't keep the page from other clients\ntype PendingPageFetch = { pkc: any; failed: boolean };\nlet fetchPagePending: { [key: string]: PendingPageFetch[] | undefined } = {};\nconst pageFetchIsPending = (key: string, pkc: any) =>\n Boolean(fetchPagePending[key]?.some((fetch) => fetch.pkc === pkc || !fetch.failed));\n// a page fetch stops retrying with its pkc client once its account was deleted, or setAccount gave\n// the account another client. An account the accounts store didn't hold when the fetch started\n// keeps retrying\nconst getShouldRetryPageFetch = (account: Account) => {\n const accountWasStored = Boolean(accountsStore.getState().accounts?.[account.id]);\n return () => {\n const storedAccount = accountsStore.getState().accounts?.[account.id];\n return storedAccount ? storedAccount.pkc === account.pkc : !accountWasStored;\n };\n};\n// setAccount gives the account a new pkc client on every edit, so a fetch that stopped retrying\n// with the replaced client continues with the account's new one, unless another fetch of the page\n// already uses it\nconst getAccountWithNewPkc = (\n account: Account,\n pendingKey: string,\n pendingFetch?: PendingPageFetch,\n): Account | undefined => {\n const storedAccount = accountsStore.getState().accounts?.[account.id];\n if (\n !storedAccount ||\n storedAccount.pkc === account.pkc ||\n fetchPagePending[pendingKey]?.some(\n (fetch) => fetch !== pendingFetch && fetch.pkc === storedAccount.pkc,\n )\n ) {\n return;\n }\n return storedAccount;\n};\nconst fetchPage = async (\n pageCid: string,\n communityAddress: string,\n account: Account,\n pageType: string,\n pendingFetch?: PendingPageFetch,\n): Promise<CommunityPage> => {\n const shouldRetry = getShouldRetryPageFetch(account);\n // community page is cached\n const pageStoreKey = getCommunityPageStoreKey(pageCid, pageType, account.id);\n const cachedCommunityPage = await communitiesPagesDatabase.getItem(pageStoreKey);\n if (cachedCommunityPage) {\n return cachedCommunityPage;\n }\n if (!fetchPageCommunities[account.id] || fetchPageCommunities[account.id].pkc !== account.pkc) {\n fetchPageCommunities[account.id] = { pkc: account.pkc, communities: {} };\n }\n const accountCommunities = fetchPageCommunities[account.id].communities;\n if (!accountCommunities[communityAddress]) {\n accountCommunities[communityAddress] = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n listeners.push(accountCommunities[communityAddress]);\n\n // set clients states on communities store so the frontend can display it\n utils.pageClientsOnStateChange(\n accountCommunities[communityAddress][pageType]?.clients,\n onCommunityPostsClientsStateChange(communityAddress),\n );\n }\n\n const onError = (error: any) => {\n if (pendingFetch) {\n pendingFetch.failed = true;\n }\n log.error(\n `communitiesPagesStore community '${communityAddress}' failed community.posts.getPage page cid '${pageCid}':`,\n error,\n );\n };\n let fetchedCommunityPage: CommunityPage;\n try {\n fetchedCommunityPage = await utils.retryInfinity(\n () => accountCommunities[communityAddress][pageType].getPage({ cid: pageCid }),\n { onError, shouldRetry },\n );\n } catch (error) {\n const accountWithNewPkc = getAccountWithNewPkc(account, pageStoreKey, pendingFetch);\n if (!accountWithNewPkc) {\n throw error;\n }\n // the fetch continues as a new fetch with the new client, starting from the page cache\n if (pendingFetch) {\n pendingFetch.pkc = accountWithNewPkc.pkc;\n pendingFetch.failed = false;\n }\n return fetchPage(pageCid, communityAddress, accountWithNewPkc, pageType, pendingFetch);\n }\n await communitiesPagesDatabase.setItem(pageStoreKey, utils.clone(fetchedCommunityPage));\n return fetchedCommunityPage;\n};\n\n/**\n * Util function to get all pages in the store for a\n * specific community+sortType using `CommunityPage.nextCid`\n */\nexport const getCommunityPages = (\n community: Community,\n sortType: string | undefined,\n communitiesPages: CommunitiesPages,\n pageType: string,\n accountId?: string,\n) => {\n assert(\n communitiesPages && typeof communitiesPages === \"object\",\n `getCommunityPages communitiesPages '${communitiesPages}' invalid`,\n );\n const pages: CommunityPage[] = [];\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n // community has no pages\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n // 'return pages' to ignore it for now\n if (!firstPageCid) {\n return pages;\n }\n const firstPage = communitiesPages[getCommunityPageStoreKey(firstPageCid, pageType, accountId)];\n if (!firstPage) {\n return pages;\n }\n pages.push(firstPage);\n while (true) {\n const nextCid = pages[pages.length - 1]?.nextCid;\n const nextPageKey = nextCid && getCommunityPageStoreKey(nextCid, pageType, accountId);\n const communityPage = nextPageKey && communitiesPages[nextPageKey];\n if (!communityPage) {\n return pages;\n }\n pages.push(communityPage);\n }\n};\n\nexport const getCommunityFirstPageCid = (\n community: Community,\n sortType: string | undefined,\n pageType = \"posts\",\n) => {\n assert(\n community && typeof community === \"object\",\n `getCommunityFirstPageCid community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `getCommunityFirstPageCid sortType '${sortType}' invalid`,\n );\n // posts served client-side from a complete preloaded page read that page instead of their own\n const pageSortType = pageType === \"posts\" ? getPostPageSortType(community, sortType) : sortType;\n if (!pageSortType) {\n return;\n }\n // community has preloaded posts for sort type\n if (community[pageType]?.pages?.[pageSortType]?.comments) {\n return community[pageType]?.pages?.[pageSortType]?.nextCid;\n }\n return community[pageType]?.pageCids?.[pageSortType];\n\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n};\n\n// reset store in between tests\nconst originalState = communitiesPagesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesPagesStore = async () => {\n fetchPagePending = {};\n storedCommunityPageKeys = {};\n for (const accountId in fetchPageCommunities) {\n delete fetchPageCommunities[accountId];\n }\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n // destroy all component subscriptions to the store\n communitiesPagesStore.destroy();\n // restore original state\n communitiesPagesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesPagesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear();\n await resetCommunitiesPagesStore();\n};\n\nexport default communitiesPagesStore;\n"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
type SortOptions = {
|
|
2
|
+
pinnedFirst?: boolean;
|
|
3
|
+
};
|
|
1
4
|
declare const _default: {
|
|
2
|
-
sort: (sortType: string | undefined, feed: any[]) => any[];
|
|
5
|
+
sort: (sortType: string | undefined, feed: any[], { pinnedFirst }?: SortOptions) => any[];
|
|
3
6
|
merge: (sortType: string | undefined, feeds: {
|
|
4
7
|
posts: any[];
|
|
5
8
|
keepOrder: boolean;
|
|
6
|
-
}[]) => any[];
|
|
9
|
+
}[], sortOptions?: SortOptions) => any[];
|
|
7
10
|
};
|
|
8
11
|
export default _default;
|
|
9
12
|
//# sourceMappingURL=feed-sorter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feed-sorter.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"feed-sorter.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":"AA8IA,KAAK,WAAW,GAAG;IAGjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;;qBASU,MAAM,GAAG,SAAS,QACtB,GAAG,EAAE,oBACa,WAAW;sBA2BzB,MAAM,GAAG,SAAS,SACrB;QAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,EAAE,gBAC/B,WAAW;;AAsC3B,wBAA+B"}
|
|
@@ -126,11 +126,22 @@ const sorters = {
|
|
|
126
126
|
oldFlat: sortByOld,
|
|
127
127
|
best: sortByBest,
|
|
128
128
|
};
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Sort a feed with the client's scorer for the sort. Pinned placement is the community's decision
|
|
131
|
+
* either way, never a consequence of the client recognising the sort name: a sort the client cannot
|
|
132
|
+
* score keeps the order the community published, pinned posts included, and a sort it re-scores
|
|
133
|
+
* puts pinned posts where the community's `pinnedFirst` says.
|
|
134
|
+
*/
|
|
135
|
+
const sort = (sortType, feed, { pinnedFirst = true } = {}) => {
|
|
136
|
+
const sorter = sortType !== undefined && Object.prototype.hasOwnProperty.call(sorters, sortType)
|
|
137
|
+
? sorters[sortType]
|
|
138
|
+
: undefined;
|
|
131
139
|
if (!sorter) {
|
|
132
140
|
return feed;
|
|
133
141
|
}
|
|
142
|
+
if (!pinnedFirst) {
|
|
143
|
+
return sorter([...feed]);
|
|
144
|
+
}
|
|
134
145
|
// NOTE: pinned posts are not sorted, maybe in a future version we can sort them based on something
|
|
135
146
|
// NOTE: with useReplies({flat: true}), nested pins are at the top, unclear yet what we should do with them
|
|
136
147
|
const pinnedPosts = feed.filter((post) => post.pinned);
|
|
@@ -143,13 +154,13 @@ const sort = (sortType, feed) => {
|
|
|
143
154
|
* is whichever feed's next post the built-in sorter ranks first, so a thread never rises above one
|
|
144
155
|
* its own community ranks higher, and feeds that all use the built-in sort merge as one sort.
|
|
145
156
|
*/
|
|
146
|
-
const merge = (sortType, feeds) => {
|
|
157
|
+
const merge = (sortType, feeds, sortOptions) => {
|
|
147
158
|
const nonEmptyFeeds = feeds.filter(({ posts }) => posts.length > 0);
|
|
148
159
|
if (nonEmptyFeeds.length === 1 && nonEmptyFeeds[0].keepOrder) {
|
|
149
160
|
return nonEmptyFeeds[0].posts;
|
|
150
161
|
}
|
|
151
162
|
const ranks = new Map();
|
|
152
|
-
sort(sortType, nonEmptyFeeds.flatMap(({ posts }) => posts)).forEach((post, index) => ranks.set(post, index));
|
|
163
|
+
sort(sortType, nonEmptyFeeds.flatMap(({ posts }) => posts), sortOptions).forEach((post, index) => ranks.set(post, index));
|
|
153
164
|
const rankOf = (post) => ranks.get(post);
|
|
154
165
|
const orderedFeeds = nonEmptyFeeds.map(({ posts, keepOrder }) => keepOrder ? posts : [...posts].sort((a, b) => rankOf(a) - rankOf(b)));
|
|
155
166
|
const nextIndexes = orderedFeeds.map(() => 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feed-sorter.js","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,CAAC,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtF,MAAM,SAAS,GAAG,CAAC,IAAW,EAAE,EAAE;IAChC,MAAM,UAAU,GAA8B,EAAE,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC;QACzD,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI;SACR,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,G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AAM,EAAE,CAAC;gBAC5C,SAAS;YACX,CAAC;YACD,IACE,aAAa,KAAK,CAAC,CAAC;gBACpB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;oBACnC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,EACjE,CAAC;gBACD,aAAa,GAAG,SAAS,CAAC;YAC5B,CAAC;QACH,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC","sourcesContent":["/** Single fallback for numeric values to reduce Istanbul branch sites */\nconst n = (v: unknown): number => (typeof v === \"number\" && !Number.isNaN(v) ? v : 0);\n\nconst sortByTop = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const score = post.upvoteCount - post.downvoteCount || 0;\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by controversial is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n */\nconst sortByControversial = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n let upvoteCount = n(post.upvoteCount) + 1; // reddit initial upvotes is 1, pkc is 0\n const downvoteCount = n(post.downvoteCount);\n const magnitude = upvoteCount + downvoteCount;\n const balance =\n upvoteCount > downvoteCount\n ? downvoteCount / upvoteCount\n : upvoteCount / (downvoteCount || 1);\n postScores[post.cid] = Math.pow(magnitude, balance);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by hot is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n * Note: a sub with not many posts will be given very high priority\n */\nconst sortByHot = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n const round = (number: number, decimalPlaces: number) => {\n const factorOfTen = Math.pow(10, decimalPlaces);\n return Math.round(number * factorOfTen) / factorOfTen;\n };\n for (const post of feed) {\n let score = n(post.upvoteCount) - n(post.downvoteCount) + 1;\n const order = Math.log10(Math.max(Math.abs(score), 1));\n let sign = 0;\n if (score > 0) sign = 1;\n else if (score < 0) sign = -1;\n const seconds = n(post.timestamp) - 1134028003;\n postScores[post.cid] = round(sign * order + seconds / 45000, 7);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by new is made using relative timestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their timestamp\n */\nconst sortByNew = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(b.timestamp) - n(a.timestamp));\n\n/**\n * Sort by active is made using relative lastReplyTimestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their lastReplyTimestamp\n */\nconst sortByActive = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort(\n (a, b) => n(b.lastReplyTimestamp ?? b.timestamp) - n(a.lastReplyTimestamp ?? a.timestamp),\n );\n\nconst sortByOld = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(a.timestamp) - n(b.timestamp));\n\n// \"best\" sort from reddit replies\n// https://web.archive.org/web/20100305052116/http://blog.reddit.com/2009/10/reddits-new-comment-sorting-system.html\n// https://medium.com/hacking-and-gonzo/how-reddit-ranking-algorithms-work-ef111e33d0d9\n// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html\n// https://github.com/reddit-archive/reddit/blob/753b17407e9a9dca09558526805922de24133d53/r2/r2/lib/db/_sorts.pyx#L70\nconst sortByBest = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const upvoteCount = n(post.upvoteCount) + 1;\n const downvoteCount = n(post.downvoteCount);\n const total = upvoteCount + downvoteCount;\n const score =\n total === 0\n ? 0\n : (() => {\n const z = 1.281551565545;\n const p = upvoteCount / total;\n const left = p + (1 / (2 * total)) * z * z;\n const right = z * Math.sqrt((p * (1 - p)) / total + (z * z) / (4 * total * total));\n const under = 1 + (1 / total) * z * z;\n return (left - right) / under;\n })();\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(a.timestamp) - n(b.timestamp))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\nconst sorters: Record<string, (feed: any[]) => any[]> = {\n new: sortByNew,\n newFlat: sortByNew,\n hot: sortByHot,\n top: sortByTop,\n topHour: sortByTop,\n topDay: sortByTop,\n topWeek: sortByTop,\n topMonth: sortByTop,\n topYear: sortByTop,\n topAll: sortByTop,\n controversial: sortByControversial,\n controversialHour: sortByControversial,\n controversialDay: sortByControversial,\n controversialWeek: sortByControversial,\n controversialMonth: sortByControversial,\n controversialYear: sortByControversial,\n controversialAll: sortByControversial,\n active: sortByActive,\n old: sortByOld,\n oldFlat: sortByOld,\n best: sortByBest,\n};\n\nconst sort = (sortType: string | undefined, feed: any[]) => {\n const sorter = sortType && sorters[sortType];\n if (!sorter) {\n return feed;\n }\n // NOTE: pinned posts are not sorted, maybe in a future version we can sort them based on something\n // NOTE: with useReplies({flat: true}), nested pins are at the top, unclear yet what we should do with them\n const pinnedPosts = feed.filter((post) => post.pinned);\n\n feed = feed.filter((post) => !post.pinned);\n return [...pinnedPosts, ...sorter(feed)];\n};\n\n/**\n * Interleave several communities' posts. A feed that keeps its order (a community's sort file, which\n * the client cannot reproduce) is never reordered and the others get the built-in sort. The next post\n * is whichever feed's next post the built-in sorter ranks first, so a thread never rises above one\n * its own community ranks higher, and feeds that all use the built-in sort merge as one sort.\n */\nconst merge = (sortType: string | undefined, feeds: { posts: any[]; keepOrder: boolean }[]) => {\n const nonEmptyFeeds = feeds.filter(({ posts }) => posts.length > 0);\n if (nonEmptyFeeds.length === 1 && nonEmptyFeeds[0].keepOrder) {\n return nonEmptyFeeds[0].posts;\n }\n const ranks = new Map<any, number>();\n sort(\n sortType,\n nonEmptyFeeds.flatMap(({ posts }) => posts),\n ).forEach((post, index) => ranks.set(post, index));\n const rankOf = (post: any) => ranks.get(post) as number;\n const orderedFeeds = nonEmptyFeeds.map(({ posts, keepOrder }) =>\n keepOrder ? posts : [...posts].sort((a, b) => rankOf(a) - rankOf(b)),\n );\n const nextIndexes = orderedFeeds.map(() => 0);\n const postCount = orderedFeeds.reduce((count, posts) => count + posts.length, 0);\n const merged: any[] = [];\n while (merged.length < postCount) {\n let nextFeedIndex = -1;\n for (const [feedIndex, posts] of orderedFeeds.entries()) {\n if (nextIndexes[feedIndex] === posts.length) {\n continue;\n }\n if (\n nextFeedIndex === -1 ||\n rankOf(posts[nextIndexes[feedIndex]]) <\n rankOf(orderedFeeds[nextFeedIndex][nextIndexes[nextFeedIndex]])\n ) {\n nextFeedIndex = feedIndex;\n }\n }\n merged.push(orderedFeeds[nextFeedIndex][nextIndexes[nextFeedIndex]++]);\n }\n return merged;\n};\n\nexport default { sort, merge };\n"]}
|
|
1
|
+
{"version":3,"file":"feed-sorter.js","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,CAAC,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,M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ACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC","sourcesContent":["/** Single fallback for numeric values to reduce Istanbul branch sites */\nconst n = (v: unknown): number => (typeof v === \"number\" && !Number.isNaN(v) ? v : 0);\n\nconst sortByTop = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const score = post.upvoteCount - post.downvoteCount || 0;\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by controversial is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n */\nconst sortByControversial = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n let upvoteCount = n(post.upvoteCount) + 1; // reddit initial upvotes is 1, pkc is 0\n const downvoteCount = n(post.downvoteCount);\n const magnitude = upvoteCount + downvoteCount;\n const balance =\n upvoteCount > downvoteCount\n ? downvoteCount / upvoteCount\n : upvoteCount / (downvoteCount || 1);\n postScores[post.cid] = Math.pow(magnitude, balance);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by hot is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n * Note: a sub with not many posts will be given very high priority\n */\nconst sortByHot = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n const round = (number: number, decimalPlaces: number) => {\n const factorOfTen = Math.pow(10, decimalPlaces);\n return Math.round(number * factorOfTen) / factorOfTen;\n };\n for (const post of feed) {\n let score = n(post.upvoteCount) - n(post.downvoteCount) + 1;\n const order = Math.log10(Math.max(Math.abs(score), 1));\n let sign = 0;\n if (score > 0) sign = 1;\n else if (score < 0) sign = -1;\n const seconds = n(post.timestamp) - 1134028003;\n postScores[post.cid] = round(sign * order + seconds / 45000, 7);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by new is made using relative timestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their timestamp\n */\nconst sortByNew = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(b.timestamp) - n(a.timestamp));\n\n/**\n * Sort by active is made using relative lastReplyTimestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their lastReplyTimestamp\n */\nconst sortByActive = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort(\n (a, b) => n(b.lastReplyTimestamp ?? b.timestamp) - n(a.lastReplyTimestamp ?? a.timestamp),\n );\n\nconst sortByOld = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(a.timestamp) - n(b.timestamp));\n\n// \"best\" sort from reddit replies\n// https://web.archive.org/web/20100305052116/http://blog.reddit.com/2009/10/reddits-new-comment-sorting-system.html\n// https://medium.com/hacking-and-gonzo/how-reddit-ranking-algorithms-work-ef111e33d0d9\n// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html\n// https://github.com/reddit-archive/reddit/blob/753b17407e9a9dca09558526805922de24133d53/r2/r2/lib/db/_sorts.pyx#L70\nconst sortByBest = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const upvoteCount = n(post.upvoteCount) + 1;\n const downvoteCount = n(post.downvoteCount);\n const total = upvoteCount + downvoteCount;\n const score =\n total === 0\n ? 0\n : (() => {\n const z = 1.281551565545;\n const p = upvoteCount / total;\n const left = p + (1 / (2 * total)) * z * z;\n const right = z * Math.sqrt((p * (1 - p)) / total + (z * z) / (4 * total * total));\n const under = 1 + (1 / total) * z * z;\n return (left - right) / under;\n })();\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(a.timestamp) - n(b.timestamp))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\nconst sorters: Record<string, (feed: any[]) => any[]> = {\n new: sortByNew,\n newFlat: sortByNew,\n hot: sortByHot,\n top: sortByTop,\n topHour: sortByTop,\n topDay: sortByTop,\n topWeek: sortByTop,\n topMonth: sortByTop,\n topYear: sortByTop,\n topAll: sortByTop,\n controversial: sortByControversial,\n controversialHour: sortByControversial,\n controversialDay: sortByControversial,\n controversialWeek: sortByControversial,\n controversialMonth: sortByControversial,\n controversialYear: sortByControversial,\n controversialAll: sortByControversial,\n active: sortByActive,\n old: sortByOld,\n oldFlat: sortByOld,\n best: sortByBest,\n};\n\ntype SortOptions = {\n // whether pinned posts go first (pkc-js `pinnedFirst`, which a community publishes per sort and\n // defaults to true). When false they are ranked like any other post.\n pinnedFirst?: boolean;\n};\n\n/**\n * Sort a feed with the client's scorer for the sort. Pinned placement is the community's decision\n * either way, never a consequence of the client recognising the sort name: a sort the client cannot\n * score keeps the order the community published, pinned posts included, and a sort it re-scores\n * puts pinned posts where the community's `pinnedFirst` says.\n */\nconst sort = (\n sortType: string | undefined,\n feed: any[],\n { pinnedFirst = true }: SortOptions = {},\n) => {\n const sorter =\n sortType !== undefined && Object.prototype.hasOwnProperty.call(sorters, sortType)\n ? sorters[sortType]\n : undefined;\n if (!sorter) {\n return feed;\n }\n if (!pinnedFirst) {\n return sorter([...feed]);\n }\n // NOTE: pinned posts are not sorted, maybe in a future version we can sort them based on something\n // NOTE: with useReplies({flat: true}), nested pins are at the top, unclear yet what we should do with them\n const pinnedPosts = feed.filter((post) => post.pinned);\n\n feed = feed.filter((post) => !post.pinned);\n return [...pinnedPosts, ...sorter(feed)];\n};\n\n/**\n * Interleave several communities' posts. A feed that keeps its order (a community's sort file, which\n * the client cannot reproduce) is never reordered and the others get the built-in sort. The next post\n * is whichever feed's next post the built-in sorter ranks first, so a thread never rises above one\n * its own community ranks higher, and feeds that all use the built-in sort merge as one sort.\n */\nconst merge = (\n sortType: string | undefined,\n feeds: { posts: any[]; keepOrder: boolean }[],\n sortOptions?: SortOptions,\n) => {\n const nonEmptyFeeds = feeds.filter(({ posts }) => posts.length > 0);\n if (nonEmptyFeeds.length === 1 && nonEmptyFeeds[0].keepOrder) {\n return nonEmptyFeeds[0].posts;\n }\n const ranks = new Map<any, number>();\n sort(\n sortType,\n nonEmptyFeeds.flatMap(({ posts }) => posts),\n sortOptions,\n ).forEach((post, index) => ranks.set(post, index));\n const rankOf = (post: any) => ranks.get(post) as number;\n const orderedFeeds = nonEmptyFeeds.map(({ posts, keepOrder }) =>\n keepOrder ? posts : [...posts].sort((a, b) => rankOf(a) - rankOf(b)),\n );\n const nextIndexes = orderedFeeds.map(() => 0);\n const postCount = orderedFeeds.reduce((count, posts) => count + posts.length, 0);\n const merged: any[] = [];\n while (merged.length < postCount) {\n let nextFeedIndex = -1;\n for (const [feedIndex, posts] of orderedFeeds.entries()) {\n if (nextIndexes[feedIndex] === posts.length) {\n continue;\n }\n if (\n nextFeedIndex === -1 ||\n rankOf(posts[nextIndexes[feedIndex]]) <\n rankOf(orderedFeeds[nextFeedIndex][nextIndexes[nextFeedIndex]])\n ) {\n nextFeedIndex = feedIndex;\n }\n }\n merged.push(orderedFeeds[nextFeedIndex][nextIndexes[nextFeedIndex]++]);\n }\n return merged;\n};\n\nexport default { sort, merge };\n"]}
|
|
@@ -15,6 +15,9 @@ type FeedsState = {
|
|
|
15
15
|
feedsCommunityKeysWithMore: {
|
|
16
16
|
[feedName: string]: string[];
|
|
17
17
|
};
|
|
18
|
+
feedsCommunityKeysWithUnavailableSort: {
|
|
19
|
+
[feedName: string]: string[];
|
|
20
|
+
};
|
|
18
21
|
addFeedToStore: Function;
|
|
19
22
|
startFeedAutoUpdate: Function;
|
|
20
23
|
stopFeedAutoUpdate: Function;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feeds-store.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,EAIL,YAAY,EAEZ,0BAA0B,EAI3B,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"feeds-store.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,EAIL,YAAY,EAEZ,0BAA0B,EAI3B,MAAM,aAAa,CAAC;AAkCrB,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAKtC,KAAK,UAAU,GAAG;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,KAAK,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;IACnB,YAAY,EAAE,KAAK,CAAC;IACpB,kCAAkC,EAAE,0BAA0B,CAAC;IAC/D,aAAa,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,gCAAgC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IACnE,0BAA0B,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IAC7D,qCAAqC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IACxE,cAAc,EAAE,QAAQ,CAAC;IACzB,mBAAmB,EAAE,QAAQ,CAAC;IAC9B,kBAAkB,EAAE,QAAQ,CAAC;IAC7B,uBAAuB,EAAE,QAAQ,CAAC;IAClC,oBAAoB,EAAE,QAAQ,CAAC;IAC/B,SAAS,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC;AA4EF,QAAA,MAAM,UAAU,yEAmbb,CAAC;AAsSJ,eAAO,MAAM,eAAe,qBAgC3B,CAAC;AAGF,eAAO,MAAM,0BAA0B,qBAGtC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -29,7 +29,7 @@ import { getCommunityRefKeys } from "../../lib/community-ref.js";
|
|
|
29
29
|
import accountsStore from "../accounts/index.js";
|
|
30
30
|
import communitiesStore, { COMMUNITY_UPDATE_STOP_GRACE_MS } from "../communities/index.js";
|
|
31
31
|
import communitiesPagesStore from "../communities-pages/index.js";
|
|
32
|
-
import { getFeedsCommunitiesFirstPageCids, getLoadedFeeds, getUpdatedFeeds, getBufferedFeedsWithoutLoadedFeeds, getFeedsCommunitiesPostCounts, getFeedsHaveMore, getAccountsBlockedAddresses, feedsHaveChangedBlockedAddresses, accountsBlockedAddressesChanged, getAccountsBlockedCids, feedsHaveChangedBlockedCids, accountsBlockedCidsChanged, feedsCommunitiesChanged, getFeedsCommunities, getFeedsCommunitiesLoadedCount, getFeedsCommunitiesPostsPagesFirstUpdatedAts, getFilteredSortedFeeds, getFeedsCommunityKeysWithNewerPosts, getFeedsCommunityKeysWithMore, } from "./utils.js";
|
|
32
|
+
import { getFeedsCommunitiesFirstPageCids, getLoadedFeeds, getUpdatedFeeds, getBufferedFeedsWithoutLoadedFeeds, getFeedsCommunitiesPostCounts, getFeedsHaveMore, getAccountsBlockedAddresses, feedsHaveChangedBlockedAddresses, accountsBlockedAddressesChanged, getAccountsBlockedCids, feedsHaveChangedBlockedCids, accountsBlockedCidsChanged, feedsCommunitiesChanged, getFeedsCommunities, getFeedsCommunitiesLoadedCount, getFeedsCommunitiesPostsPagesFirstUpdatedAts, getFilteredSortedFeeds, getFeedsCommunityKeysWithNewerPosts, getFeedsCommunityKeysWithMore, getFeedsCommunityKeysWithUnavailableSort, } from "./utils.js";
|
|
33
33
|
// reddit loads approximately 25 posts per page
|
|
34
34
|
// while infinite scrolling
|
|
35
35
|
export const defaultPostsPerPage = 25;
|
|
@@ -102,7 +102,8 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
102
102
|
feedsHaveMore: {},
|
|
103
103
|
feedsCommunityKeysWithNewerPosts: {},
|
|
104
104
|
feedsCommunityKeysWithMore: {},
|
|
105
|
-
|
|
105
|
+
feedsCommunityKeysWithUnavailableSort: {},
|
|
106
|
+
addFeedToStore(feedName, communities, communityKeys, sortType, account, isBufferedFeed, postsPerPage, filter, newerThan, accountComments, modQueue, includeBlockedCids) {
|
|
106
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
108
|
// init here because must be called after async accounts store finished initializing
|
|
108
109
|
initializeFeedsStore();
|
|
@@ -123,7 +124,13 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
123
124
|
postsPerPage = postsPerPage || defaultPostsPerPage;
|
|
124
125
|
assert(typeof postsPerPage === "number", `addFeedToStore.addFeedToStore postsPerPage '${postsPerPage}' invalid`);
|
|
125
126
|
assert(!accountComments || typeof (accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan) === "number", `addFeedToStore.addFeedToStore accountComments.newerThan '${accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan}' invalid`);
|
|
127
|
+
assert((accountComments === null || accountComments === void 0 ? void 0 : accountComments.limit) === undefined ||
|
|
128
|
+
(accountComments === null || accountComments === void 0 ? void 0 : accountComments.limit) === null ||
|
|
129
|
+
(Number.isInteger(accountComments.limit) && accountComments.limit >= 0), `addFeedToStore.addFeedToStore accountComments.limit '${accountComments === null || accountComments === void 0 ? void 0 : accountComments.limit}' invalid`);
|
|
126
130
|
assert(!modQueue || Array.isArray(modQueue), `addFeedToStore.addFeedToStore modQueue '${modQueue}' invalid`);
|
|
131
|
+
assert(includeBlockedCids === undefined ||
|
|
132
|
+
includeBlockedCids === null ||
|
|
133
|
+
typeof includeBlockedCids === "boolean", `addFeedToStore.addFeedToStore includeBlockedCids '${includeBlockedCids}' invalid`);
|
|
127
134
|
const { feedsOptions, updateFeeds } = getState();
|
|
128
135
|
touchFeed(feedName);
|
|
129
136
|
// feed is in store already, do nothing
|
|
@@ -132,19 +139,14 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
132
139
|
return;
|
|
133
140
|
}
|
|
134
141
|
// to add a buffered feed, add a feed with pageNumber 0
|
|
135
|
-
const feedOptions = {
|
|
136
|
-
communities,
|
|
142
|
+
const feedOptions = Object.assign({ communities,
|
|
137
143
|
communityKeys,
|
|
138
|
-
sortType,
|
|
139
|
-
accountId: account.id,
|
|
140
|
-
pageNumber: isBufferedFeed === true ? 0 : 1,
|
|
141
|
-
postsPerPage,
|
|
144
|
+
sortType, accountId: account.id, pageNumber: isBufferedFeed === true ? 0 : 1, postsPerPage,
|
|
142
145
|
newerThan,
|
|
143
146
|
filter,
|
|
144
147
|
accountComments,
|
|
145
148
|
// TODO: allow multiple modQueue at once, fow now only use first in array
|
|
146
|
-
modQueue,
|
|
147
|
-
};
|
|
149
|
+
modQueue }, (includeBlockedCids === true ? { includeBlockedCids } : undefined));
|
|
148
150
|
log("feedsActions.addFeedToStore", feedOptions);
|
|
149
151
|
setState(({ feedsOptions }) => ({
|
|
150
152
|
feedsOptions: Object.assign(Object.assign({}, feedsOptions), { [feedName]: feedOptions }),
|
|
@@ -287,8 +289,17 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
287
289
|
const bufferedFeedsCommunitiesPostCounts = getFeedsCommunitiesPostCounts(feedsOptions, bufferedFeeds);
|
|
288
290
|
const feedsHaveMore = getFeedsHaveMore(feedsOptions, bufferedFeeds, communities, communitiesPages, accounts);
|
|
289
291
|
const feedsCommunityKeysWithMore = getFeedsCommunityKeysWithMore(feedsOptions, bufferedFeedsCommunitiesPostCounts, communities, communitiesPages, accounts, previousState.feedsCommunityKeysWithMore);
|
|
292
|
+
const feedsCommunityKeysWithUnavailableSort = getFeedsCommunityKeysWithUnavailableSort(feedsOptions, communities, previousState.feedsCommunityKeysWithUnavailableSort);
|
|
290
293
|
const feedsCommunityKeysWithNewerPosts = getFeedsCommunityKeysWithNewerPosts(feedsOptions, filteredSortedFeeds, loadedFeeds, previousState.feedsCommunityKeysWithNewerPosts);
|
|
291
294
|
const updatedFeeds = yield getUpdatedFeeds(feedsOptions, filteredSortedFeeds, previousState.updatedFeeds, loadedFeeds, accounts);
|
|
295
|
+
// a feed reset while this pass awaited comment validation would get its old posts back, and
|
|
296
|
+
// loaded feeds never shrink, so drop this pass and calculate again from the reset feed
|
|
297
|
+
if (getState().loadedFeeds !== previousState.loadedFeeds) {
|
|
298
|
+
updateFeedsPending = false;
|
|
299
|
+
updateFeedsAgain = false;
|
|
300
|
+
updateFeeds();
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
292
303
|
// set new feeds
|
|
293
304
|
setState((state) => ({
|
|
294
305
|
bufferedFeeds,
|
|
@@ -298,6 +309,7 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
298
309
|
feedsHaveMore,
|
|
299
310
|
feedsCommunityKeysWithNewerPosts,
|
|
300
311
|
feedsCommunityKeysWithMore,
|
|
312
|
+
feedsCommunityKeysWithUnavailableSort,
|
|
301
313
|
}));
|
|
302
314
|
log.trace("feedsStore.updateFeeds", {
|
|
303
315
|
feedsOptions,
|
|
@@ -489,24 +501,22 @@ const updateFeedsOnFeedsCommunitiesChange = (communitiesStoreState) => {
|
|
|
489
501
|
// decide if feeds communities have changed by looking at all feeds communities page cids
|
|
490
502
|
// (in case that a community changed, but its first page cid didn't)
|
|
491
503
|
const feedsCommunitiesFirstPageCids = getFeedsCommunitiesFirstPageCids(feedsCommunities);
|
|
492
|
-
// first page cids
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
previousFeedsCommunitiesLoadedCount = feedsCommunitiesLoadedCount;
|
|
504
|
+
// in case a sub loads with no first page cid and first pages cids don't change, need to trigger hasMore update
|
|
505
|
+
const feedsCommunitiesLoadedCount = getFeedsCommunitiesLoadedCount(feedsCommunities);
|
|
506
|
+
// in case community.posts.pages changed without new page cids
|
|
507
|
+
const feedsCommunitiesPostsPagesFirstUpdatedAts = getFeedsCommunitiesPostsPagesFirstUpdatedAts(feedsCommunities);
|
|
508
|
+
const feedsCommunitiesPostsChanged = feedsCommunitiesFirstPageCids.toString() !== previousFeedsCommunitiesFirstPageCids.toString() ||
|
|
509
|
+
feedsCommunitiesLoadedCount !== previousFeedsCommunitiesLoadedCount ||
|
|
510
|
+
feedsCommunitiesPostsPagesFirstUpdatedAts !== previousFeedsCommunitiesPostsPagesFirstUpdatedAts;
|
|
511
|
+
// remember all of them on every pass, so the next change is compared with this one
|
|
512
|
+
previousFeedsCommunitiesFirstPageCids = feedsCommunitiesFirstPageCids;
|
|
513
|
+
previousFeedsCommunitiesLoadedCount = feedsCommunitiesLoadedCount;
|
|
514
|
+
previousFeedsCommunitiesPostsPagesFirstUpdatedAts = feedsCommunitiesPostsPagesFirstUpdatedAts;
|
|
515
|
+
// feeds communities posts haven't changed, do nothing
|
|
516
|
+
if (!feedsCommunitiesPostsChanged) {
|
|
517
|
+
return;
|
|
507
518
|
}
|
|
508
519
|
// feeds communities have changed, update feeds
|
|
509
|
-
previousFeedsCommunitiesFirstPageCids = feedsCommunitiesFirstPageCids;
|
|
510
520
|
updateFeeds();
|
|
511
521
|
};
|
|
512
522
|
let previousAccountsCommentsCount = 0;
|