@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":"feeds-store.js","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,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,EAAE,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAClF,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,EACnC,6BAA6B,GAC9B,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;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K,EAAE,CAAC;IAC9F,MAAM,eAAe,EAAE,CAAC;AAC1B,CAAC,CAAA,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import assert from \"../../lib/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, { COMMUNITY_UPDATE_STOP_GRACE_MS } 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 startFeedAutoUpdate: Function;\n stopFeedAutoUpdate: 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// hooks that show a feed. A feed keeps its communities updating while it has subscribers, and\n// fetches more community pages while it has subscribers or was used by a store-level caller\n// within the grace period. Its loaded posts stay in the store either way.\nconst feedSubscribers: { [feedName: string]: Set<string> } = {};\nconst feedsActiveUntil: { [feedName: string]: number } = {};\n// inactive feeds that skipped a page fetch, checked again when a subscriber returns\nconst feedsWithSkippedPageFetches = new Set<string>();\n// the communities each feed subscribed to, released with the same refs\nconst feedsCommunitySubscriptions: { [feedName: string]: CommunityLookupRef[] } = {};\n\nconst getFeedCommunitySubscriberId = (feedName: string) => `feed:${feedName}`;\n\nconst hasFeedSubscribers = (feedName: string) => (feedSubscribers[feedName]?.size || 0) > 0;\n\nconst isFeedActive = (feedName: string) =>\n hasFeedSubscribers(feedName) || Date.now() < (feedsActiveUntil[feedName] || 0);\n\n// a store-level caller using a feed without a subscriber keeps it active for the grace period\nconst touchFeed = (feedName: string) => {\n if (!hasFeedSubscribers(feedName)) {\n feedsActiveUntil[feedName] = Date.now() + COMMUNITY_UPDATE_STOP_GRACE_MS;\n }\n};\n\nconst subscribeFeedCommunities = (feedName: string, feedOptions: any) => {\n if (feedsCommunitySubscriptions[feedName] || !hasFeedSubscribers(feedName) || !feedOptions) {\n return;\n }\n const account = accountsStore.getState().accounts[feedOptions.accountId];\n if (!account) {\n return;\n }\n const { communities } = feedOptions;\n feedsCommunitySubscriptions[feedName] = communities;\n const { startCommunityAutoUpdate } = communitiesStore.getState();\n for (const communityRef of communities) {\n startCommunityAutoUpdate(communityRef, getFeedCommunitySubscriberId(feedName), account).catch(\n (error: unknown) =>\n log.error(\"feedsStore startCommunityAutoUpdate error\", {\n feedName,\n communityRef,\n error,\n }),\n );\n }\n};\n\nconst unsubscribeFeedCommunities = (feedName: string) => {\n const communities = feedsCommunitySubscriptions[feedName];\n if (!communities) {\n return;\n }\n delete feedsCommunitySubscriptions[feedName];\n const { stopCommunityAutoUpdate } = communitiesStore.getState();\n for (const communityRef of communities) {\n stopCommunityAutoUpdate(communityRef, getFeedCommunitySubscriberId(feedName)).catch(\n (error: unknown) =>\n log.error(\"feedsStore stopCommunityAutoUpdate error\", { feedName, communityRef, error }),\n );\n }\n};\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 touchFeed(feedName);\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 subscribeFeedCommunities(feedName, feedOptions);\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 // keep a feed's communities updating and its pages loading while a subscriber shows it\n startFeedAutoUpdate(feedName: string, subscriberId: string) {\n assert(\n feedName && typeof feedName === \"string\",\n `feedsStore.startFeedAutoUpdate feedName '${feedName}' invalid`,\n );\n assert(\n subscriberId && typeof subscriberId === \"string\",\n `feedsStore.startFeedAutoUpdate subscriberId '${subscriberId}' invalid`,\n );\n if (!feedSubscribers[feedName]) {\n feedSubscribers[feedName] = new Set();\n }\n feedSubscribers[feedName].add(subscriberId);\n delete feedsActiveUntil[feedName];\n subscribeFeedCommunities(feedName, getState().feedsOptions[feedName]);\n // pages skipped while the feed was inactive are fetched now\n if (feedsWithSkippedPageFetches.delete(feedName) && getState().feedsOptions[feedName]) {\n previousBufferedFeedsCommunitiesPostCounts = {};\n addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts();\n }\n },\n\n // a feed releases its communities when its last subscriber leaves, they stop updating a grace\n // period later, and it stops fetching pages after the same grace period\n stopFeedAutoUpdate(feedName: string, subscriberId: string) {\n const subscribers = feedSubscribers[feedName];\n if (!subscribers?.delete(subscriberId) || subscribers.size > 0) {\n return;\n }\n delete feedSubscribers[feedName];\n feedsActiveUntil[feedName] = Date.now() + COMMUNITY_UPDATE_STOP_GRACE_MS;\n unsubscribeFeedCommunities(feedName);\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 touchFeed(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 touchFeed(feedName);\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 touchFeed(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 = () => {\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 // a feed nothing shows doesn't need more pages, it fetches them again once shown\n if (!isFeedActive(feedName)) {\n feedsWithSkippedPageFetches.add(feedName);\n continue;\n }\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 for (const feedName in feedSubscribers) {\n delete feedSubscribers[feedName];\n }\n for (const feedName in feedsActiveUntil) {\n delete feedsActiveUntil[feedName];\n }\n for (const feedName in feedsCommunitySubscriptions) {\n delete feedsCommunitySubscriptions[feedName];\n }\n feedsWithSkippedPageFetches.clear();\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,kBAAkB,CAAC;AACtC,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,EAAE,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAClF,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,EACnC,6BAA6B,EAC7B,wCAAwC,GACzC,MAAM,SAAS,CAAC;AAEjB,+CAA+C;AAC/C,2BAA2B;AAC3B,MAAM,CAAC,M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A2B,GAAG,EAAE,CAAC;IACjC,qCAAqC,GAAG,EAAE,CAAC;IAC3C,wBAAwB,GAAG,IAAI,GAAG,EAAE,CAAC;IACrC,mCAAmC,GAAG,CAAC,CAAC;IACxC,iDAAiD,GAAG,EAAE,CAAC;IACvD,wBAAwB,GAAG,EAAE,CAAC;IAC9B,6BAA6B,GAAG,CAAC,CAAC;IAClC,4BAA4B,GAAG,EAAE,CAAC;IAClC,kBAAkB,GAAG,KAAK,CAAC;IAC3B,gBAAgB,GAAG,KAAK,CAAC;IACzB,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;QACvC,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IACD,KAAK,MAAM,QAAQ,IAAI,gBAAgB,EAAE,CAAC;QACxC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IACD,KAAK,MAAM,QAAQ,IAAI,2BAA2B,EAAE,CAAC;QACnD,OAAO,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IACD,2BAA2B,CAAC,KAAK,EAAE,CAAC;IACpC,mDAAmD;IACnD,UAAU,CAAC,OAAO,EAAE,CAAC;IACrB,yBAAyB;IACzB,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IACnC,qBAAqB,GAAG,KAAK,CAAC;AAChC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAS,EAAE;IACnD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC9F,MAAM,eAAe,EAAE,CAAC;AAC1B,CAAC,CAAA,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import assert from \"../../lib/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, { COMMUNITY_UPDATE_STOP_GRACE_MS } 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 getFeedsCommunityKeysWithUnavailableSort,\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 feedsCommunityKeysWithUnavailableSort: { [feedName: string]: string[] };\n addFeedToStore: Function;\n startFeedAutoUpdate: Function;\n stopFeedAutoUpdate: 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// hooks that show a feed. A feed keeps its communities updating while it has subscribers, and\n// fetches more community pages while it has subscribers or was used by a store-level caller\n// within the grace period. Its loaded posts stay in the store either way.\nconst feedSubscribers: { [feedName: string]: Set<string> } = {};\nconst feedsActiveUntil: { [feedName: string]: number } = {};\n// inactive feeds that skipped a page fetch, checked again when a subscriber returns\nconst feedsWithSkippedPageFetches = new Set<string>();\n// the communities each feed subscribed to, released with the same refs\nconst feedsCommunitySubscriptions: { [feedName: string]: CommunityLookupRef[] } = {};\n\nconst getFeedCommunitySubscriberId = (feedName: string) => `feed:${feedName}`;\n\nconst hasFeedSubscribers = (feedName: string) => (feedSubscribers[feedName]?.size || 0) > 0;\n\nconst isFeedActive = (feedName: string) =>\n hasFeedSubscribers(feedName) || Date.now() < (feedsActiveUntil[feedName] || 0);\n\n// a store-level caller using a feed without a subscriber keeps it active for the grace period\nconst touchFeed = (feedName: string) => {\n if (!hasFeedSubscribers(feedName)) {\n feedsActiveUntil[feedName] = Date.now() + COMMUNITY_UPDATE_STOP_GRACE_MS;\n }\n};\n\nconst subscribeFeedCommunities = (feedName: string, feedOptions: any) => {\n if (feedsCommunitySubscriptions[feedName] || !hasFeedSubscribers(feedName) || !feedOptions) {\n return;\n }\n const account = accountsStore.getState().accounts[feedOptions.accountId];\n if (!account) {\n return;\n }\n const { communities } = feedOptions;\n feedsCommunitySubscriptions[feedName] = communities;\n const { startCommunityAutoUpdate } = communitiesStore.getState();\n for (const communityRef of communities) {\n startCommunityAutoUpdate(communityRef, getFeedCommunitySubscriberId(feedName), account).catch(\n (error: unknown) =>\n log.error(\"feedsStore startCommunityAutoUpdate error\", {\n feedName,\n communityRef,\n error,\n }),\n );\n }\n};\n\nconst unsubscribeFeedCommunities = (feedName: string) => {\n const communities = feedsCommunitySubscriptions[feedName];\n if (!communities) {\n return;\n }\n delete feedsCommunitySubscriptions[feedName];\n const { stopCommunityAutoUpdate } = communitiesStore.getState();\n for (const communityRef of communities) {\n stopCommunityAutoUpdate(communityRef, getFeedCommunitySubscriberId(feedName)).catch(\n (error: unknown) =>\n log.error(\"feedsStore stopCommunityAutoUpdate error\", { feedName, communityRef, error }),\n );\n }\n};\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 feedsCommunityKeysWithUnavailableSort: {},\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 includeBlockedCids?: boolean,\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 accountComments?.limit === undefined ||\n accountComments?.limit === null ||\n (Number.isInteger(accountComments.limit) && accountComments.limit >= 0),\n `addFeedToStore.addFeedToStore accountComments.limit '${accountComments?.limit}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `addFeedToStore.addFeedToStore modQueue '${modQueue}' invalid`,\n );\n assert(\n includeBlockedCids === undefined ||\n includeBlockedCids === null ||\n typeof includeBlockedCids === \"boolean\",\n `addFeedToStore.addFeedToStore includeBlockedCids '${includeBlockedCids}' invalid`,\n );\n\n const { feedsOptions, updateFeeds } = getState();\n touchFeed(feedName);\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 // only set when enabled, feeds without the option keep the same options as before it existed\n ...(includeBlockedCids === true ? { includeBlockedCids } : undefined),\n };\n log(\"feedsActions.addFeedToStore\", feedOptions);\n setState(({ feedsOptions }: any) => ({\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n }));\n\n addCommunitiesToCommunitiesStore(communities, account);\n subscribeFeedCommunities(feedName, feedOptions);\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 // keep a feed's communities updating and its pages loading while a subscriber shows it\n startFeedAutoUpdate(feedName: string, subscriberId: string) {\n assert(\n feedName && typeof feedName === \"string\",\n `feedsStore.startFeedAutoUpdate feedName '${feedName}' invalid`,\n );\n assert(\n subscriberId && typeof subscriberId === \"string\",\n `feedsStore.startFeedAutoUpdate subscriberId '${subscriberId}' invalid`,\n );\n if (!feedSubscribers[feedName]) {\n feedSubscribers[feedName] = new Set();\n }\n feedSubscribers[feedName].add(subscriberId);\n delete feedsActiveUntil[feedName];\n subscribeFeedCommunities(feedName, getState().feedsOptions[feedName]);\n // pages skipped while the feed was inactive are fetched now\n if (feedsWithSkippedPageFetches.delete(feedName) && getState().feedsOptions[feedName]) {\n previousBufferedFeedsCommunitiesPostCounts = {};\n addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts();\n }\n },\n\n // a feed releases its communities when its last subscriber leaves, they stop updating a grace\n // period later, and it stops fetching pages after the same grace period\n stopFeedAutoUpdate(feedName: string, subscriberId: string) {\n const subscribers = feedSubscribers[feedName];\n if (!subscribers?.delete(subscriberId) || subscribers.size > 0) {\n return;\n }\n delete feedSubscribers[feedName];\n feedsActiveUntil[feedName] = Date.now() + COMMUNITY_UPDATE_STOP_GRACE_MS;\n unsubscribeFeedCommunities(feedName);\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 touchFeed(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 touchFeed(feedName);\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 touchFeed(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 feedsCommunityKeysWithUnavailableSort = getFeedsCommunityKeysWithUnavailableSort(\n feedsOptions,\n communities,\n previousState.feedsCommunityKeysWithUnavailableSort,\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 // a feed reset while this pass awaited comment validation would get its old posts back, and\n // loaded feeds never shrink, so drop this pass and calculate again from the reset feed\n if (getState().loadedFeeds !== previousState.loadedFeeds) {\n updateFeedsPending = false;\n updateFeedsAgain = false;\n updateFeeds();\n return;\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 feedsCommunityKeysWithUnavailableSort,\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 = () => {\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 // a feed nothing shows doesn't need more pages, it fetches them again once shown\n if (!isFeedActive(feedName)) {\n feedsWithSkippedPageFetches.add(feedName);\n continue;\n }\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 // 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 // in case community.posts.pages changed without new page cids\n const feedsCommunitiesPostsPagesFirstUpdatedAts =\n getFeedsCommunitiesPostsPagesFirstUpdatedAts(feedsCommunities);\n const feedsCommunitiesPostsChanged =\n feedsCommunitiesFirstPageCids.toString() !== previousFeedsCommunitiesFirstPageCids.toString() ||\n feedsCommunitiesLoadedCount !== previousFeedsCommunitiesLoadedCount ||\n feedsCommunitiesPostsPagesFirstUpdatedAts !== previousFeedsCommunitiesPostsPagesFirstUpdatedAts;\n // remember all of them on every pass, so the next change is compared with this one\n previousFeedsCommunitiesFirstPageCids = feedsCommunitiesFirstPageCids;\n previousFeedsCommunitiesLoadedCount = feedsCommunitiesLoadedCount;\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts = feedsCommunitiesPostsPagesFirstUpdatedAts;\n\n // feeds communities posts haven't changed, do nothing\n if (!feedsCommunitiesPostsChanged) {\n return;\n }\n\n // feeds communities have changed, update feeds\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 for (const feedName in feedSubscribers) {\n delete feedSubscribers[feedName];\n }\n for (const feedName in feedsActiveUntil) {\n delete feedsActiveUntil[feedName];\n }\n for (const feedName in feedsCommunitySubscriptions) {\n delete feedsCommunitySubscriptions[feedName];\n }\n feedsWithSkippedPageFetches.clear();\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"]}
|
|
@@ -6,6 +6,11 @@ export declare const getFilteredSortedFeeds: (feedsOptions: FeedsOptions, commun
|
|
|
6
6
|
[commentCid: string]: Comment;
|
|
7
7
|
}) => Feeds;
|
|
8
8
|
export declare const getLoadedFeeds: (feedsOptions: FeedsOptions, filteredSortedFeeds: Feeds, loadedFeeds: Feeds, bufferedFeeds: Feeds, accounts: Accounts) => Promise<Feeds>;
|
|
9
|
+
/**
|
|
10
|
+
* Keep the `limit` newest account comments (greatest timestamp, then greatest index), in their
|
|
11
|
+
* original order. No limit keeps them all.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getNewestAccountComments: (accountComments: Comment[], limit?: number | null) => Comment[];
|
|
9
14
|
export declare const addAccountsComments: (feedsOptions: FeedsOptions, loadedFeeds: Feeds) => boolean;
|
|
10
15
|
export declare const getBufferedFeedsWithoutLoadedFeeds: (bufferedFeeds: Feeds, loadedFeeds: Feeds) => Feeds;
|
|
11
16
|
export declare const getUpdatedFeeds: (feedsOptions: FeedsOptions, filteredSortedFeeds: Feeds, updatedFeeds: Feeds, loadedFeeds: Feeds, accounts: Accounts) => Promise<Feeds>;
|
|
@@ -30,6 +35,17 @@ export declare const getFeedsCommunityKeysWithMore: (feedsOptions: FeedsOptions,
|
|
|
30
35
|
}) => {
|
|
31
36
|
[feedName: string]: string[];
|
|
32
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Get which loaded communities of each feed do not serve the feed's requested sort: the community
|
|
40
|
+
* publishes sorts, but not this one, and it cannot be computed from a complete preloaded page. Such
|
|
41
|
+
* a community adds nothing to the feed, which is otherwise indistinguishable from one still loading
|
|
42
|
+
* or one without posts. A community that has not loaded yet or has no posts is not listed.
|
|
43
|
+
*/
|
|
44
|
+
export declare const getFeedsCommunityKeysWithUnavailableSort: (feedsOptions: FeedsOptions, communities: Communities, previousFeedsCommunityKeysWithUnavailableSort: {
|
|
45
|
+
[feedName: string]: string[];
|
|
46
|
+
}) => {
|
|
47
|
+
[feedName: string]: string[];
|
|
48
|
+
};
|
|
33
49
|
export declare const getFeedsCommunities: (feedsOptions: FeedsOptions, communities: Communities) => Map<string, Community>;
|
|
34
50
|
export declare const feedsCommunitiesChanged: (previousFeedsCommunities: Map<string, Community>, feedsCommunities: Map<string, Community>) => boolean;
|
|
35
51
|
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,a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AE,EAAE,EAClE,0BAA0B;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,YAY3D,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAC3C,cAAc,YAAY,EAC1B,eAAe,KAAK,EACpB,kBAAkB,MAAM,EAAE,EAC1B,0BAA0B,MAAM,EAAE,YAkCnC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,UAAU,QAAQ,aAUxD,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,6BAA6B;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,EAC7D,qBAAqB;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,YAYtD,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,cAAc,YAAY,EAC1B,eAAe,KAAK,EACpB,aAAa,MAAM,EAAE,EACrB,qBAAqB,MAAM,EAAE,YAoB9B,CAAC"}
|
|
@@ -14,7 +14,7 @@ import { communityPostsCacheExpired, commentIsValid, removeInvalidComments } fro
|
|
|
14
14
|
import { getCommentCommunityAddress, normalizeCommentCommunityAddress } from "../../lib/pkc-compat.js";
|
|
15
15
|
import { doesAddressMatchCommunityRef, getCommunityRefKeys, getMatchingCommunityRefKeys, } from "../../lib/community-ref.js";
|
|
16
16
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
17
|
-
import { getPostPageSortType, getSortTimeframeSeconds, isBuiltInPostSortType, resolvePostSortType, } from "../../lib/page-sorts.js";
|
|
17
|
+
import { getPostPageSortType, getSortTimeframeSeconds, isBuiltInPostSortType, isPinnedFirstPostSortType, isPostSortTypeUnavailable, resolvePostSortType, } from "../../lib/page-sorts.js";
|
|
18
18
|
const log = Logger("bitsocial-react-hooks:feeds:stores");
|
|
19
19
|
const getFeedCommunityRefs = (feedOptions) => feedOptions.communities || [];
|
|
20
20
|
const getFeedCommunityKeys = (feedOptions) => feedOptions.communityKeys || getCommunityRefKeys(getFeedCommunityRefs(feedOptions));
|
|
@@ -95,7 +95,7 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
|
|
|
95
95
|
for (const feedName in feedsOptions) {
|
|
96
96
|
const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);
|
|
97
97
|
const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);
|
|
98
|
-
let { sortType, accountId, filter, newerThan, modQueue } = feedsOptions[feedName];
|
|
98
|
+
let { sortType, accountId, filter, newerThan, modQueue, includeBlockedCids } = feedsOptions[feedName];
|
|
99
99
|
const newerThanTimestamp = newerThan ? Math.floor(Date.now() / 1000) - newerThan : undefined;
|
|
100
100
|
let pageType = "posts";
|
|
101
101
|
if (modQueue === null || modQueue === void 0 ? void 0 : modQueue[0]) {
|
|
@@ -132,9 +132,10 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
|
|
|
132
132
|
continue;
|
|
133
133
|
}
|
|
134
134
|
// window the reconciled post: pinned is mutable moderation state, and like the pages a
|
|
135
|
-
// community windows itself, pinned posts stay regardless of age
|
|
135
|
+
// community windows itself, pinned posts stay regardless of age unless the community
|
|
136
|
+
// ranks them like any other post
|
|
136
137
|
if (clientTimeframeTimestamp !== undefined &&
|
|
137
|
-
!nextPost.pinned &&
|
|
138
|
+
!(nextPost.pinned && isPinnedFirstPostSortType(community, sortType)) &&
|
|
138
139
|
nextPost.timestamp <= clientTimeframeTimestamp) {
|
|
139
140
|
continue;
|
|
140
141
|
}
|
|
@@ -168,15 +169,28 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
|
|
|
168
169
|
// built-in sorter of the same name would undo a sort the client cannot reproduce. A sort served
|
|
169
170
|
// from another sort's complete page still needs the client sort. Feeds over several communities
|
|
170
171
|
// interleave each community's order rather than re-sorting them together.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
172
|
+
//
|
|
173
|
+
// Pinned placement is the community's too (`pinnedFirst`, published per sort): where the client
|
|
174
|
+
// re-sorts a community's posts it puts the pinned ones first unless the community turned that
|
|
175
|
+
// off. A feed over several communities has no single top to pin to, so it leaves out the pinned
|
|
176
|
+
// posts a community puts first, and ranks the ones a community treats like any other post.
|
|
177
|
+
const isMultiCommunityFeed = communityKeys.length > 1;
|
|
178
|
+
const communityFeeds = communityFeedPosts.map(({ community, posts }) => {
|
|
179
|
+
const pinnedFirst = isPinnedFirstPostSortType(community, originalSortType);
|
|
180
|
+
return {
|
|
181
|
+
posts: isMultiCommunityFeed && pinnedFirst ? posts.filter((post) => !post.pinned) : posts,
|
|
182
|
+
pinnedFirst,
|
|
183
|
+
keepOrder: originalSortType !== undefined &&
|
|
184
|
+
getPostPageSortType(community, originalSortType) === originalSortType &&
|
|
185
|
+
!isBuiltInPostSortType(community, originalSortType),
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
const sortOptions = {
|
|
189
|
+
pinnedFirst: !isMultiCommunityFeed && communityFeeds.every(({ pinnedFirst }) => pinnedFirst),
|
|
190
|
+
};
|
|
177
191
|
const sortedBufferedFeedPosts = communityFeeds.some(({ keepOrder }) => keepOrder)
|
|
178
|
-
? feedSorter.merge(originalSortType, communityFeeds)
|
|
179
|
-
: feedSorter.sort(originalSortType, communityFeeds.flatMap(({ posts }) => posts));
|
|
192
|
+
? feedSorter.merge(originalSortType, communityFeeds, sortOptions)
|
|
193
|
+
: feedSorter.sort(originalSortType, communityFeeds.flatMap(({ posts }) => posts), sortOptions);
|
|
180
194
|
// filter the feed
|
|
181
195
|
const filteredSortedBufferedFeedPosts = [];
|
|
182
196
|
for (const post of sortedBufferedFeedPosts) {
|
|
@@ -185,13 +199,8 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
|
|
|
185
199
|
(((_b = post.author) === null || _b === void 0 ? void 0 : _b.address) && ((_c = accounts[accountId]) === null || _c === void 0 ? void 0 : _c.blockedAddresses[post.author.address]))) {
|
|
186
200
|
continue;
|
|
187
201
|
}
|
|
188
|
-
// comment cid is blocked
|
|
189
|
-
if ((_d = accounts[accountId]) === null || _d === void 0 ? void 0 : _d.blockedCids[post.cid]) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
// if a feed has more than 1 sub, don't include pinned posts
|
|
193
|
-
// TODO: add test to check if pinned are filtered
|
|
194
|
-
if (post.pinned && communityKeys.length > 1) {
|
|
202
|
+
// comment cid is blocked, unless the feed opted out of hiding blocked cids
|
|
203
|
+
if (!includeBlockedCids && ((_d = accounts[accountId]) === null || _d === void 0 ? void 0 : _d.blockedCids[post.cid])) {
|
|
195
204
|
continue;
|
|
196
205
|
}
|
|
197
206
|
// feedOptions filter function
|
|
@@ -241,6 +250,10 @@ export const getLoadedFeeds = (feedsOptions, filteredSortedFeeds, loadedFeeds, b
|
|
|
241
250
|
for (const feedName in feedsOptions) {
|
|
242
251
|
const { pageNumber, postsPerPage, accountId } = feedsOptions[feedName];
|
|
243
252
|
const pkc = (_a = accounts[accountId]) === null || _a === void 0 ? void 0 : _a.pkc;
|
|
253
|
+
// the feed's account was deleted, it can't validate posts, so leave the feed as it was
|
|
254
|
+
if (!pkc) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
244
257
|
const loadedFeedPostCount = pageNumber * postsPerPage;
|
|
245
258
|
const currentLoadedFeed = reconcileLoadedModQueueFeed(feedsOptions[feedName], loadedFeeds[feedName] || [], filteredSortedFeeds[feedName] || []);
|
|
246
259
|
if (currentLoadedFeed !== loadedFeeds[feedName]) {
|
|
@@ -293,20 +306,33 @@ const getApprovalPublicationKey = (comment) => {
|
|
|
293
306
|
(_j = comment.link) !== null && _j !== void 0 ? _j : "",
|
|
294
307
|
].join("\0");
|
|
295
308
|
};
|
|
309
|
+
/**
|
|
310
|
+
* Keep the `limit` newest account comments (greatest timestamp, then greatest index), in their
|
|
311
|
+
* original order. No limit keeps them all.
|
|
312
|
+
*/
|
|
313
|
+
export const getNewestAccountComments = (accountComments, limit) => {
|
|
314
|
+
if (limit === undefined || limit === null || accountComments.length <= limit) {
|
|
315
|
+
return accountComments;
|
|
316
|
+
}
|
|
317
|
+
const newest = new Set([...accountComments]
|
|
318
|
+
.sort((a, b) => { var _a, _b; return b.timestamp - a.timestamp || ((_a = b.index) !== null && _a !== void 0 ? _a : 0) - ((_b = a.index) !== null && _b !== void 0 ? _b : 0); })
|
|
319
|
+
.slice(0, Math.max(limit, 0)));
|
|
320
|
+
return accountComments.filter((accountComment) => newest.has(accountComment));
|
|
321
|
+
};
|
|
296
322
|
export const addAccountsComments = (feedsOptions, loadedFeeds) => {
|
|
297
323
|
let loadedFeedsChanged = false;
|
|
298
324
|
const accountsComments = accountsStore.getState().accountsComments || {};
|
|
299
325
|
for (const feedName in feedsOptions) {
|
|
300
326
|
const { accountId, accountComments: accountCommentsOptions } = feedsOptions[feedName];
|
|
301
327
|
const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);
|
|
302
|
-
const { newerThan, append } = accountCommentsOptions || {};
|
|
328
|
+
const { newerThan, append, limit } = accountCommentsOptions || {};
|
|
303
329
|
if (!newerThan) {
|
|
304
330
|
continue;
|
|
305
331
|
}
|
|
306
332
|
const newerThanTimestamp = newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;
|
|
307
333
|
const isNewerThan = (post) => post.timestamp > newerThanTimestamp;
|
|
308
334
|
const accountComments = accountsComments[accountId] || [];
|
|
309
|
-
const
|
|
335
|
+
const matchingAccountPosts = accountComments.filter((comment) => {
|
|
310
336
|
// is a reply, not a post
|
|
311
337
|
if (comment.parentCid || comment.depth > 0) {
|
|
312
338
|
return false;
|
|
@@ -316,6 +342,9 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
|
|
|
316
342
|
}
|
|
317
343
|
return (getMatchingCommunityRefKeys(communityRefs, getCommentCommunityAddress(comment)).length > 0);
|
|
318
344
|
});
|
|
345
|
+
// older account posts over the limit are treated like posts that no longer match: they are
|
|
346
|
+
// not added, and removed if a newer account post took their place
|
|
347
|
+
const accountPosts = getNewestAccountComments(matchingAccountPosts, limit);
|
|
319
348
|
const validAccountIndices = new Set(accountPosts.map((p) => p.index));
|
|
320
349
|
const accountCidToPost = new Map();
|
|
321
350
|
for (const p of accountPosts) {
|
|
@@ -451,6 +480,10 @@ export const getUpdatedFeeds = (feedsOptions, filteredSortedFeeds, updatedFeeds,
|
|
|
451
480
|
const newUpdatedFeeds = Object.assign({}, updatedFeeds);
|
|
452
481
|
for (const feedName in filteredSortedFeeds) {
|
|
453
482
|
const pkc = (_b = accounts[(_a = feedsOptions[feedName]) === null || _a === void 0 ? void 0 : _a.accountId]) === null || _b === void 0 ? void 0 : _b.pkc;
|
|
483
|
+
// the feed's account was deleted, it can't validate posts, so leave the feed as it was
|
|
484
|
+
if (!pkc) {
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
454
487
|
const updatedFeed = [...(updatedFeeds[feedName] || [])];
|
|
455
488
|
const onlyHasNewPosts = updatedFeed.length === 0;
|
|
456
489
|
let updatedFeedChanged = false;
|
|
@@ -617,6 +650,29 @@ export const getFeedsCommunityKeysWithMore = (feedsOptions, bufferedFeedsCommuni
|
|
|
617
650
|
}
|
|
618
651
|
return feedsCommunityKeysWithMore;
|
|
619
652
|
};
|
|
653
|
+
/**
|
|
654
|
+
* Get which loaded communities of each feed do not serve the feed's requested sort: the community
|
|
655
|
+
* publishes sorts, but not this one, and it cannot be computed from a complete preloaded page. Such
|
|
656
|
+
* a community adds nothing to the feed, which is otherwise indistinguishable from one still loading
|
|
657
|
+
* or one without posts. A community that has not loaded yet or has no posts is not listed.
|
|
658
|
+
*/
|
|
659
|
+
export const getFeedsCommunityKeysWithUnavailableSort = (feedsOptions, communities, previousFeedsCommunityKeysWithUnavailableSort) => {
|
|
660
|
+
const feedsCommunityKeysWithUnavailableSort = {};
|
|
661
|
+
for (const feedName in feedsOptions) {
|
|
662
|
+
const { sortType, pageType } = getFeedPageOptions(feedsOptions[feedName]);
|
|
663
|
+
const communityKeysWithUnavailableSort = pageType === "posts"
|
|
664
|
+
? getFeedCommunityKeys(feedsOptions[feedName]).filter((communityKey) => isPostSortTypeUnavailable(communities[communityKey], sortType))
|
|
665
|
+
: [];
|
|
666
|
+
// keep the previous array when the data is the same to avoid rerenders
|
|
667
|
+
const previousCommunityKeysWithUnavailableSort = previousFeedsCommunityKeysWithUnavailableSort[feedName];
|
|
668
|
+
feedsCommunityKeysWithUnavailableSort[feedName] =
|
|
669
|
+
(previousCommunityKeysWithUnavailableSort === null || previousCommunityKeysWithUnavailableSort === void 0 ? void 0 : previousCommunityKeysWithUnavailableSort.toString()) ===
|
|
670
|
+
communityKeysWithUnavailableSort.toString()
|
|
671
|
+
? previousCommunityKeysWithUnavailableSort
|
|
672
|
+
: communityKeysWithUnavailableSort;
|
|
673
|
+
}
|
|
674
|
+
return feedsCommunityKeysWithUnavailableSort;
|
|
675
|
+
};
|
|
620
676
|
// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds
|
|
621
677
|
export const getFeedsCommunities = (feedsOptions, communities) => {
|
|
622
678
|
// find all feeds communities
|
|
@@ -677,15 +733,15 @@ export const getFeedsCommunitiesFirstPageCids = (feedsCommunities) => {
|
|
|
677
733
|
}
|
|
678
734
|
return [...feedsCommunitiesFirstPageCids].sort();
|
|
679
735
|
};
|
|
680
|
-
// get all communities posts pages
|
|
736
|
+
// get all communities posts pages post cids and updatedAts, use to check if a communitiesStore change should trigger updateFeeds
|
|
737
|
+
// (a post added, removed or updated anywhere in a preloaded page changes it without new page cids)
|
|
681
738
|
export const getFeedsCommunitiesPostsPagesFirstUpdatedAts = (feedsCommunities) => {
|
|
682
|
-
var _a, _b
|
|
739
|
+
var _a, _b;
|
|
683
740
|
let feedsCommunitiesPostsPagesFirstUpdatedAts = "";
|
|
684
741
|
for (const community of feedsCommunities.values()) {
|
|
685
742
|
for (const page of Object.values(((_a = community === null || community === void 0 ? void 0 : community.posts) === null || _a === void 0 ? void 0 : _a.pages) || {})) {
|
|
686
|
-
|
|
687
|
-
feedsCommunitiesPostsPagesFirstUpdatedAts +=
|
|
688
|
-
page.comments[0].cid + page.comments[0].updatedAt;
|
|
743
|
+
for (const post of (page === null || page === void 0 ? void 0 : page.comments) || []) {
|
|
744
|
+
feedsCommunitiesPostsPagesFirstUpdatedAts += `${post === null || post === void 0 ? void 0 : post.cid}${(_b = post === null || post === void 0 ? void 0 : post.updatedAt) !== null && _b !== void 0 ? _b : ""};`;
|
|
689
745
|
}
|
|
690
746
|
}
|
|
691
747
|
}
|