@bitsocial/bitsocial-react-hooks 0.1.38 → 0.1.40
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 +21 -0
- package/README.md +13 -1
- package/dist/hooks/feeds/feeds.d.ts +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +25 -38
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/hooks/replies.d.ts.map +1 -1
- package/dist/hooks/replies.js +0 -1
- package/dist/hooks/replies.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/page-sorts.d.ts +8 -0
- package/dist/lib/page-sorts.d.ts.map +1 -0
- package/dist/lib/page-sorts.js +37 -0
- package/dist/lib/page-sorts.js.map +1 -0
- package/dist/lib/serialize-feed-key.d.ts +2 -0
- package/dist/lib/serialize-feed-key.d.ts.map +1 -0
- package/dist/lib/serialize-feed-key.js +5 -0
- package/dist/lib/serialize-feed-key.js.map +1 -0
- package/dist/lib/validator.d.ts.map +1 -1
- package/dist/lib/validator.js +5 -37
- package/dist/lib/validator.js.map +1 -1
- package/dist/lib/wordfilters.d.ts +6 -0
- package/dist/lib/wordfilters.d.ts.map +1 -0
- package/dist/lib/wordfilters.js +131 -0
- package/dist/lib/wordfilters.js.map +1 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +86 -4
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts +1 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +1 -1
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.d.ts +2 -2
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js +11 -6
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
- package/dist/stores/feeds/feed-sorter.d.ts +1 -1
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
- package/dist/stores/feeds/feed-sorter.js +28 -22
- package/dist/stores/feeds/feed-sorter.js.map +1 -1
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
- package/dist/stores/feeds/feeds-store.js +2 -6
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/stores/feeds/utils.d.ts.map +1 -1
- package/dist/stores/feeds/utils.js +10 -22
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/stores/replies/replies-store.d.ts.map +1 -1
- package/dist/stores/replies/replies-store.js +22 -5
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.d.ts +1 -1
- package/dist/stores/replies/utils.d.ts.map +1 -1
- package/dist/stores/replies/utils.js +16 -89
- package/dist/stores/replies/utils.js.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.d.ts +2 -2
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js +15 -5
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
- package/dist/types.d.ts +23 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,WAAW,EAGX,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAcrB,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAmB3D,UAAU,mBAAmB;IAC3B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"communities-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,WAAW,EAGX,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAcrB,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAmB3D,UAAU,mBAAmB;IAC3B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAoHD,eAAO,MAAM,6BAA6B,GAAI,OAAO,KAAK,YAQzD,CAAC;AAoCF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE;QAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAChD,YAAY,EAAE;QAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,mBAAmB,CAAA;KAAE,CAAC;IAClE,mBAAmB,EAAE,QAAQ,CAAC;IAC9B,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,aAAa,EAAE,QAAQ,CAAC;IACxB,eAAe,EAAE,QAAQ,CAAC;IAC1B,eAAe,EAAE,QAAQ,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,gBAAgB,+EA4XrB,CAAC;AAKF,eAAO,MAAM,qBAAqB,qBAWjC,CAAC;AAGF,eAAO,MAAM,gCAAgC,qBAG5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -98,7 +98,7 @@ const clearStoredCommunityErrors = (state, communityKey) => {
|
|
|
98
98
|
delete nextErrors[communityKey];
|
|
99
99
|
return nextErrors;
|
|
100
100
|
};
|
|
101
|
-
const isRetriableCommunityLoadError = (error) => {
|
|
101
|
+
export const isRetriableCommunityLoadError = (error) => {
|
|
102
102
|
const details = error.details;
|
|
103
103
|
return Boolean(details &&
|
|
104
104
|
typeof details === "object" &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities-store.js","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,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,CAAC;AAS/D,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3D,IAAI,sBAAsB,GAA+B,EAAE,CAAC;AAC5D,gFAAgF;AAChF,MAAM,sBAAsB,GAKxB,EAAE,CAAC;AAEP,6CAA6C;AAC7C,MAAM,SAAS,GAAQ,EAAE,CAAC;AAE1B,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAC7C,MAAM,2BAA2B,GAE7B,EAAE,CAAC;AAQP,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAE1D,MAAM,2BAA2B,GAAG,CAAC,aAAqB,EAAsB,EAAE;IAChF,IAAI,aAAa,KAAK,eAAe,EAAE,CAAC;QACtC,OAAO,UAAU,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AA2B,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 \"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 updateCommunitySyncStatus = (\n setState: Function,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n setState((state: CommunitiesState) => {\n const previousStatus = state.syncStatuses[communityKey];\n const timestamp = getNowSeconds();\n const shouldRecordAttempt = syncState === \"loading\" && previousStatus?.syncState !== \"loading\";\n return {\n ...state,\n syncStatuses: {\n ...state.syncStatuses,\n [communityKey]: {\n ...previousStatus,\n syncState,\n ...(shouldRecordAttempt ? { lastFetchAttemptAt: timestamp } : undefined),\n ...(syncState === \"succeeded\" ? { lastSuccessfulFetchAt: timestamp } : undefined),\n },\n },\n };\n });\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\nconst 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 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 } 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 await communitiesDatabase.setItem(communityKey, firstCommunityState);\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 // the community has published new posts\n community.on(\"update\", async (updatedCommunity: Community) => {\n clearPendingCommunityErrors(communityKey);\n setState((state: CommunitiesState) => ({\n ...state,\n errors: clearStoredCommunityErrors(state, communityKey),\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 updateCommunitySyncStatus(\n setState,\n communityKey,\n normalizeCommunitySyncState(updatingState),\n );\n setState((state: CommunitiesState) => ({\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 {};\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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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 \"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 updateCommunitySyncStatus = (\n setState: Function,\n communityKey: string,\n syncState: CommunitySyncState,\n) => {\n setState((state: CommunitiesState) => {\n const previousStatus = state.syncStatuses[communityKey];\n const timestamp = getNowSeconds();\n const shouldRecordAttempt = syncState === \"loading\" && previousStatus?.syncState !== \"loading\";\n return {\n ...state,\n syncStatuses: {\n ...state.syncStatuses,\n [communityKey]: {\n ...previousStatus,\n syncState,\n ...(shouldRecordAttempt ? { lastFetchAttemptAt: timestamp } : undefined),\n ...(syncState === \"succeeded\" ? { lastSuccessfulFetchAt: timestamp } : undefined),\n },\n },\n };\n });\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\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 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 } 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 await communitiesDatabase.setItem(communityKey, firstCommunityState);\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 // the community has published new posts\n community.on(\"update\", async (updatedCommunity: Community) => {\n clearPendingCommunityErrors(communityKey);\n setState((state: CommunitiesState) => ({\n ...state,\n errors: clearStoredCommunityErrors(state, communityKey),\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 updateCommunitySyncStatus(\n setState,\n communityKey,\n normalizeCommunitySyncState(updatingState),\n );\n setState((state: CommunitiesState) => ({\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 {};\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"]}
|
|
@@ -15,8 +15,8 @@ declare const communitiesPagesStore: import("zustand").UseBoundStore<import("zus
|
|
|
15
15
|
* Util function to get all pages in the store for a
|
|
16
16
|
* specific community+sortType using `CommunityPage.nextCid`
|
|
17
17
|
*/
|
|
18
|
-
export declare const getCommunityPages: (community: Community, sortType: string, communitiesPages: CommunitiesPages, pageType: string, accountId?: string) => CommunityPage[];
|
|
19
|
-
export declare const getCommunityFirstPageCid: (community: Community, sortType: string, pageType?: string) => any;
|
|
18
|
+
export declare const getCommunityPages: (community: Community, sortType: string | undefined, communitiesPages: CommunitiesPages, pageType: string, accountId?: string) => CommunityPage[];
|
|
19
|
+
export declare const getCommunityFirstPageCid: (community: Community, sortType: string | undefined, pageType?: string) => any;
|
|
20
20
|
export declare const resetCommunitiesPagesStore: () => Promise<void>;
|
|
21
21
|
export declare const resetCommunitiesPagesDatabaseAndStore: () => Promise<void>;
|
|
22
22
|
export default communitiesPagesStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities-pages-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities-pages/communities-pages-store.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAE7C,eAAO,MAAM,GAAG,QAA+C,CAAC;AAChE,OAAO,EACL,SAAS,EACT,aAAa,EACb,gBAAgB,EAEhB,OAAO,EACP,QAAQ,EACT,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"communities-pages-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities-pages/communities-pages-store.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAE7C,eAAO,MAAM,GAAG,QAA+C,CAAC;AAChE,OAAO,EACL,SAAS,EACT,aAAa,EACb,gBAAgB,EAEhB,OAAO,EACP,QAAQ,EACT,MAAM,aAAa,CAAC;AA6BrB,4HAA4H;AAC5H,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,GAAG,SAAS,KAAG,MACJ,CAAC;AAKhE,KAAK,qBAAqB,GAAG;IAC3B,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,QAAQ,EAAE,QAAQ,CAAC;IACnB,2BAA2B,EAAE,QAAQ,CAAC;IACtC,wBAAwB,EAAE,QAAQ,CAAC;IACnC,+BAA+B,EAAE,QAAQ,CAAC;CAC3C,CAAC;AAEF,QAAA,MAAM,qBAAqB,oFAgP1B,CAAC;AAsEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,WAAW,SAAS,EACpB,UAAU,MAAM,GAAG,SAAS,EAC5B,kBAAkB,gBAAgB,EAClC,UAAU,MAAM,EAChB,YAAY,MAAM,oBA6BnB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,WAAW,SAAS,EACpB,UAAU,MAAM,GAAG,SAAS,EAC5B,iBAAkB,QAuBnB,CAAC;AAKF,eAAO,MAAM,0BAA0B,qBAYtC,CAAC;AAGF,eAAO,MAAM,qCAAqC,qBAGjD,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -17,6 +17,7 @@ import localForageLru from "../../lib/localforage-lru/index.js";
|
|
|
17
17
|
import createStore from "zustand";
|
|
18
18
|
import assert from "assert";
|
|
19
19
|
import { createPkcCommunity, getPkcCreateCommunity, normalizeCommentCommunityAddress, } from "../../lib/pkc-compat.js";
|
|
20
|
+
import { resolvePostSortType } from "../../lib/page-sorts.js";
|
|
20
21
|
const communitiesPagesDatabase = localForageLru.createInstance({
|
|
21
22
|
name: "bitsocialReactHooks-communitiesPages",
|
|
22
23
|
size: 500,
|
|
@@ -39,7 +40,7 @@ const communitiesPagesStore = createStore((setState, getState) => ({
|
|
|
39
40
|
addNextCommunityPageToStore: (community, sortType, account, modQueue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
41
|
var _a;
|
|
41
42
|
assert((community === null || community === void 0 ? void 0 : community.address) && typeof (community === null || community === void 0 ? void 0 : community.address) === "string", `communitiesPagesStore.addNextCommunityPageToStore community '${community}' invalid`);
|
|
42
|
-
assert(sortType
|
|
43
|
+
assert(sortType === undefined || (typeof sortType === "string" && sortType.length > 0), `communitiesPagesStore.addNextCommunityPageToStore sortType '${sortType}' invalid`);
|
|
43
44
|
assert(typeof getPkcCreateCommunity(account === null || account === void 0 ? void 0 : account.pkc) === "function", `communitiesPagesStore.addNextCommunityPageToStore account '${account}' invalid`);
|
|
44
45
|
assert(!modQueue || Array.isArray(modQueue), `communitiesPagesStore.addNextCommunityPageToStore modQueue '${modQueue}' invalid`);
|
|
45
46
|
let pageType = "posts";
|
|
@@ -144,7 +145,7 @@ const communitiesPagesStore = createStore((setState, getState) => ({
|
|
|
144
145
|
invalidateCommunityPages: (community, sortType, modQueue, accountId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
145
146
|
var _a, _b;
|
|
146
147
|
assert((community === null || community === void 0 ? void 0 : community.address) && typeof (community === null || community === void 0 ? void 0 : community.address) === "string", `communitiesPagesStore.invalidateCommunityPages community '${community}' invalid`);
|
|
147
|
-
assert(sortType
|
|
148
|
+
assert(sortType === undefined || (typeof sortType === "string" && sortType.length > 0), `communitiesPagesStore.invalidateCommunityPages sortType '${sortType}' invalid`);
|
|
148
149
|
assert(!modQueue || Array.isArray(modQueue), `communitiesPagesStore.invalidateCommunityPages modQueue '${modQueue}' invalid`);
|
|
149
150
|
let pageType = "posts";
|
|
150
151
|
if (modQueue === null || modQueue === void 0 ? void 0 : modQueue[0]) {
|
|
@@ -282,12 +283,16 @@ export const getCommunityPages = (community, sortType, communitiesPages, pageTyp
|
|
|
282
283
|
export const getCommunityFirstPageCid = (community, sortType, pageType = "posts") => {
|
|
283
284
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
284
285
|
assert(community && typeof community === "object", `getCommunityFirstPageCid community '${community}' invalid`);
|
|
285
|
-
assert(sortType
|
|
286
|
+
assert(sortType === undefined || (typeof sortType === "string" && sortType.length > 0), `getCommunityFirstPageCid sortType '${sortType}' invalid`);
|
|
287
|
+
const resolvedSortType = pageType === "posts" ? resolvePostSortType(community, sortType) : sortType;
|
|
288
|
+
if (!resolvedSortType) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
286
291
|
// community has preloaded posts for sort type
|
|
287
|
-
if ((_c = (_b = (_a = community[pageType]) === null || _a === void 0 ? void 0 : _a.pages) === null || _b === void 0 ? void 0 : _b[
|
|
288
|
-
return (_f = (_e = (_d = community[pageType]) === null || _d === void 0 ? void 0 : _d.pages) === null || _e === void 0 ? void 0 : _e[
|
|
292
|
+
if ((_c = (_b = (_a = community[pageType]) === null || _a === void 0 ? void 0 : _a.pages) === null || _b === void 0 ? void 0 : _b[resolvedSortType]) === null || _c === void 0 ? void 0 : _c.comments) {
|
|
293
|
+
return (_f = (_e = (_d = community[pageType]) === null || _d === void 0 ? void 0 : _d.pages) === null || _e === void 0 ? void 0 : _e[resolvedSortType]) === null || _f === void 0 ? void 0 : _f.nextCid;
|
|
289
294
|
}
|
|
290
|
-
return (_h = (_g = community[pageType]) === null || _g === void 0 ? void 0 : _g.pageCids) === null || _h === void 0 ? void 0 : _h[
|
|
295
|
+
return (_h = (_g = community[pageType]) === null || _g === void 0 ? void 0 : _g.pageCids) === null || _h === void 0 ? void 0 : _h[resolvedSortType];
|
|
291
296
|
// TODO: if a loaded community doesn't have a first page, it's unclear what we should do
|
|
292
297
|
// should we try to use another sort type by default, like 'hot', or should we just ignore it?
|
|
293
298
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities-pages-store.js","sourceRoot":"","sources":["../../../src/stores/communities-pages/communities-pages-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,2DAA2D;AAC3D,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAShE,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,gBAAsC,MAAM,gBAAgB,CAAC;AACpE,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC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AAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC9F,MAAM,0BAA0B,EAAE,CAAC;AACrC,CAAC,CAAA,CAAC;AAEF,eAAe,qBAAqB,CAAC","sourcesContent":["import utils from \"../../lib/utils\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\n// include communities pages store with feeds for debugging\nexport const log = Logger(\"bitsocial-react-hooks:feeds:stores\");\nimport {\n Community,\n CommunityPage,\n CommunitiesPages,\n Account,\n Comment,\n Comments,\n} from \"../../types\";\nimport accountsStore from \"../accounts\";\nimport communitiesStore, { CommunitiesState } from \"../communities\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport createStore from \"zustand\";\nimport assert from \"assert\";\nimport {\n createPkcCommunity,\n getPkcCreateCommunity,\n normalizeCommentCommunityAddress,\n} from \"../../lib/pkc-compat\";\n\nconst communitiesPagesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communitiesPages\",\n size: 500,\n});\n\nconst getCommunityPageStoreKey = (pageCid: string, pageType: string, accountId?: string) => {\n if (pageType === \"modQueue\") {\n assert(\n accountId && typeof accountId === \"string\",\n `getCommunityPageStoreKey accountId '${accountId}' invalid for modQueue`,\n );\n return `${accountId}:${pageCid}`;\n }\n return pageCid;\n};\n\n/** Freshness for comparison: max(updatedAt, timestamp, 0). Used to decide add vs replace per CID. Exported for coverage. */\nexport const getCommentFreshness = (comment: Comment | undefined): number =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\ntype CommunitiesPagesState = {\n communitiesPages: CommunitiesPages;\n comments: Comments;\n addNextCommunityPageToStore: Function;\n invalidateCommunityPages: Function;\n addCommunityPageCommentsToStore: Function;\n};\n\nconst communitiesPagesStore = createStore<CommunitiesPagesState>(\n (setState: Function, getState: Function) => ({\n // TODO: eventually clear old pages and comments from memory\n communitiesPages: {},\n comments: {},\n\n addNextCommunityPageToStore: async (\n community: Community,\n sortType: string,\n account: Account,\n modQueue?: string[],\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.addNextCommunityPageToStore community '${community}' invalid`,\n );\n assert(\n sortType && typeof sortType === \"string\",\n `communitiesPagesStore.addNextCommunityPageToStore sortType '${sortType}' invalid`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesPagesStore.addNextCommunityPageToStore account '${account}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.addNextCommunityPageToStore modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // check the preloaded posts on community.posts.pages first, then the community.posts.pageCids\n const communityFirstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!communityFirstPageCid) {\n log(\n `communitiesPagesStore.addNextCommunityPageToStore community '${community?.address}' sortType '${sortType}' no communityFirstPageCid`,\n );\n return;\n }\n\n // all communities pages in store\n const { communitiesPages } = getState();\n // only specific pages of the community+sortType\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n account.id,\n );\n\n // if no pages exist yet, add the first page\n let pageCidToAdd: string;\n if (!communityPages.length) {\n pageCidToAdd = communityFirstPageCid;\n } else {\n const nextCid = communityPages[communityPages.length - 1]?.nextCid;\n // if last nextCid is undefined, reached end of pages\n if (!nextCid) {\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore no more pages\", {\n communityAddress: community.address,\n sortType,\n account,\n });\n return;\n }\n\n pageCidToAdd = nextCid;\n }\n\n // page is already added or pending\n const pageStoreKeyToAdd = getCommunityPageStoreKey(pageCidToAdd, pageType, account.id);\n if (communitiesPages[pageStoreKeyToAdd] || fetchPagePending[pageStoreKeyToAdd]) {\n return;\n }\n\n fetchPagePending[pageStoreKeyToAdd] = true;\n let page: CommunityPage;\n try {\n page = await fetchPage(pageCidToAdd, community.address, account, pageType);\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore community.posts.getPage\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n account,\n });\n } catch (e) {\n throw e;\n } finally {\n fetchPagePending[pageStoreKeyToAdd] = false;\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(page);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n if (pageType !== \"modQueue\") {\n for (const comment of flattenedComments) {\n const normalizedComment = normalizeCommentCommunityAddress(comment) as Comment;\n const existing = comments[normalizedComment.cid];\n if (\n normalizedComment.cid &&\n (!existing || getCommentFreshness(normalizedComment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[normalizedComment.cid] = normalizedComment;\n hasNewComments = true;\n }\n }\n }\n\n setState(({ communitiesPages, comments }: any) => {\n const newState: any = {\n communitiesPages: { ...communitiesPages, [pageStoreKeyToAdd]: page },\n };\n if (hasNewComments) {\n newState.comments = { ...comments, ...newComments };\n }\n return newState;\n });\n log(\"communitiesPagesStore.addNextCommunityPageToStore\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n sortType,\n page,\n account,\n });\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n for (const comment of flattenedComments) {\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(\n normalizeCommentCommunityAddress(comment) as Comment,\n )\n .catch((error: unknown) =>\n log.error(\n \"communitiesPagesStore.addNextCommunityPageToStore addCidToAccountComment error\",\n { comment, error },\n ),\n );\n }\n },\n\n invalidateCommunityPages: async (\n community: Community,\n sortType: string,\n modQueue?: string[],\n accountId?: string,\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.invalidateCommunityPages community '${community}' invalid`,\n );\n assert(\n sortType && typeof sortType === \"string\",\n `communitiesPagesStore.invalidateCommunityPages sortType '${sortType}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.invalidateCommunityPages modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, for now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!firstPageCid) {\n return;\n }\n\n const { communitiesPages } = getState();\n const firstPageKey = getCommunityPageStoreKey(firstPageCid, pageType, accountId);\n const pageKeysToInvalidate = new Set<string>([firstPageKey]);\n let nextPageCid = communitiesPages[firstPageKey]?.nextCid;\n while (nextPageCid) {\n const nextPageKey = getCommunityPageStoreKey(nextPageCid, pageType, accountId);\n pageKeysToInvalidate.add(nextPageKey);\n nextPageCid = communitiesPages[nextPageKey]?.nextCid;\n }\n\n await Promise.all(\n [...pageKeysToInvalidate].map((pageKey) => communitiesPagesDatabase.removeItem(pageKey)),\n );\n\n setState(({ communitiesPages }: any) => {\n const nextCommunitiesPages = { ...communitiesPages };\n for (const pageKey of pageKeysToInvalidate) {\n delete nextCommunitiesPages[pageKey];\n }\n return { communitiesPages: nextCommunitiesPages };\n });\n },\n\n // communities contain preloaded pages, those page comments must be added separately\n addCommunityPageCommentsToStore: (community: Community) => {\n if (!community.posts?.pages) {\n return;\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(community.posts.pages);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n for (const comment of flattenedComments) {\n const existing = comments[comment.cid];\n if (\n comment.cid &&\n (!existing || getCommentFreshness(comment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[comment.cid] = comment;\n hasNewComments = true;\n }\n }\n\n if (!hasNewComments) {\n return;\n }\n\n setState(({ comments }: any) => {\n return { comments: { ...comments, ...newComments } };\n });\n log(\"communitiesPagesStore.addCommunityPageCommentsToStore\", { community, newComments });\n },\n }),\n);\n\n// set clients states on communities store so the frontend can display it, dont persist in db because a reload cancels updating\nconst onCommunityPostsClientsStateChange =\n (communityAddress: string) =>\n (clientState: string, clientType: string, sortType: string, clientUrl: string) => {\n communitiesStore.setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityAddress]) {\n return {};\n }\n const client = { state: clientState };\n const community = { ...state.communities[communityAddress] };\n community.posts = { ...community.posts };\n community.posts.clients = { ...community.posts.clients };\n community.posts.clients[clientType] = { ...community.posts.clients[clientType] };\n community.posts.clients[clientType][sortType] = {\n ...community.posts.clients[clientType][sortType],\n };\n community.posts.clients[clientType][sortType][clientUrl] = client;\n return { communities: { ...state.communities, [community.address]: community } };\n });\n };\n\nconst fetchPageCommunities: {\n [accountId: string]: { pkc: any; communities: { [communityAddress: string]: any } };\n} = {}; // cache created community clients per account because creating them can be slow\nlet fetchPagePending: { [key: string]: boolean } = {};\nconst fetchPage = async (\n pageCid: string,\n communityAddress: string,\n account: Account,\n pageType: string,\n) => {\n // community page is cached\n const pageStoreKey = getCommunityPageStoreKey(pageCid, pageType, account.id);\n const cachedCommunityPage = await communitiesPagesDatabase.getItem(pageStoreKey);\n if (cachedCommunityPage) {\n return cachedCommunityPage;\n }\n if (!fetchPageCommunities[account.id] || fetchPageCommunities[account.id].pkc !== account.pkc) {\n fetchPageCommunities[account.id] = { pkc: account.pkc, communities: {} };\n }\n const accountCommunities = fetchPageCommunities[account.id].communities;\n if (!accountCommunities[communityAddress]) {\n accountCommunities[communityAddress] = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n listeners.push(accountCommunities[communityAddress]);\n\n // set clients states on communities store so the frontend can display it\n utils.pageClientsOnStateChange(\n accountCommunities[communityAddress][pageType]?.clients,\n onCommunityPostsClientsStateChange(communityAddress),\n );\n }\n\n const onError = (error: any) =>\n log.error(\n `communitiesPagesStore community '${communityAddress}' failed community.posts.getPage page cid '${pageCid}':`,\n error,\n );\n const fetchedCommunityPage = await utils.retryInfinity(\n () => accountCommunities[communityAddress][pageType].getPage({ cid: pageCid }),\n { onError },\n );\n await communitiesPagesDatabase.setItem(pageStoreKey, utils.clone(fetchedCommunityPage));\n return fetchedCommunityPage;\n};\n\n/**\n * Util function to get all pages in the store for a\n * specific community+sortType using `CommunityPage.nextCid`\n */\nexport const getCommunityPages = (\n community: Community,\n sortType: string,\n communitiesPages: CommunitiesPages,\n pageType: string,\n accountId?: string,\n) => {\n assert(\n communitiesPages && typeof communitiesPages === \"object\",\n `getCommunityPages communitiesPages '${communitiesPages}' invalid`,\n );\n const pages: CommunityPage[] = [];\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n // community has no pages\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n // 'return pages' to ignore it for now\n if (!firstPageCid) {\n return pages;\n }\n const firstPage = communitiesPages[getCommunityPageStoreKey(firstPageCid, pageType, accountId)];\n if (!firstPage) {\n return pages;\n }\n pages.push(firstPage);\n while (true) {\n const nextCid = pages[pages.length - 1]?.nextCid;\n const nextPageKey = nextCid && getCommunityPageStoreKey(nextCid, pageType, accountId);\n const communityPage = nextPageKey && communitiesPages[nextPageKey];\n if (!communityPage) {\n return pages;\n }\n pages.push(communityPage);\n }\n};\n\nexport const getCommunityFirstPageCid = (\n community: Community,\n sortType: string,\n pageType = \"posts\",\n) => {\n assert(\n community && typeof community === \"object\",\n `getCommunityFirstPageCid community '${community}' invalid`,\n );\n assert(\n sortType && typeof sortType === \"string\",\n `getCommunityFirstPageCid sortType '${sortType}' invalid`,\n );\n // community has preloaded posts for sort type\n if (community[pageType]?.pages?.[sortType]?.comments) {\n return community[pageType]?.pages?.[sortType]?.nextCid;\n }\n return community[pageType]?.pageCids?.[sortType];\n\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n};\n\n// reset store in between tests\nconst originalState = communitiesPagesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesPagesStore = async () => {\n fetchPagePending = {};\n for (const accountId in fetchPageCommunities) {\n delete fetchPageCommunities[accountId];\n }\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n // destroy all component subscriptions to the store\n communitiesPagesStore.destroy();\n // restore original state\n communitiesPagesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesPagesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear();\n await resetCommunitiesPagesStore();\n};\n\nexport default communitiesPagesStore;\n"]}
|
|
1
|
+
{"version":3,"file":"communities-pages-store.js","sourceRoot":"","sources":["../../../src/stores/communities-pages/communities-pages-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,2DAA2D;AAC3D,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAShE,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,gBAAsC,MAAM,gBAAgB,CAAC;AACpE,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,wBAAwB,GAAG,cAAc,CAAC,cAAc,CAAC;IAC7D,IAAI,EAAE,sCAAsC;IAC5C,IAAI,EAAE,GAAG;CACV,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,CAAC,OAAe,EAAE,Q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;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,qCAAqC,GAAG,GAAS,EAAE;IAC9D,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC9F,MAAM,0BAA0B,EAAE,CAAC;AACrC,CAAC,CAAA,CAAC;AAEF,eAAe,qBAAqB,CAAC","sourcesContent":["import utils from \"../../lib/utils\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\n// include communities pages store with feeds for debugging\nexport const log = Logger(\"bitsocial-react-hooks:feeds:stores\");\nimport {\n Community,\n CommunityPage,\n CommunitiesPages,\n Account,\n Comment,\n Comments,\n} from \"../../types\";\nimport accountsStore from \"../accounts\";\nimport communitiesStore, { CommunitiesState } from \"../communities\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport createStore from \"zustand\";\nimport assert from \"assert\";\nimport {\n createPkcCommunity,\n getPkcCreateCommunity,\n normalizeCommentCommunityAddress,\n} from \"../../lib/pkc-compat\";\nimport { resolvePostSortType } from \"../../lib/page-sorts\";\n\nconst communitiesPagesDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-communitiesPages\",\n size: 500,\n});\n\nconst getCommunityPageStoreKey = (pageCid: string, pageType: string, accountId?: string) => {\n if (pageType === \"modQueue\") {\n assert(\n accountId && typeof accountId === \"string\",\n `getCommunityPageStoreKey accountId '${accountId}' invalid for modQueue`,\n );\n return `${accountId}:${pageCid}`;\n }\n return pageCid;\n};\n\n/** Freshness for comparison: max(updatedAt, timestamp, 0). Used to decide add vs replace per CID. Exported for coverage. */\nexport const getCommentFreshness = (comment: Comment | undefined): number =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\n// reset all event listeners in between tests\nconst listeners: any = [];\n\ntype CommunitiesPagesState = {\n communitiesPages: CommunitiesPages;\n comments: Comments;\n addNextCommunityPageToStore: Function;\n invalidateCommunityPages: Function;\n addCommunityPageCommentsToStore: Function;\n};\n\nconst communitiesPagesStore = createStore<CommunitiesPagesState>(\n (setState: Function, getState: Function) => ({\n // TODO: eventually clear old pages and comments from memory\n communitiesPages: {},\n comments: {},\n\n addNextCommunityPageToStore: async (\n community: Community,\n sortType: string | undefined,\n account: Account,\n modQueue?: string[],\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.addNextCommunityPageToStore community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `communitiesPagesStore.addNextCommunityPageToStore sortType '${sortType}' invalid`,\n );\n assert(\n typeof getPkcCreateCommunity(account?.pkc) === \"function\",\n `communitiesPagesStore.addNextCommunityPageToStore account '${account}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.addNextCommunityPageToStore modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // check the preloaded posts on community.posts.pages first, then the community.posts.pageCids\n const communityFirstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!communityFirstPageCid) {\n log(\n `communitiesPagesStore.addNextCommunityPageToStore community '${community?.address}' sortType '${sortType}' no communityFirstPageCid`,\n );\n return;\n }\n\n // all communities pages in store\n const { communitiesPages } = getState();\n // only specific pages of the community+sortType\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n account.id,\n );\n\n // if no pages exist yet, add the first page\n let pageCidToAdd: string;\n if (!communityPages.length) {\n pageCidToAdd = communityFirstPageCid;\n } else {\n const nextCid = communityPages[communityPages.length - 1]?.nextCid;\n // if last nextCid is undefined, reached end of pages\n if (!nextCid) {\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore no more pages\", {\n communityAddress: community.address,\n sortType,\n account,\n });\n return;\n }\n\n pageCidToAdd = nextCid;\n }\n\n // page is already added or pending\n const pageStoreKeyToAdd = getCommunityPageStoreKey(pageCidToAdd, pageType, account.id);\n if (communitiesPages[pageStoreKeyToAdd] || fetchPagePending[pageStoreKeyToAdd]) {\n return;\n }\n\n fetchPagePending[pageStoreKeyToAdd] = true;\n let page: CommunityPage;\n try {\n page = await fetchPage(pageCidToAdd, community.address, account, pageType);\n log.trace(\"communitiesPagesStore.addNextCommunityPageToStore community.posts.getPage\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n account,\n });\n } catch (e) {\n throw e;\n } finally {\n fetchPagePending[pageStoreKeyToAdd] = false;\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(page);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n if (pageType !== \"modQueue\") {\n for (const comment of flattenedComments) {\n const normalizedComment = normalizeCommentCommunityAddress(comment) as Comment;\n const existing = comments[normalizedComment.cid];\n if (\n normalizedComment.cid &&\n (!existing || getCommentFreshness(normalizedComment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[normalizedComment.cid] = normalizedComment;\n hasNewComments = true;\n }\n }\n }\n\n setState(({ communitiesPages, comments }: any) => {\n const newState: any = {\n communitiesPages: { ...communitiesPages, [pageStoreKeyToAdd]: page },\n };\n if (hasNewComments) {\n newState.comments = { ...comments, ...newComments };\n }\n return newState;\n });\n log(\"communitiesPagesStore.addNextCommunityPageToStore\", {\n pageCid: pageCidToAdd,\n communityAddress: community.address,\n sortType,\n page,\n account,\n });\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n for (const comment of flattenedComments) {\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(\n normalizeCommentCommunityAddress(comment) as Comment,\n )\n .catch((error: unknown) =>\n log.error(\n \"communitiesPagesStore.addNextCommunityPageToStore addCidToAccountComment error\",\n { comment, error },\n ),\n );\n }\n },\n\n invalidateCommunityPages: async (\n community: Community,\n sortType: string | undefined,\n modQueue?: string[],\n accountId?: string,\n ) => {\n assert(\n community?.address && typeof community?.address === \"string\",\n `communitiesPagesStore.invalidateCommunityPages community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `communitiesPagesStore.invalidateCommunityPages sortType '${sortType}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `communitiesPagesStore.invalidateCommunityPages modQueue '${modQueue}' invalid`,\n );\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, for now only use first in array\n // TODO: fix 'sortType' is not accurate variable name when pageType is 'modQueue'\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n if (!firstPageCid) {\n return;\n }\n\n const { communitiesPages } = getState();\n const firstPageKey = getCommunityPageStoreKey(firstPageCid, pageType, accountId);\n const pageKeysToInvalidate = new Set<string>([firstPageKey]);\n let nextPageCid = communitiesPages[firstPageKey]?.nextCid;\n while (nextPageCid) {\n const nextPageKey = getCommunityPageStoreKey(nextPageCid, pageType, accountId);\n pageKeysToInvalidate.add(nextPageKey);\n nextPageCid = communitiesPages[nextPageKey]?.nextCid;\n }\n\n await Promise.all(\n [...pageKeysToInvalidate].map((pageKey) => communitiesPagesDatabase.removeItem(pageKey)),\n );\n\n setState(({ communitiesPages }: any) => {\n const nextCommunitiesPages = { ...communitiesPages };\n for (const pageKey of pageKeysToInvalidate) {\n delete nextCommunitiesPages[pageKey];\n }\n return { communitiesPages: nextCommunitiesPages };\n });\n },\n\n // communities contain preloaded pages, those page comments must be added separately\n addCommunityPageCommentsToStore: (community: Community) => {\n if (!community.posts?.pages) {\n return;\n }\n\n // find new comments in the page\n const flattenedComments = utils.flattenCommentsPages(community.posts.pages);\n const { comments } = getState();\n let hasNewComments = false;\n const newComments: Comments = {};\n for (const comment of flattenedComments) {\n const existing = comments[comment.cid];\n if (\n comment.cid &&\n (!existing || getCommentFreshness(comment) > getCommentFreshness(existing))\n ) {\n // don't clone the comment to save memory, comments remain a pointer to the page object\n newComments[comment.cid] = comment;\n hasNewComments = true;\n }\n }\n\n if (!hasNewComments) {\n return;\n }\n\n setState(({ comments }: any) => {\n return { comments: { ...comments, ...newComments } };\n });\n log(\"communitiesPagesStore.addCommunityPageCommentsToStore\", { community, newComments });\n },\n }),\n);\n\n// set clients states on communities store so the frontend can display it, dont persist in db because a reload cancels updating\nconst onCommunityPostsClientsStateChange =\n (communityAddress: string) =>\n (clientState: string, clientType: string, sortType: string, clientUrl: string) => {\n communitiesStore.setState((state: CommunitiesState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.communities[communityAddress]) {\n return {};\n }\n const client = { state: clientState };\n const community = { ...state.communities[communityAddress] };\n community.posts = { ...community.posts };\n community.posts.clients = { ...community.posts.clients };\n community.posts.clients[clientType] = { ...community.posts.clients[clientType] };\n community.posts.clients[clientType][sortType] = {\n ...community.posts.clients[clientType][sortType],\n };\n community.posts.clients[clientType][sortType][clientUrl] = client;\n return { communities: { ...state.communities, [community.address]: community } };\n });\n };\n\nconst fetchPageCommunities: {\n [accountId: string]: { pkc: any; communities: { [communityAddress: string]: any } };\n} = {}; // cache created community clients per account because creating them can be slow\nlet fetchPagePending: { [key: string]: boolean } = {};\nconst fetchPage = async (\n pageCid: string,\n communityAddress: string,\n account: Account,\n pageType: string,\n) => {\n // community page is cached\n const pageStoreKey = getCommunityPageStoreKey(pageCid, pageType, account.id);\n const cachedCommunityPage = await communitiesPagesDatabase.getItem(pageStoreKey);\n if (cachedCommunityPage) {\n return cachedCommunityPage;\n }\n if (!fetchPageCommunities[account.id] || fetchPageCommunities[account.id].pkc !== account.pkc) {\n fetchPageCommunities[account.id] = { pkc: account.pkc, communities: {} };\n }\n const accountCommunities = fetchPageCommunities[account.id].communities;\n if (!accountCommunities[communityAddress]) {\n accountCommunities[communityAddress] = await createPkcCommunity(account.pkc, {\n address: communityAddress,\n });\n listeners.push(accountCommunities[communityAddress]);\n\n // set clients states on communities store so the frontend can display it\n utils.pageClientsOnStateChange(\n accountCommunities[communityAddress][pageType]?.clients,\n onCommunityPostsClientsStateChange(communityAddress),\n );\n }\n\n const onError = (error: any) =>\n log.error(\n `communitiesPagesStore community '${communityAddress}' failed community.posts.getPage page cid '${pageCid}':`,\n error,\n );\n const fetchedCommunityPage = await utils.retryInfinity(\n () => accountCommunities[communityAddress][pageType].getPage({ cid: pageCid }),\n { onError },\n );\n await communitiesPagesDatabase.setItem(pageStoreKey, utils.clone(fetchedCommunityPage));\n return fetchedCommunityPage;\n};\n\n/**\n * Util function to get all pages in the store for a\n * specific community+sortType using `CommunityPage.nextCid`\n */\nexport const getCommunityPages = (\n community: Community,\n sortType: string | undefined,\n communitiesPages: CommunitiesPages,\n pageType: string,\n accountId?: string,\n) => {\n assert(\n communitiesPages && typeof communitiesPages === \"object\",\n `getCommunityPages communitiesPages '${communitiesPages}' invalid`,\n );\n const pages: CommunityPage[] = [];\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n // community has no pages\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n // 'return pages' to ignore it for now\n if (!firstPageCid) {\n return pages;\n }\n const firstPage = communitiesPages[getCommunityPageStoreKey(firstPageCid, pageType, accountId)];\n if (!firstPage) {\n return pages;\n }\n pages.push(firstPage);\n while (true) {\n const nextCid = pages[pages.length - 1]?.nextCid;\n const nextPageKey = nextCid && getCommunityPageStoreKey(nextCid, pageType, accountId);\n const communityPage = nextPageKey && communitiesPages[nextPageKey];\n if (!communityPage) {\n return pages;\n }\n pages.push(communityPage);\n }\n};\n\nexport const getCommunityFirstPageCid = (\n community: Community,\n sortType: string | undefined,\n pageType = \"posts\",\n) => {\n assert(\n community && typeof community === \"object\",\n `getCommunityFirstPageCid community '${community}' invalid`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `getCommunityFirstPageCid sortType '${sortType}' invalid`,\n );\n const resolvedSortType =\n pageType === \"posts\" ? resolvePostSortType(community, sortType) : sortType;\n if (!resolvedSortType) {\n return;\n }\n // community has preloaded posts for sort type\n if (community[pageType]?.pages?.[resolvedSortType]?.comments) {\n return community[pageType]?.pages?.[resolvedSortType]?.nextCid;\n }\n return community[pageType]?.pageCids?.[resolvedSortType];\n\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n};\n\n// reset store in between tests\nconst originalState = communitiesPagesStore.getState();\n// async function because some stores have async init\nexport const resetCommunitiesPagesStore = async () => {\n fetchPagePending = {};\n for (const accountId in fetchPageCommunities) {\n delete fetchPageCommunities[accountId];\n }\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n listeners.length = 0;\n // destroy all component subscriptions to the store\n communitiesPagesStore.destroy();\n // restore original state\n communitiesPagesStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommunitiesPagesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear();\n await resetCommunitiesPagesStore();\n};\n\nexport default communitiesPagesStore;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feed-sorter.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"feed-sorter.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":";qBA8IwB,MAAM,GAAG,SAAS,QAAQ,GAAG,EAAE;;AAavD,wBAAwB"}
|
|
@@ -103,33 +103,39 @@ const sortByBest = (feed) => {
|
|
|
103
103
|
.sort((a, b) => n(a.timestamp) - n(b.timestamp))
|
|
104
104
|
.sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));
|
|
105
105
|
};
|
|
106
|
+
const sorters = {
|
|
107
|
+
new: sortByNew,
|
|
108
|
+
newFlat: sortByNew,
|
|
109
|
+
hot: sortByHot,
|
|
110
|
+
top: sortByTop,
|
|
111
|
+
topHour: sortByTop,
|
|
112
|
+
topDay: sortByTop,
|
|
113
|
+
topWeek: sortByTop,
|
|
114
|
+
topMonth: sortByTop,
|
|
115
|
+
topYear: sortByTop,
|
|
116
|
+
topAll: sortByTop,
|
|
117
|
+
controversial: sortByControversial,
|
|
118
|
+
controversialHour: sortByControversial,
|
|
119
|
+
controversialDay: sortByControversial,
|
|
120
|
+
controversialWeek: sortByControversial,
|
|
121
|
+
controversialMonth: sortByControversial,
|
|
122
|
+
controversialYear: sortByControversial,
|
|
123
|
+
controversialAll: sortByControversial,
|
|
124
|
+
active: sortByActive,
|
|
125
|
+
old: sortByOld,
|
|
126
|
+
oldFlat: sortByOld,
|
|
127
|
+
best: sortByBest,
|
|
128
|
+
};
|
|
106
129
|
const sort = (sortType, feed) => {
|
|
130
|
+
const sorter = sortType && sorters[sortType];
|
|
131
|
+
if (!sorter) {
|
|
132
|
+
return feed;
|
|
133
|
+
}
|
|
107
134
|
// NOTE: pinned posts are not sorted, maybe in a future version we can sort them based on something
|
|
108
135
|
// NOTE: with useReplies({flat: true}), nested pins are at the top, unclear yet what we should do with them
|
|
109
136
|
const pinnedPosts = feed.filter((post) => post.pinned);
|
|
110
137
|
feed = feed.filter((post) => !post.pinned);
|
|
111
|
-
|
|
112
|
-
return [...pinnedPosts, ...sortByNew(feed)];
|
|
113
|
-
}
|
|
114
|
-
if (sortType.match("hot")) {
|
|
115
|
-
return [...pinnedPosts, ...sortByHot(feed)];
|
|
116
|
-
}
|
|
117
|
-
if (sortType.match("top")) {
|
|
118
|
-
return [...pinnedPosts, ...sortByTop(feed)];
|
|
119
|
-
}
|
|
120
|
-
if (sortType.match("controversial")) {
|
|
121
|
-
return [...pinnedPosts, ...sortByControversial(feed)];
|
|
122
|
-
}
|
|
123
|
-
if (sortType.match("active")) {
|
|
124
|
-
return [...pinnedPosts, ...sortByActive(feed)];
|
|
125
|
-
}
|
|
126
|
-
if (sortType.match("old")) {
|
|
127
|
-
return [...pinnedPosts, ...sortByOld(feed)];
|
|
128
|
-
}
|
|
129
|
-
if (sortType.match("best")) {
|
|
130
|
-
return [...pinnedPosts, ...sortByBest(feed)];
|
|
131
|
-
}
|
|
132
|
-
throw Error(`feedsStore feedSorter sort type '${sortType}' doesn't exist`);
|
|
138
|
+
return [...pinnedPosts, ...sorter(feed)];
|
|
133
139
|
};
|
|
134
140
|
export default { sort };
|
|
135
141
|
//# sourceMappingURL=feed-sorter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feed-sorter.js","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,CAAC,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtF,MAAM,SAAS,GAAG,CAAC,IAAW,EAAE,EAAE;IAChC,MAAM,UAAU,GAA8B,EAAE,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC;QACzD,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI;SACR,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;SAC/C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC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number.isNaN(v) ? v : 0);\n\nconst sortByTop = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const score = post.upvoteCount - post.downvoteCount || 0;\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by controversial is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n */\nconst sortByControversial = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n let upvoteCount = n(post.upvoteCount) + 1; // reddit initial upvotes is 1, pkc is 0\n const downvoteCount = n(post.downvoteCount);\n const magnitude = upvoteCount + downvoteCount;\n const balance =\n upvoteCount > downvoteCount\n ? downvoteCount / upvoteCount\n : upvoteCount / (downvoteCount || 1);\n postScores[post.cid] = Math.pow(magnitude, balance);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by hot is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n * Note: a sub with not many posts will be given very high priority\n */\nconst sortByHot = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n const round = (number: number, decimalPlaces: number) => {\n const factorOfTen = Math.pow(10, decimalPlaces);\n return Math.round(number * factorOfTen) / factorOfTen;\n };\n for (const post of feed) {\n let score = n(post.upvoteCount) - n(post.downvoteCount) + 1;\n const order = Math.log10(Math.max(Math.abs(score), 1));\n let sign = 0;\n if (score > 0) sign = 1;\n else if (score < 0) sign = -1;\n const seconds = n(post.timestamp) - 1134028003;\n postScores[post.cid] = round(sign * order + seconds / 45000, 7);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by new is made using relative timestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their timestamp\n */\nconst sortByNew = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(b.timestamp) - n(a.timestamp));\n\n/**\n * Sort by active is made using relative lastReplyTimestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their lastReplyTimestamp\n */\nconst sortByActive = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort(\n (a, b) => n(b.lastReplyTimestamp ?? b.timestamp) - n(a.lastReplyTimestamp ?? a.timestamp),\n );\n\nconst sortByOld = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(a.timestamp) - n(b.timestamp));\n\n// \"best\" sort from reddit replies\n// https://web.archive.org/web/20100305052116/http://blog.reddit.com/2009/10/reddits-new-comment-sorting-system.html\n// https://medium.com/hacking-and-gonzo/how-reddit-ranking-algorithms-work-ef111e33d0d9\n// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html\n// https://github.com/reddit-archive/reddit/blob/753b17407e9a9dca09558526805922de24133d53/r2/r2/lib/db/_sorts.pyx#L70\nconst sortByBest = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const upvoteCount = n(post.upvoteCount) + 1;\n const downvoteCount = n(post.downvoteCount);\n const total = upvoteCount + downvoteCount;\n const score =\n total === 0\n ? 0\n : (() => {\n const z = 1.281551565545;\n const p = upvoteCount / total;\n const left = p + (1 / (2 * total)) * z * z;\n const right = z * Math.sqrt((p * (1 - p)) / total + (z * z) / (4 * total * total));\n const under = 1 + (1 / total) * z * z;\n return (left - right) / under;\n })();\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(a.timestamp) - n(b.timestamp))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\nconst sort = (sortType: string, feed: any[]) => {\n // NOTE: pinned posts are not sorted, maybe in a future version we can sort them based on something\n // NOTE: with useReplies({flat: true}), nested pins are at the top, unclear yet what we should do with them\n const pinnedPosts = feed.filter((post) => post.pinned);\n\n feed = feed.filter((post) => !post.pinned);\n if (sortType.match(\"new\")) {\n return [...pinnedPosts, ...sortByNew(feed)];\n }\n if (sortType.match(\"hot\")) {\n return [...pinnedPosts, ...sortByHot(feed)];\n }\n if (sortType.match(\"top\")) {\n return [...pinnedPosts, ...sortByTop(feed)];\n }\n if (sortType.match(\"controversial\")) {\n return [...pinnedPosts, ...sortByControversial(feed)];\n }\n if (sortType.match(\"active\")) {\n return [...pinnedPosts, ...sortByActive(feed)];\n }\n if (sortType.match(\"old\")) {\n return [...pinnedPosts, ...sortByOld(feed)];\n }\n if (sortType.match(\"best\")) {\n return [...pinnedPosts, ...sortByBest(feed)];\n }\n throw Error(`feedsStore feedSorter sort type '${sortType}' doesn't exist`);\n};\n\nexport default { sort };\n"]}
|
|
1
|
+
{"version":3,"file":"feed-sorter.js","sourceRoot":"","sources":["../../../src/stores/feeds/feed-sorter.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,CAAC,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtF,MAAM,SAAS,GAAG,CAAC,IAAW,EAAE,EAAE;IAChC,MAAM,UAAU,GAA8B,EAAE,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,aAAa,IAAI,CAAC,CAAC;QACzD,UAA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AAS;IACd,OAAO,EAAE,SAAS;IAClB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,SAAS;IACnB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IACjB,aAAa,EAAE,mBAAmB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,mBAAmB;IACrC,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,mBAAmB;IACvC,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,mBAAmB;IACrC,MAAM,EAAE,YAAY;IACpB,GAAG,EAAE,SAAS;IACd,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,UAAU;CACjB,CAAC;AAEF,MAAM,IAAI,GAAG,CAAC,QAA4B,EAAE,IAAW,EAAE,EAAE;IACzD,MAAM,MAAM,GAAG,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,mGAAmG;IACnG,2GAA2G;IAC3G,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEvD,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,WAAW,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF,eAAe,EAAE,IAAI,EAAE,CAAC","sourcesContent":["/** Single fallback for numeric values to reduce Istanbul branch sites */\nconst n = (v: unknown): number => (typeof v === \"number\" && !Number.isNaN(v) ? v : 0);\n\nconst sortByTop = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const score = post.upvoteCount - post.downvoteCount || 0;\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by controversial is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n */\nconst sortByControversial = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n let upvoteCount = n(post.upvoteCount) + 1; // reddit initial upvotes is 1, pkc is 0\n const downvoteCount = n(post.downvoteCount);\n const magnitude = upvoteCount + downvoteCount;\n const balance =\n upvoteCount > downvoteCount\n ? downvoteCount / upvoteCount\n : upvoteCount / (downvoteCount || 1);\n postScores[post.cid] = Math.pow(magnitude, balance);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by hot is made using relative score, to encourage small communities to grow\n * and to not incentivize communities to inflate their vote counts\n * Note: a sub with not many posts will be given very high priority\n */\nconst sortByHot = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n const round = (number: number, decimalPlaces: number) => {\n const factorOfTen = Math.pow(10, decimalPlaces);\n return Math.round(number * factorOfTen) / factorOfTen;\n };\n for (const post of feed) {\n let score = n(post.upvoteCount) - n(post.downvoteCount) + 1;\n const order = Math.log10(Math.max(Math.abs(score), 1));\n let sign = 0;\n if (score > 0) sign = 1;\n else if (score < 0) sign = -1;\n const seconds = n(post.timestamp) - 1134028003;\n postScores[post.cid] = round(sign * order + seconds / 45000, 7);\n }\n return feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\n/**\n * Sort by new is made using relative timestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their timestamp\n */\nconst sortByNew = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(b.timestamp) - n(a.timestamp));\n\n/**\n * Sort by active is made using relative lastReplyTimestamp score, to encourage small communities to grow\n * and to not incentivize communities to inflate their lastReplyTimestamp\n */\nconst sortByActive = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.timestamp) - n(a.timestamp))\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort(\n (a, b) => n(b.lastReplyTimestamp ?? b.timestamp) - n(a.lastReplyTimestamp ?? a.timestamp),\n );\n\nconst sortByOld = (feed: any[]) =>\n feed\n .sort((a, b) => n(b.upvoteCount) - n(a.upvoteCount))\n .sort((a, b) => n(a.timestamp) - n(b.timestamp));\n\n// \"best\" sort from reddit replies\n// https://web.archive.org/web/20100305052116/http://blog.reddit.com/2009/10/reddits-new-comment-sorting-system.html\n// https://medium.com/hacking-and-gonzo/how-reddit-ranking-algorithms-work-ef111e33d0d9\n// http://www.evanmiller.org/how-not-to-sort-by-average-rating.html\n// https://github.com/reddit-archive/reddit/blob/753b17407e9a9dca09558526805922de24133d53/r2/r2/lib/db/_sorts.pyx#L70\nconst sortByBest = (feed: any[]) => {\n const postScores: { [key: string]: number } = {};\n for (const post of feed) {\n const upvoteCount = n(post.upvoteCount) + 1;\n const downvoteCount = n(post.downvoteCount);\n const total = upvoteCount + downvoteCount;\n const score =\n total === 0\n ? 0\n : (() => {\n const z = 1.281551565545;\n const p = upvoteCount / total;\n const left = p + (1 / (2 * total)) * z * z;\n const right = z * Math.sqrt((p * (1 - p)) / total + (z * z) / (4 * total * total));\n const under = 1 + (1 / total) * z * z;\n return (left - right) / under;\n })();\n postScores[post.cid] = score;\n }\n return feed\n .sort((a, b) => n(a.timestamp) - n(b.timestamp))\n .sort((a, b) => n(postScores[b.cid]) - n(postScores[a.cid]));\n};\n\nconst sorters: Record<string, (feed: any[]) => any[]> = {\n new: sortByNew,\n newFlat: sortByNew,\n hot: sortByHot,\n top: sortByTop,\n topHour: sortByTop,\n topDay: sortByTop,\n topWeek: sortByTop,\n topMonth: sortByTop,\n topYear: sortByTop,\n topAll: sortByTop,\n controversial: sortByControversial,\n controversialHour: sortByControversial,\n controversialDay: sortByControversial,\n controversialWeek: sortByControversial,\n controversialMonth: sortByControversial,\n controversialYear: sortByControversial,\n controversialAll: sortByControversial,\n active: sortByActive,\n old: sortByOld,\n oldFlat: sortByOld,\n best: sortByBest,\n};\n\nconst sort = (sortType: string | undefined, feed: any[]) => {\n const sorter = sortType && sorters[sortType];\n if (!sorter) {\n return feed;\n }\n // NOTE: pinned posts are not sorted, maybe in a future version we can sort them based on something\n // NOTE: with useReplies({flat: true}), nested pins are at the top, unclear yet what we should do with them\n const pinnedPosts = feed.filter((post) => post.pinned);\n\n feed = feed.filter((post) => !post.pinned);\n return [...pinnedPosts, ...sorter(feed)];\n};\n\nexport default { sort };\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;
|
|
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;AAgCrB,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,yEA+Vb,CAAC;AAuSJ,eAAO,MAAM,eAAe,qBAsB3B,CAAC;AAGF,eAAO,MAAM,0BAA0B,qBAGtC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|