@bitsocial/bitsocial-react-hooks 0.1.52 → 0.1.53

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.
@@ -1 +1 @@
1
- {"version":3,"file":"feeds-store.js","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAczD,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAsB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,gBAAgB,MAAM,gBAAgB,CAAC;AAC9C,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,gCAAgC,EAChC,cAAc,EACd,eAAe,EACf,kCAAkC,EAClC,6BAA6B,EAC7B,gBAAgB,EAChB,2BAA2B,EAC3B,gCAAgC,EAChC,+BAA+B,EAC/B,sBAAsB,EACtB,2BAA2B,EAC3B,0BAA0B,EAC1B,uBAAuB,EACvB,mBAAmB,EACnB,8BAA8B,EAC9B,4CAA4C,EAC5C,sBAAsB,EACtB,mCAAmC,GACpC,MAAM,SAAS,CAAC;AAEjB,+CAA+C;AAC/C,2BAA2B;AAC3B,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,kDAAkD;AAClD,MAAM,gCAAgC,GAAG,EAAE,CAAC;AAiB5C,kEAAkE;AAClE,IAAI,kBAAkB,GAAG,KAAK,CAAC;AAC/B,IAAI,gBAAgB,GAA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AM,eAAe,EAAE,CAAC;AAC1B,CAAC,CAAA,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:stores\");\nimport {\n Feed,\n Feeds,\n Community,\n Communities,\n Account,\n FeedsOptions,\n CommunityPage,\n FeedsCommunitiesPostCounts,\n CommentsFilter,\n FeedOptionsAccountComments,\n Comment,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport { communityPostsCacheExpired } from \"../../lib/utils\";\nimport { getPkcGetCommunity } from \"../../lib/pkc-compat\";\nimport { CommunityLookupRef, getCommunityRefKeys } from \"../../lib/community-ref\";\nimport accountsStore from \"../accounts\";\nimport communitiesStore from \"../communities\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport {\n getFeedsCommunitiesFirstPageCids,\n getLoadedFeeds,\n getUpdatedFeeds,\n getBufferedFeedsWithoutLoadedFeeds,\n getFeedsCommunitiesPostCounts,\n getFeedsHaveMore,\n getAccountsBlockedAddresses,\n feedsHaveChangedBlockedAddresses,\n accountsBlockedAddressesChanged,\n getAccountsBlockedCids,\n feedsHaveChangedBlockedCids,\n accountsBlockedCidsChanged,\n feedsCommunitiesChanged,\n getFeedsCommunities,\n getFeedsCommunitiesLoadedCount,\n getFeedsCommunitiesPostsPagesFirstUpdatedAts,\n getFilteredSortedFeeds,\n getFeedsCommunityKeysWithNewerPosts,\n} from \"./utils\";\n\n// reddit loads approximately 25 posts per page\n// while infinite scrolling\nexport const defaultPostsPerPage = 25;\n\n// keep large buffer because fetching cids is slow\nconst communityPostsLeftBeforeNextPage = 50;\n\ntype FeedsState = {\n feedsOptions: FeedsOptions;\n bufferedFeeds: Feeds;\n loadedFeeds: Feeds;\n updatedFeeds: Feeds;\n bufferedFeedsCommunitiesPostCounts: FeedsCommunitiesPostCounts;\n feedsHaveMore: { [feedName: string]: boolean };\n feedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] };\n addFeedToStore: Function;\n incrementFeedPageNumber: Function;\n expandFeedTimeWindow: Function;\n resetFeed: Function;\n updateFeeds: Function;\n};\n\n// don't updateFeeds more than once per updateFeedsMinIntervalTime\nlet updateFeedsPending = false;\nlet updateFeedsAgain = false;\nconst updateFeedsMinIntervalTime = 100;\n\nconst feedsStore = createStore<FeedsState>((setState: Function, getState: Function) => ({\n feedsOptions: {},\n bufferedFeeds: {},\n loadedFeeds: {},\n updatedFeeds: {},\n bufferedFeedsCommunitiesPostCounts: {},\n feedsHaveMore: {},\n feedsCommunityKeysWithNewerPosts: {},\n\n async addFeedToStore(\n feedName: string,\n communities: CommunityLookupRef[],\n communityKeys: string[],\n sortType: string | undefined,\n account: Account,\n isBufferedFeed?: boolean,\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: FeedOptionsAccountComments,\n modQueue?: string[],\n ) {\n // init here because must be called after async accounts store finished initializing\n initializeFeedsStore();\n\n assert(\n feedName && typeof feedName === \"string\",\n `feedsStore.addFeedToStore feedName '${feedName}' invalid`,\n );\n assert(\n Array.isArray(communities),\n `addFeedToStore.addFeedToStore communities '${communities}' invalid`,\n );\n assert(\n Array.isArray(communityKeys),\n `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' invalid`,\n );\n const derivedCommunityKeys = getCommunityRefKeys(communities);\n assert(\n communityKeys.length === derivedCommunityKeys.length &&\n communityKeys.every((communityKey, index) => communityKey === derivedCommunityKeys[index]),\n `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' do not match communities`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `addFeedToStore.addFeedToStore sortType '${sortType}' invalid`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `addFeedToStore.addFeedToStore account '${account}' invalid`,\n );\n assert(\n typeof isBufferedFeed === \"boolean\" ||\n isBufferedFeed === undefined ||\n isBufferedFeed === null,\n `addFeedToStore.addFeedToStore isBufferedFeed '${isBufferedFeed}' invalid`,\n );\n assert(\n !filter || typeof filter?.filter === \"function\",\n `addFeedToStore.addFeedToStore filter.filter '${filter?.filter}' invalid`,\n );\n assert(\n !filter || typeof filter?.key === \"string\",\n `addFeedToStore.addFeedToStore filter.key '${filter?.key}' invalid`,\n );\n assert(\n !newerThan || typeof newerThan === \"number\",\n `addFeedToStore.addFeedToStore newerThan '${newerThan}' invalid`,\n );\n postsPerPage = postsPerPage || defaultPostsPerPage;\n assert(\n typeof postsPerPage === \"number\",\n `addFeedToStore.addFeedToStore postsPerPage '${postsPerPage}' invalid`,\n );\n assert(\n !accountComments || typeof accountComments?.newerThan === \"number\",\n `addFeedToStore.addFeedToStore accountComments.newerThan '${accountComments?.newerThan}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `addFeedToStore.addFeedToStore modQueue '${modQueue}' invalid`,\n );\n\n const { feedsOptions, updateFeeds } = getState();\n // feed is in store already, do nothing\n // if the feed already exist but is at page 0, reset it to page 1\n if (feedsOptions[feedName] && feedsOptions[feedName].pageNumber !== 0) {\n return;\n }\n // to add a buffered feed, add a feed with pageNumber 0\n const feedOptions = {\n communities,\n communityKeys,\n sortType,\n accountId: account.id,\n pageNumber: isBufferedFeed === true ? 0 : 1,\n postsPerPage,\n newerThan,\n filter,\n accountComments,\n // TODO: allow multiple modQueue at once, fow now only use first in array\n modQueue,\n };\n log(\"feedsActions.addFeedToStore\", feedOptions);\n setState(({ feedsOptions }: any) => ({\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n }));\n\n addCommunitiesToCommunitiesStore(communities, account);\n\n // update feeds right away to use the already loaded communities and pages\n // if no new communities are added by the feed, like for a sort type change,\n // a feed update will never be triggered, so must be triggered it manually\n updateFeeds();\n },\n\n incrementFeedPageNumber(feedName: string) {\n const { feedsOptions, loadedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`,\n );\n log(\"feedsActions.incrementFeedPageNumber\", { feedName });\n\n assert(\n feedsOptions[feedName].pageNumber * feedsOptions[feedName].postsPerPage <=\n loadedFeeds[feedName].length,\n `feedsActions.incrementFeedPageNumber cannot increment feed page number before current page has loaded`,\n );\n setState(({ feedsOptions, loadedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: feedsOptions[feedName].pageNumber + 1,\n };\n return { feedsOptions: { ...feedsOptions, [feedName]: feedOptions } };\n });\n\n // do not update feed at the same time as increment a page number or it might cause\n // a race condition, rather schedule a feed update\n updateFeeds();\n },\n\n expandFeedTimeWindow(feedName: string, newerThan?: number) {\n const { feedsOptions, loadedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.expandFeedTimeWindow feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n newerThan === undefined || typeof newerThan === \"number\",\n `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' invalid`,\n );\n\n const currentFeedOptions = feedsOptions[feedName];\n const currentNewerThan = currentFeedOptions.newerThan;\n\n if (currentNewerThan === newerThan) {\n return;\n }\n\n const isExpandedTimeWindow =\n typeof currentNewerThan === \"number\" &&\n (newerThan === undefined || newerThan > currentNewerThan);\n assert(\n isExpandedTimeWindow,\n `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' must broaden the current window '${currentNewerThan}'`,\n );\n\n const loadedFeed = loadedFeeds[feedName] || [];\n const shouldPrefetchExpandedPage =\n currentFeedOptions.pageNumber > 0 &&\n loadedFeed.length >= currentFeedOptions.pageNumber * currentFeedOptions.postsPerPage;\n\n setState(({ feedsOptions }: any) => ({\n feedsOptions: {\n ...feedsOptions,\n [feedName]: {\n ...currentFeedOptions,\n newerThan,\n pageNumber: shouldPrefetchExpandedPage\n ? currentFeedOptions.pageNumber + 1\n : currentFeedOptions.pageNumber,\n },\n },\n }));\n\n updateFeeds();\n },\n\n async resetFeed(feedName: string) {\n const { feedsOptions, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.resetFeed feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n feedsOptions[feedName].pageNumber >= 1,\n `feedsActions.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`,\n );\n log(\"feedsActions.resetFeed\", { feedName });\n\n const { modQueue, sortType, communities, communityKeys, accountId } = feedsOptions[feedName];\n const account = accountsStore.getState().accounts[accountId];\n assert(\n account,\n `feedsActions.resetFeed account id '${accountId}' does not exist in accounts store`,\n );\n\n setState(({ feedsOptions, loadedFeeds, updatedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: 1,\n };\n return {\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n loadedFeeds: { ...loadedFeeds, [feedName]: [] },\n updatedFeeds: { ...updatedFeeds, [feedName]: [] },\n };\n });\n\n if (modQueue?.[0]) {\n const { communities } = communitiesStore.getState();\n const { invalidateCommunityPages } = communitiesPagesStore.getState();\n const loadedCommunities = communityKeys\n .map((communityKey: string) => communities[communityKey])\n .filter((community: Community | undefined): community is Community => Boolean(community));\n await Promise.all(\n loadedCommunities.map((community: Community) =>\n invalidateCommunityPages(community, sortType, modQueue, account.id),\n ),\n );\n }\n\n await Promise.all(\n communities.map((communityRef: CommunityLookupRef, communityIndex: number) =>\n communitiesStore\n .getState()\n .refreshCommunity(communityRef, account)\n .catch((error: unknown) =>\n log.error(\"feedsStore.resetFeed refreshCommunity error\", {\n feedName,\n community: communityRef,\n communityKey: communityKeys[communityIndex],\n error,\n }),\n ),\n ),\n );\n\n updateFeeds();\n },\n\n // recalculate all feeds using new communities.post.pages, communitiesPagesStore and page numbers\n updateFeeds() {\n if (updateFeedsPending) {\n updateFeedsAgain = true;\n return;\n }\n updateFeedsPending = true;\n\n // don't update feeds more than once per updateFeedsMinIntervalTime\n const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;\n\n setTimeout(async () => {\n // get state from all stores\n const previousState = getState();\n const { feedsOptions, updateFeeds } = previousState;\n const { communities } = communitiesStore.getState();\n const { communitiesPages } = communitiesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // calculate new feeds\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n communities,\n communitiesPages,\n accounts,\n communitiesPagesStore.getState().comments,\n );\n const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n filteredSortedFeeds,\n previousState.loadedFeeds,\n );\n const loadedFeeds = await getLoadedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.loadedFeeds,\n bufferedFeedsWithoutPreviousLoadedFeeds,\n accounts,\n );\n // after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds\n const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n loadedFeeds,\n );\n const bufferedFeedsCommunitiesPostCounts = getFeedsCommunitiesPostCounts(\n feedsOptions,\n bufferedFeeds,\n );\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n communities,\n communitiesPages,\n accounts,\n );\n const feedsCommunityKeysWithNewerPosts = getFeedsCommunityKeysWithNewerPosts(\n feedsOptions,\n filteredSortedFeeds,\n loadedFeeds,\n previousState.feedsCommunityKeysWithNewerPosts,\n );\n const updatedFeeds = await getUpdatedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.updatedFeeds,\n loadedFeeds,\n accounts,\n );\n\n // set new feeds\n setState((state: any) => ({\n bufferedFeeds,\n loadedFeeds,\n updatedFeeds,\n bufferedFeedsCommunitiesPostCounts,\n feedsHaveMore,\n feedsCommunityKeysWithNewerPosts,\n }));\n log.trace(\"feedsStore.updateFeeds\", {\n feedsOptions,\n bufferedFeeds,\n loadedFeeds,\n updatedFeeds,\n bufferedFeedsCommunitiesPostCounts,\n feedsHaveMore,\n communities,\n communitiesPages,\n feedsCommunityKeysWithNewerPosts,\n });\n\n updateFeedsPending = false;\n\n // If a community/page update arrived during this calculation, run one\n // more pass so feedsHaveMore and loadedFeeds cannot stay on stale input.\n if (updateFeedsAgain) {\n updateFeedsAgain = false;\n updateFeeds();\n }\n }, timeUntilNextUpdate);\n },\n}));\n\nlet feedsStoreInitialized = false;\nconst initializeFeedsStore = async () => {\n if (feedsStoreInitialized) {\n return;\n }\n // TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommunitiesChange(communities)\n // subscribe to communities store changes\n communitiesStore.subscribe(updateFeedsOnFeedsCommunitiesChange);\n // subscribe to bufferedFeedsCommunitiesPostCounts change\n feedsStore.subscribe(addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts);\n // subscribe to communities pages store changes\n communitiesPagesStore.subscribe(updateFeedsOnFeedsCommunitiesPagesChange);\n // subscribe to accounts store change (for blocked addresses)\n accountsStore.subscribe(updateFeedsOnAccountsBlockedAddressesChange);\n // subscribe to accounts store change (for blocked cids)\n accountsStore.subscribe(updateFeedsOnAccountsBlockedCidsChange);\n // subscribe to accounts store changes (for account comments)\n accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);\n feedsStoreInitialized = true;\n};\n\nlet previousBlockedAddresses: string[] = [];\nlet previousAccountsBlockedAddresses: { [address: string]: boolean }[] = [];\nconst updateFeedsOnAccountsBlockedAddressesChange = (accountsStoreState: any) => {\n const { accounts } = accountsStoreState;\n\n // blocked addresses haven't changed, do nothing\n const accountsBlockedAddresses = [];\n for (const i in accounts) {\n accountsBlockedAddresses.push(accounts[i].blockedAddresses);\n }\n if (\n !accountsBlockedAddressesChanged(previousAccountsBlockedAddresses, accountsBlockedAddresses)\n ) {\n return;\n }\n previousAccountsBlockedAddresses = accountsBlockedAddresses;\n\n const blockedAddresses = getAccountsBlockedAddresses(accounts);\n\n // blocked addresses haven't changed, do nothing\n if (blockedAddresses.toString() === previousBlockedAddresses.toString()) {\n return;\n }\n\n const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();\n const _feedsHaveChangedBlockedAddresses = feedsHaveChangedBlockedAddresses(\n feedsOptions,\n bufferedFeeds,\n blockedAddresses,\n previousBlockedAddresses,\n );\n previousBlockedAddresses = blockedAddresses;\n\n // if changed blocked addresses arent used in the feeds, do nothing\n // NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update\n if (!_feedsHaveChangedBlockedAddresses) {\n return;\n }\n\n updateFeeds();\n};\n\nlet previousBlockedCids: string[] = [];\nlet previousAccountsBlockedCids: { [cid: string]: boolean }[] = [];\nconst updateFeedsOnAccountsBlockedCidsChange = (accountsStoreState: any) => {\n const { accounts } = accountsStoreState;\n\n // blocked cids haven't changed, do nothing\n const accountsBlockedCids = [];\n for (const i in accounts) {\n accountsBlockedCids.push(accounts[i].blockedCids);\n }\n if (!accountsBlockedCidsChanged(previousAccountsBlockedCids, accountsBlockedCids)) {\n return;\n }\n previousAccountsBlockedCids = accountsBlockedCids;\n\n const blockedCids = getAccountsBlockedCids(accounts);\n\n // blocked cids haven't changed, do nothing\n if (blockedCids.toString() === previousBlockedCids.toString()) {\n return;\n }\n\n const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();\n const _feedsHaveChangedBlockedCids = feedsHaveChangedBlockedCids(\n feedsOptions,\n bufferedFeeds,\n blockedCids,\n previousBlockedCids,\n );\n previousBlockedCids = blockedCids;\n\n // if changed blocked cids arent used in the feeds, do nothing\n // NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update\n if (!_feedsHaveChangedBlockedCids) {\n return;\n }\n\n updateFeeds();\n};\n\nlet previousCommunitiesPages: { [pageCid: string]: CommunityPage } = {};\nconst updateFeedsOnFeedsCommunitiesPagesChange = (communitiesPagesStoreState: any) => {\n const { communitiesPages } = communitiesPagesStoreState;\n\n // no changes, do nothing\n if (communitiesPages === previousCommunitiesPages) {\n return;\n }\n previousCommunitiesPages = communitiesPages;\n\n // currently only the feeds use communitiesPagesStore, so any change must\n // trigger a feed update, if in the future another hook uses the communitiesPagesStore\n // we should check if the communities pages changed are actually used by the feeds before\n // triggering an update\n feedsStore.getState().updateFeeds();\n};\n\nlet previousBufferedFeedsCommunitiesPostCountsPageCids: string[] = [];\nlet previousBufferedFeedsCommunities = new Map<string, Community>();\nlet previousBufferedFeedsCommunitiesPostCounts: FeedsCommunitiesPostCounts = {};\nconst addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts = (feedsStoreState: any) => {\n const { bufferedFeedsCommunitiesPostCounts, feedsOptions } = feedsStore.getState();\n const { communities } = communitiesStore.getState();\n\n // if feeds communities have changed, we must try adding them even if buffered posts counts haven't changed\n const bufferedFeedsCommunities = getFeedsCommunities(feedsOptions, communities);\n const _feedsCommunitiesChanged = feedsCommunitiesChanged(\n previousBufferedFeedsCommunities,\n bufferedFeedsCommunities,\n );\n const bufferedFeedsCommunitiesPostCountsChanged =\n previousBufferedFeedsCommunitiesPostCounts !== bufferedFeedsCommunitiesPostCounts;\n\n // if feeds communities havent changed and buffered posts counts also havent changed, do nothing\n if (!_feedsCommunitiesChanged && !bufferedFeedsCommunitiesPostCountsChanged) {\n return;\n }\n previousBufferedFeedsCommunities = bufferedFeedsCommunities;\n previousBufferedFeedsCommunitiesPostCounts = bufferedFeedsCommunitiesPostCounts;\n\n // in case feeds community changed, but the first page cids haven't\n const bufferedFeedsCommunitiesPostCountsPageCids =\n getFeedsCommunitiesFirstPageCids(bufferedFeedsCommunities);\n const bufferedFeedsCommunitiesPostCountsPageCidsChanged =\n bufferedFeedsCommunitiesPostCountsPageCids.toString() !==\n previousBufferedFeedsCommunitiesPostCountsPageCids.toString();\n if (\n !bufferedFeedsCommunitiesPostCountsPageCidsChanged &&\n !bufferedFeedsCommunitiesPostCountsChanged\n ) {\n return;\n }\n previousBufferedFeedsCommunitiesPostCountsPageCids = bufferedFeedsCommunitiesPostCountsPageCids;\n\n const { addNextCommunityPageToStore } = communitiesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // bufferedFeedsCommunitiesPostCounts have changed, check if any of them are low\n for (const feedName in bufferedFeedsCommunitiesPostCounts) {\n const account = accounts[feedsOptions[feedName].accountId];\n const communitiesPostCounts = bufferedFeedsCommunitiesPostCounts[feedName];\n const { sortType, modQueue } = feedsOptions[feedName];\n for (const communityAddress in communitiesPostCounts) {\n // don't fetch more pages if community address is blocked\n if (account?.blockedAddresses[communityAddress]) {\n continue;\n }\n\n // community hasn't loaded yet\n if (!communities[communityAddress]) {\n continue;\n }\n\n // if community posts cache is expired, don't use, wait for next community update\n if (communityPostsCacheExpired(communities[communityAddress])) {\n continue;\n }\n\n // community post count is low, fetch next community page\n if (communitiesPostCounts[communityAddress] <= communityPostsLeftBeforeNextPage) {\n addNextCommunityPageToStore(\n communities[communityAddress],\n sortType,\n account,\n modQueue,\n ).catch((error: unknown) =>\n log.error(\"feedsStore communitiesActions.addNextCommunityPageToStore error\", {\n communityAddress,\n community: communities[communityAddress],\n sortType,\n error,\n }),\n );\n }\n }\n }\n};\n\nlet previousFeedsCommunitiesFirstPageCids: string[] = [];\nlet previousFeedsCommunities: Map<string, Community> = new Map();\nlet previousFeedsCommunitiesLoadedCount = 0;\nlet previousFeedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\nconst updateFeedsOnFeedsCommunitiesChange = (communitiesStoreState: any) => {\n const { communities } = communitiesStoreState;\n const { feedsOptions, updateFeeds } = feedsStore.getState();\n\n // feeds communities haven't changed, do nothing\n const feedsCommunities = getFeedsCommunities(feedsOptions, communities);\n if (!feedsCommunitiesChanged(previousFeedsCommunities, feedsCommunities)) {\n return;\n }\n previousFeedsCommunities = feedsCommunities;\n\n // decide if feeds communities have changed by looking at all feeds communities page cids\n // (in case that a community changed, but its first page cid didn't)\n const feedsCommunitiesFirstPageCids = getFeedsCommunitiesFirstPageCids(feedsCommunities);\n\n // first page cids haven't changed, do nothing\n if (\n feedsCommunitiesFirstPageCids.toString() === previousFeedsCommunitiesFirstPageCids.toString()\n ) {\n // if no new feed communities have loaded, do nothing\n // in case a sub loads with no first page cid and first pages cids don't change, need to trigger hasMore update\n const feedsCommunitiesLoadedCount = getFeedsCommunitiesLoadedCount(feedsCommunities);\n if (feedsCommunitiesLoadedCount === previousFeedsCommunitiesLoadedCount) {\n // if community.posts.pages haven't changed, do nothing\n const feedsCommunitiesPostsPagesFirstUpdatedAts =\n getFeedsCommunitiesPostsPagesFirstUpdatedAts(feedsCommunities);\n if (\n feedsCommunitiesPostsPagesFirstUpdatedAts ===\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts\n ) {\n return;\n }\n\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts = feedsCommunitiesPostsPagesFirstUpdatedAts;\n }\n previousFeedsCommunitiesLoadedCount = feedsCommunitiesLoadedCount;\n }\n\n // feeds communities have changed, update feeds\n previousFeedsCommunitiesFirstPageCids = feedsCommunitiesFirstPageCids;\n updateFeeds();\n};\n\nlet previousAccountsCommentsCount = 0;\nlet previousAccountsCommentsCids = \"\";\nconst updateFeedsOnAccountsCommentsChange = (accountsStoreState: any) => {\n const { accountsComments } = accountsStoreState;\n const accountsCommentsCount = Object.values(accountsComments as Comment[][]).reduce(\n (count, accountComments) => count + accountComments.length,\n 0,\n );\n\n // no changes, do nothing\n if (accountsCommentsCount === previousAccountsCommentsCount) {\n // if cids haven't changed (account comments receive cids after pending), do nothing\n const accountsCommentsCids = Object.values(accountsComments as Comment[][]).reduce(\n (cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || \"\")),\n \"\",\n );\n if (accountsCommentsCids === previousAccountsCommentsCids) {\n return;\n }\n previousAccountsCommentsCids = accountsCommentsCids;\n }\n previousAccountsCommentsCount = accountsCommentsCount;\n\n // TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid\n feedsStore.getState().updateFeeds();\n};\n\nconst addCommunitiesToCommunitiesStore = (\n communityRefs: CommunityLookupRef[],\n account: Account,\n) => {\n const addCommunityToStore = communitiesStore.getState().addCommunityToStore;\n for (const communityRef of communityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"feedsStore communitiesActions.addCommunityToStore error\", {\n communityRef,\n error,\n }),\n );\n }\n};\n\n// reset store in between tests\nconst originalState = feedsStore.getState();\n// async function because some stores have async init\nexport const resetFeedsStore = async () => {\n previousBufferedFeedsCommunitiesPostCounts = {};\n previousBufferedFeedsCommunitiesPostCountsPageCids = [];\n previousBufferedFeedsCommunities = new Map();\n previousBlockedAddresses = [];\n previousAccountsBlockedAddresses = [];\n previousBlockedCids = [];\n previousAccountsBlockedCids = [];\n previousFeedsCommunitiesFirstPageCids = [];\n previousFeedsCommunities = new Map();\n previousFeedsCommunitiesLoadedCount = 0;\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\n previousCommunitiesPages = {};\n previousAccountsCommentsCount = 0;\n previousAccountsCommentsCids = \"\";\n updateFeedsPending = false;\n updateFeedsAgain = false;\n // destroy all component subscriptions to the store\n feedsStore.destroy();\n // restore original state\n feedsStore.setState(originalState);\n feedsStoreInitialized = false;\n};\n\n// reset database and store in between tests\nexport const resetFeedsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear();\n await resetFeedsStore();\n};\n\nexport default feedsStore;\n"]}
1
+ {"version":3,"file":"feeds-store.js","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAczD,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAsB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,aAAa,M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eAAe,EAAE,CAAC;AAC1B,CAAC,CAAA,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:stores\");\nimport {\n Feed,\n Feeds,\n Community,\n Communities,\n Account,\n FeedsOptions,\n CommunityPage,\n FeedsCommunitiesPostCounts,\n CommentsFilter,\n FeedOptionsAccountComments,\n Comment,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport { communityPostsCacheExpired } from \"../../lib/utils\";\nimport { getPkcGetCommunity } from \"../../lib/pkc-compat\";\nimport { CommunityLookupRef, getCommunityRefKeys } from \"../../lib/community-ref\";\nimport accountsStore from \"../accounts\";\nimport communitiesStore from \"../communities\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport {\n getFeedsCommunitiesFirstPageCids,\n getLoadedFeeds,\n getUpdatedFeeds,\n getBufferedFeedsWithoutLoadedFeeds,\n getFeedsCommunitiesPostCounts,\n getFeedsHaveMore,\n getAccountsBlockedAddresses,\n feedsHaveChangedBlockedAddresses,\n accountsBlockedAddressesChanged,\n getAccountsBlockedCids,\n feedsHaveChangedBlockedCids,\n accountsBlockedCidsChanged,\n feedsCommunitiesChanged,\n getFeedsCommunities,\n getFeedsCommunitiesLoadedCount,\n getFeedsCommunitiesPostsPagesFirstUpdatedAts,\n getFilteredSortedFeeds,\n getFeedsCommunityKeysWithNewerPosts,\n getFeedsCommunityKeysWithMore,\n} from \"./utils\";\n\n// reddit loads approximately 25 posts per page\n// while infinite scrolling\nexport const defaultPostsPerPage = 25;\n\n// keep large buffer because fetching cids is slow\nconst communityPostsLeftBeforeNextPage = 50;\n\ntype FeedsState = {\n feedsOptions: FeedsOptions;\n bufferedFeeds: Feeds;\n loadedFeeds: Feeds;\n updatedFeeds: Feeds;\n bufferedFeedsCommunitiesPostCounts: FeedsCommunitiesPostCounts;\n feedsHaveMore: { [feedName: string]: boolean };\n feedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] };\n feedsCommunityKeysWithMore: { [feedName: string]: string[] };\n addFeedToStore: Function;\n incrementFeedPageNumber: Function;\n expandFeedTimeWindow: Function;\n resetFeed: Function;\n updateFeeds: Function;\n};\n\n// don't updateFeeds more than once per updateFeedsMinIntervalTime\nlet updateFeedsPending = false;\nlet updateFeedsAgain = false;\nconst updateFeedsMinIntervalTime = 100;\n\n// a feed whose options changed has no community keys with more until it is calculated again, so\n// useFeed reports every community as still loading instead of the previous options' result\nconst withoutFeed = (feedsCommunityKeys: { [feedName: string]: string[] }, feedName: string) => {\n const { [feedName]: _removedFeedCommunityKeys, ...otherFeedsCommunityKeys } = feedsCommunityKeys;\n return otherFeedsCommunityKeys;\n};\n\nconst feedsStore = createStore<FeedsState>((setState: Function, getState: Function) => ({\n feedsOptions: {},\n bufferedFeeds: {},\n loadedFeeds: {},\n updatedFeeds: {},\n bufferedFeedsCommunitiesPostCounts: {},\n feedsHaveMore: {},\n feedsCommunityKeysWithNewerPosts: {},\n feedsCommunityKeysWithMore: {},\n\n async addFeedToStore(\n feedName: string,\n communities: CommunityLookupRef[],\n communityKeys: string[],\n sortType: string | undefined,\n account: Account,\n isBufferedFeed?: boolean,\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: FeedOptionsAccountComments,\n modQueue?: string[],\n ) {\n // init here because must be called after async accounts store finished initializing\n initializeFeedsStore();\n\n assert(\n feedName && typeof feedName === \"string\",\n `feedsStore.addFeedToStore feedName '${feedName}' invalid`,\n );\n assert(\n Array.isArray(communities),\n `addFeedToStore.addFeedToStore communities '${communities}' invalid`,\n );\n assert(\n Array.isArray(communityKeys),\n `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' invalid`,\n );\n const derivedCommunityKeys = getCommunityRefKeys(communities);\n assert(\n communityKeys.length === derivedCommunityKeys.length &&\n communityKeys.every((communityKey, index) => communityKey === derivedCommunityKeys[index]),\n `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' do not match communities`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `addFeedToStore.addFeedToStore sortType '${sortType}' invalid`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `addFeedToStore.addFeedToStore account '${account}' invalid`,\n );\n assert(\n typeof isBufferedFeed === \"boolean\" ||\n isBufferedFeed === undefined ||\n isBufferedFeed === null,\n `addFeedToStore.addFeedToStore isBufferedFeed '${isBufferedFeed}' invalid`,\n );\n assert(\n !filter || typeof filter?.filter === \"function\",\n `addFeedToStore.addFeedToStore filter.filter '${filter?.filter}' invalid`,\n );\n assert(\n !filter || typeof filter?.key === \"string\",\n `addFeedToStore.addFeedToStore filter.key '${filter?.key}' invalid`,\n );\n assert(\n !newerThan || typeof newerThan === \"number\",\n `addFeedToStore.addFeedToStore newerThan '${newerThan}' invalid`,\n );\n postsPerPage = postsPerPage || defaultPostsPerPage;\n assert(\n typeof postsPerPage === \"number\",\n `addFeedToStore.addFeedToStore postsPerPage '${postsPerPage}' invalid`,\n );\n assert(\n !accountComments || typeof accountComments?.newerThan === \"number\",\n `addFeedToStore.addFeedToStore accountComments.newerThan '${accountComments?.newerThan}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `addFeedToStore.addFeedToStore modQueue '${modQueue}' invalid`,\n );\n\n const { feedsOptions, updateFeeds } = getState();\n // feed is in store already, do nothing\n // if the feed already exist but is at page 0, reset it to page 1\n if (feedsOptions[feedName] && feedsOptions[feedName].pageNumber !== 0) {\n return;\n }\n // to add a buffered feed, add a feed with pageNumber 0\n const feedOptions = {\n communities,\n communityKeys,\n sortType,\n accountId: account.id,\n pageNumber: isBufferedFeed === true ? 0 : 1,\n postsPerPage,\n newerThan,\n filter,\n accountComments,\n // TODO: allow multiple modQueue at once, fow now only use first in array\n modQueue,\n };\n log(\"feedsActions.addFeedToStore\", feedOptions);\n setState(({ feedsOptions }: any) => ({\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n }));\n\n addCommunitiesToCommunitiesStore(communities, account);\n\n // update feeds right away to use the already loaded communities and pages\n // if no new communities are added by the feed, like for a sort type change,\n // a feed update will never be triggered, so must be triggered it manually\n updateFeeds();\n },\n\n incrementFeedPageNumber(feedName: string) {\n const { feedsOptions, loadedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`,\n );\n log(\"feedsActions.incrementFeedPageNumber\", { feedName });\n\n assert(\n feedsOptions[feedName].pageNumber * feedsOptions[feedName].postsPerPage <=\n loadedFeeds[feedName].length,\n `feedsActions.incrementFeedPageNumber cannot increment feed page number before current page has loaded`,\n );\n setState(({ feedsOptions, loadedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: feedsOptions[feedName].pageNumber + 1,\n };\n return { feedsOptions: { ...feedsOptions, [feedName]: feedOptions } };\n });\n\n // do not update feed at the same time as increment a page number or it might cause\n // a race condition, rather schedule a feed update\n updateFeeds();\n },\n\n expandFeedTimeWindow(feedName: string, newerThan?: number) {\n const { feedsOptions, loadedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.expandFeedTimeWindow feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n newerThan === undefined || typeof newerThan === \"number\",\n `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' invalid`,\n );\n\n const currentFeedOptions = feedsOptions[feedName];\n const currentNewerThan = currentFeedOptions.newerThan;\n\n if (currentNewerThan === newerThan) {\n return;\n }\n\n const isExpandedTimeWindow =\n typeof currentNewerThan === \"number\" &&\n (newerThan === undefined || newerThan > currentNewerThan);\n assert(\n isExpandedTimeWindow,\n `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' must broaden the current window '${currentNewerThan}'`,\n );\n\n const loadedFeed = loadedFeeds[feedName] || [];\n const shouldPrefetchExpandedPage =\n currentFeedOptions.pageNumber > 0 &&\n loadedFeed.length >= currentFeedOptions.pageNumber * currentFeedOptions.postsPerPage;\n\n setState(({ feedsOptions, feedsCommunityKeysWithMore }: any) => ({\n feedsOptions: {\n ...feedsOptions,\n [feedName]: {\n ...currentFeedOptions,\n newerThan,\n pageNumber: shouldPrefetchExpandedPage\n ? currentFeedOptions.pageNumber + 1\n : currentFeedOptions.pageNumber,\n },\n },\n feedsCommunityKeysWithMore: withoutFeed(feedsCommunityKeysWithMore, feedName),\n }));\n\n updateFeeds();\n },\n\n async resetFeed(feedName: string) {\n const { feedsOptions, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.resetFeed feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n feedsOptions[feedName].pageNumber >= 1,\n `feedsActions.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`,\n );\n log(\"feedsActions.resetFeed\", { feedName });\n\n const { modQueue, sortType, communities, communityKeys, accountId } = feedsOptions[feedName];\n const account = accountsStore.getState().accounts[accountId];\n assert(\n account,\n `feedsActions.resetFeed account id '${accountId}' does not exist in accounts store`,\n );\n\n setState(({ feedsOptions, loadedFeeds, updatedFeeds, feedsCommunityKeysWithMore }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: 1,\n };\n return {\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n loadedFeeds: { ...loadedFeeds, [feedName]: [] },\n updatedFeeds: { ...updatedFeeds, [feedName]: [] },\n feedsCommunityKeysWithMore: withoutFeed(feedsCommunityKeysWithMore, feedName),\n };\n });\n\n if (modQueue?.[0]) {\n const { communities } = communitiesStore.getState();\n const { invalidateCommunityPages } = communitiesPagesStore.getState();\n const loadedCommunities = communityKeys\n .map((communityKey: string) => communities[communityKey])\n .filter((community: Community | undefined): community is Community => Boolean(community));\n await Promise.all(\n loadedCommunities.map((community: Community) =>\n invalidateCommunityPages(community, sortType, modQueue, account.id),\n ),\n );\n }\n\n await Promise.all(\n communities.map((communityRef: CommunityLookupRef, communityIndex: number) =>\n communitiesStore\n .getState()\n .refreshCommunity(communityRef, account)\n .catch((error: unknown) =>\n log.error(\"feedsStore.resetFeed refreshCommunity error\", {\n feedName,\n community: communityRef,\n communityKey: communityKeys[communityIndex],\n error,\n }),\n ),\n ),\n );\n\n updateFeeds();\n },\n\n // recalculate all feeds using new communities.post.pages, communitiesPagesStore and page numbers\n updateFeeds() {\n if (updateFeedsPending) {\n updateFeedsAgain = true;\n return;\n }\n updateFeedsPending = true;\n\n // don't update feeds more than once per updateFeedsMinIntervalTime\n const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;\n\n setTimeout(async () => {\n // get state from all stores\n const previousState = getState();\n const { feedsOptions, updateFeeds } = previousState;\n const { communities } = communitiesStore.getState();\n const { communitiesPages } = communitiesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // calculate new feeds\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n communities,\n communitiesPages,\n accounts,\n communitiesPagesStore.getState().comments,\n );\n const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n filteredSortedFeeds,\n previousState.loadedFeeds,\n );\n const loadedFeeds = await getLoadedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.loadedFeeds,\n bufferedFeedsWithoutPreviousLoadedFeeds,\n accounts,\n );\n // after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds\n const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n loadedFeeds,\n );\n const bufferedFeedsCommunitiesPostCounts = getFeedsCommunitiesPostCounts(\n feedsOptions,\n bufferedFeeds,\n );\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n communities,\n communitiesPages,\n accounts,\n );\n const feedsCommunityKeysWithMore = getFeedsCommunityKeysWithMore(\n feedsOptions,\n bufferedFeedsCommunitiesPostCounts,\n communities,\n communitiesPages,\n accounts,\n previousState.feedsCommunityKeysWithMore,\n );\n const feedsCommunityKeysWithNewerPosts = getFeedsCommunityKeysWithNewerPosts(\n feedsOptions,\n filteredSortedFeeds,\n loadedFeeds,\n previousState.feedsCommunityKeysWithNewerPosts,\n );\n const updatedFeeds = await getUpdatedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.updatedFeeds,\n loadedFeeds,\n accounts,\n );\n\n // set new feeds\n setState((state: any) => ({\n bufferedFeeds,\n loadedFeeds,\n updatedFeeds,\n bufferedFeedsCommunitiesPostCounts,\n feedsHaveMore,\n feedsCommunityKeysWithNewerPosts,\n feedsCommunityKeysWithMore,\n }));\n log.trace(\"feedsStore.updateFeeds\", {\n feedsOptions,\n bufferedFeeds,\n loadedFeeds,\n updatedFeeds,\n bufferedFeedsCommunitiesPostCounts,\n feedsHaveMore,\n feedsCommunityKeysWithMore,\n communities,\n communitiesPages,\n feedsCommunityKeysWithNewerPosts,\n });\n\n updateFeedsPending = false;\n\n // If a community/page update arrived during this calculation, run one\n // more pass so feedsHaveMore and loadedFeeds cannot stay on stale input.\n if (updateFeedsAgain) {\n updateFeedsAgain = false;\n updateFeeds();\n }\n }, timeUntilNextUpdate);\n },\n}));\n\nlet feedsStoreInitialized = false;\nconst initializeFeedsStore = async () => {\n if (feedsStoreInitialized) {\n return;\n }\n // TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommunitiesChange(communities)\n // subscribe to communities store changes\n communitiesStore.subscribe(updateFeedsOnFeedsCommunitiesChange);\n // subscribe to bufferedFeedsCommunitiesPostCounts change\n feedsStore.subscribe(addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts);\n // subscribe to communities pages store changes\n communitiesPagesStore.subscribe(updateFeedsOnFeedsCommunitiesPagesChange);\n // subscribe to accounts store change (for blocked addresses)\n accountsStore.subscribe(updateFeedsOnAccountsBlockedAddressesChange);\n // subscribe to accounts store change (for blocked cids)\n accountsStore.subscribe(updateFeedsOnAccountsBlockedCidsChange);\n // subscribe to accounts store changes (for account comments)\n accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);\n feedsStoreInitialized = true;\n};\n\nlet previousBlockedAddresses: string[] = [];\nlet previousAccountsBlockedAddresses: { [address: string]: boolean }[] = [];\nconst updateFeedsOnAccountsBlockedAddressesChange = (accountsStoreState: any) => {\n const { accounts } = accountsStoreState;\n\n // blocked addresses haven't changed, do nothing\n const accountsBlockedAddresses = [];\n for (const i in accounts) {\n accountsBlockedAddresses.push(accounts[i].blockedAddresses);\n }\n if (\n !accountsBlockedAddressesChanged(previousAccountsBlockedAddresses, accountsBlockedAddresses)\n ) {\n return;\n }\n previousAccountsBlockedAddresses = accountsBlockedAddresses;\n\n const blockedAddresses = getAccountsBlockedAddresses(accounts);\n\n // blocked addresses haven't changed, do nothing\n if (blockedAddresses.toString() === previousBlockedAddresses.toString()) {\n return;\n }\n\n const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();\n const _feedsHaveChangedBlockedAddresses = feedsHaveChangedBlockedAddresses(\n feedsOptions,\n bufferedFeeds,\n blockedAddresses,\n previousBlockedAddresses,\n );\n previousBlockedAddresses = blockedAddresses;\n\n // if changed blocked addresses arent used in the feeds, do nothing\n // NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update\n if (!_feedsHaveChangedBlockedAddresses) {\n return;\n }\n\n updateFeeds();\n};\n\nlet previousBlockedCids: string[] = [];\nlet previousAccountsBlockedCids: { [cid: string]: boolean }[] = [];\nconst updateFeedsOnAccountsBlockedCidsChange = (accountsStoreState: any) => {\n const { accounts } = accountsStoreState;\n\n // blocked cids haven't changed, do nothing\n const accountsBlockedCids = [];\n for (const i in accounts) {\n accountsBlockedCids.push(accounts[i].blockedCids);\n }\n if (!accountsBlockedCidsChanged(previousAccountsBlockedCids, accountsBlockedCids)) {\n return;\n }\n previousAccountsBlockedCids = accountsBlockedCids;\n\n const blockedCids = getAccountsBlockedCids(accounts);\n\n // blocked cids haven't changed, do nothing\n if (blockedCids.toString() === previousBlockedCids.toString()) {\n return;\n }\n\n const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();\n const _feedsHaveChangedBlockedCids = feedsHaveChangedBlockedCids(\n feedsOptions,\n bufferedFeeds,\n blockedCids,\n previousBlockedCids,\n );\n previousBlockedCids = blockedCids;\n\n // if changed blocked cids arent used in the feeds, do nothing\n // NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update\n if (!_feedsHaveChangedBlockedCids) {\n return;\n }\n\n updateFeeds();\n};\n\nlet previousCommunitiesPages: { [pageCid: string]: CommunityPage } = {};\nconst updateFeedsOnFeedsCommunitiesPagesChange = (communitiesPagesStoreState: any) => {\n const { communitiesPages } = communitiesPagesStoreState;\n\n // no changes, do nothing\n if (communitiesPages === previousCommunitiesPages) {\n return;\n }\n previousCommunitiesPages = communitiesPages;\n\n // currently only the feeds use communitiesPagesStore, so any change must\n // trigger a feed update, if in the future another hook uses the communitiesPagesStore\n // we should check if the communities pages changed are actually used by the feeds before\n // triggering an update\n feedsStore.getState().updateFeeds();\n};\n\nlet previousBufferedFeedsCommunitiesPostCountsPageCids: string[] = [];\nlet previousBufferedFeedsCommunities = new Map<string, Community>();\nlet previousBufferedFeedsCommunitiesPostCounts: FeedsCommunitiesPostCounts = {};\nconst addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts = (feedsStoreState: any) => {\n const { bufferedFeedsCommunitiesPostCounts, feedsOptions } = feedsStore.getState();\n const { communities } = communitiesStore.getState();\n\n // if feeds communities have changed, we must try adding them even if buffered posts counts haven't changed\n const bufferedFeedsCommunities = getFeedsCommunities(feedsOptions, communities);\n const _feedsCommunitiesChanged = feedsCommunitiesChanged(\n previousBufferedFeedsCommunities,\n bufferedFeedsCommunities,\n );\n const bufferedFeedsCommunitiesPostCountsChanged =\n previousBufferedFeedsCommunitiesPostCounts !== bufferedFeedsCommunitiesPostCounts;\n\n // if feeds communities havent changed and buffered posts counts also havent changed, do nothing\n if (!_feedsCommunitiesChanged && !bufferedFeedsCommunitiesPostCountsChanged) {\n return;\n }\n previousBufferedFeedsCommunities = bufferedFeedsCommunities;\n previousBufferedFeedsCommunitiesPostCounts = bufferedFeedsCommunitiesPostCounts;\n\n // in case feeds community changed, but the first page cids haven't\n const bufferedFeedsCommunitiesPostCountsPageCids =\n getFeedsCommunitiesFirstPageCids(bufferedFeedsCommunities);\n const bufferedFeedsCommunitiesPostCountsPageCidsChanged =\n bufferedFeedsCommunitiesPostCountsPageCids.toString() !==\n previousBufferedFeedsCommunitiesPostCountsPageCids.toString();\n if (\n !bufferedFeedsCommunitiesPostCountsPageCidsChanged &&\n !bufferedFeedsCommunitiesPostCountsChanged\n ) {\n return;\n }\n previousBufferedFeedsCommunitiesPostCountsPageCids = bufferedFeedsCommunitiesPostCountsPageCids;\n\n const { addNextCommunityPageToStore } = communitiesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // bufferedFeedsCommunitiesPostCounts have changed, check if any of them are low\n for (const feedName in bufferedFeedsCommunitiesPostCounts) {\n const account = accounts[feedsOptions[feedName].accountId];\n const communitiesPostCounts = bufferedFeedsCommunitiesPostCounts[feedName];\n const { sortType, modQueue } = feedsOptions[feedName];\n for (const communityAddress in communitiesPostCounts) {\n // don't fetch more pages if community address is blocked\n if (account?.blockedAddresses[communityAddress]) {\n continue;\n }\n\n // community hasn't loaded yet\n if (!communities[communityAddress]) {\n continue;\n }\n\n // if community posts cache is expired, don't use, wait for next community update\n if (communityPostsCacheExpired(communities[communityAddress])) {\n continue;\n }\n\n // community post count is low, fetch next community page\n if (communitiesPostCounts[communityAddress] <= communityPostsLeftBeforeNextPage) {\n addNextCommunityPageToStore(\n communities[communityAddress],\n sortType,\n account,\n modQueue,\n ).catch((error: unknown) =>\n log.error(\"feedsStore communitiesActions.addNextCommunityPageToStore error\", {\n communityAddress,\n community: communities[communityAddress],\n sortType,\n error,\n }),\n );\n }\n }\n }\n};\n\nlet previousFeedsCommunitiesFirstPageCids: string[] = [];\nlet previousFeedsCommunities: Map<string, Community> = new Map();\nlet previousFeedsCommunitiesLoadedCount = 0;\nlet previousFeedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\nconst updateFeedsOnFeedsCommunitiesChange = (communitiesStoreState: any) => {\n const { communities } = communitiesStoreState;\n const { feedsOptions, updateFeeds } = feedsStore.getState();\n\n // feeds communities haven't changed, do nothing\n const feedsCommunities = getFeedsCommunities(feedsOptions, communities);\n if (!feedsCommunitiesChanged(previousFeedsCommunities, feedsCommunities)) {\n return;\n }\n previousFeedsCommunities = feedsCommunities;\n\n // decide if feeds communities have changed by looking at all feeds communities page cids\n // (in case that a community changed, but its first page cid didn't)\n const feedsCommunitiesFirstPageCids = getFeedsCommunitiesFirstPageCids(feedsCommunities);\n\n // first page cids haven't changed, do nothing\n if (\n feedsCommunitiesFirstPageCids.toString() === previousFeedsCommunitiesFirstPageCids.toString()\n ) {\n // if no new feed communities have loaded, do nothing\n // in case a sub loads with no first page cid and first pages cids don't change, need to trigger hasMore update\n const feedsCommunitiesLoadedCount = getFeedsCommunitiesLoadedCount(feedsCommunities);\n if (feedsCommunitiesLoadedCount === previousFeedsCommunitiesLoadedCount) {\n // if community.posts.pages haven't changed, do nothing\n const feedsCommunitiesPostsPagesFirstUpdatedAts =\n getFeedsCommunitiesPostsPagesFirstUpdatedAts(feedsCommunities);\n if (\n feedsCommunitiesPostsPagesFirstUpdatedAts ===\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts\n ) {\n return;\n }\n\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts = feedsCommunitiesPostsPagesFirstUpdatedAts;\n }\n previousFeedsCommunitiesLoadedCount = feedsCommunitiesLoadedCount;\n }\n\n // feeds communities have changed, update feeds\n previousFeedsCommunitiesFirstPageCids = feedsCommunitiesFirstPageCids;\n updateFeeds();\n};\n\nlet previousAccountsCommentsCount = 0;\nlet previousAccountsCommentsCids = \"\";\nconst updateFeedsOnAccountsCommentsChange = (accountsStoreState: any) => {\n const { accountsComments } = accountsStoreState;\n const accountsCommentsCount = Object.values(accountsComments as Comment[][]).reduce(\n (count, accountComments) => count + accountComments.length,\n 0,\n );\n\n // no changes, do nothing\n if (accountsCommentsCount === previousAccountsCommentsCount) {\n // if cids haven't changed (account comments receive cids after pending), do nothing\n const accountsCommentsCids = Object.values(accountsComments as Comment[][]).reduce(\n (cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || \"\")),\n \"\",\n );\n if (accountsCommentsCids === previousAccountsCommentsCids) {\n return;\n }\n previousAccountsCommentsCids = accountsCommentsCids;\n }\n previousAccountsCommentsCount = accountsCommentsCount;\n\n // TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid\n feedsStore.getState().updateFeeds();\n};\n\nconst addCommunitiesToCommunitiesStore = (\n communityRefs: CommunityLookupRef[],\n account: Account,\n) => {\n const addCommunityToStore = communitiesStore.getState().addCommunityToStore;\n for (const communityRef of communityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"feedsStore communitiesActions.addCommunityToStore error\", {\n communityRef,\n error,\n }),\n );\n }\n};\n\n// reset store in between tests\nconst originalState = feedsStore.getState();\n// async function because some stores have async init\nexport const resetFeedsStore = async () => {\n previousBufferedFeedsCommunitiesPostCounts = {};\n previousBufferedFeedsCommunitiesPostCountsPageCids = [];\n previousBufferedFeedsCommunities = new Map();\n previousBlockedAddresses = [];\n previousAccountsBlockedAddresses = [];\n previousBlockedCids = [];\n previousAccountsBlockedCids = [];\n previousFeedsCommunitiesFirstPageCids = [];\n previousFeedsCommunities = new Map();\n previousFeedsCommunitiesLoadedCount = 0;\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\n previousCommunitiesPages = {};\n previousAccountsCommentsCount = 0;\n previousAccountsCommentsCids = \"\";\n updateFeedsPending = false;\n updateFeedsAgain = false;\n // destroy all component subscriptions to the store\n feedsStore.destroy();\n // restore original state\n feedsStore.setState(originalState);\n feedsStoreInitialized = false;\n};\n\n// reset database and store in between tests\nexport const resetFeedsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear();\n await resetFeedsStore();\n};\n\nexport default feedsStore;\n"]}
@@ -21,6 +21,15 @@ export declare const getFeedsCommunitiesPostCounts: (feedsOptions: FeedsOptions,
21
21
  export declare const getFeedsHaveMore: (feedsOptions: FeedsOptions, bufferedFeeds: Feeds, communities: Communities, communitiesPages: CommunitiesPages, accounts: Accounts) => {
22
22
  [feedName: string]: boolean;
23
23
  };
24
+ /**
25
+ * Get which communities of each feed still have more posts: buffered posts the feed has not loaded
26
+ * yet, or pages not fetched yet. Blocked communities are left out.
27
+ */
28
+ export declare const getFeedsCommunityKeysWithMore: (feedsOptions: FeedsOptions, bufferedFeedsCommunitiesPostCounts: FeedsCommunitiesPostCounts, communities: Communities, communitiesPages: CommunitiesPages, accounts: Accounts, previousFeedsCommunityKeysWithMore: {
29
+ [feedName: string]: string[];
30
+ }) => {
31
+ [feedName: string]: string[];
32
+ };
24
33
  export declare const getFeedsCommunities: (feedsOptions: FeedsOptions, communities: Communities) => Map<string, Community>;
25
34
  export declare const feedsCommunitiesChanged: (previousFeedsCommunities: Map<string, Community>, feedsCommunities: Map<string, Community>) => boolean;
26
35
  export declare const getFeedsCommunitiesFirstPageCids: (feedsCommunities: Map<string, Community>) => string[];
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EAEP,KAAK,EAEL,YAAY,EACZ,SAAS,EACT,WAAW,EAEX,QAAQ,EAER,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AA0HrB;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,cAAc,YAAY,EAC1B,aAAa,WAAW,EACxB,kBAAkB,gBAAgB,EAClC,UAAU,QAAQ,EAClB,mBAAmB;IAAE,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,UAgKrD,CAA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iesPag
103
103
  sortType = modQueue[0];
104
104
  pageType = "modQueue";
105
105
  }
