@bitsocial/bitsocial-react-hooks 0.1.64 → 0.2.0
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 +23 -0
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +49 -11
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +34 -1
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +2 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.js +17 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts +5 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +272 -36
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/feeds/feeds-store.d.ts +2 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
- package/dist/stores/feeds/feeds-store.js +97 -2
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities-store.js","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,MAAM,mBAAmB,GAAG,cAAc,CAAC,cAAc,CAAC;IACxD,IAAI,EAAE,iCAAiC;IACvC,IAAI,EAAE,GAAG;CACV,CAAC,CAAC;AACH,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,0CAA0C,CAAC,CAA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ClD,qDAAqD;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAS,EAAE;IAC9C,sBAAsB,GAAG,EAAE,CAAC;IAC5B,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAC9E,6BAA6B;IAC7B,SAAS,CAAC,OAAO,CAAC,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACxE,mDAAmD;IACnD,gBAAgB,CAAC,OAAO,EAAE,CAAC;IAC3B,yBAAyB;IACzB,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC3C,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAS,EAAE;IACzD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACzF,MAAM,qBAAqB,EAAE,CAAC;AAChC,CAAC,CAAA,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import assert from \"../../lib/assert\";\nimport localForageLru from \"../../lib/localforage-lru\";\nconst communitiesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communities\",\n size: 500,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:stores\");\nimport {\n Community,\n Communities,\n Account,\n CommunityIdentifier,\n CommunitySyncState,\n CreateCommunityOptions,\n} from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport { getCommunityLookupOptions, getCommunityRefKey } from \"../../lib/community-ref\";\nimport {\n createPkcCommunity,\n getPkcCommunity,\n getPkcCommunityAddresses,\n getPkcCreateCommunity,\n getPkcGetCommunity,\n} from \"../../lib/pkc-compat\";\n\nexport const COMMUNITY_UPDATE_INTERVAL_MS = 15 * 60 * 1000;\n\nlet pkcGetCommunityPending: { [key: string]: boolean } = {};\n// Key pollers by community so delete/reset can stop the matching live instance.\nconst communityUpdatePollers: {\n [communityKey: string]: {\n community: any;\n updateInterval: ReturnType<typeof setInterval>;\n };\n} = {};\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\nconst COMMUNITY_ERROR_UPDATE_GRACE_MS = 1000;\nconst pendingCommunityErrorTimers: {\n [communityKey: string]: ReturnType<typeof setTimeout>[];\n} = {};\n\ninterface CommunitySyncStatus {\n syncState: CommunitySyncState;\n lastFetchAttemptAt?: number;\n lastSuccessfulFetchAt?: number;\n}\n\nconst getNowSeconds = () => Math.floor(Date.now() / 1000);\n\nconst normalizeCommunitySyncState = (updatingState: string): CommunitySyncState => {\n if (updatingState === \"waiting-retry\") {\n return \"retrying\";\n }\n if (updatingState === \"succeeded\" || updatingState === \"failed\" || updatingState === \"stopped\") {\n return updatingState;\n }\n return \"loading\";\n};\n\nconst getNextSyncStatuses = (\n state: CommunitiesState,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n const previousStatus = state.syncStatuses[communityKey];\n const timestamp = getNowSeconds();\n const shouldRecordAttempt = syncState === \"loading\" && previousStatus?.syncState !== \"loading\";\n return {\n ...state.syncStatuses,\n [communityKey]: {\n ...previousStatus,\n syncState,\n ...(shouldRecordAttempt ? { lastFetchAttemptAt: timestamp } : undefined),\n ...(syncState === \"succeeded\" ? { lastSuccessfulFetchAt: timestamp } : undefined),\n },\n };\n};\n\nconst updateCommunitySyncStatus = (\n setState: Function,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n setState((state: CommunitiesState) => ({\n ...state,\n syncStatuses: getNextSyncStatuses(state, communityKey, syncState),\n }));\n};\n\n// identifies a signed community record, to recognize pkc-js re-emitting a record already in the store\nconst getCommunityRecordId = (community: any): string | undefined => {\n const signature = community?.signature?.signature;\n if (typeof signature !== \"string\" || typeof community?.updatedAt !== \"number\") {\n return;\n }\n return `${community.updatedAt}:${signature}`;\n};\n\nconst createCommunityWithLookupFallback = async (\n pkc: any,\n communityLookupOptions: { address?: string; name?: string; publicKey?: string },\n communityKey: string,\n) => {\n const supportsAddressLookup = \"address\" in communityLookupOptions;\n const community = await createPkcCommunity(pkc, communityLookupOptions);\n if (community?.address || supportsAddressLookup) {\n return community;\n }\n throw Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`);\n};\n\nconst updateCommunity = (\n community: Community,\n {\n communityAddressOrRef,\n communityKey,\n }: { communityAddressOrRef: string | CommunityIdentifier; communityKey: string },\n) => {\n community.update().catch((error: unknown) =>\n log.trace(\"community.update error\", {\n communityAddressOrRef,\n communityKey,\n community,\n error,\n }),\n );\n};\n\nconst startCommunityUpdatePolling = (\n community: Community,\n {\n communityAddressOrRef,\n communityKey,\n }: { communityAddressOrRef: string | CommunityIdentifier; communityKey: string },\n) => {\n stopCommunityUpdatePolling(communityKey);\n updateCommunity(community, { communityAddressOrRef, communityKey });\n communityUpdatePollers[communityKey] = {\n community,\n updateInterval: setInterval(\n () => updateCommunity(community, { communityAddressOrRef, communityKey }),\n COMMUNITY_UPDATE_INTERVAL_MS,\n ),\n };\n};\n\nconst stopCommunityUpdatePolling = (communityKey: string) => {\n const polling = communityUpdatePollers[communityKey];\n if (!polling) {\n return;\n }\n\n clearPendingCommunityErrors(communityKey);\n clearInterval(polling.updateInterval);\n polling.community.removeAllListeners();\n const listenerIndex = listeners.indexOf(polling.community);\n if (listenerIndex >= 0) {\n listeners.splice(listenerIndex, 1);\n }\n delete communityUpdatePollers[communityKey];\n};\n\nconst clearPendingCommunityErrors = (communityKey: string) => {\n pendingCommunityErrorTimers[communityKey]?.forEach((timeout) => clearTimeout(timeout));\n delete pendingCommunityErrorTimers[communityKey];\n};\n\nconst clearStoredCommunityErrors = (state: CommunitiesState, communityKey: string) => {\n if (!state.errors[communityKey]) {\n return state.errors;\n }\n const nextErrors = { ...state.errors };\n delete nextErrors[communityKey];\n return nextErrors;\n};\n\n// returning the same state skips notifying subscribers when there is nothing to clear\nconst clearStoredCommunityErrorsState = (state: CommunitiesState, communityKey: string) =>\n state.errors[communityKey]\n ? { ...state, errors: clearStoredCommunityErrors(state, communityKey) }\n : state;\n\nexport const isRetriableCommunityLoadError = (error: Error) => {\n const details = (error as Error & { details?: unknown }).details;\n return Boolean(\n details &&\n typeof details === \"object\" &&\n \"retriableError\" in details &&\n (details as { retriableError?: unknown }).retriableError === true,\n );\n};\n\nconst scheduleCommunityError = (setState: Function, communityKey: string, error: Error) => {\n if (isRetriableCommunityLoadError(error)) {\n return;\n }\n\n const timeout = setTimeout(() => {\n const pendingTimeouts = pendingCommunityErrorTimers[communityKey];\n if (!pendingTimeouts?.includes(timeout)) {\n return;\n }\n\n const remainingTimeouts = pendingTimeouts.filter(\n (pendingTimeout) => pendingTimeout !== timeout,\n );\n if (remainingTimeouts.length === 0) {\n delete pendingCommunityErrorTimers[communityKey];\n } else {\n pendingCommunityErrorTimers[communityKey] = remainingTimeouts;\n }\n setState((state: CommunitiesState) => {\n const communityErrors = state.errors[communityKey] || [];\n return {\n ...state,\n errors: { ...state.errors, [communityKey]: [...communityErrors, error] },\n };\n });\n }, COMMUNITY_ERROR_UPDATE_GRACE_MS);\n\n pendingCommunityErrorTimers[communityKey] = [\n ...(pendingCommunityErrorTimers[communityKey] || []),\n timeout,\n ];\n};\n\nexport type CommunitiesState = {\n communities: Communities;\n errors: { [communityAddress: string]: Error[] };\n syncStatuses: { [communityAddress: string]: CommunitySyncStatus };\n addCommunityToStore: Function;\n refreshCommunity: Function;\n editCommunity: Function;\n createCommunity: Function;\n deleteCommunity: Function;\n};\n\nconst communitiesStore = createStore<CommunitiesState>(\n (setState: Function, getState: Function) => ({\n communities: {},\n errors: {},\n syncStatuses: {},\n\n async addCommunityToStore(\n communityAddressOrRef: string | CommunityIdentifier,\n account: Account,\n ) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.addCommunityToStore invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.addCommunityToStore invalid account argument '${account}'`,\n );\n\n // community is in store already, do nothing\n const { communities } = getState();\n let community: Community | undefined = communities[communityKey];\n const pendingKey = communityKey + account.id;\n if (community || pkcGetCommunityPending[pendingKey]) {\n return;\n }\n\n // start trying to get community\n pkcGetCommunityPending[pendingKey] = true;\n updateCommunitySyncStatus(setState, communityKey, \"initializing\");\n let errorGettingCommunity: any;\n try {\n // try to find community in owner communities\n if (getPkcCommunityAddresses(account.pkc).includes(communityKey)) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // try to find community in database\n let fetchedAt: number | undefined;\n let isFromCache = false;\n if (!community) {\n const communityData: any = await communitiesDatabase.getItem(communityKey);\n const lookupName =\n \"name\" in communityLookupOptions ? communityLookupOptions.name : undefined;\n const lookupPublicKey =\n \"publicKey\" in communityLookupOptions ? communityLookupOptions.publicKey : undefined;\n const lookupAddress =\n \"address\" in communityLookupOptions ? communityLookupOptions.address : undefined;\n const hasCachedPosts =\n Object.keys(communityData?.posts?.pageCids || {}).length > 0 ||\n Object.keys(communityData?.posts?.pages || {}).length > 0;\n const isUnresolvedNameCache =\n communityData &&\n lookupName &&\n !lookupPublicKey &&\n !lookupAddress &&\n !communityData.publicKey &&\n !communityData.updatedAt &&\n !communityData.updateCid &&\n !communityData.title &&\n !communityData.description &&\n !hasCachedPosts;\n if (communityData && !isUnresolvedNameCache) {\n fetchedAt = communityData.fetchedAt;\n delete communityData.fetchedAt; // not part of pkc-js schema\n try {\n community = await createPkcCommunity(account.pkc, communityData);\n isFromCache = Boolean(community);\n } catch (e) {\n fetchedAt = undefined;\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createCommunity(cachedCommunity)\", {\n cachedCommunity: communityData,\n error: e,\n });\n }\n }\n if (community) {\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(community);\n }\n }\n\n // community not in database, try to fetch from pkc-js\n if (!community) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // failure getting community\n if (!community) {\n if (errorGettingCommunity) {\n setState((state: CommunitiesState) => {\n let communityErrors = state.errors[communityKey] || [];\n communityErrors = [...communityErrors, errorGettingCommunity];\n return { ...state, errors: { ...state.errors, [communityKey]: communityErrors } };\n });\n }\n\n throw (\n errorGettingCommunity ||\n Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`)\n );\n }\n\n // success getting community\n const firstCommunityState = utils.clone({\n ...community,\n ...(fetchedAt !== undefined ? { fetchedAt } : undefined),\n });\n // a cache hit already is the database entry, rewriting it would only delay the store\n // update behind an IndexedDB write of the whole record\n if (!isFromCache) {\n await communitiesDatabase.setItem(communityKey, firstCommunityState);\n }\n log(\"communitiesStore.addCommunityToStore\", {\n communityAddressOrRef,\n communityKey,\n community,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: firstCommunityState },\n }));\n\n // pkc-js re-emits the record a community was created with when update() starts\n let cachedRecordId = isFromCache ? getCommunityRecordId(firstCommunityState) : undefined;\n\n // the community has published new posts\n community.on(\"update\", async (updatedCommunity: Community) => {\n clearPendingCommunityErrors(communityKey);\n setState((state: CommunitiesState) =>\n clearStoredCommunityErrorsState(state, communityKey),\n );\n\n const isCachedRecordReplay =\n cachedRecordId !== undefined &&\n getCommunityRecordId(updatedCommunity) === cachedRecordId;\n cachedRecordId = undefined;\n if (isCachedRecordReplay) {\n // the replayed record is already in the store and the database, only refresh fetchedAt\n // like a fetched update would, without cloning and rewriting the whole record\n setState((state: CommunitiesState) => {\n const storedCommunity = state.communities[communityKey];\n if (!storedCommunity) {\n return state;\n }\n return {\n communities: {\n ...state.communities,\n [communityKey]: { ...storedCommunity, fetchedAt: getNowSeconds() },\n },\n };\n });\n // pass the cloned record, account state keeps references to its roles\n accountsStore\n .getState()\n .accountsActionsInternal.addCommunityRoleToAccountsCommunities(firstCommunityState);\n return;\n }\n\n updatedCommunity = utils.clone(updatedCommunity);\n\n // add fetchedAt to be able to expire the cache\n // NOTE: fetchedAt is undefined on owner communities because never stale\n updatedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, updatedCommunity);\n log(\"communitiesStore community update\", {\n communityAddressOrRef,\n communityKey,\n updatedCommunity,\n account,\n });\n setState((state: any) => ({\n ...state,\n communities: { ...state.communities, [communityKey]: updatedCommunity },\n }));\n\n // if a community has a role with an account's address add it to the account.communities\n accountsStore\n .getState()\n .accountsActionsInternal.addCommunityRoleToAccountsCommunities(updatedCommunity);\n\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(updatedCommunity);\n });\n\n community.on(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommunitiesState) => ({\n syncStatuses: getNextSyncStatuses(\n state,\n communityKey,\n normalizeCommunitySyncState(updatingState),\n ),\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], updatingState },\n },\n }));\n });\n\n community.on(\"error\", (error: Error) => {\n scheduleCommunityError(setState, communityKey, error);\n });\n\n // set clients on community so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n community?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityKey]) {\n return state;\n }\n const clients = { ...state.communities[communityKey]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], clients },\n },\n };\n });\n },\n );\n\n listeners.push(community);\n startCommunityUpdatePolling(community, { communityAddressOrRef, communityKey });\n } catch (error) {\n updateCommunitySyncStatus(setState, communityKey, \"failed\");\n throw error;\n } finally {\n pkcGetCommunityPending[pendingKey] = false;\n }\n },\n\n async refreshCommunity(communityAddressOrRef: string | CommunityIdentifier, account: Account) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.refreshCommunity invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `communitiesStore.refreshCommunity invalid account argument '${account}'`,\n );\n\n const refreshedCommunity = utils.clone(\n await getPkcCommunity(account.pkc, communityLookupOptions),\n );\n refreshedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, refreshedCommunity);\n log(\"communitiesStore.refreshCommunity\", {\n communityAddressOrRef,\n communityKey,\n refreshedCommunity,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: refreshedCommunity },\n }));\n\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(refreshedCommunity);\n\n return refreshedCommunity;\n },\n\n // user is the owner of the community and can edit it locally\n async editCommunity(communityAddress: string, communityEditOptions: any, account: Account) {\n assert(\n communityAddress !== \"\" && typeof communityAddress === \"string\",\n `communitiesStore.editCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n communityEditOptions && typeof communityEditOptions === \"object\",\n `communitiesStore.editCommunity invalid communityEditOptions argument '${communityEditOptions}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.editCommunity invalid account argument '${account}'`,\n );\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(communityAddress, account);\n\n // `communityAddress` is different from `communityEditOptions.address` when editing the community address\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.edit(communityEditOptions);\n\n const updatedCommunity = utils.clone(community);\n // edit db of both old and new community address to not break the UI\n await communitiesDatabase.setItem(communityAddress, updatedCommunity);\n await communitiesDatabase.setItem(community.address, updatedCommunity);\n log(\"communitiesStore.editCommunity\", {\n communityAddress,\n communityEditOptions,\n community,\n account,\n });\n setState((state: any) => ({\n communities: {\n ...state.communities,\n // edit react state of both old and new community address to not break the UI\n [communityAddress]: updatedCommunity,\n [community.address]: updatedCommunity,\n },\n }));\n },\n\n // internal action called by accountsActions.createCommunity\n async createCommunity(createCommunityOptions: CreateCommunityOptions, account: Account) {\n assert(\n !createCommunityOptions || typeof createCommunityOptions === \"object\",\n `communitiesStore.createCommunity invalid createCommunityOptions argument '${createCommunityOptions}'`,\n );\n if (!createCommunityOptions?.signer) {\n assert(\n !createCommunityOptions?.address,\n `communitiesStore.createCommunity createCommunityOptions.address '${createCommunityOptions?.address}' must be undefined to create a community`,\n );\n }\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.createCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, createCommunityOptions);\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(community.address, account);\n\n await communitiesDatabase.setItem(community.address, utils.clone(community));\n log(\"communitiesStore.createCommunity\", { createCommunityOptions, community, account });\n setState((state: any) => ({\n communities: { ...state.communities, [community.address]: utils.clone(community) },\n }));\n return community;\n },\n\n // internal action called by accountsActions.deleteCommunity\n async deleteCommunity(communityAddress: string, account: Account) {\n assert(\n communityAddress && typeof communityAddress === \"string\",\n `communitiesStore.deleteCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.deleteCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.delete();\n stopCommunityUpdatePolling(communityAddress);\n await communitiesDatabase.removeItem(communityAddress);\n log(\"communitiesStore.deleteCommunity\", { communityAddress, community, account });\n setState((state: CommunitiesState) => {\n const syncStatuses = { ...state.syncStatuses };\n delete syncStatuses[communityAddress];\n const errors = { ...state.errors };\n delete errors[communityAddress];\n return {\n communities: { ...state.communities, [communityAddress]: undefined },\n errors,\n syncStatuses,\n };\n });\n },\n }),\n);\n\n// reset store in between tests\nconst originalState = communitiesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesStore = async () => {\n pkcGetCommunityPending = {};\n Object.keys(pendingCommunityErrorTimers).forEach(clearPendingCommunityErrors);\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n Object.keys(communityUpdatePollers).forEach(stopCommunityUpdatePolling);\n // destroy all component subscriptions to the store\n communitiesStore.destroy();\n // restore original state\n communitiesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communities\" }).clear();\n await resetCommunitiesStore();\n};\n\nexport default communitiesStore;\n"]}
|
|
1
|
+
{"version":3,"file":"communities-store.js","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;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B;IAC7B,SAAS,CAAC,OAAO,CAAC,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACjE,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAClE,KAAK,MAAM,YAAY,IAAI,0BAA0B,EAAE,CAAC;QACtD,OAAO,0BAA0B,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IACD,mDAAmD;IACnD,gBAAgB,CAAC,OAAO,EAAE,CAAC;IAC3B,yBAAyB;IACzB,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC3C,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAS,EAAE;IACzD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,iCAAiC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACzF,MAAM,qBAAqB,EAAE,CAAC;AAChC,CAAC,CAAA,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import assert from \"../../lib/assert\";\nimport localForageLru from \"../../lib/localforage-lru\";\nconst communitiesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communities\",\n size: 500,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:stores\");\nimport {\n Community,\n Communities,\n Account,\n CommunityIdentifier,\n CommunitySyncState,\n CreateCommunityOptions,\n} from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport { getCommunityLookupOptions, getCommunityRefKey } from \"../../lib/community-ref\";\nimport {\n createPkcCommunity,\n getPkcCommunity,\n getPkcCommunityAddresses,\n getPkcCreateCommunity,\n getPkcGetCommunity,\n} from \"../../lib/pkc-compat\";\n\nexport const COMMUNITY_UPDATE_INTERVAL_MS = 15 * 60 * 1000;\n\n// How long a community keeps updating after nothing uses it anymore. pkc-js forgets the record\n// CIDs and gateway ETags it already loaded when a community stops, so every restart downloads the\n// whole record again, while a running loop downloads it once per publish. Communities publish\n// between every ~20 seconds when busy and every 15 minutes when idle, so 2 minutes keeps quick\n// back-and-forth navigation from re-downloading records and bounds what an abandoned busy\n// community costs to about one restart's worth of downloads.\nexport const COMMUNITY_UPDATE_STOP_GRACE_MS = 2 * 60 * 1000;\n\nlet pkcGetCommunityPending: { [key: string]: boolean } = {};\n\n// The pkc-js instance kept for each community in the store, keyed by community so\n// delete/reset can stop it and subscribers can stop and restart its update loop.\ntype LiveCommunity = {\n community: any;\n communityAddressOrRef: string | CommunityIdentifier;\n // defined while the update loop runs\n updateInterval?: ReturnType<typeof setInterval>;\n updateCall?: Promise<void>;\n stopping?: Promise<void>;\n // update() re-emits the record the instance already holds, recognized so it is not stored as\n // a new fetch\n replayRecordId?: string;\n // the cached record replayed on the first update() counts as fetched, a record replayed on a\n // restart keeps the fetchedAt of its real fetch\n replayRefreshesFetchedAt: boolean;\n // the loop started and has neither fetched a record nor failed yet\n openingUpdatePending: boolean;\n stopWhenOpeningUpdateEnds: boolean;\n onUpdatingStateChange: (updatingState: string) => void;\n};\nconst liveCommunities: { [communityKey: string]: LiveCommunity } = {};\n// hooks and feeds that need a community kept updating, the loop stops after the last one leaves\nconst communityUpdateSubscribers: { [communityKey: string]: Set<string> } = {};\nconst communityStopTimers: { [communityKey: string]: ReturnType<typeof setTimeout> } = {};\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\nconst COMMUNITY_ERROR_UPDATE_GRACE_MS = 1000;\nconst pendingCommunityErrorTimers: {\n [communityKey: string]: ReturnType<typeof setTimeout>[];\n} = {};\n\ninterface CommunitySyncStatus {\n syncState: CommunitySyncState;\n lastFetchAttemptAt?: number;\n lastSuccessfulFetchAt?: number;\n // why the community is being retried; retriable errors stay out of `errors` so they do not\n // flash in the UI, but a community that never loads needs a reason to show\n lastRetriableError?: Error;\n // stopped because nothing used it, the next subscriber restarts it\n stoppedUntilUsed?: true;\n}\n\nconst omitLastRetriableError = (syncStatus: CommunitySyncStatus): CommunitySyncStatus => {\n const nextSyncStatus = { ...syncStatus };\n delete nextSyncStatus.lastRetriableError;\n return nextSyncStatus;\n};\n\nconst getNowSeconds = () => Math.floor(Date.now() / 1000);\n\nconst normalizeCommunitySyncState = (updatingState: string): CommunitySyncState => {\n if (updatingState === \"waiting-retry\") {\n return \"retrying\";\n }\n if (updatingState === \"succeeded\" || updatingState === \"failed\" || updatingState === \"stopped\") {\n return updatingState;\n }\n return \"loading\";\n};\n\nconst getNextSyncStatuses = (\n state: CommunitiesState,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n const previousStatus = state.syncStatuses[communityKey];\n const timestamp = getNowSeconds();\n const shouldRecordAttempt = syncState === \"loading\" && previousStatus?.syncState !== \"loading\";\n const nextStatus: CommunitySyncStatus = {\n ...previousStatus,\n syncState,\n ...(shouldRecordAttempt ? { lastFetchAttemptAt: timestamp } : undefined),\n ...(syncState === \"succeeded\" ? { lastSuccessfulFetchAt: timestamp } : undefined),\n };\n return {\n ...state.syncStatuses,\n // a success ends the retries, so their error is no longer current\n [communityKey]: syncState === \"succeeded\" ? omitLastRetriableError(nextStatus) : nextStatus,\n };\n};\n\nconst updateCommunitySyncStatus = (\n setState: Function,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n setState((state: CommunitiesState) => ({\n ...state,\n syncStatuses: getNextSyncStatuses(state, communityKey, syncState),\n }));\n};\n\n// identifies a signed community record, to recognize pkc-js re-emitting a record already in the store\nconst getCommunityRecordId = (community: any): string | undefined => {\n const signature = community?.signature?.signature;\n if (typeof signature !== \"string\" || typeof community?.updatedAt !== \"number\") {\n return;\n }\n return `${community.updatedAt}:${signature}`;\n};\n\nconst createCommunityWithLookupFallback = async (\n pkc: any,\n communityLookupOptions: { address?: string; name?: string; publicKey?: string },\n communityKey: string,\n) => {\n const supportsAddressLookup = \"address\" in communityLookupOptions;\n const community = await createPkcCommunity(pkc, communityLookupOptions);\n if (community?.address || supportsAddressLookup) {\n return community;\n }\n throw Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`);\n};\n\nconst getCommunityKey = (communityAddressOrRef: string | CommunityIdentifier) =>\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n\nconst hasCommunityUpdateSubscribers = (communityKey: string) =>\n (communityUpdateSubscribers[communityKey]?.size || 0) > 0;\n\nconst updateCommunity = (communityKey: string, liveCommunity: LiveCommunity) => {\n const { community, communityAddressOrRef } = liveCommunity;\n liveCommunity.updateCall = Promise.resolve()\n .then(() => community.update())\n .catch((error: unknown) =>\n log.trace(\"community.update error\", {\n communityAddressOrRef,\n communityKey,\n community,\n error,\n }),\n );\n};\n\nconst startCommunityUpdatePolling = (communityKey: string, liveCommunity: LiveCommunity) => {\n clearInterval(liveCommunity.updateInterval);\n liveCommunity.openingUpdatePending = true;\n liveCommunity.stopWhenOpeningUpdateEnds = false;\n updateCommunity(communityKey, liveCommunity);\n liveCommunity.updateInterval = setInterval(\n () => updateCommunity(communityKey, liveCommunity),\n COMMUNITY_UPDATE_INTERVAL_MS,\n );\n};\n\nconst pauseCommunityUpdatePolling = (communityKey: string) => {\n const liveCommunity = liveCommunities[communityKey];\n if (!liveCommunity?.updateInterval) {\n return;\n }\n clearInterval(liveCommunity.updateInterval);\n liveCommunity.updateInterval = undefined;\n liveCommunity.openingUpdatePending = false;\n liveCommunity.stopWhenOpeningUpdateEnds = false;\n liveCommunity.replayRecordId = undefined;\n clearPendingCommunityErrors(communityKey);\n const { community, updateCall } = liveCommunity;\n // stopping while update() is still attaching to the shared updating instance would leave its\n // listeners attached, so wait for the call to return first\n const stopping = (async () => {\n await updateCall;\n if (typeof community.stop !== \"function\") {\n return;\n }\n try {\n await community.stop();\n } catch (error) {\n log.trace(\"community.stop error\", { communityKey, community, error });\n }\n })();\n liveCommunity.stopping = stopping;\n stopping.finally(() => {\n if (liveCommunity.stopping === stopping) {\n liveCommunity.stopping = undefined;\n }\n });\n log(\"communitiesStore community update loop stopped\", { communityKey });\n};\n\nconst resumeCommunityUpdatePolling = async (communityKey: string) => {\n const liveCommunity = liveCommunities[communityKey];\n if (!liveCommunity || liveCommunity.updateInterval) {\n return;\n }\n // update() is a no-op until a stop in progress ends\n if (liveCommunity.stopping) {\n await liveCommunity.stopping;\n }\n if (\n liveCommunities[communityKey] !== liveCommunity ||\n liveCommunity.updateInterval ||\n !hasCommunityUpdateSubscribers(communityKey)\n ) {\n return;\n }\n liveCommunity.replayRecordId = getCommunityRecordId(liveCommunity.community);\n liveCommunity.replayRefreshesFetchedAt = false;\n startCommunityUpdatePolling(communityKey, liveCommunity);\n log(\"communitiesStore community update loop restarted\", { communityKey });\n // joining a shared pkc-js instance that another consumer kept updating emits no state change\n // until its next fetch, so take its current state\n await liveCommunity.updateCall;\n const { updatingState } = liveCommunity.community;\n if (\n liveCommunity.updateInterval &&\n typeof updatingState === \"string\" &&\n updatingState !== \"stopped\" &&\n communitiesStore.getState().syncStatuses[communityKey]?.stoppedUntilUsed\n ) {\n liveCommunity.onUpdatingStateChange(updatingState);\n }\n};\n\nconst clearCommunityStopTimer = (communityKey: string) => {\n clearTimeout(communityStopTimers[communityKey]);\n delete communityStopTimers[communityKey];\n};\n\nconst scheduleCommunityUpdateStop = (communityKey: string) => {\n clearCommunityStopTimer(communityKey);\n communityStopTimers[communityKey] = setTimeout(() => {\n delete communityStopTimers[communityKey];\n const liveCommunity = liveCommunities[communityKey];\n if (hasCommunityUpdateSubscribers(communityKey) || !liveCommunity?.updateInterval) {\n return;\n }\n // stopping before the first fetch ends would leave a store-level caller without the record\n // it loaded the community for\n if (liveCommunity.openingUpdatePending) {\n liveCommunity.stopWhenOpeningUpdateEnds = true;\n return;\n }\n pauseCommunityUpdatePolling(communityKey);\n }, COMMUNITY_UPDATE_STOP_GRACE_MS);\n};\n\nconst endOpeningCommunityUpdate = (communityKey: string, liveCommunity: LiveCommunity) => {\n if (!liveCommunity.openingUpdatePending) {\n return;\n }\n liveCommunity.openingUpdatePending = false;\n if (!liveCommunity.stopWhenOpeningUpdateEnds) {\n return;\n }\n liveCommunity.stopWhenOpeningUpdateEnds = false;\n if (!hasCommunityUpdateSubscribers(communityKey)) {\n pauseCommunityUpdatePolling(communityKey);\n }\n};\n\nconst stopCommunityUpdatePolling = (communityKey: string) => {\n clearCommunityStopTimer(communityKey);\n const liveCommunity = liveCommunities[communityKey];\n if (!liveCommunity) {\n return;\n }\n\n clearPendingCommunityErrors(communityKey);\n clearInterval(liveCommunity.updateInterval);\n liveCommunity.updateInterval = undefined;\n liveCommunity.community.removeAllListeners();\n const listenerIndex = listeners.indexOf(liveCommunity.community);\n if (listenerIndex >= 0) {\n listeners.splice(listenerIndex, 1);\n }\n delete liveCommunities[communityKey];\n};\n\nconst clearPendingCommunityErrors = (communityKey: string) => {\n pendingCommunityErrorTimers[communityKey]?.forEach((timeout) => clearTimeout(timeout));\n delete pendingCommunityErrorTimers[communityKey];\n};\n\nconst clearStoredCommunityErrors = (state: CommunitiesState, communityKey: string) => {\n if (!state.errors[communityKey]) {\n return state.errors;\n }\n const nextErrors = { ...state.errors };\n delete nextErrors[communityKey];\n return nextErrors;\n};\n\n// returning the same state skips notifying subscribers when there is nothing to clear\nconst clearStoredCommunityErrorsState = (state: CommunitiesState, communityKey: string) => {\n const syncStatus = state.syncStatuses[communityKey];\n const hasRetriableError = syncStatus?.lastRetriableError !== undefined;\n if (!state.errors[communityKey] && !hasRetriableError) {\n return state;\n }\n return {\n ...state,\n errors: clearStoredCommunityErrors(state, communityKey),\n syncStatuses: hasRetriableError\n ? { ...state.syncStatuses, [communityKey]: omitLastRetriableError(syncStatus) }\n : state.syncStatuses,\n };\n};\n\nexport const isRetriableCommunityLoadError = (error: Error) => {\n const details = (error as Error & { details?: unknown }).details;\n return Boolean(\n details &&\n typeof details === \"object\" &&\n \"retriableError\" in details &&\n (details as { retriableError?: unknown }).retriableError === true,\n );\n};\n\nconst recordRetriableCommunityError = (setState: Function, communityKey: string, error: Error) => {\n setState((state: CommunitiesState) => {\n const syncStatus = state.syncStatuses[communityKey];\n // a deleted community has no sync status left to report on\n if (!syncStatus) {\n return state;\n }\n return {\n syncStatuses: {\n ...state.syncStatuses,\n [communityKey]: { ...syncStatus, lastRetriableError: error },\n },\n };\n });\n};\n\nconst scheduleCommunityError = (setState: Function, communityKey: string, error: Error) => {\n if (isRetriableCommunityLoadError(error)) {\n recordRetriableCommunityError(setState, communityKey, error);\n return;\n }\n\n const timeout = setTimeout(() => {\n const pendingTimeouts = pendingCommunityErrorTimers[communityKey];\n if (!pendingTimeouts?.includes(timeout)) {\n return;\n }\n\n const remainingTimeouts = pendingTimeouts.filter(\n (pendingTimeout) => pendingTimeout !== timeout,\n );\n if (remainingTimeouts.length === 0) {\n delete pendingCommunityErrorTimers[communityKey];\n } else {\n pendingCommunityErrorTimers[communityKey] = remainingTimeouts;\n }\n setState((state: CommunitiesState) => {\n const communityErrors = state.errors[communityKey] || [];\n return {\n ...state,\n errors: { ...state.errors, [communityKey]: [...communityErrors, error] },\n };\n });\n }, COMMUNITY_ERROR_UPDATE_GRACE_MS);\n\n pendingCommunityErrorTimers[communityKey] = [\n ...(pendingCommunityErrorTimers[communityKey] || []),\n timeout,\n ];\n};\n\nexport type CommunitiesState = {\n communities: Communities;\n errors: { [communityAddress: string]: Error[] };\n syncStatuses: { [communityAddress: string]: CommunitySyncStatus };\n addCommunityToStore: Function;\n startCommunityAutoUpdate: Function;\n stopCommunityAutoUpdate: Function;\n refreshCommunity: Function;\n editCommunity: Function;\n createCommunity: Function;\n deleteCommunity: Function;\n};\n\nconst communitiesStore = createStore<CommunitiesState>(\n (setState: Function, getState: Function) => ({\n communities: {},\n errors: {},\n syncStatuses: {},\n\n async addCommunityToStore(\n communityAddressOrRef: string | CommunityIdentifier,\n account: Account,\n ) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.addCommunityToStore invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.addCommunityToStore invalid account argument '${account}'`,\n );\n\n // community is in store already, do nothing\n const { communities } = getState();\n let community: Community | undefined = communities[communityKey];\n const pendingKey = communityKey + account.id;\n if (community || pkcGetCommunityPending[pendingKey]) {\n return;\n }\n\n // start trying to get community\n pkcGetCommunityPending[pendingKey] = true;\n updateCommunitySyncStatus(setState, communityKey, \"initializing\");\n let errorGettingCommunity: any;\n try {\n // try to find community in owner communities\n if (getPkcCommunityAddresses(account.pkc).includes(communityKey)) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // try to find community in database\n let fetchedAt: number | undefined;\n let isFromCache = false;\n if (!community) {\n const communityData: any = await communitiesDatabase.getItem(communityKey);\n const lookupName =\n \"name\" in communityLookupOptions ? communityLookupOptions.name : undefined;\n const lookupPublicKey =\n \"publicKey\" in communityLookupOptions ? communityLookupOptions.publicKey : undefined;\n const lookupAddress =\n \"address\" in communityLookupOptions ? communityLookupOptions.address : undefined;\n const hasCachedPosts =\n Object.keys(communityData?.posts?.pageCids || {}).length > 0 ||\n Object.keys(communityData?.posts?.pages || {}).length > 0;\n const isUnresolvedNameCache =\n communityData &&\n lookupName &&\n !lookupPublicKey &&\n !lookupAddress &&\n !communityData.publicKey &&\n !communityData.updatedAt &&\n !communityData.updateCid &&\n !communityData.title &&\n !communityData.description &&\n !hasCachedPosts;\n if (communityData && !isUnresolvedNameCache) {\n fetchedAt = communityData.fetchedAt;\n delete communityData.fetchedAt; // not part of pkc-js schema\n try {\n community = await createPkcCommunity(account.pkc, communityData);\n isFromCache = Boolean(community);\n } catch (e) {\n fetchedAt = undefined;\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createCommunity(cachedCommunity)\", {\n cachedCommunity: communityData,\n error: e,\n });\n }\n }\n if (community) {\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(community);\n }\n }\n\n // community not in database, try to fetch from pkc-js\n if (!community) {\n try {\n community = await createCommunityWithLookupFallback(\n account.pkc,\n communityLookupOptions,\n communityKey,\n );\n } catch (e) {\n errorGettingCommunity = e;\n }\n }\n\n // failure getting community\n if (!community) {\n if (errorGettingCommunity) {\n setState((state: CommunitiesState) => {\n let communityErrors = state.errors[communityKey] || [];\n communityErrors = [...communityErrors, errorGettingCommunity];\n return { ...state, errors: { ...state.errors, [communityKey]: communityErrors } };\n });\n }\n\n throw (\n errorGettingCommunity ||\n Error(`communitiesStore.addCommunityToStore failed getting community '${communityKey}'`)\n );\n }\n\n // success getting community\n const firstCommunityState = utils.clone({\n ...community,\n ...(fetchedAt !== undefined ? { fetchedAt } : undefined),\n });\n // a cache hit already is the database entry, rewriting it would only delay the store\n // update behind an IndexedDB write of the whole record\n if (!isFromCache) {\n await communitiesDatabase.setItem(communityKey, firstCommunityState);\n }\n // another load of this community, e.g. by another account, finished first and keeps it\n // updating, so this instance is discarded before it starts updating\n if (liveCommunities[communityKey]) {\n return;\n }\n log(\"communitiesStore.addCommunityToStore\", {\n communityAddressOrRef,\n communityKey,\n community,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: firstCommunityState },\n }));\n\n const liveCommunity: LiveCommunity = {\n community,\n communityAddressOrRef,\n // pkc-js re-emits the record a community was created with when update() starts\n replayRecordId: isFromCache ? getCommunityRecordId(firstCommunityState) : undefined,\n replayRefreshesFetchedAt: true,\n openingUpdatePending: false,\n stopWhenOpeningUpdateEnds: false,\n onUpdatingStateChange: (updatingState: string) => {\n setState((state: CommunitiesState) => {\n const syncStatuses = getNextSyncStatuses(\n state,\n communityKey,\n normalizeCommunitySyncState(updatingState),\n );\n const { stoppedUntilUsed: _stoppedUntilUsed, ...syncStatus } =\n syncStatuses[communityKey];\n // the loop is not running when the store stopped the community itself\n syncStatuses[communityKey] =\n updatingState === \"stopped\" && !liveCommunity.updateInterval\n ? { ...syncStatus, stoppedUntilUsed: true }\n : syncStatus;\n return {\n syncStatuses,\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], updatingState },\n },\n };\n });\n if (\n updatingState === \"succeeded\" ||\n updatingState === \"failed\" ||\n updatingState === \"waiting-retry\"\n ) {\n endOpeningCommunityUpdate(communityKey, liveCommunity);\n }\n },\n };\n\n // the community has published new posts\n community.on(\"update\", async (updatedCommunity: Community) => {\n clearPendingCommunityErrors(communityKey);\n setState((state: CommunitiesState) =>\n clearStoredCommunityErrorsState(state, communityKey),\n );\n\n const isRecordReplay =\n liveCommunity.replayRecordId !== undefined &&\n getCommunityRecordId(updatedCommunity) === liveCommunity.replayRecordId;\n liveCommunity.replayRecordId = undefined;\n if (isRecordReplay && !liveCommunity.replayRefreshesFetchedAt) {\n // a restarted loop replays the record the store already has, it was not fetched now\n return;\n }\n if (isRecordReplay) {\n // the replayed record is already in the store and the database, only refresh fetchedAt\n // like a fetched update would, without cloning and rewriting the whole record\n setState((state: CommunitiesState) => {\n const storedCommunity = state.communities[communityKey];\n if (!storedCommunity) {\n return state;\n }\n return {\n communities: {\n ...state.communities,\n [communityKey]: { ...storedCommunity, fetchedAt: getNowSeconds() },\n },\n };\n });\n // pass the cloned record, account state keeps references to its roles\n accountsStore\n .getState()\n .accountsActionsInternal.addCommunityRoleToAccountsCommunities(firstCommunityState);\n return;\n }\n\n updatedCommunity = utils.clone(updatedCommunity);\n\n // add fetchedAt to be able to expire the cache\n // NOTE: fetchedAt is undefined on owner communities because never stale\n updatedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n // pkc-js reports the fetch succeeded right after this event, so store the record first:\n // a succeeded sync state must not be shown with the previous record, e.g. a stale one\n // kept while the community was not updating\n setState((state: any) => ({\n ...state,\n communities: { ...state.communities, [communityKey]: updatedCommunity },\n }));\n log(\"communitiesStore community update\", {\n communityAddressOrRef,\n communityKey,\n updatedCommunity,\n account,\n });\n await communitiesDatabase.setItem(communityKey, updatedCommunity);\n\n // if a community has a role with an account's address add it to the account.communities\n accountsStore\n .getState()\n .accountsActionsInternal.addCommunityRoleToAccountsCommunities(updatedCommunity);\n\n // add page comments to communitiesPagesStore so they can be used in useComment\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(updatedCommunity);\n\n endOpeningCommunityUpdate(communityKey, liveCommunity);\n });\n\n community.on(\"updatingstatechange\", liveCommunity.onUpdatingStateChange);\n\n community.on(\"error\", (error: Error) => {\n scheduleCommunityError(setState, communityKey, error);\n });\n\n // set clients on community so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n community?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityKey]) {\n return state;\n }\n const clients = { ...state.communities[communityKey]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n communities: {\n ...state.communities,\n [communityKey]: { ...state.communities[communityKey], clients },\n },\n };\n });\n },\n );\n\n listeners.push(community);\n liveCommunities[communityKey] = liveCommunity;\n startCommunityUpdatePolling(communityKey, liveCommunity);\n // loaded without a subscriber, e.g. by a store-level caller: update until the grace period\n // ends, and at least until the first fetch ends\n if (!hasCommunityUpdateSubscribers(communityKey)) {\n scheduleCommunityUpdateStop(communityKey);\n }\n } catch (error) {\n updateCommunitySyncStatus(setState, communityKey, \"failed\");\n throw error;\n } finally {\n pkcGetCommunityPending[pendingKey] = false;\n }\n },\n\n // keep a community updating while a subscriber (a mounted hook or feed) needs it, and restart\n // its update loop if it stopped after its previous subscribers left\n async startCommunityAutoUpdate(\n communityAddressOrRef: string | CommunityIdentifier,\n subscriberId: string,\n account: Account,\n ) {\n const communityKey = getCommunityKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.startCommunityAutoUpdate invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n subscriberId && typeof subscriberId === \"string\",\n `communitiesStore.startCommunityAutoUpdate invalid subscriberId argument '${subscriberId}'`,\n );\n if (!communityUpdateSubscribers[communityKey]) {\n communityUpdateSubscribers[communityKey] = new Set();\n }\n communityUpdateSubscribers[communityKey].add(subscriberId);\n clearCommunityStopTimer(communityKey);\n\n const liveCommunity = liveCommunities[communityKey];\n if (liveCommunity) {\n liveCommunity.stopWhenOpeningUpdateEnds = false;\n await resumeCommunityUpdatePolling(communityKey);\n return;\n }\n await getState().addCommunityToStore(communityAddressOrRef, account);\n },\n\n // the community stops updating a grace period after its last subscriber leaves\n async stopCommunityAutoUpdate(\n communityAddressOrRef: string | CommunityIdentifier,\n subscriberId: string,\n ) {\n const communityKey = getCommunityKey(communityAddressOrRef);\n const subscribers = communityUpdateSubscribers[communityKey];\n if (!subscribers?.delete(subscriberId)) {\n return;\n }\n if (subscribers.size > 0) {\n return;\n }\n delete communityUpdateSubscribers[communityKey];\n if (liveCommunities[communityKey]) {\n scheduleCommunityUpdateStop(communityKey);\n }\n },\n\n async refreshCommunity(communityAddressOrRef: string | CommunityIdentifier, account: Account) {\n const communityLookupOptions = getCommunityLookupOptions(communityAddressOrRef);\n const communityKey =\n typeof communityAddressOrRef === \"string\"\n ? communityAddressOrRef\n : getCommunityRefKey(communityAddressOrRef);\n assert(\n communityKey !== \"\" && typeof communityKey === \"string\",\n `communitiesStore.refreshCommunity invalid communityAddress argument '${communityAddressOrRef}'`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `communitiesStore.refreshCommunity invalid account argument '${account}'`,\n );\n\n const refreshedCommunity = utils.clone(\n await getPkcCommunity(account.pkc, communityLookupOptions),\n );\n refreshedCommunity.fetchedAt = Math.floor(Date.now() / 1000);\n\n await communitiesDatabase.setItem(communityKey, refreshedCommunity);\n log(\"communitiesStore.refreshCommunity\", {\n communityAddressOrRef,\n communityKey,\n refreshedCommunity,\n account,\n });\n setState((state: any) => ({\n communities: { ...state.communities, [communityKey]: refreshedCommunity },\n }));\n\n communitiesPagesStore.getState().addCommunityPageCommentsToStore(refreshedCommunity);\n\n return refreshedCommunity;\n },\n\n // user is the owner of the community and can edit it locally\n async editCommunity(communityAddress: string, communityEditOptions: any, account: Account) {\n assert(\n communityAddress !== \"\" && typeof communityAddress === \"string\",\n `communitiesStore.editCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n communityEditOptions && typeof communityEditOptions === \"object\",\n `communitiesStore.editCommunity invalid communityEditOptions argument '${communityEditOptions}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.editCommunity invalid account argument '${account}'`,\n );\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(communityAddress, account);\n\n // `communityAddress` is different from `communityEditOptions.address` when editing the community address\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.edit(communityEditOptions);\n\n const updatedCommunity = utils.clone(community);\n // edit db of both old and new community address to not break the UI\n await communitiesDatabase.setItem(communityAddress, updatedCommunity);\n await communitiesDatabase.setItem(community.address, updatedCommunity);\n log(\"communitiesStore.editCommunity\", {\n communityAddress,\n communityEditOptions,\n community,\n account,\n });\n setState((state: any) => ({\n communities: {\n ...state.communities,\n // edit react state of both old and new community address to not break the UI\n [communityAddress]: updatedCommunity,\n [community.address]: updatedCommunity,\n },\n }));\n },\n\n // internal action called by accountsActions.createCommunity\n async createCommunity(createCommunityOptions: CreateCommunityOptions, account: Account) {\n assert(\n !createCommunityOptions || typeof createCommunityOptions === \"object\",\n `communitiesStore.createCommunity invalid createCommunityOptions argument '${createCommunityOptions}'`,\n );\n if (!createCommunityOptions?.signer) {\n assert(\n !createCommunityOptions?.address,\n `communitiesStore.createCommunity createCommunityOptions.address '${createCommunityOptions?.address}' must be undefined to create a community`,\n );\n }\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.createCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, createCommunityOptions);\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n // if not added to store first, community.update() is never called\n await getState().addCommunityToStore(community.address, account);\n\n await communitiesDatabase.setItem(community.address, utils.clone(community));\n log(\"communitiesStore.createCommunity\", { createCommunityOptions, community, account });\n setState((state: any) => ({\n communities: { ...state.communities, [community.address]: utils.clone(community) },\n }));\n return community;\n },\n\n // internal action called by accountsActions.deleteCommunity\n async deleteCommunity(communityAddress: string, account: Account) {\n assert(\n communityAddress && typeof communityAddress === \"string\",\n `communitiesStore.deleteCommunity invalid communityAddress argument '${communityAddress}'`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesStore.deleteCommunity invalid account argument '${account}'`,\n );\n\n const community = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n\n // could fix some test issues\n community.on(\"error\", console.log);\n\n await community.delete();\n stopCommunityUpdatePolling(communityAddress);\n await communitiesDatabase.removeItem(communityAddress);\n log(\"communitiesStore.deleteCommunity\", { communityAddress, community, account });\n setState((state: CommunitiesState) => {\n const syncStatuses = { ...state.syncStatuses };\n delete syncStatuses[communityAddress];\n const errors = { ...state.errors };\n delete errors[communityAddress];\n return {\n communities: { ...state.communities, [communityAddress]: undefined },\n errors,\n syncStatuses,\n };\n });\n },\n }),\n);\n\n// reset store in between tests\nconst originalState = communitiesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesStore = async () => {\n pkcGetCommunityPending = {};\n Object.keys(pendingCommunityErrorTimers).forEach(clearPendingCommunityErrors);\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n Object.keys(liveCommunities).forEach(stopCommunityUpdatePolling);\n Object.keys(communityStopTimers).forEach(clearCommunityStopTimer);\n for (const communityKey in communityUpdateSubscribers) {\n delete communityUpdateSubscribers[communityKey];\n }\n // destroy all component subscriptions to the store\n communitiesStore.destroy();\n // restore original state\n communitiesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communities\" }).clear();\n await resetCommunitiesStore();\n};\n\nexport default communitiesStore;\n"]}
|
|
@@ -1 +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,0BAA0B,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAA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|
@@ -27,7 +27,7 @@ import { communityPostsCacheExpired } from "../../lib/utils/index.js";
|
|
|
27
27
|
import { getPkcGetCommunity } from "../../lib/pkc-compat.js";
|
|
28
28
|
import { getCommunityRefKeys } from "../../lib/community-ref.js";
|
|
29
29
|
import accountsStore from "../accounts/index.js";
|
|
30
|
-
import communitiesStore from "../communities/index.js";
|
|
30
|
+
import communitiesStore, { COMMUNITY_UPDATE_STOP_GRACE_MS } from "../communities/index.js";
|
|
31
31
|
import communitiesPagesStore from "../communities-pages/index.js";
|
|
32
32
|
import { getFeedsCommunitiesFirstPageCids, getLoadedFeeds, getUpdatedFeeds, getBufferedFeedsWithoutLoadedFeeds, getFeedsCommunitiesPostCounts, getFeedsHaveMore, getAccountsBlockedAddresses, feedsHaveChangedBlockedAddresses, accountsBlockedAddressesChanged, getAccountsBlockedCids, feedsHaveChangedBlockedCids, accountsBlockedCidsChanged, feedsCommunitiesChanged, getFeedsCommunities, getFeedsCommunitiesLoadedCount, getFeedsCommunitiesPostsPagesFirstUpdatedAts, getFilteredSortedFeeds, getFeedsCommunityKeysWithNewerPosts, getFeedsCommunityKeysWithMore, } from "./utils.js";
|
|
33
33
|
// reddit loads approximately 25 posts per page
|
|
@@ -39,6 +39,54 @@ const communityPostsLeftBeforeNextPage = 50;
|
|
|
39
39
|
let updateFeedsPending = false;
|
|
40
40
|
let updateFeedsAgain = false;
|
|
41
41
|
const updateFeedsMinIntervalTime = 100;
|
|
42
|
+
// hooks that show a feed. A feed keeps its communities updating while it has subscribers, and
|
|
43
|
+
// fetches more community pages while it has subscribers or was used by a store-level caller
|
|
44
|
+
// within the grace period. Its loaded posts stay in the store either way.
|
|
45
|
+
const feedSubscribers = {};
|
|
46
|
+
const feedsActiveUntil = {};
|
|
47
|
+
// inactive feeds that skipped a page fetch, checked again when a subscriber returns
|
|
48
|
+
const feedsWithSkippedPageFetches = new Set();
|
|
49
|
+
// the communities each feed subscribed to, released with the same refs
|
|
50
|
+
const feedsCommunitySubscriptions = {};
|
|
51
|
+
const getFeedCommunitySubscriberId = (feedName) => `feed:${feedName}`;
|
|
52
|
+
const hasFeedSubscribers = (feedName) => { var _a; return (((_a = feedSubscribers[feedName]) === null || _a === void 0 ? void 0 : _a.size) || 0) > 0; };
|
|
53
|
+
const isFeedActive = (feedName) => hasFeedSubscribers(feedName) || Date.now() < (feedsActiveUntil[feedName] || 0);
|
|
54
|
+
// a store-level caller using a feed without a subscriber keeps it active for the grace period
|
|
55
|
+
const touchFeed = (feedName) => {
|
|
56
|
+
if (!hasFeedSubscribers(feedName)) {
|
|
57
|
+
feedsActiveUntil[feedName] = Date.now() + COMMUNITY_UPDATE_STOP_GRACE_MS;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const subscribeFeedCommunities = (feedName, feedOptions) => {
|
|
61
|
+
if (feedsCommunitySubscriptions[feedName] || !hasFeedSubscribers(feedName) || !feedOptions) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const account = accountsStore.getState().accounts[feedOptions.accountId];
|
|
65
|
+
if (!account) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const { communities } = feedOptions;
|
|
69
|
+
feedsCommunitySubscriptions[feedName] = communities;
|
|
70
|
+
const { startCommunityAutoUpdate } = communitiesStore.getState();
|
|
71
|
+
for (const communityRef of communities) {
|
|
72
|
+
startCommunityAutoUpdate(communityRef, getFeedCommunitySubscriberId(feedName), account).catch((error) => log.error("feedsStore startCommunityAutoUpdate error", {
|
|
73
|
+
feedName,
|
|
74
|
+
communityRef,
|
|
75
|
+
error,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const unsubscribeFeedCommunities = (feedName) => {
|
|
80
|
+
const communities = feedsCommunitySubscriptions[feedName];
|
|
81
|
+
if (!communities) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
delete feedsCommunitySubscriptions[feedName];
|
|
85
|
+
const { stopCommunityAutoUpdate } = communitiesStore.getState();
|
|
86
|
+
for (const communityRef of communities) {
|
|
87
|
+
stopCommunityAutoUpdate(communityRef, getFeedCommunitySubscriberId(feedName)).catch((error) => log.error("feedsStore stopCommunityAutoUpdate error", { feedName, communityRef, error }));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
42
90
|
// a feed whose options changed has no community keys with more until it is calculated again, so
|
|
43
91
|
// useFeed reports every community as still loading instead of the previous options' result
|
|
44
92
|
const withoutFeed = (feedsCommunityKeys, feedName) => {
|
|
@@ -77,6 +125,7 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
77
125
|
assert(!accountComments || typeof (accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan) === "number", `addFeedToStore.addFeedToStore accountComments.newerThan '${accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan}' invalid`);
|
|
78
126
|
assert(!modQueue || Array.isArray(modQueue), `addFeedToStore.addFeedToStore modQueue '${modQueue}' invalid`);
|
|
79
127
|
const { feedsOptions, updateFeeds } = getState();
|
|
128
|
+
touchFeed(feedName);
|
|
80
129
|
// feed is in store already, do nothing
|
|
81
130
|
// if the feed already exist but is at page 0, reset it to page 1
|
|
82
131
|
if (feedsOptions[feedName] && feedsOptions[feedName].pageNumber !== 0) {
|
|
@@ -101,16 +150,45 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
101
150
|
feedsOptions: Object.assign(Object.assign({}, feedsOptions), { [feedName]: feedOptions }),
|
|
102
151
|
}));
|
|
103
152
|
addCommunitiesToCommunitiesStore(communities, account);
|
|
153
|
+
subscribeFeedCommunities(feedName, feedOptions);
|
|
104
154
|
// update feeds right away to use the already loaded communities and pages
|
|
105
155
|
// if no new communities are added by the feed, like for a sort type change,
|
|
106
156
|
// a feed update will never be triggered, so must be triggered it manually
|
|
107
157
|
updateFeeds();
|
|
108
158
|
});
|
|
109
159
|
},
|
|
160
|
+
// keep a feed's communities updating and its pages loading while a subscriber shows it
|
|
161
|
+
startFeedAutoUpdate(feedName, subscriberId) {
|
|
162
|
+
assert(feedName && typeof feedName === "string", `feedsStore.startFeedAutoUpdate feedName '${feedName}' invalid`);
|
|
163
|
+
assert(subscriberId && typeof subscriberId === "string", `feedsStore.startFeedAutoUpdate subscriberId '${subscriberId}' invalid`);
|
|
164
|
+
if (!feedSubscribers[feedName]) {
|
|
165
|
+
feedSubscribers[feedName] = new Set();
|
|
166
|
+
}
|
|
167
|
+
feedSubscribers[feedName].add(subscriberId);
|
|
168
|
+
delete feedsActiveUntil[feedName];
|
|
169
|
+
subscribeFeedCommunities(feedName, getState().feedsOptions[feedName]);
|
|
170
|
+
// pages skipped while the feed was inactive are fetched now
|
|
171
|
+
if (feedsWithSkippedPageFetches.delete(feedName) && getState().feedsOptions[feedName]) {
|
|
172
|
+
previousBufferedFeedsCommunitiesPostCounts = {};
|
|
173
|
+
addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts();
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
// a feed releases its communities when its last subscriber leaves, they stop updating a grace
|
|
177
|
+
// period later, and it stops fetching pages after the same grace period
|
|
178
|
+
stopFeedAutoUpdate(feedName, subscriberId) {
|
|
179
|
+
const subscribers = feedSubscribers[feedName];
|
|
180
|
+
if (!(subscribers === null || subscribers === void 0 ? void 0 : subscribers.delete(subscriberId)) || subscribers.size > 0) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
delete feedSubscribers[feedName];
|
|
184
|
+
feedsActiveUntil[feedName] = Date.now() + COMMUNITY_UPDATE_STOP_GRACE_MS;
|
|
185
|
+
unsubscribeFeedCommunities(feedName);
|
|
186
|
+
},
|
|
110
187
|
incrementFeedPageNumber(feedName) {
|
|
111
188
|
const { feedsOptions, loadedFeeds, updateFeeds } = getState();
|
|
112
189
|
assert(feedsOptions[feedName], `feedsActions.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`);
|
|
113
190
|
log("feedsActions.incrementFeedPageNumber", { feedName });
|
|
191
|
+
touchFeed(feedName);
|
|
114
192
|
assert(feedsOptions[feedName].pageNumber * feedsOptions[feedName].postsPerPage <=
|
|
115
193
|
loadedFeeds[feedName].length, `feedsActions.incrementFeedPageNumber cannot increment feed page number before current page has loaded`);
|
|
116
194
|
setState(({ feedsOptions, loadedFeeds }) => {
|
|
@@ -130,6 +208,7 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
130
208
|
if (currentNewerThan === newerThan) {
|
|
131
209
|
return;
|
|
132
210
|
}
|
|
211
|
+
touchFeed(feedName);
|
|
133
212
|
const isExpandedTimeWindow = typeof currentNewerThan === "number" &&
|
|
134
213
|
(newerThan === undefined || newerThan > currentNewerThan);
|
|
135
214
|
assert(isExpandedTimeWindow, `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' must broaden the current window '${currentNewerThan}'`);
|
|
@@ -150,6 +229,7 @@ const feedsStore = createStore((setState, getState) => ({
|
|
|
150
229
|
assert(feedsOptions[feedName], `feedsActions.resetFeed feed name '${feedName}' does not exist in feeds store`);
|
|
151
230
|
assert(feedsOptions[feedName].pageNumber >= 1, `feedsActions.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`);
|
|
152
231
|
log("feedsActions.resetFeed", { feedName });
|
|
232
|
+
touchFeed(feedName);
|
|
153
233
|
const { modQueue, sortType, communities, communityKeys, accountId } = feedsOptions[feedName];
|
|
154
234
|
const account = accountsStore.getState().accounts[accountId];
|
|
155
235
|
assert(account, `feedsActions.resetFeed account id '${accountId}' does not exist in accounts store`);
|
|
@@ -334,7 +414,7 @@ const updateFeedsOnFeedsCommunitiesPagesChange = (communitiesPagesStoreState) =>
|
|
|
334
414
|
let previousBufferedFeedsCommunitiesPostCountsPageCids = [];
|
|
335
415
|
let previousBufferedFeedsCommunities = new Map();
|
|
336
416
|
let previousBufferedFeedsCommunitiesPostCounts = {};
|
|
337
|
-
const addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts = (
|
|
417
|
+
const addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts = () => {
|
|
338
418
|
const { bufferedFeedsCommunitiesPostCounts, feedsOptions } = feedsStore.getState();
|
|
339
419
|
const { communities } = communitiesStore.getState();
|
|
340
420
|
// if feeds communities have changed, we must try adding them even if buffered posts counts haven't changed
|
|
@@ -360,6 +440,11 @@ const addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts = (feedsStoreSt
|
|
|
360
440
|
const { accounts } = accountsStore.getState();
|
|
361
441
|
// bufferedFeedsCommunitiesPostCounts have changed, check if any of them are low
|
|
362
442
|
for (const feedName in bufferedFeedsCommunitiesPostCounts) {
|
|
443
|
+
// a feed nothing shows doesn't need more pages, it fetches them again once shown
|
|
444
|
+
if (!isFeedActive(feedName)) {
|
|
445
|
+
feedsWithSkippedPageFetches.add(feedName);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
363
448
|
const account = accounts[feedsOptions[feedName].accountId];
|
|
364
449
|
const communitiesPostCounts = bufferedFeedsCommunitiesPostCounts[feedName];
|
|
365
450
|
const { sortType, modQueue } = feedsOptions[feedName];
|
|
@@ -471,6 +556,16 @@ export const resetFeedsStore = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
471
556
|
previousAccountsCommentsCids = "";
|
|
472
557
|
updateFeedsPending = false;
|
|
473
558
|
updateFeedsAgain = false;
|
|
559
|
+
for (const feedName in feedSubscribers) {
|
|
560
|
+
delete feedSubscribers[feedName];
|
|
561
|
+
}
|
|
562
|
+
for (const feedName in feedsActiveUntil) {
|
|
563
|
+
delete feedsActiveUntil[feedName];
|
|
564
|
+
}
|
|
565
|
+
for (const feedName in feedsCommunitySubscriptions) {
|
|
566
|
+
delete feedsCommunitySubscriptions[feedName];
|
|
567
|
+
}
|
|
568
|
+
feedsWithSkippedPageFetches.clear();
|
|
474
569
|
// destroy all component subscriptions to the store
|
|
475
570
|
feedsStore.destroy();
|
|
476
571
|
// restore original state
|