@bitsocial/bitsocial-react-hooks 0.1.65 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +49 -11
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +34 -1
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +2 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.js +17 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -1
- package/dist/lib/validator.d.ts.map +1 -1
- package/dist/lib/validator.js +2 -0
- package/dist/lib/validator.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts +2 -2
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +127 -43
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts +4 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +241 -33
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/feeds/feeds-store.d.ts +2 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
- package/dist/stores/feeds/feeds-store.js +97 -2
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
## [0.2.1](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.2.0...v0.2.1) (2026-11-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **accounts:** let clients rebuild a comment's options before its automatic republish ([#164](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/164)) ([4dae767](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/4dae767bbb8ca1bbf40318fb94e4ee5a7ac64f91))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# [0.2.0](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.65...v0.2.0) (2026-11-04)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Performance Improvements
|
|
14
|
+
|
|
15
|
+
* **communities:** stop community updates nothing uses ([0a83c75](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/0a83c75ce22b23a6789ab1524c39b593733288c5))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
* **communities:** a loaded community no longer keeps updating forever. It stops 2 minutes after the last mounted useCommunity, useCommunities, useCommunityStats, useCommunitiesStates, useAccountCommunities, useFeed or useBufferedFeeds using it unmounts, and restarts when one mounts again. Code that reads the stores directly or uses onlyIfCached gets the last stored record of a stopped community: mount one of those hooks to keep it updating, or call useFeed().reset() for a fresh record. Apps that judge a community offline by the age of updatedAt should measure that age at lastSuccessfulFetchAt while syncStatus.stoppedUntilUsed is set or useCommunity reports syncState loading after a restart, so a community that was online when it stopped does not flash offline.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
1
24
|
## [0.1.65](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.64...v0.1.65) (2026-10-31)
|
|
2
25
|
|
|
3
26
|
|
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ corepack yarn install
|
|
|
82
82
|
corepack yarn build
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
Read [
|
|
85
|
+
Read the [contributing guide](CONTRIBUTING.md) before opening a pull request, then [testing and development](docs/testing.md) and [verification](docs/agent-playbooks/verification.md) for focused checks. Keep API examples aligned with the public exports and types; after documentation changes, run `corepack yarn llms:generate`.
|
|
86
86
|
|
|
87
87
|
## License
|
|
88
88
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities.d.ts","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,cAAc,
|
|
1
|
+
{"version":3,"file":"communities.d.ts","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,cAAc,EAEd,kCAAkC,EAClC,iCAAiC,EACjC,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,UAAU,CAAC;AA2ClB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,kBAAkB,CAmJ9E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,uBAAuB,CAyF7F;AAeD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAsGpF;AAGD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,YAqBtD;AAED;;;;GAIG;AAEH,wBAAgB,2BAA2B,CACzC,OAAO,CAAC,EAAE,kCAAkC,GAC3C,iCAAiC,CAgGnC;AAGD,eAAO,MAAM,uBAAuB,GAClC,kBAAkB,MAAM,EACxB,gBAAgB,cAAc,iBAe/B,CAAC"}
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { useEffect, useState, useMemo } from "react";
|
|
10
|
+
import { useEffect, useState, useMemo, useRef } from "react";
|
|
11
11
|
import { useAccount } from "./accounts/index.js";
|
|
12
12
|
import validator from "../lib/validator.js";
|
|
13
13
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
@@ -21,6 +21,7 @@ import useAccountsStore from "../stores/accounts/index.js";
|
|
|
21
21
|
import shallow from "zustand/shallow";
|
|
22
22
|
import { getChainProviders, getPkcCommunityAddresses } from "../lib/pkc-compat.js";
|
|
23
23
|
import { getCommunityRefKey, getUniqueSortedCommunityRefs } from "../lib/community-ref.js";
|
|
24
|
+
let communityAutoUpdateSubscriptionCount = 0;
|
|
24
25
|
const parseMaybeJson = (value) => (typeof value === "string" ? JSON.parse(value) : value);
|
|
25
26
|
const tryParseMaybeJson = (value) => {
|
|
26
27
|
try {
|
|
@@ -54,7 +55,7 @@ const parseFetchedCommunityStats = (fetchedCid) => {
|
|
|
54
55
|
export function useCommunity(options) {
|
|
55
56
|
assert(!options || typeof options === "object", `useCommunity options argument '${options}' not an object`);
|
|
56
57
|
const opts = options !== null && options !== void 0 ? options : {};
|
|
57
|
-
const { community: communityInput, accountName, onlyIfCached } = opts;
|
|
58
|
+
const { community: communityInput, accountName, onlyIfCached, autoUpdate = true } = opts;
|
|
58
59
|
const account = useAccount({ accountName });
|
|
59
60
|
const accountId = (account === null || account === void 0 ? void 0 : account.id) || "";
|
|
60
61
|
validator.validateUseCommunityArguments({
|
|
@@ -65,6 +66,9 @@ export function useCommunity(options) {
|
|
|
65
66
|
const communityKey = communityInput ? getCommunityRefKey(communityInput) : "";
|
|
66
67
|
const storedCommunity = useCommunitiesStore((state) => state.communities[communityKey]);
|
|
67
68
|
const addCommunityToStore = useCommunitiesStore((state) => state.addCommunityToStore);
|
|
69
|
+
const startCommunityAutoUpdate = useCommunitiesStore((state) => state.startCommunityAutoUpdate);
|
|
70
|
+
const stopCommunityAutoUpdate = useCommunitiesStore((state) => state.stopCommunityAutoUpdate);
|
|
71
|
+
const autoUpdateSubscriptionId = useRef(`useCommunity-${++communityAutoUpdateSubscriptionCount}`);
|
|
68
72
|
const errors = useCommunitiesStore((state) => state.errors[communityKey]);
|
|
69
73
|
const syncStatus = useCommunitiesStore((state) => state.syncStatuses[communityKey]);
|
|
70
74
|
const communityEditSummary = useAccountsStore((state) => {
|
|
@@ -84,14 +88,24 @@ export function useCommunity(options) {
|
|
|
84
88
|
}
|
|
85
89
|
});
|
|
86
90
|
useEffect(() => {
|
|
87
|
-
if (!communityInput || !account) {
|
|
91
|
+
if (!communityInput || !account || onlyIfCached) {
|
|
88
92
|
return;
|
|
89
93
|
}
|
|
90
|
-
if (!
|
|
91
|
-
//
|
|
92
|
-
|
|
94
|
+
if (!autoUpdate) {
|
|
95
|
+
// load the community once if it isn't already in store, without keeping it updating
|
|
96
|
+
if (!storedCommunity) {
|
|
97
|
+
addCommunityToStore(communityInput, account).catch((error) => log.error("useCommunity addCommunityToStore error", { communityInput, error }));
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
93
100
|
}
|
|
94
|
-
|
|
101
|
+
// keep the community updating while mounted, it stops a grace period after the last
|
|
102
|
+
// subscriber unmounts
|
|
103
|
+
const subscriberId = autoUpdateSubscriptionId.current;
|
|
104
|
+
startCommunityAutoUpdate(communityInput, subscriberId, account).catch((error) => log.error("useCommunity startCommunityAutoUpdate error", { communityInput, error }));
|
|
105
|
+
return () => {
|
|
106
|
+
stopCommunityAutoUpdate(communityInput, subscriberId).catch((error) => log.error("useCommunity stopCommunityAutoUpdate error", { communityInput, error }));
|
|
107
|
+
};
|
|
108
|
+
}, [communityKey, account === null || account === void 0 ? void 0 : account.id, onlyIfCached, autoUpdate]);
|
|
95
109
|
if (account && communityInput) {
|
|
96
110
|
log("useCommunity", {
|
|
97
111
|
community: communityInput,
|
|
@@ -130,7 +144,14 @@ export function useCommunity(options) {
|
|
|
130
144
|
if (mergedCommunity === null || mergedCommunity === void 0 ? void 0 : mergedCommunity.updatedAt) {
|
|
131
145
|
state = "succeeded";
|
|
132
146
|
}
|
|
133
|
-
|
|
147
|
+
let syncState = (syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.syncState) || (onlyIfCached ? "stopped" : "initializing");
|
|
148
|
+
// the store stops a community once nothing uses it and this hook's effect restarts it, so the
|
|
149
|
+
// render before the effect does not report a terminal state for a community about to load
|
|
150
|
+
if ((syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.stoppedUntilUsed) && !onlyIfCached && autoUpdate && communityInput && account) {
|
|
151
|
+
syncState = "loading";
|
|
152
|
+
}
|
|
153
|
+
return useMemo(() => (Object.assign(Object.assign({}, mergedCommunity), { state,
|
|
154
|
+
syncState, hasCachedData: typeof (mergedCommunity === null || mergedCommunity === void 0 ? void 0 : mergedCommunity.updatedAt) === "number", lastFetchAttemptAt: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastFetchAttemptAt, lastSuccessfulFetchAt: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastSuccessfulFetchAt, lastRetriableError: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastRetriableError, error: errors === null || errors === void 0 ? void 0 : errors[errors.length - 1], errors: errors || [] })), [mergedCommunity, communityKey, errors, syncState, syncStatus]);
|
|
134
155
|
}
|
|
135
156
|
/**
|
|
136
157
|
* @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}
|
|
@@ -221,7 +242,7 @@ const useCommunitiesStatsStore = createStore((setState) => ({
|
|
|
221
242
|
export function useCommunities(options) {
|
|
222
243
|
assert(!options || typeof options === "object", `useCommunities options argument '${options}' not an object`);
|
|
223
244
|
const opts = options !== null && options !== void 0 ? options : {};
|
|
224
|
-
const { communities: communitiesInput, accountName, onlyIfCached } = opts;
|
|
245
|
+
const { communities: communitiesInput, accountName, onlyIfCached, autoUpdate = true } = opts;
|
|
225
246
|
const account = useAccount({ accountName });
|
|
226
247
|
validator.validateUseCommunitiesArguments({
|
|
227
248
|
communities: communitiesInput,
|
|
@@ -234,6 +255,10 @@ export function useCommunities(options) {
|
|
|
234
255
|
const communities = useCommunitiesStore((state) => communityKeys.map((communityKey) => state.communities[communityKey || ""]), shallow);
|
|
235
256
|
const communitiesErrors = useCommunitiesStore((state) => communityKeys.map((communityKey) => state.errors[communityKey || ""]), shallow);
|
|
236
257
|
const addCommunityToStore = useCommunitiesStore((state) => state.addCommunityToStore);
|
|
258
|
+
const startCommunityAutoUpdate = useCommunitiesStore((state) => state.startCommunityAutoUpdate);
|
|
259
|
+
const stopCommunityAutoUpdate = useCommunitiesStore((state) => state.stopCommunityAutoUpdate);
|
|
260
|
+
const autoUpdateSubscriptionId = useRef(`useCommunities-${++communityAutoUpdateSubscriptionCount}`);
|
|
261
|
+
// keyed by the community keys, so a new array of the same communities does not resubscribe
|
|
237
262
|
useEffect(() => {
|
|
238
263
|
if (!normalizedCommunityRefs.length || !account) {
|
|
239
264
|
return;
|
|
@@ -242,10 +267,23 @@ export function useCommunities(options) {
|
|
|
242
267
|
return;
|
|
243
268
|
}
|
|
244
269
|
const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);
|
|
270
|
+
if (!autoUpdate) {
|
|
271
|
+
// load the communities once, without keeping them updating
|
|
272
|
+
for (const communityRef of uniqueCommunityRefs) {
|
|
273
|
+
addCommunityToStore(communityRef, account).catch((error) => log.error("useCommunities addCommunityToStore error", { communityRef, error }));
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const subscriberId = autoUpdateSubscriptionId.current;
|
|
245
278
|
for (const communityRef of uniqueCommunityRefs) {
|
|
246
|
-
|
|
279
|
+
startCommunityAutoUpdate(communityRef, subscriberId, account).catch((error) => log.error("useCommunities startCommunityAutoUpdate error", { communityRef, error }));
|
|
247
280
|
}
|
|
248
|
-
|
|
281
|
+
return () => {
|
|
282
|
+
for (const communityRef of uniqueCommunityRefs) {
|
|
283
|
+
stopCommunityAutoUpdate(communityRef, subscriberId).catch((error) => log.error("useCommunities stopCommunityAutoUpdate error", { communityRef, error }));
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}, [account === null || account === void 0 ? void 0 : account.id, communityKeys.toString(), onlyIfCached, autoUpdate]);
|
|
249
287
|
if (account && normalizedCommunityRefs.length) {
|
|
250
288
|
log("useCommunities", {
|
|
251
289
|
requestedCommunities: normalizedCommunityRefs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities.js","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,yCAAyC,CAAC,CAAC;AAC9D,OAAO,MAAM,MAAM,eAAe,CAAC;AAcnC,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAExF,MAAM,cAAc,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAEnG,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAE,EAAE;IAC3C,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC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CAClD,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,EACL,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,IAAI,0CAAG,CAAC,CAAC,EAClC,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,OAAO,CACjC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,CAAC,qDAAqD,gBAAgB,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:hooks\");\nimport assert from \"../lib/assert\";\nimport {\n Community,\n CommunityStats,\n ChainProviders,\n UseResolvedCommunityAddressOptions,\n UseResolvedCommunityAddressResult,\n UseCommunityOptions,\n UseCommunityResult,\n UseCommunitiesOptions,\n UseCommunitiesResult,\n UseCommunityStatsOptions,\n UseCommunityStatsResult,\n} from \"../types\";\nimport useInterval from \"./utils/use-interval\";\nimport createStore from \"zustand\";\nimport { resolveEnsTxtRecord } from \"../lib/chain\";\nimport useCommunitiesStore from \"../stores/communities\";\nimport useAccountsStore from \"../stores/accounts\";\nimport shallow from \"zustand/shallow\";\nimport { getChainProviders, getPkcCommunityAddresses } from \"../lib/pkc-compat\";\nimport { getCommunityRefKey, getUniqueSortedCommunityRefs } from \"../lib/community-ref\";\n\nconst parseMaybeJson = (value: unknown) => (typeof value === \"string\" ? JSON.parse(value) : value);\n\nconst tryParseMaybeJson = (value: unknown) => {\n try {\n return parseMaybeJson(value);\n } catch {\n return value;\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === \"object\";\n\nconst isCommunityStatsPayload = (value: unknown): value is CommunityStats =>\n isRecord(value) &&\n (\"hourActiveUserCount\" in value || \"weekActiveUserCount\" in value || \"allPostCount\" in value);\n\nconst parseFetchedCommunityStats = (fetchedCid: unknown): CommunityStats => {\n const parsedCid = parseMaybeJson(fetchedCid);\n if (isCommunityStatsPayload(parsedCid)) {\n return parsedCid;\n }\n if (isRecord(parsedCid) && \"content\" in parsedCid) {\n const parsedContent = tryParseMaybeJson(parsedCid.content);\n if (isCommunityStatsPayload(parsedContent)) {\n return parsedContent;\n }\n }\n return parsedCid as CommunityStats;\n};\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunity(options?: UseCommunityOptions): UseCommunityResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunity options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community: communityInput, accountName, onlyIfCached } = opts;\n const account = useAccount({ accountName });\n const accountId = account?.id || \"\";\n validator.validateUseCommunityArguments({\n community: communityInput,\n communityAddress: (opts as any).communityAddress,\n account,\n });\n const communityKey = communityInput ? getCommunityRefKey(communityInput) : \"\";\n const storedCommunity = useCommunitiesStore((state: any) => state.communities[communityKey]);\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const errors = useCommunitiesStore((state: any) => state.errors[communityKey]);\n const syncStatus = useCommunitiesStore((state: any) => state.syncStatuses[communityKey]);\n const communityEditSummary = useAccountsStore((state: any) => {\n const accountEditsSummaries = state.accountsEditsSummaries[accountId] || {};\n const candidateCommunityKeys = [\n storedCommunity?.address,\n storedCommunity?.name,\n storedCommunity?.publicKey,\n communityInput?.name,\n communityInput?.publicKey,\n ];\n for (const candidateCommunityKey of candidateCommunityKeys) {\n if (\n typeof candidateCommunityKey === \"string\" &&\n accountEditsSummaries[candidateCommunityKey]\n ) {\n return accountEditsSummaries[candidateCommunityKey];\n }\n }\n });\n\n useEffect(() => {\n if (!communityInput || !account) {\n return;\n }\n if (!storedCommunity && !onlyIfCached) {\n // if community isn't already in store, add it\n addCommunityToStore(communityInput, account).catch((error: unknown) =>\n log.error(\"useCommunity addCommunityToStore error\", { communityInput, error }),\n );\n }\n }, [communityKey, account?.id]);\n\n if (account && communityInput) {\n log(\"useCommunity\", {\n community: communityInput,\n communityKey,\n storedCommunity,\n account,\n });\n }\n\n const mergedCommunity = useMemo(() => {\n if (!communityEditSummary) {\n return storedCommunity;\n }\n const localCommunityAddresses = getPkcCommunityAddresses(account?.pkc);\n const editedCommunityAddress = communityEditSummary.address?.value;\n const inputCommunityIdentifiers = [communityInput?.name, communityInput?.publicKey].filter(\n (communityIdentifier): communityIdentifier is string =>\n typeof communityIdentifier === \"string\",\n );\n if (\n !storedCommunity &&\n editedCommunityAddress &&\n !inputCommunityIdentifiers.some((communityIdentifier) =>\n localCommunityAddresses.includes(communityIdentifier),\n ) &&\n !localCommunityAddresses.includes(editedCommunityAddress)\n ) {\n return storedCommunity;\n }\n if (\n storedCommunity?.address &&\n editedCommunityAddress &&\n storedCommunity.address !== editedCommunityAddress\n ) {\n return storedCommunity;\n }\n const summaryValues = Object.fromEntries(\n Object.entries(communityEditSummary).map(([propertyName, propertySummary]: [string, any]) => [\n propertyName,\n propertySummary?.value,\n ]),\n );\n return {\n ...(storedCommunity || { address: communityInput?.name || communityInput?.publicKey }),\n ...summaryValues,\n };\n }, [account?.pkc, storedCommunity, communityInput, communityEditSummary]);\n\n let state = mergedCommunity?.updatingState || \"initializing\";\n // force succeeded even if the community is fecthing a new update\n if (mergedCommunity?.updatedAt) {\n state = \"succeeded\";\n }\n\n return useMemo(\n () => ({\n ...mergedCommunity,\n state,\n syncState: syncStatus?.syncState || (onlyIfCached ? \"stopped\" : \"initializing\"),\n hasCachedData: typeof mergedCommunity?.updatedAt === \"number\",\n lastFetchAttemptAt: syncStatus?.lastFetchAttemptAt,\n lastSuccessfulFetchAt: syncStatus?.lastSuccessfulFetchAt,\n lastRetriableError: syncStatus?.lastRetriableError,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [mergedCommunity, communityKey, errors, onlyIfCached, syncStatus],\n );\n}\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunityStats(options?: UseCommunityStatsOptions): UseCommunityStatsResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunityStats options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community, accountName, onlyIfCached } = opts;\n validator.validateUseCommunityStatsArguments({\n community,\n communityAddress: (opts as any).communityAddress,\n });\n const account = useAccount({ accountName });\n const communityKey = community ? getCommunityRefKey(community) : \"\";\n const fetchedCommunity = useCommunity({ community, onlyIfCached });\n const communityStatsCid = fetchedCommunity?.statsCid;\n const communityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.communitiesStats[communityKey],\n );\n const setCommunityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.setCommunityStats,\n );\n const [fetchError, setFetchError] = useState<Error | undefined>();\n\n useEffect(() => {\n setFetchError(undefined);\n if (!communityKey || !communityStatsCid || !account) {\n return;\n }\n let cancelled = false;\n (async () => {\n let fetchedCid;\n try {\n fetchedCid = await account.pkc.fetchCid({ cid: communityStatsCid });\n fetchedCid = parseFetchedCommunityStats(fetchedCid);\n if (cancelled) {\n return;\n }\n setCommunityStats(communityKey, fetchedCid);\n } catch (error) {\n const normalizedError =\n error instanceof Error ? error : new Error(typeof error === \"string\" ? error : \"error\");\n if (cancelled) {\n return;\n }\n setFetchError(normalizedError);\n log.error(\"useCommunityStats pkc.fetchCid error\", {\n community,\n communityKey,\n communityStatsCid,\n fetchedCommunity,\n fetchedCid,\n error: normalizedError,\n });\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [communityStatsCid, account?.id, communityKey, setCommunityStats]);\n\n if (account && communityStatsCid) {\n log(\"useCommunityStats\", {\n community,\n communityKey,\n communityStatsCid,\n communityStats,\n fetchedCommunity,\n account,\n });\n }\n\n const state =\n !communityKey || !account || !communityStatsCid\n ? \"uninitialized\"\n : fetchError\n ? \"failed\"\n : communityStats\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\n return useMemo(\n () => ({\n ...communityStats,\n state,\n error: fetchError,\n errors: fetchError ? [fetchError] : [],\n }),\n [communityStats, state, fetchError],\n );\n}\n\ntype CommunitiesStatsState = {\n communitiesStats: { [communityAddress: string]: CommunityStats };\n setCommunityStats: Function;\n};\n\nconst useCommunitiesStatsStore = createStore<CommunitiesStatsState>((setState: Function) => ({\n communitiesStats: {},\n setCommunityStats: (communityAddress: string, communityStats: CommunityStats) =>\n setState((state: CommunitiesStatsState) => ({\n communitiesStats: { ...state.communitiesStats, [communityAddress]: communityStats },\n })),\n}));\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunities(options?: UseCommunitiesOptions): UseCommunitiesResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunities options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { communities: communitiesInput, accountName, onlyIfCached } = opts;\n const account = useAccount({ accountName });\n validator.validateUseCommunitiesArguments({\n communities: communitiesInput,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n account,\n });\n const normalizedCommunityRefs = useMemo(() => communitiesInput || [], [communitiesInput]);\n const communityKeys = useMemo(\n () => normalizedCommunityRefs.map(getCommunityRefKey),\n [normalizedCommunityRefs],\n );\n const communities: (Community | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.communities[communityKey || \"\"]),\n shallow,\n );\n const communitiesErrors: (Error[] | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.errors[communityKey || \"\"]),\n shallow,\n );\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n\n useEffect(() => {\n if (!normalizedCommunityRefs.length || !account) {\n return;\n }\n if (onlyIfCached) {\n return;\n }\n const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);\n for (const communityRef of uniqueCommunityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"useCommunities addCommunityToStore error\", { communityRef, error }),\n );\n }\n }, [account?.id, communityKeys.toString(), onlyIfCached, normalizedCommunityRefs]);\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useCommunities\", {\n requestedCommunities: normalizedCommunityRefs,\n communityKeys,\n communities,\n account,\n });\n }\n\n const errors = useMemo(\n () => communitiesErrors.flatMap((communityErrors) => communityErrors || []),\n [communitiesErrors],\n );\n const hasFailedCommunity = communities.some(\n (community, index) => !community && Boolean(communitiesErrors[index]?.length),\n );\n const state = hasFailedCommunity\n ? \"failed\"\n : communities.indexOf(undefined) === -1\n ? \"succeeded\"\n : \"fetching-ipns\";\n\n return useMemo(\n () => ({\n communities,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [communities, state, errors, communityKeys.toString()],\n );\n}\n\n// TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling\n/**\n * Returns all the owner communities created by pkc-js by calling pkc.listCommunities()\n */\nexport function useListCommunities(accountName?: string) {\n const account = useAccount({ accountName });\n const [communityAddresses, setCommunityAddresses] = useState<string[]>([]);\n\n const delay = 1000;\n const immediate = true;\n useInterval(\n () => {\n const pkc = account?.pkc;\n if (!pkc) return;\n const newAddrs = getPkcCommunityAddresses(pkc);\n if (newAddrs.toString() !== communityAddresses.toString()) {\n log(\"useListCommunities\", { communityAddresses });\n setCommunityAddresses(newAddrs);\n }\n },\n delay,\n immediate,\n );\n\n return communityAddresses;\n}\n\n/**\n * @param communityAddress - The community address to resolve to a public key, e.g. 'news.eth' resolves to '12D3KooW...'.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useResolvedCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport function useResolvedCommunityAddress(\n options?: UseResolvedCommunityAddressOptions,\n): UseResolvedCommunityAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useResolvedCommunityAddress options argument '${options}' not an object`,\n );\n let { communityAddress, accountName, cache } = options ?? {};\n\n // cache by default\n if (typeof cache !== \"boolean\") {\n cache = true;\n }\n\n // poll every 15 seconds, about the duration of an eth block\n let interval = 15000;\n // no point in polling often if caching is on\n if (cache) {\n interval = 1000 * 60 * 60 * 25;\n }\n\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [resolvedAddress, setResolvedAddress] = useState<string>();\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n\n let initialState = \"initializing\";\n // before those defined, nothing can happen\n if (options && account && communityAddress) {\n initialState = \"ready\";\n }\n\n useInterval(\n () => {\n if (!account || !communityAddress) {\n setResolvedAddress(undefined);\n setState(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n return;\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!communityAddress?.includes(\".\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"not a crypto domain\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n // only support resolving '.eth' for now\n if (!communityAddress?.endsWith(\".eth\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n setState(\"resolving\");\n const res = await resolveCommunityAddress(communityAddress, chainProviders);\n setState(\"succeeded\");\n if (res !== resolvedAddress) {\n setResolvedAddress(res);\n }\n } catch (error: any) {\n setErrors([...errors, error]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n log.error(\"useResolvedCommunityAddress resolveCommunityAddress error\", {\n communityAddress,\n chainProviders,\n error,\n });\n }\n })();\n },\n interval,\n true,\n [communityAddress, chainProviders],\n );\n\n // only support ENS at the moment\n const chainProvider = chainProviders?.[\"eth\"];\n\n // log('useResolvedCommunityAddress', {communityAddress, state, errors, resolvedAddress, chainProviders})\n return {\n resolvedAddress,\n chainProvider,\n state: state || initialState,\n error: errors[errors.length - 1],\n errors,\n };\n}\n\n// NOTE: resolveCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport const resolveCommunityAddress = async (\n communityAddress: string,\n chainProviders: ChainProviders,\n) => {\n let resolvedCommunityAddress;\n if (communityAddress.endsWith(\".eth\")) {\n resolvedCommunityAddress = await resolveEnsTxtRecord(\n communityAddress,\n \"community-address\",\n \"eth\",\n chainProviders?.[\"eth\"]?.urls?.[0],\n chainProviders?.[\"eth\"]?.chainId,\n );\n } else {\n throw Error(`resolveCommunityAddress invalid communityAddress '${communityAddress}'`);\n }\n return resolvedCommunityAddress;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"communities.js","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,yCAAyC,CAAC,CAAC;AAC9D,OAAO,MAAM,MAAM,eAAe,CAAC;AAenC,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO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AI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,wBAAwB,GAAG,MAAM,mBAAmB,CAClD,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,EACL,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,IAAI,0CAAG,CAAC,CAAC,EAClC,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,OAAO,CACjC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,CAAC,qDAAqD,gBAAgB,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo, useRef } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:hooks\");\nimport assert from \"../lib/assert\";\nimport {\n Community,\n CommunityStats,\n ChainProviders,\n CommunitySyncState,\n UseResolvedCommunityAddressOptions,\n UseResolvedCommunityAddressResult,\n UseCommunityOptions,\n UseCommunityResult,\n UseCommunitiesOptions,\n UseCommunitiesResult,\n UseCommunityStatsOptions,\n UseCommunityStatsResult,\n} from \"../types\";\nimport useInterval from \"./utils/use-interval\";\nimport createStore from \"zustand\";\nimport { resolveEnsTxtRecord } from \"../lib/chain\";\nimport useCommunitiesStore from \"../stores/communities\";\nimport useAccountsStore from \"../stores/accounts\";\nimport shallow from \"zustand/shallow\";\nimport { getChainProviders, getPkcCommunityAddresses } from \"../lib/pkc-compat\";\nimport { getCommunityRefKey, getUniqueSortedCommunityRefs } from \"../lib/community-ref\";\n\nlet communityAutoUpdateSubscriptionCount = 0;\n\nconst parseMaybeJson = (value: unknown) => (typeof value === \"string\" ? JSON.parse(value) : value);\n\nconst tryParseMaybeJson = (value: unknown) => {\n try {\n return parseMaybeJson(value);\n } catch {\n return value;\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === \"object\";\n\nconst isCommunityStatsPayload = (value: unknown): value is CommunityStats =>\n isRecord(value) &&\n (\"hourActiveUserCount\" in value || \"weekActiveUserCount\" in value || \"allPostCount\" in value);\n\nconst parseFetchedCommunityStats = (fetchedCid: unknown): CommunityStats => {\n const parsedCid = parseMaybeJson(fetchedCid);\n if (isCommunityStatsPayload(parsedCid)) {\n return parsedCid;\n }\n if (isRecord(parsedCid) && \"content\" in parsedCid) {\n const parsedContent = tryParseMaybeJson(parsedCid.content);\n if (isCommunityStatsPayload(parsedContent)) {\n return parsedContent;\n }\n }\n return parsedCid as CommunityStats;\n};\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunity(options?: UseCommunityOptions): UseCommunityResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunity options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community: communityInput, accountName, onlyIfCached, autoUpdate = true } = opts;\n const account = useAccount({ accountName });\n const accountId = account?.id || \"\";\n validator.validateUseCommunityArguments({\n community: communityInput,\n communityAddress: (opts as any).communityAddress,\n account,\n });\n const communityKey = communityInput ? getCommunityRefKey(communityInput) : \"\";\n const storedCommunity = useCommunitiesStore((state: any) => state.communities[communityKey]);\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const startCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.startCommunityAutoUpdate,\n );\n const stopCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.stopCommunityAutoUpdate,\n );\n const autoUpdateSubscriptionId = useRef(`useCommunity-${++communityAutoUpdateSubscriptionCount}`);\n const errors = useCommunitiesStore((state: any) => state.errors[communityKey]);\n const syncStatus = useCommunitiesStore((state: any) => state.syncStatuses[communityKey]);\n const communityEditSummary = useAccountsStore((state: any) => {\n const accountEditsSummaries = state.accountsEditsSummaries[accountId] || {};\n const candidateCommunityKeys = [\n storedCommunity?.address,\n storedCommunity?.name,\n storedCommunity?.publicKey,\n communityInput?.name,\n communityInput?.publicKey,\n ];\n for (const candidateCommunityKey of candidateCommunityKeys) {\n if (\n typeof candidateCommunityKey === \"string\" &&\n accountEditsSummaries[candidateCommunityKey]\n ) {\n return accountEditsSummaries[candidateCommunityKey];\n }\n }\n });\n\n useEffect(() => {\n if (!communityInput || !account || onlyIfCached) {\n return;\n }\n if (!autoUpdate) {\n // load the community once if it isn't already in store, without keeping it updating\n if (!storedCommunity) {\n addCommunityToStore(communityInput, account).catch((error: unknown) =>\n log.error(\"useCommunity addCommunityToStore error\", { communityInput, error }),\n );\n }\n return;\n }\n // keep the community updating while mounted, it stops a grace period after the last\n // subscriber unmounts\n const subscriberId = autoUpdateSubscriptionId.current;\n startCommunityAutoUpdate(communityInput, subscriberId, account).catch((error: unknown) =>\n log.error(\"useCommunity startCommunityAutoUpdate error\", { communityInput, error }),\n );\n return () => {\n stopCommunityAutoUpdate(communityInput, subscriberId).catch((error: unknown) =>\n log.error(\"useCommunity stopCommunityAutoUpdate error\", { communityInput, error }),\n );\n };\n }, [communityKey, account?.id, onlyIfCached, autoUpdate]);\n\n if (account && communityInput) {\n log(\"useCommunity\", {\n community: communityInput,\n communityKey,\n storedCommunity,\n account,\n });\n }\n\n const mergedCommunity = useMemo(() => {\n if (!communityEditSummary) {\n return storedCommunity;\n }\n const localCommunityAddresses = getPkcCommunityAddresses(account?.pkc);\n const editedCommunityAddress = communityEditSummary.address?.value;\n const inputCommunityIdentifiers = [communityInput?.name, communityInput?.publicKey].filter(\n (communityIdentifier): communityIdentifier is string =>\n typeof communityIdentifier === \"string\",\n );\n if (\n !storedCommunity &&\n editedCommunityAddress &&\n !inputCommunityIdentifiers.some((communityIdentifier) =>\n localCommunityAddresses.includes(communityIdentifier),\n ) &&\n !localCommunityAddresses.includes(editedCommunityAddress)\n ) {\n return storedCommunity;\n }\n if (\n storedCommunity?.address &&\n editedCommunityAddress &&\n storedCommunity.address !== editedCommunityAddress\n ) {\n return storedCommunity;\n }\n const summaryValues = Object.fromEntries(\n Object.entries(communityEditSummary).map(([propertyName, propertySummary]: [string, any]) => [\n propertyName,\n propertySummary?.value,\n ]),\n );\n return {\n ...(storedCommunity || { address: communityInput?.name || communityInput?.publicKey }),\n ...summaryValues,\n };\n }, [account?.pkc, storedCommunity, communityInput, communityEditSummary]);\n\n let state = mergedCommunity?.updatingState || \"initializing\";\n // force succeeded even if the community is fecthing a new update\n if (mergedCommunity?.updatedAt) {\n state = \"succeeded\";\n }\n\n let syncState: CommunitySyncState =\n syncStatus?.syncState || (onlyIfCached ? \"stopped\" : \"initializing\");\n // the store stops a community once nothing uses it and this hook's effect restarts it, so the\n // render before the effect does not report a terminal state for a community about to load\n if (syncStatus?.stoppedUntilUsed && !onlyIfCached && autoUpdate && communityInput && account) {\n syncState = \"loading\";\n }\n\n return useMemo(\n () => ({\n ...mergedCommunity,\n state,\n syncState,\n hasCachedData: typeof mergedCommunity?.updatedAt === \"number\",\n lastFetchAttemptAt: syncStatus?.lastFetchAttemptAt,\n lastSuccessfulFetchAt: syncStatus?.lastSuccessfulFetchAt,\n lastRetriableError: syncStatus?.lastRetriableError,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [mergedCommunity, communityKey, errors, syncState, syncStatus],\n );\n}\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunityStats(options?: UseCommunityStatsOptions): UseCommunityStatsResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunityStats options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community, accountName, onlyIfCached } = opts;\n validator.validateUseCommunityStatsArguments({\n community,\n communityAddress: (opts as any).communityAddress,\n });\n const account = useAccount({ accountName });\n const communityKey = community ? getCommunityRefKey(community) : \"\";\n const fetchedCommunity = useCommunity({ community, onlyIfCached });\n const communityStatsCid = fetchedCommunity?.statsCid;\n const communityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.communitiesStats[communityKey],\n );\n const setCommunityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.setCommunityStats,\n );\n const [fetchError, setFetchError] = useState<Error | undefined>();\n\n useEffect(() => {\n setFetchError(undefined);\n if (!communityKey || !communityStatsCid || !account) {\n return;\n }\n let cancelled = false;\n (async () => {\n let fetchedCid;\n try {\n fetchedCid = await account.pkc.fetchCid({ cid: communityStatsCid });\n fetchedCid = parseFetchedCommunityStats(fetchedCid);\n if (cancelled) {\n return;\n }\n setCommunityStats(communityKey, fetchedCid);\n } catch (error) {\n const normalizedError =\n error instanceof Error ? error : new Error(typeof error === \"string\" ? error : \"error\");\n if (cancelled) {\n return;\n }\n setFetchError(normalizedError);\n log.error(\"useCommunityStats pkc.fetchCid error\", {\n community,\n communityKey,\n communityStatsCid,\n fetchedCommunity,\n fetchedCid,\n error: normalizedError,\n });\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [communityStatsCid, account?.id, communityKey, setCommunityStats]);\n\n if (account && communityStatsCid) {\n log(\"useCommunityStats\", {\n community,\n communityKey,\n communityStatsCid,\n communityStats,\n fetchedCommunity,\n account,\n });\n }\n\n const state =\n !communityKey || !account || !communityStatsCid\n ? \"uninitialized\"\n : fetchError\n ? \"failed\"\n : communityStats\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\n return useMemo(\n () => ({\n ...communityStats,\n state,\n error: fetchError,\n errors: fetchError ? [fetchError] : [],\n }),\n [communityStats, state, fetchError],\n );\n}\n\ntype CommunitiesStatsState = {\n communitiesStats: { [communityAddress: string]: CommunityStats };\n setCommunityStats: Function;\n};\n\nconst useCommunitiesStatsStore = createStore<CommunitiesStatsState>((setState: Function) => ({\n communitiesStats: {},\n setCommunityStats: (communityAddress: string, communityStats: CommunityStats) =>\n setState((state: CommunitiesStatsState) => ({\n communitiesStats: { ...state.communitiesStats, [communityAddress]: communityStats },\n })),\n}));\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunities(options?: UseCommunitiesOptions): UseCommunitiesResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunities options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { communities: communitiesInput, accountName, onlyIfCached, autoUpdate = true } = opts;\n const account = useAccount({ accountName });\n validator.validateUseCommunitiesArguments({\n communities: communitiesInput,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n account,\n });\n const normalizedCommunityRefs = useMemo(() => communitiesInput || [], [communitiesInput]);\n const communityKeys = useMemo(\n () => normalizedCommunityRefs.map(getCommunityRefKey),\n [normalizedCommunityRefs],\n );\n const communities: (Community | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.communities[communityKey || \"\"]),\n shallow,\n );\n const communitiesErrors: (Error[] | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.errors[communityKey || \"\"]),\n shallow,\n );\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const startCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.startCommunityAutoUpdate,\n );\n const stopCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.stopCommunityAutoUpdate,\n );\n const autoUpdateSubscriptionId = useRef(\n `useCommunities-${++communityAutoUpdateSubscriptionCount}`,\n );\n\n // keyed by the community keys, so a new array of the same communities does not resubscribe\n useEffect(() => {\n if (!normalizedCommunityRefs.length || !account) {\n return;\n }\n if (onlyIfCached) {\n return;\n }\n const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);\n if (!autoUpdate) {\n // load the communities once, without keeping them updating\n for (const communityRef of uniqueCommunityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"useCommunities addCommunityToStore error\", { communityRef, error }),\n );\n }\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n for (const communityRef of uniqueCommunityRefs) {\n startCommunityAutoUpdate(communityRef, subscriberId, account).catch((error: unknown) =>\n log.error(\"useCommunities startCommunityAutoUpdate error\", { communityRef, error }),\n );\n }\n return () => {\n for (const communityRef of uniqueCommunityRefs) {\n stopCommunityAutoUpdate(communityRef, subscriberId).catch((error: unknown) =>\n log.error(\"useCommunities stopCommunityAutoUpdate error\", { communityRef, error }),\n );\n }\n };\n }, [account?.id, communityKeys.toString(), onlyIfCached, autoUpdate]);\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useCommunities\", {\n requestedCommunities: normalizedCommunityRefs,\n communityKeys,\n communities,\n account,\n });\n }\n\n const errors = useMemo(\n () => communitiesErrors.flatMap((communityErrors) => communityErrors || []),\n [communitiesErrors],\n );\n const hasFailedCommunity = communities.some(\n (community, index) => !community && Boolean(communitiesErrors[index]?.length),\n );\n const state = hasFailedCommunity\n ? \"failed\"\n : communities.indexOf(undefined) === -1\n ? \"succeeded\"\n : \"fetching-ipns\";\n\n return useMemo(\n () => ({\n communities,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [communities, state, errors, communityKeys.toString()],\n );\n}\n\n// TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling\n/**\n * Returns all the owner communities created by pkc-js by calling pkc.listCommunities()\n */\nexport function useListCommunities(accountName?: string) {\n const account = useAccount({ accountName });\n const [communityAddresses, setCommunityAddresses] = useState<string[]>([]);\n\n const delay = 1000;\n const immediate = true;\n useInterval(\n () => {\n const pkc = account?.pkc;\n if (!pkc) return;\n const newAddrs = getPkcCommunityAddresses(pkc);\n if (newAddrs.toString() !== communityAddresses.toString()) {\n log(\"useListCommunities\", { communityAddresses });\n setCommunityAddresses(newAddrs);\n }\n },\n delay,\n immediate,\n );\n\n return communityAddresses;\n}\n\n/**\n * @param communityAddress - The community address to resolve to a public key, e.g. 'news.eth' resolves to '12D3KooW...'.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useResolvedCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport function useResolvedCommunityAddress(\n options?: UseResolvedCommunityAddressOptions,\n): UseResolvedCommunityAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useResolvedCommunityAddress options argument '${options}' not an object`,\n );\n let { communityAddress, accountName, cache } = options ?? {};\n\n // cache by default\n if (typeof cache !== \"boolean\") {\n cache = true;\n }\n\n // poll every 15 seconds, about the duration of an eth block\n let interval = 15000;\n // no point in polling often if caching is on\n if (cache) {\n interval = 1000 * 60 * 60 * 25;\n }\n\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [resolvedAddress, setResolvedAddress] = useState<string>();\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n\n let initialState = \"initializing\";\n // before those defined, nothing can happen\n if (options && account && communityAddress) {\n initialState = \"ready\";\n }\n\n useInterval(\n () => {\n if (!account || !communityAddress) {\n setResolvedAddress(undefined);\n setState(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n return;\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!communityAddress?.includes(\".\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"not a crypto domain\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n // only support resolving '.eth' for now\n if (!communityAddress?.endsWith(\".eth\")) {\n if (state !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n setState(\"resolving\");\n const res = await resolveCommunityAddress(communityAddress, chainProviders);\n setState(\"succeeded\");\n if (res !== resolvedAddress) {\n setResolvedAddress(res);\n }\n } catch (error: any) {\n setErrors([...errors, error]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n log.error(\"useResolvedCommunityAddress resolveCommunityAddress error\", {\n communityAddress,\n chainProviders,\n error,\n });\n }\n })();\n },\n interval,\n true,\n [communityAddress, chainProviders],\n );\n\n // only support ENS at the moment\n const chainProvider = chainProviders?.[\"eth\"];\n\n // log('useResolvedCommunityAddress', {communityAddress, state, errors, resolvedAddress, chainProviders})\n return {\n resolvedAddress,\n chainProvider,\n state: state || initialState,\n error: errors[errors.length - 1],\n errors,\n };\n}\n\n// NOTE: resolveCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport const resolveCommunityAddress = async (\n communityAddress: string,\n chainProviders: ChainProviders,\n) => {\n let resolvedCommunityAddress;\n if (communityAddress.endsWith(\".eth\")) {\n resolvedCommunityAddress = await resolveEnsTxtRecord(\n communityAddress,\n \"community-address\",\n \"eth\",\n chainProviders?.[\"eth\"]?.urls?.[0],\n chainProviders?.[\"eth\"]?.chainId,\n );\n } else {\n throw Error(`resolveCommunityAddress invalid communityAddress '${communityAddress}'`);\n }\n return resolvedCommunityAddress;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feeds.d.ts","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,aAAa,EAEd,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"feeds.d.ts","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,aAAa,EAEd,MAAM,aAAa,CAAC;AAerB;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CA6M/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,sBAAsB,CA6J1F"}
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { useEffect, useMemo, useState } from "react";
|
|
10
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
11
11
|
import { useAccount } from "../accounts/index.js";
|
|
12
12
|
import validator from "../../lib/validator.js";
|
|
13
13
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
@@ -20,6 +20,7 @@ import { addOptimisticVoteCountsToComments } from "../../lib/utils/optimistic-vo
|
|
|
20
20
|
import shallow from "zustand/shallow";
|
|
21
21
|
import { getCommunityRefKeys, getUniqueSortedCommunityRefs, } from "../../lib/community-ref.js";
|
|
22
22
|
import { serializeFeedKey } from "../../lib/serialize-feed-key.js";
|
|
23
|
+
let feedAutoUpdateSubscriptionCount = 0;
|
|
23
24
|
/**
|
|
24
25
|
* @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]
|
|
25
26
|
* @param sortType - A sort name published by the community, or a standard sort computed client-side
|
|
@@ -45,6 +46,9 @@ export function useFeed(options) {
|
|
|
45
46
|
const account = useAccount({ accountName });
|
|
46
47
|
const accountVotes = useAccountsStore((state) => (account === null || account === void 0 ? void 0 : account.id) ? state.accountsVotes[account.id] : undefined);
|
|
47
48
|
const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);
|
|
49
|
+
const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);
|
|
50
|
+
const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);
|
|
51
|
+
const autoUpdateSubscriptionId = useRef(`useFeed-${++feedAutoUpdateSubscriptionCount}`);
|
|
48
52
|
const incrementFeedPageNumber = useFeedsStore((state) => state.incrementFeedPageNumber);
|
|
49
53
|
const expandFeedTimeWindow = useFeedsStore((state) => state.expandFeedTimeWindow);
|
|
50
54
|
const resetFeed = useFeedsStore((state) => state.resetFeed);
|
|
@@ -63,6 +67,15 @@ export function useFeed(options) {
|
|
|
63
67
|
const isBufferedFeed = false;
|
|
64
68
|
addFeedToStore(feedName, uniqueCommunityRefs, uniqueCommunityKeys, sortType, account, isBufferedFeed, postsPerPage, filter, newerThan, accountComments, modQueue).catch((error) => log.error("useFeed addFeedToStore error", { feedName, error }));
|
|
65
69
|
}, [feedName]);
|
|
70
|
+
// keep the feed's communities updating while mounted, after the feed was added above
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!uniqueCommunityRefs.length || !account) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const subscriberId = autoUpdateSubscriptionId.current;
|
|
76
|
+
startFeedAutoUpdate(feedName, subscriberId);
|
|
77
|
+
return () => stopFeedAutoUpdate(feedName, subscriberId);
|
|
78
|
+
}, [feedName]);
|
|
66
79
|
const feedKey = feedName;
|
|
67
80
|
const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);
|
|
68
81
|
const updatedFeed = useFeedsStore((state) => state.updatedFeeds[feedKey]);
|
|
@@ -174,6 +187,9 @@ export function useBufferedFeeds(options) {
|
|
|
174
187
|
validator.validateUseBufferedFeedsArguments({ feedsOptions, accountName });
|
|
175
188
|
const account = useAccount({ accountName });
|
|
176
189
|
const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);
|
|
190
|
+
const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);
|
|
191
|
+
const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);
|
|
192
|
+
const autoUpdateSubscriptionId = useRef(`useBufferedFeeds-${++feedAutoUpdateSubscriptionCount}`);
|
|
177
193
|
// do a bunch of calculations to get feedsOptionsFlattened and feedNames
|
|
178
194
|
const feedsOpts = feedsOptions;
|
|
179
195
|
const { communityRefsArrays, communityKeysArrays, sortTypes, postsPerPages, filters, newerThans, } = useMemo(() => {
|
|
@@ -237,6 +253,23 @@ export function useBufferedFeeds(options) {
|
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
}, [feedNames]);
|
|
256
|
+
// keep the buffered feeds' communities updating while mounted, keyed by the names so
|
|
257
|
+
// inline options recreated on every render do not resubscribe
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
if (!account) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const subscriberId = autoUpdateSubscriptionId.current;
|
|
263
|
+
const subscribedFeedNames = feedNames.filter((_, i) => { var _a; return (_a = communityRefsArrays[i]) === null || _a === void 0 ? void 0 : _a.length; });
|
|
264
|
+
for (const feedName of subscribedFeedNames) {
|
|
265
|
+
startFeedAutoUpdate(feedName, subscriberId);
|
|
266
|
+
}
|
|
267
|
+
return () => {
|
|
268
|
+
for (const feedName of subscribedFeedNames) {
|
|
269
|
+
stopFeedAutoUpdate(feedName, subscriberId);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}, [JSON.stringify(feedNames), account === null || account === void 0 ? void 0 : account.id]);
|
|
240
273
|
// only give to the user the buffered feeds he requested
|
|
241
274
|
const bufferedFeedsArray = useMemo(() => {
|
|
242
275
|
const bufferedFeedsArray = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,mCAAmC,CAAC,CAAC;AACxD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAUtC,OAAO,aAAa,MA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AC;aACd,CAAC,CACH,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,yBAAyB,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport { useAccount } from \"../accounts\";\nimport validator from \"../../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:hooks\");\nimport assert from \"../../lib/assert\";\nimport {\n Feed,\n Feeds,\n UseBufferedFeedsOptions,\n UseBufferedFeedsResult,\n UseFeedOptions,\n UseFeedResult,\n CommentsFilter,\n} from \"../../types\";\nimport useFeedsStore from \"../../stores/feeds\";\nimport useAccountsStore from \"../../stores/accounts\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport { addOptimisticVoteCountsToComments } from \"../../lib/utils/optimistic-vote-counts\";\nimport shallow from \"zustand/shallow\";\nimport {\n CommunityLookupRef,\n getCommunityRefKeys,\n getUniqueSortedCommunityRefs,\n} from \"../../lib/community-ref\";\nimport { serializeFeedKey } from \"../../lib/serialize-feed-key\";\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param sortType - A sort name published by the community, or a standard sort computed client-side\n * when every post fits in the preloaded page. Omit it to use the preloaded sort.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useFeed(options?: UseFeedOptions): UseFeedResult {\n assert(\n !options || typeof options === \"object\",\n `useFeed options argument '${options}' not an object`,\n );\n const opts = options || {};\n let {\n communities,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n } = opts;\n validator.validateUseFeedArguments({\n communities,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n });\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const incrementFeedPageNumber = useFeedsStore((state) => state.incrementFeedPageNumber);\n const expandFeedTimeWindow = useFeedsStore((state) => state.expandFeedTimeWindow);\n const resetFeed = useFeedsStore((state) => state.resetFeed);\n const normalizedCommunityRefs = useMemo(() => communities || [], [communities]);\n const uniqueCommunityRefs = useUniqueSortedCommunityRefs(normalizedCommunityRefs);\n const uniqueCommunityKeys = useMemo(\n () => getCommunityRefKeys(uniqueCommunityRefs),\n [uniqueCommunityRefs],\n );\n const feedName = useFeedName(\n account?.id,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n );\n const [errors, setErrors] = useState<Error[]>([]);\n const communityKeysWithNewerPosts = useFeedsStore(\n (state) => state.feedsCommunityKeysWithNewerPosts[feedName],\n );\n const feedCommunityKeysWithMore = useFeedsStore(\n (state) => state.feedsCommunityKeysWithMore[feedName],\n );\n\n // add feed to store\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const isBufferedFeed = false;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n ).catch((error: unknown) => log.error(\"useFeed addFeedToStore error\", { feedName, error }));\n }, [feedName]);\n\n const feedKey = feedName;\n const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);\n const updatedFeed = useFeedsStore((state) => state.updatedFeeds[feedKey]);\n const bufferedFeed = useFeedsStore((state) => state.bufferedFeeds[feedKey]);\n let hasMore = useFeedsStore((state) => state.feedsHaveMore[feedKey]);\n if (!feedName || typeof hasMore !== \"boolean\") {\n hasMore = true;\n }\n if (!normalizedCommunityRefs.length) {\n hasMore = false;\n }\n\n const loadMore = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot load more feed not initalized yet\");\n }\n incrementFeedPageNumber(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const reset = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot reset feed not initalized yet\");\n }\n await resetFeed(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const expandTimeWindow = async (nextNewerThan?: number) => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot expand time window before feed initialized yet\");\n }\n expandFeedTimeWindow(feedName, nextNewerThan);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useFeed\", {\n feedLength: feed?.length || 0,\n hasMore,\n communities: normalizedCommunityRefs,\n communityKeys: uniqueCommunityKeys,\n sortType,\n account,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = !hasMore ? \"succeeded\" : \"fetching-ipns\";\n // until the feed is first calculated, every community still has more\n let communityKeysWithMore = feedCommunityKeysWithMore || uniqueCommunityKeys;\n if (!normalizedCommunityRefs.length) {\n communityKeysWithMore = [];\n }\n // apply the account's pending votes like useComment/useComments/useReplies do, so voting from a\n // feed updates the score immediately instead of only once the community publishes the new counts\n const normalizedFeed = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(feed), accountVotes),\n [feed, accountVotes],\n );\n const normalizedBufferedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(bufferedFeed), accountVotes),\n [bufferedFeed, accountVotes],\n );\n const normalizedUpdatedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(updatedFeed), accountVotes),\n [updatedFeed, accountVotes],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n communityKeysWithMore,\n loadMore,\n expandTimeWindow,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedFeed,\n normalizedBufferedFeed,\n normalizedUpdatedFeed,\n feedName,\n hasMore,\n errors,\n communityKeysWithNewerPosts,\n communityKeysWithMore,\n ],\n );\n}\n\n/**\n * Use useBufferedFeeds to buffer multiple feeds in the background so what when\n * they are called by useFeed later, they are already preloaded.\n *\n * @param feedOptions - The options of the feed\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useBufferedFeeds(options?: UseBufferedFeedsOptions): UseBufferedFeedsResult {\n assert(\n !options || typeof options === \"object\",\n `useBufferedFeeds options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { feedsOptions = [], accountName } = opts;\n validator.validateUseBufferedFeedsArguments({ feedsOptions, accountName });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n\n // do a bunch of calculations to get feedsOptionsFlattened and feedNames\n const feedsOpts = feedsOptions;\n const {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n } = useMemo(() => {\n const communityRefsArrays: CommunityLookupRef[][] = [];\n const communityKeysArrays: string[][] = [];\n const sortTypes: (string | undefined)[] = [];\n const postsPerPages: (number | undefined)[] = [];\n const filters: (CommentsFilter | undefined)[] = [];\n const newerThans: (number | undefined)[] = [];\n for (const feedOptions of feedsOpts) {\n validator.validateUseFeedArguments({\n communities: feedOptions.communities,\n communityRefs: (feedOptions as any).communityRefs,\n communityAddresses: (feedOptions as any).communityAddresses,\n sortType: feedOptions.sortType,\n accountName,\n postsPerPage: feedOptions.postsPerPage,\n filter: feedOptions.filter,\n newerThan: feedOptions.newerThan,\n accountComments: feedOptions.accountComments,\n });\n const normalizedCommunityRefs = getUniqueSortedCommunityRefs(feedOptions.communities || []);\n communityRefsArrays.push(normalizedCommunityRefs);\n communityKeysArrays.push(getCommunityRefKeys(normalizedCommunityRefs));\n sortTypes.push(feedOptions.sortType);\n postsPerPages.push(feedOptions.postsPerPage);\n filters.push(feedOptions.filter);\n newerThans.push(feedOptions.newerThan);\n }\n return {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n };\n }, [feedsOpts]);\n const feedNames = useFeedNames(\n account?.id,\n sortTypes,\n communityKeysArrays,\n postsPerPages,\n filters,\n newerThans,\n );\n\n const bufferedFeeds = useFeedsStore((state) => {\n const bufferedFeeds: Feeds = {};\n for (const feedName of feedNames) {\n bufferedFeeds[feedName] = state.bufferedFeeds[feedName];\n }\n return bufferedFeeds;\n }, shallow);\n\n // add feed to store\n useEffect(() => {\n for (const [i] of communityRefsArrays.entries()) {\n const sortType = sortTypes[i];\n const uniqueCommunityRefs = communityRefsArrays[i];\n const uniqueCommunityKeys = communityKeysArrays[i];\n validator.validateFeedSortType(sortType);\n const feedName = feedNames[i];\n if (!account || !uniqueCommunityRefs.length) {\n continue;\n }\n if (!bufferedFeeds[feedName]) {\n const isBufferedFeed = true;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n ).catch((error: unknown) =>\n log.error(\"useBufferedFeeds addFeedToStore error\", { feedName, error }),\n );\n }\n }\n }, [feedNames]);\n\n // only give to the user the buffered feeds he requested\n const bufferedFeedsArray: Feed[] = useMemo(() => {\n const bufferedFeedsArray: Feed[] = [];\n for (const feedName of feedNames) {\n bufferedFeedsArray.push(addCommentModerationToComments(bufferedFeeds[feedName]));\n }\n return bufferedFeedsArray;\n }, [bufferedFeeds, feedNames]);\n\n if (account && feedsOptions?.length) {\n log(\"useBufferedFeeds\", {\n bufferedFeeds,\n feedsOptions,\n account,\n accountName,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = \"fetching-ipns\";\n\n return useMemo(\n () => ({\n bufferedFeeds: bufferedFeedsArray,\n state,\n error: undefined,\n errors: [],\n }),\n [bufferedFeedsArray, feedsOptions],\n );\n}\n\nfunction useUniqueSortedCommunityRefs(communityRefs?: CommunityLookupRef[]) {\n return useMemo(() => {\n return getUniqueSortedCommunityRefs(communityRefs);\n }, [communityRefs]);\n}\n\nfunction useFeedName(\n accountId: string,\n sortType: string | undefined,\n uniqueCommunityKeys: string[],\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: UseFeedOptions[\"accountComments\"],\n modQueue?: string[],\n) {\n const filterKey = filter?.key;\n const accountCommentsNewerThan = accountComments?.newerThan;\n const accountCommentsAppend = accountComments?.append;\n return useMemo(() => {\n return serializeFeedKey([\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue,\n ]);\n }, [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue?.toString(),\n ]);\n}\n\nfunction useFeedNames(\n accountId: string,\n sortTypes: (string | undefined)[],\n uniqueCommunityKeysArrays: string[][],\n postsPerPages: (number | undefined)[],\n filters: (CommentsFilter | undefined)[],\n newerThans: (number | undefined)[],\n) {\n return useMemo(() => {\n const feedNames: string[] = [];\n for (const [i] of sortTypes.entries()) {\n feedNames.push(\n serializeFeedKey([\n accountId,\n sortTypes[i],\n uniqueCommunityKeysArrays[i],\n postsPerPages[i],\n filters[i]?.key,\n newerThans[i],\n ]),\n );\n }\n return feedNames;\n }, [accountId, sortTypes, uniqueCommunityKeysArrays, postsPerPages, filters, newerThans]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,mCAAmC,CAAC,CAAC;AACxD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAUtC,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAC/C,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAEL,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,IAAI,+BAA+B,GAAG,CAAC,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,OAAwB;IAC9C,MAAM,CACJ,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EACvC,6BAA6B,OAAO,iBAAiB,CACtD,CAAC;IACF,MAAM,IAAI,GAAG,OAAO,IAAI,EAAE,CAAC;IAC3B,IAAI,EACF,WAAW,EACX,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,MAAM,EACN,SAAS,EACT,eAAe,EACf,QAAQ,GACT,GAAG,IAAI,CAAC;IACT,S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Account } from \"../accounts\";\nimport validator from \"../../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:hooks\");\nimport assert from \"../../lib/assert\";\nimport {\n Feed,\n Feeds,\n UseBufferedFeedsOptions,\n UseBufferedFeedsResult,\n UseFeedOptions,\n UseFeedResult,\n CommentsFilter,\n} from \"../../types\";\nimport useFeedsStore from \"../../stores/feeds\";\nimport useAccountsStore from \"../../stores/accounts\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport { addOptimisticVoteCountsToComments } from \"../../lib/utils/optimistic-vote-counts\";\nimport shallow from \"zustand/shallow\";\nimport {\n CommunityLookupRef,\n getCommunityRefKeys,\n getUniqueSortedCommunityRefs,\n} from \"../../lib/community-ref\";\nimport { serializeFeedKey } from \"../../lib/serialize-feed-key\";\n\nlet feedAutoUpdateSubscriptionCount = 0;\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param sortType - A sort name published by the community, or a standard sort computed client-side\n * when every post fits in the preloaded page. Omit it to use the preloaded sort.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useFeed(options?: UseFeedOptions): UseFeedResult {\n assert(\n !options || typeof options === \"object\",\n `useFeed options argument '${options}' not an object`,\n );\n const opts = options || {};\n let {\n communities,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n } = opts;\n validator.validateUseFeedArguments({\n communities,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n });\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useFeed-${++feedAutoUpdateSubscriptionCount}`);\n const incrementFeedPageNumber = useFeedsStore((state) => state.incrementFeedPageNumber);\n const expandFeedTimeWindow = useFeedsStore((state) => state.expandFeedTimeWindow);\n const resetFeed = useFeedsStore((state) => state.resetFeed);\n const normalizedCommunityRefs = useMemo(() => communities || [], [communities]);\n const uniqueCommunityRefs = useUniqueSortedCommunityRefs(normalizedCommunityRefs);\n const uniqueCommunityKeys = useMemo(\n () => getCommunityRefKeys(uniqueCommunityRefs),\n [uniqueCommunityRefs],\n );\n const feedName = useFeedName(\n account?.id,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n );\n const [errors, setErrors] = useState<Error[]>([]);\n const communityKeysWithNewerPosts = useFeedsStore(\n (state) => state.feedsCommunityKeysWithNewerPosts[feedName],\n );\n const feedCommunityKeysWithMore = useFeedsStore(\n (state) => state.feedsCommunityKeysWithMore[feedName],\n );\n\n // add feed to store\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const isBufferedFeed = false;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n ).catch((error: unknown) => log.error(\"useFeed addFeedToStore error\", { feedName, error }));\n }, [feedName]);\n\n // keep the feed's communities updating while mounted, after the feed was added above\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n startFeedAutoUpdate(feedName, subscriberId);\n return () => stopFeedAutoUpdate(feedName, subscriberId);\n }, [feedName]);\n\n const feedKey = feedName;\n const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);\n const updatedFeed = useFeedsStore((state) => state.updatedFeeds[feedKey]);\n const bufferedFeed = useFeedsStore((state) => state.bufferedFeeds[feedKey]);\n let hasMore = useFeedsStore((state) => state.feedsHaveMore[feedKey]);\n if (!feedName || typeof hasMore !== \"boolean\") {\n hasMore = true;\n }\n if (!normalizedCommunityRefs.length) {\n hasMore = false;\n }\n\n const loadMore = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot load more feed not initalized yet\");\n }\n incrementFeedPageNumber(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const reset = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot reset feed not initalized yet\");\n }\n await resetFeed(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n const expandTimeWindow = async (nextNewerThan?: number) => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot expand time window before feed initialized yet\");\n }\n expandFeedTimeWindow(feedName, nextNewerThan);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n setErrors([...errors, e]);\n }\n };\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useFeed\", {\n feedLength: feed?.length || 0,\n hasMore,\n communities: normalizedCommunityRefs,\n communityKeys: uniqueCommunityKeys,\n sortType,\n account,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = !hasMore ? \"succeeded\" : \"fetching-ipns\";\n // until the feed is first calculated, every community still has more\n let communityKeysWithMore = feedCommunityKeysWithMore || uniqueCommunityKeys;\n if (!normalizedCommunityRefs.length) {\n communityKeysWithMore = [];\n }\n // apply the account's pending votes like useComment/useComments/useReplies do, so voting from a\n // feed updates the score immediately instead of only once the community publishes the new counts\n const normalizedFeed = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(feed), accountVotes),\n [feed, accountVotes],\n );\n const normalizedBufferedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(bufferedFeed), accountVotes),\n [bufferedFeed, accountVotes],\n );\n const normalizedUpdatedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(updatedFeed), accountVotes),\n [updatedFeed, accountVotes],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n communityKeysWithMore,\n loadMore,\n expandTimeWindow,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedFeed,\n normalizedBufferedFeed,\n normalizedUpdatedFeed,\n feedName,\n hasMore,\n errors,\n communityKeysWithNewerPosts,\n communityKeysWithMore,\n ],\n );\n}\n\n/**\n * Use useBufferedFeeds to buffer multiple feeds in the background so what when\n * they are called by useFeed later, they are already preloaded.\n *\n * @param feedOptions - The options of the feed\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useBufferedFeeds(options?: UseBufferedFeedsOptions): UseBufferedFeedsResult {\n assert(\n !options || typeof options === \"object\",\n `useBufferedFeeds options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { feedsOptions = [], accountName } = opts;\n validator.validateUseBufferedFeedsArguments({ feedsOptions, accountName });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useBufferedFeeds-${++feedAutoUpdateSubscriptionCount}`);\n\n // do a bunch of calculations to get feedsOptionsFlattened and feedNames\n const feedsOpts = feedsOptions;\n const {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n } = useMemo(() => {\n const communityRefsArrays: CommunityLookupRef[][] = [];\n const communityKeysArrays: string[][] = [];\n const sortTypes: (string | undefined)[] = [];\n const postsPerPages: (number | undefined)[] = [];\n const filters: (CommentsFilter | undefined)[] = [];\n const newerThans: (number | undefined)[] = [];\n for (const feedOptions of feedsOpts) {\n validator.validateUseFeedArguments({\n communities: feedOptions.communities,\n communityRefs: (feedOptions as any).communityRefs,\n communityAddresses: (feedOptions as any).communityAddresses,\n sortType: feedOptions.sortType,\n accountName,\n postsPerPage: feedOptions.postsPerPage,\n filter: feedOptions.filter,\n newerThan: feedOptions.newerThan,\n accountComments: feedOptions.accountComments,\n });\n const normalizedCommunityRefs = getUniqueSortedCommunityRefs(feedOptions.communities || []);\n communityRefsArrays.push(normalizedCommunityRefs);\n communityKeysArrays.push(getCommunityRefKeys(normalizedCommunityRefs));\n sortTypes.push(feedOptions.sortType);\n postsPerPages.push(feedOptions.postsPerPage);\n filters.push(feedOptions.filter);\n newerThans.push(feedOptions.newerThan);\n }\n return {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n };\n }, [feedsOpts]);\n const feedNames = useFeedNames(\n account?.id,\n sortTypes,\n communityKeysArrays,\n postsPerPages,\n filters,\n newerThans,\n );\n\n const bufferedFeeds = useFeedsStore((state) => {\n const bufferedFeeds: Feeds = {};\n for (const feedName of feedNames) {\n bufferedFeeds[feedName] = state.bufferedFeeds[feedName];\n }\n return bufferedFeeds;\n }, shallow);\n\n // add feed to store\n useEffect(() => {\n for (const [i] of communityRefsArrays.entries()) {\n const sortType = sortTypes[i];\n const uniqueCommunityRefs = communityRefsArrays[i];\n const uniqueCommunityKeys = communityKeysArrays[i];\n validator.validateFeedSortType(sortType);\n const feedName = feedNames[i];\n if (!account || !uniqueCommunityRefs.length) {\n continue;\n }\n if (!bufferedFeeds[feedName]) {\n const isBufferedFeed = true;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n ).catch((error: unknown) =>\n log.error(\"useBufferedFeeds addFeedToStore error\", { feedName, error }),\n );\n }\n }\n }, [feedNames]);\n\n // keep the buffered feeds' communities updating while mounted, keyed by the names so\n // inline options recreated on every render do not resubscribe\n useEffect(() => {\n if (!account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n const subscribedFeedNames = feedNames.filter((_, i) => communityRefsArrays[i]?.length);\n for (const feedName of subscribedFeedNames) {\n startFeedAutoUpdate(feedName, subscriberId);\n }\n return () => {\n for (const feedName of subscribedFeedNames) {\n stopFeedAutoUpdate(feedName, subscriberId);\n }\n };\n }, [JSON.stringify(feedNames), account?.id]);\n\n // only give to the user the buffered feeds he requested\n const bufferedFeedsArray: Feed[] = useMemo(() => {\n const bufferedFeedsArray: Feed[] = [];\n for (const feedName of feedNames) {\n bufferedFeedsArray.push(addCommentModerationToComments(bufferedFeeds[feedName]));\n }\n return bufferedFeedsArray;\n }, [bufferedFeeds, feedNames]);\n\n if (account && feedsOptions?.length) {\n log(\"useBufferedFeeds\", {\n bufferedFeeds,\n feedsOptions,\n account,\n accountName,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = \"fetching-ipns\";\n\n return useMemo(\n () => ({\n bufferedFeeds: bufferedFeedsArray,\n state,\n error: undefined,\n errors: [],\n }),\n [bufferedFeedsArray, feedsOptions],\n );\n}\n\nfunction useUniqueSortedCommunityRefs(communityRefs?: CommunityLookupRef[]) {\n return useMemo(() => {\n return getUniqueSortedCommunityRefs(communityRefs);\n }, [communityRefs]);\n}\n\nfunction useFeedName(\n accountId: string,\n sortType: string | undefined,\n uniqueCommunityKeys: string[],\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: UseFeedOptions[\"accountComments\"],\n modQueue?: string[],\n) {\n const filterKey = filter?.key;\n const accountCommentsNewerThan = accountComments?.newerThan;\n const accountCommentsAppend = accountComments?.append;\n return useMemo(() => {\n return serializeFeedKey([\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue,\n ]);\n }, [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue?.toString(),\n ]);\n}\n\nfunction useFeedNames(\n accountId: string,\n sortTypes: (string | undefined)[],\n uniqueCommunityKeysArrays: string[][],\n postsPerPages: (number | undefined)[],\n filters: (CommentsFilter | undefined)[],\n newerThans: (number | undefined)[],\n) {\n return useMemo(() => {\n const feedNames: string[] = [];\n for (const [i] of sortTypes.entries()) {\n feedNames.push(\n serializeFeedKey([\n accountId,\n sortTypes[i],\n uniqueCommunityKeysArrays[i],\n postsPerPages[i],\n filters[i]?.key,\n newerThans[i],\n ]),\n );\n }\n return feedNames;\n }, [accountId, sortTypes, uniqueCommunityKeysArrays, postsPerPages, filters, newerThans]);\n}\n"]}
|
|
@@ -74,6 +74,7 @@ export declare class Pages {
|
|
|
74
74
|
}
|
|
75
75
|
export declare class Community extends EventEmitter {
|
|
76
76
|
updateCalledTimes: number;
|
|
77
|
+
stopCalledTimes: number;
|
|
77
78
|
updating: boolean;
|
|
78
79
|
firstUpdate: boolean;
|
|
79
80
|
address: string | undefined;
|
|
@@ -89,6 +90,7 @@ export declare class Community extends EventEmitter {
|
|
|
89
90
|
updatingState: string;
|
|
90
91
|
constructor(createCommunityOptions?: any);
|
|
91
92
|
update(): Promise<void>;
|
|
93
|
+
stop(): Promise<void>;
|
|
92
94
|
delete(): Promise<void>;
|
|
93
95
|
get exports(): any[];
|
|
94
96
|
export(exportCommunityOptions?: any): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pk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