106
- // find all fetched posts
107
- const bufferedFeedPosts = [];
106
+ // find all fetched posts, each community's in the order its pages list them
107
+ const communityFeedPosts = [];
108
108
  // add each comment from each page, do not filter at this stage, filter after sorting
109
109
  for (const [communityIndex, communityKey] of communityKeys.entries()) {
110
110
  const communityRef = communityRefs[communityIndex];
@@ -117,6 +117,7 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
117
117
  if (communityPostsCacheExpired(community) && window.navigator.onLine) {
118
118
  continue;
119
119
  }
120
+ const communityPosts = [];
120
121
  // use community preloaded posts if any
121
122
  const preloadedPosts = getPreloadedPosts(community, sortType);
122
123
  if (preloadedPosts) {
@@ -137,7 +138,7 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
137
138
  nextPost.timestamp <= clientTimeframeTimestamp) {
138
139
  continue;
139
140
  }
140
- bufferedFeedPosts.push(nextPost);
141
+ communityPosts.push(nextPost);
141
142
  }
142
143
  }
143
144
  // add all posts from community pages
@@ -151,29 +152,31 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
151
152
  }
152
153
  const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);
153
154
  if (nextPost) {
154
- bufferedFeedPosts.push(nextPost);
155
+ communityPosts.push(nextPost);
155
156
  }
