@bitsocial/bitsocial-react-hooks 0.1.23 → 0.1.25

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 CHANGED
@@ -1,3 +1,16 @@
1
+ ## [0.1.25](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.24...v0.1.25) (2026-06-28)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **feeds:** replay queued feed recalculations ([0350baa](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/0350baaff9ce739ae80bbda4a8e64439ec75e014))
7
+
8
+
9
+
10
+ ## [0.1.24](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.23...v0.1.24) (2026-06-28)
11
+
12
+
13
+
1
14
  ## [0.1.23](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.22...v0.1.23) (2026-06-27)
2
15
 
3
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"feeds-store.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,EAIL,YAAY,EAEZ,0BAA0B,EAI3B,MAAM,aAAa,CAAC;AAiCrB,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAKtC,KAAK,UAAU,GAAG;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,KAAK,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;IACnB,YAAY,EAAE,KAAK,CAAC;IACpB,kCAAkC,EAAE,0BAA0B,CAAC;IAC/D,aAAa,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,gCAAgC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IACnE,cAAc,EAAE,QAAQ,CAAC;IACzB,uBAAuB,EAAE,QAAQ,CAAC;IAClC,oBAAoB,EAAE,QAAQ,CAAC;IAC/B,SAAS,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC;AAMF,QAAA,MAAM,UAAU,yEAgWb,CAAC;AAuSJ,eAAO,MAAM,eAAe,qBAqB3B,CAAC;AAGF,eAAO,MAAM,0BAA0B,qBAGtC,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"feeds-store.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,EAIL,YAAY,EAEZ,0BAA0B,EAI3B,MAAM,aAAa,CAAC;AAiCrB,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAKtC,KAAK,UAAU,GAAG;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,KAAK,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;IACnB,YAAY,EAAE,KAAK,CAAC;IACpB,kCAAkC,EAAE,0BAA0B,CAAC;IAC/D,aAAa,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,gCAAgC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IACnE,cAAc,EAAE,QAAQ,CAAC;IACzB,uBAAuB,EAAE,QAAQ,CAAC;IAClC,oBAAoB,EAAE,QAAQ,CAAC;IAC/B,SAAS,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC;AAOF,QAAA,MAAM,UAAU,yEAuWb,CAAC;AAuSJ,eAAO,MAAM,eAAe,qBAsB3B,CAAC;AAGF,eAAO,MAAM,0BAA0B,qBAGtC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -27,6 +27,7 @@ export const defaultPostsPerPage = 25;
27
27
  const communityPostsLeftBeforeNextPage = 50;
28
28
  // don't updateFeeds more than once per updateFeedsMinIntervalTime
29
29
  let updateFeedsPending = false;
30
+ let updateFeedsAgain = false;
30
31
  const updateFeedsMinIntervalTime = 100;