156
157
  }
157
158
  }
158
159
  }
160
+ communityFeedPosts.push({ community, posts: communityPosts });
159
161
  }
160
162
  // sort the feed before filtering to get more accurate results
161
163
  const resolvedDefaultSortTypes = communityKeys.map((communityKey) => resolvePostSortType(communities[communityKey], feedsOptions[feedName].sortType));
162
164
  const uniqueResolvedDefaultSortTypes = new Set(resolvedDefaultSortTypes);
163
165
  const originalSortType = feedsOptions[feedName].sortType ||
164
166
  (uniqueResolvedDefaultSortTypes.size === 1 ? resolvedDefaultSortTypes[0] : undefined);
165
- // one community's pages of a sort already arrive in its order; re-sorting them with the built-in
166
- // sorter of the same name would undo a sort the client cannot reproduce. A sort served from
167
- // another sort's complete page still needs the client sort, and feeds merging several
168
- // communities need a common order, so both keep using the built-in sorter.
169
- const singleCommunity = communityKeys.length === 1 ? communities[communityKeys[0]] : undefined;
170
- const keepCommunityOrder = !!singleCommunity &&
171
- originalSortType !== undefined &&
172
- getPostPageSortType(singleCommunity, originalSortType) === originalSortType &&
173
- !isBuiltInPostSortType(singleCommunity, originalSortType);
174
- const sortedBufferedFeedPosts = keepCommunityOrder
175
- ? bufferedFeedPosts
176
- : feedSorter.sort(originalSortType, bufferedFeedPosts);
167
+ // a community's pages of a sort file already arrive in its order; re-sorting them with the
168
+ // built-in sorter of the same name would undo a sort the client cannot reproduce. A sort served
169
+ // from another sort's complete page still needs the client sort. Feeds over several communities
170
+ // interleave each community's order rather than re-sorting them together.
171
+ const communityFeeds = communityFeedPosts.map(({ community, posts }) => ({
172
+ posts,
173
+ keepOrder: originalSortType !== undefined &&
174
+ getPostPageSortType(community, originalSortType) === originalSortType &&
175
+ !isBuiltInPostSortType(community, originalSortType),
176
+ }));
177
+ const sortedBufferedFeedPosts = communityFeeds.some(({ keepOrder }) => keepOrder)
178
+ ? feedSorter.merge(originalSortType, communityFeeds)
179
+ : feedSorter.sort(originalSortType, communityFeeds.flatMap(({ posts }) => posts));
177
180
  // filter the feed
178
181
  const filteredSortedBufferedFeedPosts = [];
179
182
  for (const post of sortedBufferedFeedPosts) {
@@ -539,69 +542,81 @@ export const getFeedsCommunitiesPostCounts = (feedsOptions, feeds) => {
539
542
  }
540
543
  return feedsCommunitiesPostCounts;
541
544
  };
545
+ const getFeedPageOptions = (feedOptions) => {
546
+ let { sortType, modQueue } = feedOptions;
547
+ let pageType = "posts";
548
+ if (modQueue === null || modQueue === void 0 ? void 0 : modQueue[0]) {
549
+ // TODO: allow multiple modQueue at once, fow now only use first in array
550
+ sortType = modQueue[0];
551
+ pageType = "modQueue";
552
+ }
553
+ return { sortType, pageType };
554
+ };
555
+ const isFeedCommunityBlocked = (accounts, accountId, communityRef, community) => {
556
+ var _a;
557
+ return Object.keys(((_a = accounts[accountId]) === null || _a === void 0 ? void 0 : _a.blockedAddresses) || {}).some((blockedAddress) => communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community));
558
+ };
559
+ // a community has more pages until it has loaded, its posts cache is fresh and its last page has no next page
560
+ const communityHasMorePages = (community, sortType, pageType, communitiesPages, accountId) => {
561
+ if (!(community === null || community === void 0 ? void 0 : community.updatedAt) || communityPostsCacheExpired(community)) {
562
+ return true;
563
+ }
564
+ // TODO: if a loaded community doesn't have a first page, it's unclear what we should do
565
+ // should we try to use another sort type by default, like 'hot', or should we just ignore it?
566
+ // ignore it for now
567
+ const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);
568
+ if (!firstPageCid) {
569
+ return false;
570
+ }
571
+ const pages = getCommunityPages(community, sortType, communitiesPages, pageType, accountId);
572
+ return !pages.length || !!pages[pages.length - 1].nextCid;
573
+ };
542
574
  /**
543
575
  * Get which feeds have more posts, i.e. have not reached the final page of all subs
544
576
  */