31
32
  const feedsStore = createStore((setState, getState) => ({
32
33
  feedsOptions: {},
@@ -168,6 +169,7 @@ const feedsStore = createStore((setState, getState) => ({
168
169
  // recalculate all feeds using new communities.post.pages, communitiesPagesStore and page numbers
169
170
  updateFeeds() {
170
171
  if (updateFeedsPending) {
172
+ updateFeedsAgain = true;
171
173
  return;
172
174
  }
173
175
  updateFeedsPending = true;
@@ -176,7 +178,7 @@ const feedsStore = createStore((setState, getState) => ({
176
178
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
177
179
  // get state from all stores
178
180
  const previousState = getState();
179
- const { feedsOptions } = previousState;
181
+ const { feedsOptions, updateFeeds } = previousState;
180
182
  const { communities } = communitiesStore.getState();
181
183
  const { communitiesPages } = communitiesPagesStore.getState();
182
184
  const { accounts } = accountsStore.getState();
@@ -210,8 +212,13 @@ const feedsStore = createStore((setState, getState) => ({
210
212
  communitiesPages,
211
213
  feedsCommunityKeysWithNewerPosts,
212
214
  });
213
- // TODO: if updateFeeds was called while updateFeedsPending = true, maybe we should recall updateFeeds here
214
215
  updateFeedsPending = false;
216
+ // If a community/page update arrived during this calculation, run one
217
+ // more pass so feedsHaveMore and loadedFeeds cannot stay on stale input.
218
+ if (updateFeedsAgain) {
219
+ updateFeedsAgain = false;
220
+ updateFeeds();
221
+ }
215
222
  }), timeUntilNextUpdate);
216
223
  },
217
224
  }));
@@ -444,6 +451,7 @@ export const resetFeedsStore = () => __awaiter(void 0, void 0, void 0, function*
444
451
  previousAccountsCommentsCount = 0;
445
452
  previousAccountsCommentsCids = "";
446
453
  updateFeedsPending = false;
454
+ updateFeedsAgain = false;
447
455
  // destroy all component subscriptions to the store
448
456
  feedsStore.destroy();
449
457
  // restore original state
@@ -1 +1 @@
1
- {"version":3,"file":"feeds-store.js","sourceRoot":"","sources":["../../../src/stores/feeds/feeds-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OA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C;AACH,CAAC,CAAC;AAEF,+BAA+B;AAC/B,MAAM,aAAa,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;AAC5C,qDAAqD;AACrD,MAAM,CAAC,MAAM,eAAe,GAAG,GAAS,EAAE;IACxC,0CAA0C,GAAG,EAAE,CAAC;IAChD,kDAAkD,GAAG,EAAE,CAAC;IACxD,gCAAgC,GAAG,IAAI,GAAG,EAAE,CAAC;IAC7C,wBAAwB,GAAG,EAAE,CAAC;IAC9B,gCAAgC,GAAG,EAAE,CAAC;IACtC,mBAAmB,GAAG,EAAE,CAAC;IACzB,2BAA2B,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,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 \"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 { deriveFeedSortType } from \"../../lib/feed-sort-type\";\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;\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,\n account: Account,\n isBufferedFeed?: boolean,\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: FeedOptionsAccountComments,\n modQueue?: string[],\n requestedSortType?: 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 && typeof sortType === \"string\",\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 requestedSortType: requestedSortType || 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 nextSortType = deriveFeedSortType(currentFeedOptions.requestedSortType, newerThan);\n assert(\n nextSortType === currentFeedOptions.sortType,\n `feedsActions.expandFeedTimeWindow cannot change sort type from '${currentFeedOptions.sortType}' to '${nextSortType}'`,\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 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 } = 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 // TODO: if updateFeeds was called while updateFeedsPending = true, maybe we should recall updateFeeds here\n updateFeedsPending = false;\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 // 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,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAsB,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,gBAAgB,MAAM,gBAAgB,CAAC;AAC9C,OAAO,qBAAqB,MAAM,sBAAsB,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IACtC,mBAAmB,GAAG,EAAE,CAAC;IACzB,2BAA2B,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,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 \"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 { deriveFeedSortType } from \"../../lib/feed-sort-type\";\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,\n account: Account,\n isBufferedFeed?: boolean,\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: FeedOptionsAccountComments,\n modQueue?: string[],\n requestedSortType?: 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 && typeof sortType === \"string\",\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 requestedSortType: requestedSortType || 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 nextSortType = deriveFeedSortType(currentFeedOptions.requestedSortType, newerThan);\n assert(\n nextSortType === currentFeedOptions.sortType,\n `feedsActions.expandFeedTimeWindow cannot change sort type from '${currentFeedOptions.sortType}' to '${nextSortType}'`,\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"]}
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
- "version": "0.1.23",
16
+ "version": "0.1.25",
17
17
  "packageManager": "yarn@4.13.0",
18
18
  "files": [
19
19
  "CHANGELOG.md",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@bitsocial/bso-resolver": "0.0.8",
51
- "@pkcprotocol/pkc-js": "0.0.57",
51
+ "@pkcprotocol/pkc-js": "0.0.59",
52
52
  "@pkcprotocol/pkc-logger": "0.1.0",
53
53
  "assert": "2.0.0",
54
54
  "ethers": "5.8.0",