545
577
  export const getFeedsHaveMore = (feedsOptions, bufferedFeeds, communities, communitiesPages, accounts) => {
546
- var _a, _b;
578
+ var _a;
547
579
  const feedsHaveMore = {};
548
- feedsLoop: for (const feedName in feedsOptions) {
580
+ for (const feedName in feedsOptions) {
549
581
  // if the feed still has buffered posts, then it still has more
550
582
  if ((_a = bufferedFeeds[feedName]) === null || _a === void 0 ? void 0 : _a.length) {
551
583
  feedsHaveMore[feedName] = true;
552
- continue feedsLoop;
584
+ continue;
553
585
  }
554
586
  const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);
555
- const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);
556
- let { sortType, accountId, modQueue } = feedsOptions[feedName];
557
- let pageType = "posts";
558
- if (modQueue === null || modQueue === void 0 ? void 0 : modQueue[0]) {
559
- // TODO: allow multiple modQueue at once, fow now only use first in array
560
- sortType = modQueue[0];
561
- pageType = "modQueue";
562
- }
563
- communityKeysLoop: for (const [communityIndex, communityKey] of communityKeys.entries()) {
564
- const community = communities[communityKey];
565
- const communityRef = communityRefs[communityIndex];
566
- const isBlockedCommunity = Object.keys(((_b = accounts[accountId]) === null || _b === void 0 ? void 0 : _b.blockedAddresses) || {}).some((blockedAddress) => communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community));
567
- // don't consider the sub if the address is blocked
568
- if (isBlockedCommunity) {
569
- continue communityKeysLoop;
570
- }
571
- // if at least 1 community hasn't loaded yet, then the feed still has more
572
- if (!(community === null || community === void 0 ? void 0 : community.updatedAt)) {
573
- feedsHaveMore[feedName] = true;
574
- continue feedsLoop;
575
- }
576
- // if at least 1 community has posts cache expired, then the feed still has more
577
- if (communityPostsCacheExpired(community)) {
578
- feedsHaveMore[feedName] = true;
579
- continue feedsLoop;
580
- }
581
- const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);
582
- // TODO: if a loaded community doesn't have a first page, it's unclear what we should do
583
- // should we try to use another sort type by default, like 'hot', or should we just ignore it?
584
- // 'continue' to ignore it for now
585
- if (!firstPageCid) {
586
- continue communityKeysLoop;
587
- }
588
- const pages = getCommunityPages(community, sortType, communitiesPages, pageType, accountId);
589
- // if first page isn't loaded yet, then the feed still has more
590
- if (!pages.length) {
591
- feedsHaveMore[feedName] = true;
592
- continue feedsLoop;
593
- }
594
- const lastPage = pages[pages.length - 1];
595
- if (lastPage.nextCid) {
596
- feedsHaveMore[feedName] = true;
597
- continue feedsLoop;
598
- }
599
- }
600
- // if buffered feeds are empty and no last page of any community has a next page, then has more is false
601
- feedsHaveMore[feedName] = false;
587
+ const { accountId } = feedsOptions[feedName];
588
+ const { sortType, pageType } = getFeedPageOptions(feedsOptions[feedName]);
589
+ // a blocked community is not considered
590
+ feedsHaveMore[feedName] = getFeedCommunityKeys(feedsOptions[feedName]).some((communityKey, communityIndex) => !isFeedCommunityBlocked(accounts, accountId, communityRefs[communityIndex], communities[communityKey]) &&
591
+ communityHasMorePages(communities[communityKey], sortType, pageType, communitiesPages, accountId));
602
592
  }
603
593
  return feedsHaveMore;
604
594
  };
595
+ /**
596
+ * Get which communities of each feed still have more posts: buffered posts the feed has not loaded
597
+ * yet, or pages not fetched yet. Blocked communities are left out.
598
+ */
599
+ export const getFeedsCommunityKeysWithMore = (feedsOptions, bufferedFeedsCommunitiesPostCounts, communities, communitiesPages, accounts, previousFeedsCommunityKeysWithMore) => {
600
+ const feedsCommunityKeysWithMore = {};
601
+ for (const feedName in feedsOptions) {
602
+ const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);
603
+ const { accountId } = feedsOptions[feedName];
604
+ const { sortType, pageType } = getFeedPageOptions(feedsOptions[feedName]);
605
+ const communityKeysWithMore = getFeedCommunityKeys(feedsOptions[feedName]).filter((communityKey, communityIndex) => {
606
+ var _a;
607
+ return !isFeedCommunityBlocked(accounts, accountId, communityRefs[communityIndex], communities[communityKey]) &&
608
+ (((_a = bufferedFeedsCommunitiesPostCounts[feedName]) === null || _a === void 0 ? void 0 : _a[communityKey]) > 0 ||
609
+ communityHasMorePages(communities[communityKey], sortType, pageType, communitiesPages, accountId));
610
+ });
611
+ // keep the previous array when the data is the same to avoid rerenders
612
+ const previousCommunityKeysWithMore = previousFeedsCommunityKeysWithMore[feedName];
613
+ feedsCommunityKeysWithMore[feedName] =
614
+ (previousCommunityKeysWithMore === null || previousCommunityKeysWithMore === void 0 ? void 0 : previousCommunityKeysWithMore.toString()) === communityKeysWithMore.toString()
615
+ ? previousCommunityKeysWithMore
616
+ : communityKeysWithMore;
617
+ }
618
+ return feedsCommunityKeysWithMore;
619
+ };
605
620
  // get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds
606
621
  export const getFeedsCommunities = (feedsOptions, communities) => {
607
622
  // find all feeds communities