@bitsocial/bitsocial-react-hooks 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -880,19 +880,29 @@ const account = useAccount() // or useAccount('Account 2') to use an account oth
880
880
 
881
881
  // `account.author.wallets` only auto-generates an `eth` wallet by default.
882
882
  // `account.chainProviders` is the canonical chain config for wallets, NFT lookups, and other chain reads.
883
- // `account.nameResolversChainProviders` optionally overrides only the RPCs used for `.eth` / `.bso` author-name resolution.
883
+ // Defaults use multiple explicit Ethereum RPCs for `.eth` / `.bso` author-name resolution.
884
+ // `account.nameResolversChainProviders` optionally overrides only the RPCs used for that resolution.
884
885
  console.log(account.author.wallets.eth)
885
886
 
887
+ const ethResolverRpcUrls = [
888
+ 'https://ethereum-rpc.publicnode.com',
889
+ 'https://eth.drpc.org',
890
+ 'https://ethereum.publicnode.com',
891
+ 'https://rpc.mevblocker.io',
892
+ 'https://1rpc.io/eth',
893
+ 'https://eth-pokt.nodies.app',
894
+ ]
895
+
886
896
  const author: {...account.author, displayName: 'John'}
887
897
  const editedAccount = {
888
898
  ...account,
889
899
  author,
890
900
  chainProviders: {
891
901
  ...account.chainProviders,
892
- eth: { urls: ['https://ethereum-rpc.publicnode.com', 'viem', 'ethers.js'], chainId: 1 },
902
+ eth: { urls: [...ethResolverRpcUrls, 'ethers.js'], chainId: 1 },
893
903
  },
894
904
  nameResolversChainProviders: {
895
- eth: { urls: ['https://ethereum-rpc.publicnode.com', 'viem'], chainId: 1 },
905
+ eth: { urls: ethResolverRpcUrls, chainId: 1 },
896
906
  },
897
907
  }
898
908
 
@@ -1006,6 +1016,9 @@ const { replies } = useReplies({
1006
1016
  comment: post,
1007
1017
  accountComments: { newerThan: Infinity, append: false },
1008
1018
  });
1019
+
1020
+ // pending local account comments are reconciled with their approved network version
1021
+ // so the same post or reply is not shown twice after moderation approval
1009
1022
  ```
1010
1023
 
1011
1024
  #### Determine if a comment is your own
@@ -1,5 +1,6 @@
1
1
  import { AccountCommunity, ChainProviders } from "../../types.js";
2
2
  export declare const DEFAULT_ETH_RPC_URL = "https://ethereum-rpc.publicnode.com";
3
+ export declare const DEFAULT_ETH_RPC_URLS: string[];
3
4
  export declare const overwritePkcOptions: {
4
5
  resolveAuthorNames: boolean;
5
6
  resolveAuthorAddresses: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"account-generator.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASzE,eAAO,MAAM,mBAAmB,wCAAwC,CAAC;AAgBzE,eAAO,MAAM,mBAAmB;;;;CAI/B,CAAC;AAqBF,eAAO,MAAM,wBAAwB,QAQd,cACtB,CAAC;AAGF,eAAO,MAAM,oBAAoB;;;CAoChC,CAAC;AAuFF,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"account-generator.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASzE,eAAO,MAAM,mBAAmB,wCAAwC,CAAC;AACzE,eAAO,MAAM,oBAAoB,UAOhC,CAAC;AAgBF,eAAO,MAAM,mBAAmB;;;;CAI/B,CAAC;AAqBF,eAAO,MAAM,wBAAwB,QAQd,cACtB,CAAC;AAGF,eAAO,MAAM,oBAAoB;;;CAoChC,CAAC;AAuFF,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -16,11 +16,19 @@ import { getPkcClientOptions, normalizeAccountProtocolConfig, withProtocolAliase
16
16
  import Logger from "@pkcprotocol/pkc-logger";
17
17
  const log = Logger("bitsocial-react-hooks:accounts:stores");
18
18
  export const DEFAULT_ETH_RPC_URL = "https://ethereum-rpc.publicnode.com";
19
+ export const DEFAULT_ETH_RPC_URLS = [
20
+ DEFAULT_ETH_RPC_URL,
21
+ "https://eth.drpc.org",
22
+ "https://ethereum.publicnode.com",
23
+ "https://rpc.mevblocker.io",
24
+ "https://1rpc.io/eth",
25
+ "https://eth-pokt.nodies.app",
26
+ ];
19
27
  // default chain providers
20
28
  const chainProviders = {
21
29
  eth: {
22
- // default should not use a url, but rather ethers' default provider
23
- urls: [DEFAULT_ETH_RPC_URL, "viem", "ethers.js"],
30
+ // Use explicit RPCs for default name resolution; viem's default transport is opt-in.
31
+ urls: [...DEFAULT_ETH_RPC_URLS, "ethers.js"],
24
32
  chainId: 1,
25
33
  },
26
34
  matic: {
@@ -1 +1 @@
1
- {"version":3,"file":"account-generator.js","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAEzE,0BAA0B;AAC1B,MAAM,cAAc,GAAmB;IACrC,GAAG,EAAE;QACH,oEAAoE;QACpE,IAAI,EAAE,CAAC,mBAAmB,EAAE,MAAM,EAAE,WAAW,CAAC;QAChD,OAAO,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BAAwB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAoB,MAAM,gBAAgB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QACjF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IACD,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,CAAC,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,CAAA,EAAE,CAAC;QAC1B,OAAO,WAAW,aAAa,EAAE,CAAC;IACpC,CAAC;IACD,SAAS,CAAC,oCAAoC,CAAC,YAAY,CAAC,CAAC;IAE7D,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,WAAW,GAAG,WAAW,aAAa,EAAE,CAAC;QAC/C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,aAAa,EAAE,CAAC;IAClB,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,MAAM,gBAAgB,GAAG;IACvB,sBAAsB;IACtB,oBAAoB;CACrB,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import PkcJs from \"../../lib/pkc-js\";\nimport validator from \"../../lib/validator\";\nimport chain from \"../../lib/chain\";\nimport { v4 as uuid } from \"uuid\";\nimport accountsDatabase from \"./accounts-database\";\nimport { Accounts, AccountCommunity, ChainProviders } from \"../../types\";\nimport {\n getPkcClientOptions,\n normalizeAccountProtocolConfig,\n withProtocolAliases,\n} from \"../../lib/pkc-compat\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\n\nexport const DEFAULT_ETH_RPC_URL = \"https://ethereum-rpc.publicnode.com\";\n\n// default chain providers\nconst chainProviders: ChainProviders = {\n eth: {\n // default should not use a url, but rather ethers' default provider\n urls: [DEFAULT_ETH_RPC_URL, \"viem\", \"ethers.js\"],\n chainId: 1,\n },\n matic: {\n urls: [\"https://polygon-rpc.com\"],\n chainId: 137,\n },\n};\n\n// force using these options or can cause bugs\nexport const overwritePkcOptions = {\n resolveAuthorNames: false,\n resolveAuthorAddresses: false,\n validatePages: false,\n};\n\nconst aliasProtocolOptions = (options: Record<string, any>) => ({\n ...options,\n resolveAuthorNames: options.resolveAuthorNames ?? options.resolveAuthorAddresses ?? false,\n resolveAuthorAddresses: options.resolveAuthorAddresses ?? options.resolveAuthorNames ?? false,\n});\n\nconst addMissingChainProviders = (options: Record<string, any>) => {\n const optionsWithChainProviders = { ...options };\n if (!optionsWithChainProviders.chainProviders) {\n optionsWithChainProviders.chainProviders = {};\n }\n for (const chainTicker in chainProviders) {\n if (!optionsWithChainProviders.chainProviders[chainTicker]) {\n optionsWithChainProviders.chainProviders[chainTicker] = chainProviders[chainTicker];\n }\n }\n return optionsWithChainProviders;\n};\n\nexport const getDefaultChainProviders = () => {\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n const windowChainProviders = defaultWindowOptions?.chainProviders\n ? JSON.parse(JSON.stringify(defaultWindowOptions.chainProviders))\n : undefined;\n return addMissingChainProviders({\n chainProviders: windowChainProviders,\n }).chainProviders as ChainProviders;\n};\n\n// default options aren't saved to database so they can be changed\nexport const getDefaultPkcOptions = () => {\n // default PKC options defined by the electron process\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n if (defaultWindowOptions) {\n // @ts-ignore\n const defaultPkcOptions: any = JSON.parse(\n JSON.stringify({ ...defaultWindowOptions, libp2pJsClientsOptions: undefined }),\n );\n delete defaultPkcOptions.chainProviders;\n delete defaultPkcOptions.nameResolversChainProviders;\n // @ts-ignore\n defaultPkcOptions.libp2pJsClientsOptions = defaultWindowOptions.libp2pJsClientsOptions; // libp2pJsClientsOptions is not always just json\n return aliasProtocolOptions({ ...defaultPkcOptions, ...overwritePkcOptions });\n }\n // default PKC options for web client\n return aliasProtocolOptions({\n ipfsGatewayUrls: [\n \"https://ipfsgateway.xyz\",\n \"https://gateway.plebpubsub.xyz\",\n \"https://gateway.forumindex.com\",\n ],\n kuboRpcClientsOptions: undefined,\n pubsubKuboRpcClientsOptions: [\n \"https://pubsubprovider.xyz/api/v0\",\n \"https://plebpubsub.xyz/api/v0\",\n \"https://rannithepleb.com/api/v0\",\n ],\n httpRoutersOptions: [\n \"https://routing.lol\",\n \"https://peers.pleb.bot\",\n \"https://peers.plebpubsub.xyz\",\n \"https://peers.forumindex.com\",\n ],\n ...overwritePkcOptions,\n });\n};\n\n// the gateway to use in <img src> for nft avatars\n// @ts-ignore\nconst defaultMediaIpfsGatewayUrl = window.defaultMediaIpfsGatewayUrl || \"https://ipfs.io\";\n\nconst generateDefaultAccount = async () => {\n const pkcOptions = getDefaultPkcOptions();\n const chainProviders = getDefaultChainProviders();\n const pkc = await PkcJs.PKC(\n getPkcClientOptions(\n {\n chainProviders,\n pkcOptions,\n },\n pkcOptions,\n ),\n );\n // handle errors or error events are uncaught\n // no need to log them because pkc-js already logs them\n pkc.on(\"error\", (error: any) =>\n log.error(\"uncaught pkc instance error, should never happen\", { error }),\n );\n\n const signer = await pkc.createSigner();\n const author = {\n address: signer.address,\n wallets: {\n eth: await chain.getEthWalletFromPkcPrivateKey(signer.privateKey, signer.address),\n },\n };\n\n const accountName = await getNextAvailableDefaultAccountName();\n\n // communities where the account has a role, like moderator, admin, owner, etc.\n const communities: { [communityAddress: string]: AccountCommunity } = {};\n\n const account = normalizeAccountProtocolConfig(\n withProtocolAliases(\n {\n id: uuid(),\n version: accountsDatabase.accountVersion,\n name: accountName,\n author,\n signer,\n chainProviders,\n pkcOptions,\n subscriptions: [],\n blockedAddresses: {},\n blockedCids: {},\n communities,\n mediaIpfsGatewayUrl: defaultMediaIpfsGatewayUrl,\n },\n pkc,\n pkcOptions,\n ),\n chainProviders,\n );\n return account;\n};\n\nconst getNextAvailableDefaultAccountName = async () => {\n const accountIds: string[] | null =\n await accountsDatabase.accountsMetadataDatabase.getItem(\"accountIds\");\n const accountNames = [];\n if (accountIds?.length) {\n const accounts: Accounts | null = await accountsDatabase.getAccounts(accountIds);\n for (const accountId of accountIds) {\n accountNames.push(accounts[accountId].name);\n }\n }\n let accountNumber = 1;\n if (!accountNames?.length) {\n return `Account ${accountNumber}`;\n }\n validator.validateAccountsDatabaseAccountNames(accountNames);\n\n const accountNamesSet = new Set(accountNames);\n while (true) {\n const accountName = `Account ${accountNumber}`;\n if (!accountNamesSet.has(accountName)) {\n return accountName;\n }\n accountNumber++;\n }\n};\n\nconst accountGenerator = {\n generateDefaultAccount,\n getDefaultPkcOptions,\n};\n\nexport default accountGenerator;\n"]}
1
+ {"version":3,"file":"account-generator.js","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAE5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AACzE,MAAM,CAAC,MAAM,oBAAoB,GAAG;IACl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sourcesContent":["import PkcJs from \"../../lib/pkc-js\";\nimport validator from \"../../lib/validator\";\nimport chain from \"../../lib/chain\";\nimport { v4 as uuid } from \"uuid\";\nimport accountsDatabase from \"./accounts-database\";\nimport { Accounts, AccountCommunity, ChainProviders } from \"../../types\";\nimport {\n getPkcClientOptions,\n normalizeAccountProtocolConfig,\n withProtocolAliases,\n} from \"../../lib/pkc-compat\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\n\nexport const DEFAULT_ETH_RPC_URL = \"https://ethereum-rpc.publicnode.com\";\nexport const DEFAULT_ETH_RPC_URLS = [\n DEFAULT_ETH_RPC_URL,\n \"https://eth.drpc.org\",\n \"https://ethereum.publicnode.com\",\n \"https://rpc.mevblocker.io\",\n \"https://1rpc.io/eth\",\n \"https://eth-pokt.nodies.app\",\n];\n\n// default chain providers\nconst chainProviders: ChainProviders = {\n eth: {\n // Use explicit RPCs for default name resolution; viem's default transport is opt-in.\n urls: [...DEFAULT_ETH_RPC_URLS, \"ethers.js\"],\n chainId: 1,\n },\n matic: {\n urls: [\"https://polygon-rpc.com\"],\n chainId: 137,\n },\n};\n\n// force using these options or can cause bugs\nexport const overwritePkcOptions = {\n resolveAuthorNames: false,\n resolveAuthorAddresses: false,\n validatePages: false,\n};\n\nconst aliasProtocolOptions = (options: Record<string, any>) => ({\n ...options,\n resolveAuthorNames: options.resolveAuthorNames ?? options.resolveAuthorAddresses ?? false,\n resolveAuthorAddresses: options.resolveAuthorAddresses ?? options.resolveAuthorNames ?? false,\n});\n\nconst addMissingChainProviders = (options: Record<string, any>) => {\n const optionsWithChainProviders = { ...options };\n if (!optionsWithChainProviders.chainProviders) {\n optionsWithChainProviders.chainProviders = {};\n }\n for (const chainTicker in chainProviders) {\n if (!optionsWithChainProviders.chainProviders[chainTicker]) {\n optionsWithChainProviders.chainProviders[chainTicker] = chainProviders[chainTicker];\n }\n }\n return optionsWithChainProviders;\n};\n\nexport const getDefaultChainProviders = () => {\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n const windowChainProviders = defaultWindowOptions?.chainProviders\n ? JSON.parse(JSON.stringify(defaultWindowOptions.chainProviders))\n : undefined;\n return addMissingChainProviders({\n chainProviders: windowChainProviders,\n }).chainProviders as ChainProviders;\n};\n\n// default options aren't saved to database so they can be changed\nexport const getDefaultPkcOptions = () => {\n // default PKC options defined by the electron process\n // @ts-ignore\n const defaultWindowOptions = window.defaultPkcOptions;\n if (defaultWindowOptions) {\n // @ts-ignore\n const defaultPkcOptions: any = JSON.parse(\n JSON.stringify({ ...defaultWindowOptions, libp2pJsClientsOptions: undefined }),\n );\n delete defaultPkcOptions.chainProviders;\n delete defaultPkcOptions.nameResolversChainProviders;\n // @ts-ignore\n defaultPkcOptions.libp2pJsClientsOptions = defaultWindowOptions.libp2pJsClientsOptions; // libp2pJsClientsOptions is not always just json\n return aliasProtocolOptions({ ...defaultPkcOptions, ...overwritePkcOptions });\n }\n // default PKC options for web client\n return aliasProtocolOptions({\n ipfsGatewayUrls: [\n \"https://ipfsgateway.xyz\",\n \"https://gateway.plebpubsub.xyz\",\n \"https://gateway.forumindex.com\",\n ],\n kuboRpcClientsOptions: undefined,\n pubsubKuboRpcClientsOptions: [\n \"https://pubsubprovider.xyz/api/v0\",\n \"https://plebpubsub.xyz/api/v0\",\n \"https://rannithepleb.com/api/v0\",\n ],\n httpRoutersOptions: [\n \"https://routing.lol\",\n \"https://peers.pleb.bot\",\n \"https://peers.plebpubsub.xyz\",\n \"https://peers.forumindex.com\",\n ],\n ...overwritePkcOptions,\n });\n};\n\n// the gateway to use in <img src> for nft avatars\n// @ts-ignore\nconst defaultMediaIpfsGatewayUrl = window.defaultMediaIpfsGatewayUrl || \"https://ipfs.io\";\n\nconst generateDefaultAccount = async () => {\n const pkcOptions = getDefaultPkcOptions();\n const chainProviders = getDefaultChainProviders();\n const pkc = await PkcJs.PKC(\n getPkcClientOptions(\n {\n chainProviders,\n pkcOptions,\n },\n pkcOptions,\n ),\n );\n // handle errors or error events are uncaught\n // no need to log them because pkc-js already logs them\n pkc.on(\"error\", (error: any) =>\n log.error(\"uncaught pkc instance error, should never happen\", { error }),\n );\n\n const signer = await pkc.createSigner();\n const author = {\n address: signer.address,\n wallets: {\n eth: await chain.getEthWalletFromPkcPrivateKey(signer.privateKey, signer.address),\n },\n };\n\n const accountName = await getNextAvailableDefaultAccountName();\n\n // communities where the account has a role, like moderator, admin, owner, etc.\n const communities: { [communityAddress: string]: AccountCommunity } = {};\n\n const account = normalizeAccountProtocolConfig(\n withProtocolAliases(\n {\n id: uuid(),\n version: accountsDatabase.accountVersion,\n name: accountName,\n author,\n signer,\n chainProviders,\n pkcOptions,\n subscriptions: [],\n blockedAddresses: {},\n blockedCids: {},\n communities,\n mediaIpfsGatewayUrl: defaultMediaIpfsGatewayUrl,\n },\n pkc,\n pkcOptions,\n ),\n chainProviders,\n );\n return account;\n};\n\nconst getNextAvailableDefaultAccountName = async () => {\n const accountIds: string[] | null =\n await accountsDatabase.accountsMetadataDatabase.getItem(\"accountIds\");\n const accountNames = [];\n if (accountIds?.length) {\n const accounts: Accounts | null = await accountsDatabase.getAccounts(accountIds);\n for (const accountId of accountIds) {\n accountNames.push(accounts[accountId].name);\n }\n }\n let accountNumber = 1;\n if (!accountNames?.length) {\n return `Account ${accountNumber}`;\n }\n validator.validateAccountsDatabaseAccountNames(accountNames);\n\n const accountNamesSet = new Set(accountNames);\n while (true) {\n const accountName = `Account ${accountNumber}`;\n if (!accountNamesSet.has(accountName)) {\n return accountName;\n }\n accountNumber++;\n }\n};\n\nconst accountGenerator = {\n generateDefaultAccount,\n getDefaultPkcOptions,\n};\n\nexport default accountGenerator;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EAEP,KAAK,EAEL,YAAY,EACZ,SAAS,EACT,WAAW,EAEX,QA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eds = (feedsOptions, filteredSortedFeeds, loadedFeeds, b
260
260
  }
261
261
  return nextLoadedFeeds;
262
262
  });
263
+ const getApprovalPublicationKey = (comment) => {
264
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
265
+ return [
266
+ (_a = comment.timestamp) !== null && _a !== void 0 ? _a : "",
267
+ (_b = comment.parentCid) !== null && _b !== void 0 ? _b : "",
268
+ (_c = comment.postCid) !== null && _c !== void 0 ? _c : "",
269
+ (_d = getCommentCommunityAddress(comment)) !== null && _d !== void 0 ? _d : "",
270
+ (_f = (_e = comment.author) === null || _e === void 0 ? void 0 : _e.address) !== null && _f !== void 0 ? _f : "",
271
+ (_g = comment.title) !== null && _g !== void 0 ? _g : "",
272
+ (_h = comment.content) !== null && _h !== void 0 ? _h : "",
273
+ (_j = comment.link) !== null && _j !== void 0 ? _j : "",
274
+ ].join("\0");
275
+ };
263
276
  export const addAccountsComments = (feedsOptions, loadedFeeds) => {
264
277
  let loadedFeedsChanged = false;
265
278
  const accountsComments = accountsStore.getState().accountsComments || {};
@@ -290,6 +303,9 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
290
303
  accountCidToPost.set(p.cid, p);
291
304
  }
292
305
  let loadedFeed = loadedFeeds[feedName] || [];
306
+ const approvedPublicationKeys = new Set(loadedFeed
307
+ .filter((post) => post.pendingApproval !== true)
308
+ .map((post) => getApprovalPublicationKey(post)));
293
309
  // prune stale local-account entries and replace when cid matches but index changed
294
310
  const prunedLoadedFeed = [];
295
311
  for (const post of loadedFeed) {
@@ -297,6 +313,11 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
297
313
  prunedLoadedFeed.push(post);
298
314
  continue;
299
315
  }
316
+ if (post.pendingApproval === true &&
317
+ approvedPublicationKeys.has(getApprovalPublicationKey(post))) {
318
+ loadedFeedsChanged = true;
319
+ continue;
320
+ }
300
321
  if (!validAccountIndices.has(post.index)) {
301
322
  loadedFeedsChanged = true;
302
323
  continue;
@@ -321,16 +342,23 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
321
342
  loadedFeed.forEach((post, loadedFeedIndex) => {
322
343
  if (post.cid)
323
344
  loadedFeedMap.set(post.cid, loadedFeedIndex);
324
- if (post.index)
345
+ if (typeof post.index === "number")
325
346
  loadedFeedMap.set(post.index, loadedFeedIndex);
326
347
  if (!post.cid)
327
348
  loadedFeedMap.set(post.timestamp, loadedFeedIndex);
349
+ if (post.pendingApproval !== true) {
350
+ loadedFeedMap.set(getApprovalPublicationKey(post), loadedFeedIndex);
351
+ }
328
352
  });
329
353
  for (const accountPost of accountPosts) {
330
354
  // account post with cid already added
331
355
  if (accountPost.cid && loadedFeedMap.has(accountPost.cid)) {
332
356
  continue;
333
357
  }
358
+ if (accountPost.pendingApproval === true &&
359
+ loadedFeedMap.has(getApprovalPublicationKey(accountPost))) {
360
+ continue;
361
+ }
334
362
  // account post without cid already added, but now we have the cid
335
363
  if (accountPost.cid && loadedFeedMap.has(accountPost.index)) {
336
364
  const loadedFeedIndex = loadedFeedMap.get(accountPost.index);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":";;;;;;;;;AAeA,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAEL,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAEzD,MAAM,oBAAoB,GA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C;QACrC,KAAK,MAAM,IAAI,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;YACjD,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,KAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC;gBACtD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import assert from \"assert\";\nimport {\n Comment,\n Feed,\n Feeds,\n FeedOptions,\n FeedsOptions,\n Community,\n Communities,\n Account,\n Accounts,\n CommunityPage,\n CommunitiesPages,\n FeedsCommunitiesPostCounts,\n} from \"../../types\";\nimport { getCommunityPages, getCommunityFirstPageCid } from \"../communities-pages\";\nimport accountsStore from \"../accounts\";\nimport feedSorter from \"./feed-sorter\";\nimport { communityPostsCacheExpired, commentIsValid, removeInvalidComments } from \"../../lib/utils\";\nimport { getCommentCommunityAddress, normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\nimport {\n CommunityLookupRef,\n doesAddressMatchCommunityRef,\n getCommunityRefKeys,\n getMatchingCommunityRefKeys,\n} from \"../../lib/community-ref\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:stores\");\n\nconst getFeedCommunityRefs = (feedOptions: Partial<FeedOptions>): CommunityLookupRef[] =>\n feedOptions.communities || [];\n\nconst getFeedCommunityKeys = (feedOptions: Partial<FeedOptions>) =>\n feedOptions.communityKeys || getCommunityRefKeys(getFeedCommunityRefs(feedOptions));\n\nconst getCommentFreshness = (comment: Comment | undefined) =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\nconst commentMatchesModQueue = (comment: Comment | undefined, modQueue?: string[]) => {\n const modQueueName = modQueue?.[0];\n if (!modQueueName) {\n return true;\n }\n if (modQueueName === \"pendingApproval\") {\n return comment?.pendingApproval === true;\n }\n return true;\n};\n\nconst getFeedPost = (\n post: Comment,\n communityRef: CommunityLookupRef,\n community: Community,\n modQueue?: string[],\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n const normalizedPost = normalizeCommentCommunityAddress(post) as Comment;\n const freshestComment = post.cid\n ? normalizeCommentCommunityAddress(freshestComments?.[post.cid])\n : undefined;\n const postCommunityAddress = getCommentCommunityAddress(normalizedPost);\n if (!doesAddressMatchCommunityRef(postCommunityAddress, communityRef, community)) {\n return;\n }\n if (!commentMatchesModQueue(normalizedPost, modQueue)) {\n return;\n }\n if (\n !freshestComment ||\n getCommentFreshness(freshestComment) <= getCommentFreshness(normalizedPost)\n ) {\n return normalizedPost;\n }\n if (!commentMatchesModQueue(freshestComment, modQueue)) {\n return;\n }\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(freshestComment),\n communityRef,\n community,\n )\n ) {\n return;\n }\n return freshestComment;\n};\n\nconst reconcileLoadedModQueueFeed = (\n feedOptions: FeedOptions,\n loadedFeed: Feed,\n filteredSortedFeed: Feed,\n) => {\n if (!feedOptions?.modQueue?.[0] || !loadedFeed?.length) {\n return loadedFeed;\n }\n\n const filteredSortedFeedByCid = new Map<string, Comment>();\n for (const post of filteredSortedFeed) {\n if (post.cid) {\n filteredSortedFeedByCid.set(post.cid, post);\n }\n }\n\n let changed = false;\n const nextLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (!post.cid) {\n nextLoadedFeed.push(post);\n continue;\n }\n\n const sourcePost = filteredSortedFeedByCid.get(post.cid);\n if (!sourcePost) {\n changed = true;\n continue;\n }\n\n if (getCommentFreshness(sourcePost) > getCommentFreshness(post)) {\n nextLoadedFeed.push(sourcePost);\n changed = true;\n continue;\n }\n\n nextLoadedFeed.push(post);\n }\n\n return changed ? nextLoadedFeed : loadedFeed;\n};\n\n/**\n * Calculate the feeds from all the loaded community pages, filter and sort them\n */\nexport const getFilteredSortedFeeds = (\n feedsOptions: FeedsOptions,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n // calculate each feed\n let feeds: Feeds = {};\n for (const feedName in feedsOptions) {\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, filter, newerThan, modQueue } = feedsOptions[feedName];\n const newerThanTimestamp = newerThan ? Math.floor(Date.now() / 1000) - newerThan : undefined;\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // find all fetched posts\n const bufferedFeedPosts = [];\n\n // add each comment from each page, do not filter at this stage, filter after sorting\n for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const communityRef = communityRefs[communityIndex];\n // community hasn't loaded yet\n const community = communities[communityKey];\n if (!community || !communityRef) {\n continue;\n }\n\n // if cache is expired and has internet access, don't use, wait for next community update\n if (communityPostsCacheExpired(community) && window.navigator.onLine) {\n continue;\n }\n\n // use community preloaded posts if any\n const preloadedPosts = getPreloadedPosts(community, sortType);\n if (preloadedPosts) {\n for (const post of preloadedPosts) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(getCommentCommunityAddress(post), communityRef, community)\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (nextPost) {\n bufferedFeedPosts.push(nextPost);\n }\n }\n }\n\n // add all posts from community pages\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n accountId,\n );\n for (const communityPage of communityPages) {\n if (communityPage?.comments) {\n for (const post of communityPage.comments) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(post),\n communityRef,\n community,\n )\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (nextPost) {\n bufferedFeedPosts.push(nextPost);\n }\n }\n }\n }\n }\n\n // sort the feed before filtering to get more accurate results\n const originalSortType = feedsOptions[feedName].sortType;\n const sortedBufferedFeedPosts = feedSorter.sort(originalSortType, bufferedFeedPosts);\n\n // filter the feed\n const filteredSortedBufferedFeedPosts = [];\n for (const post of sortedBufferedFeedPosts) {\n // address is blocked\n if (\n accounts[accountId]?.blockedAddresses[getCommentCommunityAddress(post) || \"\"] ||\n (post.author?.address && accounts[accountId]?.blockedAddresses[post.author.address])\n ) {\n continue;\n }\n\n // comment cid is blocked\n if (accounts[accountId]?.blockedCids[post.cid]) {\n continue;\n }\n\n // if a feed has more than 1 sub, don't include pinned posts\n // TODO: add test to check if pinned are filtered\n if (post.pinned && communityKeys.length > 1) {\n continue;\n }\n\n // feedOptions filter function\n if (filter && !filter.filter(post)) {\n continue;\n }\n\n // filter posts older than newerThan option\n if (newerThanTimestamp) {\n if (sortType === \"active\") {\n if ((post.lastReplyTimestamp || post.timestamp) <= newerThanTimestamp) {\n continue;\n }\n } else {\n if (post.timestamp <= newerThanTimestamp) {\n continue;\n }\n }\n }\n\n filteredSortedBufferedFeedPosts.push(post);\n }\n\n feeds[feedName] = filteredSortedBufferedFeedPosts;\n }\n return feeds;\n};\n\nconst getPreloadedPosts = (community: Community, sortType: string) => {\n let preloadedPosts = community.posts?.pages?.[sortType]?.comments;\n if (preloadedPosts) {\n return preloadedPosts;\n }\n const hasPageCids = Object.keys(community.posts?.pageCids || {}).length !== 0;\n if (hasPageCids) {\n return;\n }\n const pages: any[] = Object.values(community.posts?.pages || {});\n if (!pages.length) {\n return;\n }\n const nextCids = pages.map((page: any) => page?.nextCid).filter((nextCid) => !!nextCid);\n if (nextCids.length > 0) {\n return;\n }\n // if has a preloaded page, but no pageCids and no nextCids, it means all posts fit in a single preloaded page\n // so any sort type can be used, and later be resorted by the client\n if (pages[0]?.comments?.length) {\n return pages[0].comments;\n }\n};\n\nexport const getLoadedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n bufferedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const nextLoadedFeeds: Feeds = { ...loadedFeeds };\n let loadedFeedsChanged = false;\n for (const feedName in feedsOptions) {\n const { pageNumber, postsPerPage, accountId } = feedsOptions[feedName];\n const pkc = accounts[accountId]?.pkc;\n const loadedFeedPostCount = pageNumber * postsPerPage;\n const currentLoadedFeed = reconcileLoadedModQueueFeed(\n feedsOptions[feedName],\n loadedFeeds[feedName] || [],\n filteredSortedFeeds[feedName] || [],\n );\n if (currentLoadedFeed !== loadedFeeds[feedName]) {\n nextLoadedFeeds[feedName] = currentLoadedFeed;\n loadedFeedsChanged = true;\n }\n const missingPostsCount =\n loadedFeedPostCount - currentLoadedFeed.filter((post) => post.index === undefined).length;\n\n // get new posts from buffered feed\n const bufferedFeed = bufferedFeeds[feedName] || [];\n\n let missingPosts: any[] = [];\n for (const post of bufferedFeed) {\n if (missingPosts.length >= missingPostsCount) {\n missingPosts = await removeInvalidComments(missingPosts, { validateReplies: false }, pkc);\n // only stop if there were no invalid comments\n if (missingPosts.length >= missingPostsCount) {\n break;\n }\n }\n missingPosts.push(post);\n }\n\n // the current loaded feed already exist and doesn't need new posts\n if (\n missingPosts.length === 0 &&\n loadedFeeds[feedName] &&\n currentLoadedFeed === loadedFeeds[feedName]\n ) {\n continue;\n }\n nextLoadedFeeds[feedName] = [...currentLoadedFeed, ...missingPosts];\n if (missingPosts.length > 0) {\n loadedFeedsChanged = true;\n }\n }\n\n // add account comments\n const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, nextLoadedFeeds);\n\n // do nothing if there are no missing posts\n if (!loadedFeedsChanged && !accountCommentsChangedFeeds) {\n return loadedFeeds;\n }\n return nextLoadedFeeds;\n};\n\nexport const addAccountsComments = (feedsOptions: FeedsOptions, loadedFeeds: Feeds) => {\n let loadedFeedsChanged = false;\n const accountsComments = accountsStore.getState().accountsComments || {};\n for (const feedName in feedsOptions) {\n const { accountId, accountComments: accountCommentsOptions } = feedsOptions[feedName];\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const { newerThan, append } = accountCommentsOptions || {};\n if (!newerThan) {\n continue;\n }\n const newerThanTimestamp =\n newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;\n const isNewerThan = (post: Comment) => post.timestamp > newerThanTimestamp;\n\n const accountComments = accountsComments[accountId] || [];\n const accountPosts = accountComments.filter((comment) => {\n // is a reply, not a post\n if (comment.parentCid || comment.depth > 0) {\n return false;\n }\n if (!isNewerThan(comment)) {\n return false;\n }\n return (\n getMatchingCommunityRefKeys(communityRefs, getCommentCommunityAddress(comment)).length > 0\n );\n });\n const validAccountIndices = new Set(accountPosts.map((p) => p.index));\n const accountCidToPost = new Map<string, Comment>();\n for (const p of accountPosts) {\n if (p.cid) accountCidToPost.set(p.cid, p);\n }\n\n let loadedFeed = loadedFeeds[feedName] || [];\n // prune stale local-account entries and replace when cid matches but index changed\n const prunedLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (post.index === undefined) {\n prunedLoadedFeed.push(post);\n continue;\n }\n if (!validAccountIndices.has(post.index)) {\n loadedFeedsChanged = true;\n continue;\n }\n if (post.cid) {\n const freshAccountPost = accountCidToPost.get(post.cid);\n if (freshAccountPost && freshAccountPost.index !== post.index) {\n prunedLoadedFeed.push(freshAccountPost);\n loadedFeedsChanged = true;\n continue;\n }\n }\n prunedLoadedFeed.push(post);\n }\n loadedFeed = loadedFeeds[feedName] = prunedLoadedFeed;\n\n if (!accountPosts.length) {\n continue;\n }\n // if a loaded comment doesn't have a cid, then it's pending\n // and pending account comments should always have unique timestamps\n const loadedFeedMap = new Map();\n loadedFeed.forEach((post, loadedFeedIndex) => {\n if (post.cid) loadedFeedMap.set(post.cid, loadedFeedIndex);\n if (post.index) loadedFeedMap.set(post.index, loadedFeedIndex);\n if (!post.cid) loadedFeedMap.set(post.timestamp, loadedFeedIndex);\n });\n for (const accountPost of accountPosts) {\n // account post with cid already added\n if (accountPost.cid && loadedFeedMap.has(accountPost.cid)) {\n continue;\n }\n // account post without cid already added, but now we have the cid\n if (accountPost.cid && loadedFeedMap.has(accountPost.index)) {\n const loadedFeedIndex = loadedFeedMap.get(accountPost.index);\n // update the feed with the accountPost.cid now that we have it\n loadedFeed[loadedFeedIndex] = accountPost;\n loadedFeedsChanged = true;\n continue;\n }\n if (loadedFeedMap.has(accountPost.index)) {\n continue;\n }\n // pending account post without cid already added\n if (!accountPost.cid && loadedFeedMap.has(accountPost.timestamp)) {\n continue;\n }\n if (append) {\n loadedFeed.push(accountPost);\n } else {\n loadedFeed.unshift(accountPost);\n }\n loadedFeedsChanged = true;\n }\n }\n return loadedFeedsChanged;\n};\n\nexport const getBufferedFeedsWithoutLoadedFeeds = (bufferedFeeds: Feeds, loadedFeeds: Feeds) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const loadedFeedsPosts: { [key: string]: Set<string> } = {};\n for (const feedName in loadedFeeds) {\n loadedFeedsPosts[feedName] = new Set();\n for (const post of loadedFeeds[feedName]) {\n loadedFeedsPosts[feedName].add(post.cid);\n }\n }\n\n const newBufferedFeeds: Feeds = {};\n for (const feedName in bufferedFeeds) {\n newBufferedFeeds[feedName] = [];\n let bufferedFeedPostChanged = false;\n for (const [i, post] of bufferedFeeds[feedName].entries()) {\n if (loadedFeedsPosts[feedName]?.has(post.cid)) {\n continue;\n }\n newBufferedFeeds[feedName].push(post);\n if (\n !bufferedFeedPostChanged &&\n (newBufferedFeeds[feedName][i]?.cid !== bufferedFeeds[feedName][i]?.cid ||\n (newBufferedFeeds[feedName][i]?.updatedAt || 0) >\n (bufferedFeeds[feedName][i]?.updatedAt || 0))\n ) {\n bufferedFeedPostChanged = true;\n }\n }\n if (\n !bufferedFeedPostChanged &&\n newBufferedFeeds[feedName].length === bufferedFeeds[feedName].length\n ) {\n newBufferedFeeds[feedName] = bufferedFeeds[feedName];\n }\n }\n return newBufferedFeeds;\n};\n\nexport const getUpdatedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n updatedFeeds: Feeds,\n loadedFeeds: Feeds,\n accounts: Accounts,\n) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const updatedFeedsPosts: { [feedName: string]: { [postCid: string]: any } } = {};\n for (const feedName in updatedFeeds) {\n updatedFeedsPosts[feedName] = {};\n for (const [index, updatedPost] of updatedFeeds[feedName].entries()) {\n updatedFeedsPosts[feedName][updatedPost.cid] = { index, updatedPost };\n }\n }\n\n const newUpdatedFeeds: Feeds = { ...updatedFeeds };\n for (const feedName in filteredSortedFeeds) {\n const pkc = accounts[feedsOptions[feedName]?.accountId]?.pkc;\n const updatedFeed = [...(updatedFeeds[feedName] || [])];\n const onlyHasNewPosts = updatedFeed.length === 0;\n let updatedFeedChanged = false;\n\n // add new posts from loadedFeed posts\n while (updatedFeed.length < loadedFeeds[feedName].length) {\n updatedFeed[updatedFeed.length] = loadedFeeds[feedName][updatedFeed.length];\n updatedFeedChanged = true;\n }\n\n // add updated post from filteredSortedFeed\n if (!onlyHasNewPosts) {\n const promises = [];\n for (const post of filteredSortedFeeds[feedName]) {\n if (updatedFeedsPosts[feedName]?.[post.cid]) {\n const { index, updatedPost } = updatedFeedsPosts[feedName][post.cid];\n // faster to validate comments async\n promises.push(\n (async () => {\n if (\n (post.updatedAt || 0) > (updatedPost.updatedAt || 0) &&\n (await commentIsValid(post, { validateReplies: false }, pkc))\n ) {\n updatedFeed[index] = post;\n updatedFeedChanged = true;\n }\n })(),\n );\n }\n }\n await Promise.all(promises);\n }\n\n if (updatedFeedChanged) {\n newUpdatedFeeds[feedName] = updatedFeed;\n }\n }\n return newUpdatedFeeds;\n};\n\n// find with communities have posts newer (or ranked higher) than the loaded feeds\n// can be used to display \"new posts in x, y, z subs\" alert, like on twitter\nexport const getFeedsCommunityKeysWithNewerPosts = (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n previousFeedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] },\n) => {\n const feedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] } = {};\n for (const feedName in loadedFeeds) {\n const loadedFeed = loadedFeeds[feedName];\n const cidsInLoadedFeed = new Set();\n for (const post of loadedFeed) {\n cidsInLoadedFeed.add(post.cid);\n }\n const communityKeysWithNewerPostsSet = new Set<string>();\n for (const [i, post] of filteredSortedFeeds[feedName].entries()) {\n if (i >= loadedFeed.length) {\n break;\n }\n // if any post in filteredSortedFeeds ranks higher than the loaded feed count, it's a newer post\n if (!cidsInLoadedFeed.has(post.cid)) {\n const postCommunityAddress = getCommentCommunityAddress(post);\n if (postCommunityAddress) {\n getMatchingCommunityRefKeys(\n getFeedCommunityRefs(feedsOptions[feedName] || {}),\n postCommunityAddress,\n ).forEach((communityKey) => communityKeysWithNewerPostsSet.add(communityKey));\n }\n }\n }\n const communityKeysWithNewerPosts = [...communityKeysWithNewerPostsSet];\n\n // don't update the array if the data is the same to avoid rerenders\n const previousCommunityKeysWithNewerPosts =\n previousFeedsCommunityKeysWithNewerPosts[feedName] || [];\n if (\n communityKeysWithNewerPosts.length === previousCommunityKeysWithNewerPosts.length &&\n communityKeysWithNewerPosts.toString() === previousCommunityKeysWithNewerPosts.toString()\n ) {\n feedsCommunityKeysWithNewerPosts[feedName] =\n previousFeedsCommunityKeysWithNewerPosts[feedName];\n } else {\n feedsCommunityKeysWithNewerPosts[feedName] = communityKeysWithNewerPosts;\n }\n }\n return feedsCommunityKeysWithNewerPosts;\n};\n\n// find how many posts are left in each communities in a buffereds feeds\nexport const getFeedsCommunitiesPostCounts = (feedsOptions: FeedsOptions, feeds: Feeds) => {\n const feedsCommunitiesPostCounts: FeedsCommunitiesPostCounts = {};\n for (const feedName in feedsOptions) {\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n feedsCommunitiesPostCounts[feedName] = {};\n for (const communityKey of communityKeys) {\n feedsCommunitiesPostCounts[feedName][communityKey] = 0;\n }\n for (const comment of feeds[feedName] || []) {\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress) {\n getMatchingCommunityRefKeys(communityRefs, commentCommunityAddress).forEach(\n (communityKey) => {\n feedsCommunitiesPostCounts[feedName][communityKey] =\n (feedsCommunitiesPostCounts[feedName][communityKey] || 0) + 1;\n },\n );\n }\n }\n }\n return feedsCommunitiesPostCounts;\n};\n\n/**\n * Get which feeds have more posts, i.e. have not reached the final page of all subs\n */\nexport const getFeedsHaveMore = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n) => {\n const feedsHaveMore: { [feedName: string]: boolean } = {};\n feedsLoop: for (const feedName in feedsOptions) {\n // if the feed still has buffered posts, then it still has more\n if (bufferedFeeds[feedName]?.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, modQueue } = feedsOptions[feedName];\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n communityKeysLoop: for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const community = communities[communityKey];\n const communityRef = communityRefs[communityIndex];\n const isBlockedCommunity = Object.keys(accounts[accountId]?.blockedAddresses || {}).some(\n (blockedAddress) =>\n communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community),\n );\n\n // don't consider the sub if the address is blocked\n if (isBlockedCommunity) {\n continue communityKeysLoop;\n }\n\n // if at least 1 community hasn't loaded yet, then the feed still has more\n if (!community?.updatedAt) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n // if at least 1 community has posts cache expired, then the feed still has more\n if (communityPostsCacheExpired(community)) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\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 // 'continue' to ignore it for now\n if (!firstPageCid) {\n continue communityKeysLoop;\n }\n const pages = getCommunityPages(community, sortType, communitiesPages, pageType, accountId);\n // if first page isn't loaded yet, then the feed still has more\n if (!pages.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n const lastPage = pages[pages.length - 1];\n if (lastPage.nextCid) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n }\n\n // if buffered feeds are empty and no last page of any community has a next page, then has more is false\n feedsHaveMore[feedName] = false;\n }\n return feedsHaveMore;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunities = (feedsOptions: FeedsOptions, communities: Communities) => {\n // find all feeds communities\n const feedsCommunityAddresses = new Set<string>();\n Object.keys(feedsOptions).forEach((i) =>\n getFeedCommunityKeys(feedsOptions[i]).forEach((a) => feedsCommunityAddresses.add(a)),\n );\n\n // use map for performance increase when checking size\n const feedsCommunities = new Map<string, Community>();\n for (const communityAddress of feedsCommunityAddresses) {\n feedsCommunities.set(communityAddress, communities[communityAddress]);\n }\n return feedsCommunities;\n};\n\nexport const feedsCommunitiesChanged = (\n previousFeedsCommunities: Map<string, Community>,\n feedsCommunities: Map<string, Community>,\n) => {\n if (previousFeedsCommunities.size !== feedsCommunities.size) {\n return true;\n }\n for (let communityAddress of previousFeedsCommunities.keys()) {\n // check if the object is still the same\n if (previousFeedsCommunities.get(communityAddress) !== feedsCommunities.get(communityAddress)) {\n return true;\n }\n }\n return false;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesFirstPageCids = (\n feedsCommunities: Map<string, Community>,\n): string[] => {\n // find all the feeds communities first page cids\n const feedsCommunitiesFirstPageCids = new Set<string>();\n for (const community of feedsCommunities.values()) {\n if (!community?.posts && !community?.modQueue) {\n continue;\n }\n\n // check pages\n if (community.posts?.pages) {\n for (const page of Object.values<CommunityPage>(community.posts.pages)) {\n if (page?.nextCid) {\n feedsCommunitiesFirstPageCids.add(page?.nextCid);\n }\n }\n }\n\n // check pageCids\n if (community.posts?.pageCids) {\n for (const pageCid of Object.values<string>(community.posts.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n\n // TODO: would be more performant to only check modQueue if there's a feedOptions with modQueue\n if (community.modQueue?.pageCids) {\n for (const pageCid of Object.values<string>(community.modQueue.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n }\n\n return [...feedsCommunitiesFirstPageCids].sort();\n};\n\n// get all communities posts pages first post updatedAts, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesPostsPagesFirstUpdatedAts = (\n feedsCommunities: Map<string, Community>,\n): string => {\n let feedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\n for (const community of feedsCommunities.values()) {\n for (const page of Object.values<CommunityPage>(community?.posts?.pages || {})) {\n if (page?.comments?.[0]?.updatedAt) {\n feedsCommunitiesPostsPagesFirstUpdatedAts +=\n page.comments[0].cid + page.comments[0].updatedAt;\n }\n }\n }\n return feedsCommunitiesPostsPagesFirstUpdatedAts;\n};\n\n// get number of feeds community that are loaded\nexport const getFeedsCommunitiesLoadedCount = (\n feedsCommunities: Map<string, Community>,\n): number => {\n let count = 0;\n for (const community of feedsCommunities.values()) {\n if (community?.updatedAt) {\n count++;\n }\n }\n return count;\n};\n\nexport const getAccountsBlockedAddresses = (accounts: Accounts) => {\n const blockedAddressesSet = new Set<string>();\n for (const { blockedAddresses } of Object.values(accounts)) {\n for (const address in blockedAddresses) {\n if (blockedAddresses[address]) {\n blockedAddressesSet.add(address);\n }\n }\n }\n return [...blockedAddressesSet].sort();\n};\n\nexport const accountsBlockedAddressesChanged = (\n previousAccountsBlockedAddresses: { [address: string]: boolean }[],\n accountsBlockedAddresses: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedAddresses.length !== accountsBlockedAddresses.length) {\n return true;\n }\n for (const i in previousAccountsBlockedAddresses) {\n // check if the object is still the same\n if (previousAccountsBlockedAddresses[i] !== accountsBlockedAddresses[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedAddresses = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedAddresses: string[],\n previousBlockedAddresses: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedAddresses = blockedAddresses\n .filter((x) => !previousBlockedAddresses.includes(x))\n .concat(previousBlockedAddresses.filter((x) => !blockedAddresses.includes(x)));\n\n // if changed blocked addresses arent used in the feeds, do nothing\n for (const address of changedBlockedAddresses) {\n for (const feedName in feedsOptions) {\n const feedOptions = feedsOptions[feedName];\n if (\n getMatchingCommunityRefKeys(getFeedCommunityRefs(feedOptions), address).some(\n (communityKey) => getFeedCommunityKeys(feedOptions).includes(communityKey),\n )\n ) {\n return true;\n }\n }\n }\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedAddressesSet = new Set(changedBlockedAddresses);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.author?.address && changedBlockedAddressesSet.has(post.author.address)) {\n return true;\n }\n }\n }\n\n return false;\n};\n\nexport const getAccountsBlockedCids = (accounts: Accounts) => {\n const blockedCidsSet = new Set<string>();\n for (const { blockedCids } of Object.values(accounts)) {\n for (const address in blockedCids) {\n if (blockedCids[address]) {\n blockedCidsSet.add(address);\n }\n }\n }\n return [...blockedCidsSet].sort();\n};\n\nexport const accountsBlockedCidsChanged = (\n previousAccountsBlockedCids: { [address: string]: boolean }[],\n accountsBlockedCids: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedCids.length !== accountsBlockedCids.length) {\n return true;\n }\n for (const i in previousAccountsBlockedCids) {\n // check if the object is still the same\n if (previousAccountsBlockedCids[i] !== accountsBlockedCids[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedCids = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedCids: string[],\n previousBlockedCids: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedCids = blockedCids\n .filter((x) => !previousBlockedCids.includes(x))\n .concat(previousBlockedCids.filter((x) => !blockedCids.includes(x)));\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedCidsSet = new Set(changedBlockedCids);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.cid && changedBlockedCidsSet.has(post?.cid)) {\n return true;\n }\n }\n }\n\n return false;\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":";;;;;;;;;AAeA,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAEL,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAEzD,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MAAM,IAAI,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;YACjD,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,KAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC;gBACtD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import assert from \"assert\";\nimport {\n Comment,\n Feed,\n Feeds,\n FeedOptions,\n FeedsOptions,\n Community,\n Communities,\n Account,\n Accounts,\n CommunityPage,\n CommunitiesPages,\n FeedsCommunitiesPostCounts,\n} from \"../../types\";\nimport { getCommunityPages, getCommunityFirstPageCid } from \"../communities-pages\";\nimport accountsStore from \"../accounts\";\nimport feedSorter from \"./feed-sorter\";\nimport { communityPostsCacheExpired, commentIsValid, removeInvalidComments } from \"../../lib/utils\";\nimport { getCommentCommunityAddress, normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\nimport {\n CommunityLookupRef,\n doesAddressMatchCommunityRef,\n getCommunityRefKeys,\n getMatchingCommunityRefKeys,\n} from \"../../lib/community-ref\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:stores\");\n\nconst getFeedCommunityRefs = (feedOptions: Partial<FeedOptions>): CommunityLookupRef[] =>\n feedOptions.communities || [];\n\nconst getFeedCommunityKeys = (feedOptions: Partial<FeedOptions>) =>\n feedOptions.communityKeys || getCommunityRefKeys(getFeedCommunityRefs(feedOptions));\n\nconst getCommentFreshness = (comment: Comment | undefined) =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\nconst commentMatchesModQueue = (comment: Comment | undefined, modQueue?: string[]) => {\n const modQueueName = modQueue?.[0];\n if (!modQueueName) {\n return true;\n }\n if (modQueueName === \"pendingApproval\") {\n return comment?.pendingApproval === true;\n }\n return true;\n};\n\nconst getFeedPost = (\n post: Comment,\n communityRef: CommunityLookupRef,\n community: Community,\n modQueue?: string[],\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n const normalizedPost = normalizeCommentCommunityAddress(post) as Comment;\n const freshestComment = post.cid\n ? normalizeCommentCommunityAddress(freshestComments?.[post.cid])\n : undefined;\n const postCommunityAddress = getCommentCommunityAddress(normalizedPost);\n if (!doesAddressMatchCommunityRef(postCommunityAddress, communityRef, community)) {\n return;\n }\n if (!commentMatchesModQueue(normalizedPost, modQueue)) {\n return;\n }\n if (\n !freshestComment ||\n getCommentFreshness(freshestComment) <= getCommentFreshness(normalizedPost)\n ) {\n return normalizedPost;\n }\n if (!commentMatchesModQueue(freshestComment, modQueue)) {\n return;\n }\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(freshestComment),\n communityRef,\n community,\n )\n ) {\n return;\n }\n return freshestComment;\n};\n\nconst reconcileLoadedModQueueFeed = (\n feedOptions: FeedOptions,\n loadedFeed: Feed,\n filteredSortedFeed: Feed,\n) => {\n if (!feedOptions?.modQueue?.[0] || !loadedFeed?.length) {\n return loadedFeed;\n }\n\n const filteredSortedFeedByCid = new Map<string, Comment>();\n for (const post of filteredSortedFeed) {\n if (post.cid) {\n filteredSortedFeedByCid.set(post.cid, post);\n }\n }\n\n let changed = false;\n const nextLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (!post.cid) {\n nextLoadedFeed.push(post);\n continue;\n }\n\n const sourcePost = filteredSortedFeedByCid.get(post.cid);\n if (!sourcePost) {\n changed = true;\n continue;\n }\n\n if (getCommentFreshness(sourcePost) > getCommentFreshness(post)) {\n nextLoadedFeed.push(sourcePost);\n changed = true;\n continue;\n }\n\n nextLoadedFeed.push(post);\n }\n\n return changed ? nextLoadedFeed : loadedFeed;\n};\n\n/**\n * Calculate the feeds from all the loaded community pages, filter and sort them\n */\nexport const getFilteredSortedFeeds = (\n feedsOptions: FeedsOptions,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n // calculate each feed\n let feeds: Feeds = {};\n for (const feedName in feedsOptions) {\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, filter, newerThan, modQueue } = feedsOptions[feedName];\n const newerThanTimestamp = newerThan ? Math.floor(Date.now() / 1000) - newerThan : undefined;\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // find all fetched posts\n const bufferedFeedPosts = [];\n\n // add each comment from each page, do not filter at this stage, filter after sorting\n for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const communityRef = communityRefs[communityIndex];\n // community hasn't loaded yet\n const community = communities[communityKey];\n if (!community || !communityRef) {\n continue;\n }\n\n // if cache is expired and has internet access, don't use, wait for next community update\n if (communityPostsCacheExpired(community) && window.navigator.onLine) {\n continue;\n }\n\n // use community preloaded posts if any\n const preloadedPosts = getPreloadedPosts(community, sortType);\n if (preloadedPosts) {\n for (const post of preloadedPosts) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(getCommentCommunityAddress(post), communityRef, community)\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (nextPost) {\n bufferedFeedPosts.push(nextPost);\n }\n }\n }\n\n // add all posts from community pages\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n accountId,\n );\n for (const communityPage of communityPages) {\n if (communityPage?.comments) {\n for (const post of communityPage.comments) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(post),\n communityRef,\n community,\n )\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (nextPost) {\n bufferedFeedPosts.push(nextPost);\n }\n }\n }\n }\n }\n\n // sort the feed before filtering to get more accurate results\n const originalSortType = feedsOptions[feedName].sortType;\n const sortedBufferedFeedPosts = feedSorter.sort(originalSortType, bufferedFeedPosts);\n\n // filter the feed\n const filteredSortedBufferedFeedPosts = [];\n for (const post of sortedBufferedFeedPosts) {\n // address is blocked\n if (\n accounts[accountId]?.blockedAddresses[getCommentCommunityAddress(post) || \"\"] ||\n (post.author?.address && accounts[accountId]?.blockedAddresses[post.author.address])\n ) {\n continue;\n }\n\n // comment cid is blocked\n if (accounts[accountId]?.blockedCids[post.cid]) {\n continue;\n }\n\n // if a feed has more than 1 sub, don't include pinned posts\n // TODO: add test to check if pinned are filtered\n if (post.pinned && communityKeys.length > 1) {\n continue;\n }\n\n // feedOptions filter function\n if (filter && !filter.filter(post)) {\n continue;\n }\n\n // filter posts older than newerThan option\n if (newerThanTimestamp) {\n if (sortType === \"active\") {\n if ((post.lastReplyTimestamp || post.timestamp) <= newerThanTimestamp) {\n continue;\n }\n } else {\n if (post.timestamp <= newerThanTimestamp) {\n continue;\n }\n }\n }\n\n filteredSortedBufferedFeedPosts.push(post);\n }\n\n feeds[feedName] = filteredSortedBufferedFeedPosts;\n }\n return feeds;\n};\n\nconst getPreloadedPosts = (community: Community, sortType: string) => {\n let preloadedPosts = community.posts?.pages?.[sortType]?.comments;\n if (preloadedPosts) {\n return preloadedPosts;\n }\n const hasPageCids = Object.keys(community.posts?.pageCids || {}).length !== 0;\n if (hasPageCids) {\n return;\n }\n const pages: any[] = Object.values(community.posts?.pages || {});\n if (!pages.length) {\n return;\n }\n const nextCids = pages.map((page: any) => page?.nextCid).filter((nextCid) => !!nextCid);\n if (nextCids.length > 0) {\n return;\n }\n // if has a preloaded page, but no pageCids and no nextCids, it means all posts fit in a single preloaded page\n // so any sort type can be used, and later be resorted by the client\n if (pages[0]?.comments?.length) {\n return pages[0].comments;\n }\n};\n\nexport const getLoadedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n bufferedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const nextLoadedFeeds: Feeds = { ...loadedFeeds };\n let loadedFeedsChanged = false;\n for (const feedName in feedsOptions) {\n const { pageNumber, postsPerPage, accountId } = feedsOptions[feedName];\n const pkc = accounts[accountId]?.pkc;\n const loadedFeedPostCount = pageNumber * postsPerPage;\n const currentLoadedFeed = reconcileLoadedModQueueFeed(\n feedsOptions[feedName],\n loadedFeeds[feedName] || [],\n filteredSortedFeeds[feedName] || [],\n );\n if (currentLoadedFeed !== loadedFeeds[feedName]) {\n nextLoadedFeeds[feedName] = currentLoadedFeed;\n loadedFeedsChanged = true;\n }\n const missingPostsCount =\n loadedFeedPostCount - currentLoadedFeed.filter((post) => post.index === undefined).length;\n\n // get new posts from buffered feed\n const bufferedFeed = bufferedFeeds[feedName] || [];\n\n let missingPosts: any[] = [];\n for (const post of bufferedFeed) {\n if (missingPosts.length >= missingPostsCount) {\n missingPosts = await removeInvalidComments(missingPosts, { validateReplies: false }, pkc);\n // only stop if there were no invalid comments\n if (missingPosts.length >= missingPostsCount) {\n break;\n }\n }\n missingPosts.push(post);\n }\n\n // the current loaded feed already exist and doesn't need new posts\n if (\n missingPosts.length === 0 &&\n loadedFeeds[feedName] &&\n currentLoadedFeed === loadedFeeds[feedName]\n ) {\n continue;\n }\n nextLoadedFeeds[feedName] = [...currentLoadedFeed, ...missingPosts];\n if (missingPosts.length > 0) {\n loadedFeedsChanged = true;\n }\n }\n\n // add account comments\n const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, nextLoadedFeeds);\n\n // do nothing if there are no missing posts\n if (!loadedFeedsChanged && !accountCommentsChangedFeeds) {\n return loadedFeeds;\n }\n return nextLoadedFeeds;\n};\n\nconst getApprovalPublicationKey = (comment: Comment) =>\n [\n comment.timestamp ?? \"\",\n comment.parentCid ?? \"\",\n comment.postCid ?? \"\",\n getCommentCommunityAddress(comment) ?? \"\",\n comment.author?.address ?? \"\",\n comment.title ?? \"\",\n comment.content ?? \"\",\n comment.link ?? \"\",\n ].join(\"\\0\");\n\nexport const addAccountsComments = (feedsOptions: FeedsOptions, loadedFeeds: Feeds) => {\n let loadedFeedsChanged = false;\n const accountsComments = accountsStore.getState().accountsComments || {};\n for (const feedName in feedsOptions) {\n const { accountId, accountComments: accountCommentsOptions } = feedsOptions[feedName];\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const { newerThan, append } = accountCommentsOptions || {};\n if (!newerThan) {\n continue;\n }\n const newerThanTimestamp =\n newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;\n const isNewerThan = (post: Comment) => post.timestamp > newerThanTimestamp;\n\n const accountComments = accountsComments[accountId] || [];\n const accountPosts = accountComments.filter((comment) => {\n // is a reply, not a post\n if (comment.parentCid || comment.depth > 0) {\n return false;\n }\n if (!isNewerThan(comment)) {\n return false;\n }\n return (\n getMatchingCommunityRefKeys(communityRefs, getCommentCommunityAddress(comment)).length > 0\n );\n });\n const validAccountIndices = new Set(accountPosts.map((p) => p.index));\n const accountCidToPost = new Map<string, Comment>();\n for (const p of accountPosts) {\n if (p.cid) accountCidToPost.set(p.cid, p);\n }\n\n let loadedFeed = loadedFeeds[feedName] || [];\n const approvedPublicationKeys = new Set(\n loadedFeed\n .filter((post) => post.pendingApproval !== true)\n .map((post) => getApprovalPublicationKey(post)),\n );\n // prune stale local-account entries and replace when cid matches but index changed\n const prunedLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (post.index === undefined) {\n prunedLoadedFeed.push(post);\n continue;\n }\n if (\n post.pendingApproval === true &&\n approvedPublicationKeys.has(getApprovalPublicationKey(post))\n ) {\n loadedFeedsChanged = true;\n continue;\n }\n if (!validAccountIndices.has(post.index)) {\n loadedFeedsChanged = true;\n continue;\n }\n if (post.cid) {\n const freshAccountPost = accountCidToPost.get(post.cid);\n if (freshAccountPost && freshAccountPost.index !== post.index) {\n prunedLoadedFeed.push(freshAccountPost);\n loadedFeedsChanged = true;\n continue;\n }\n }\n prunedLoadedFeed.push(post);\n }\n loadedFeed = loadedFeeds[feedName] = prunedLoadedFeed;\n\n if (!accountPosts.length) {\n continue;\n }\n // if a loaded comment doesn't have a cid, then it's pending\n // and pending account comments should always have unique timestamps\n const loadedFeedMap = new Map();\n loadedFeed.forEach((post, loadedFeedIndex) => {\n if (post.cid) loadedFeedMap.set(post.cid, loadedFeedIndex);\n if (typeof post.index === \"number\") loadedFeedMap.set(post.index, loadedFeedIndex);\n if (!post.cid) loadedFeedMap.set(post.timestamp, loadedFeedIndex);\n if (post.pendingApproval !== true) {\n loadedFeedMap.set(getApprovalPublicationKey(post), loadedFeedIndex);\n }\n });\n for (const accountPost of accountPosts) {\n // account post with cid already added\n if (accountPost.cid && loadedFeedMap.has(accountPost.cid)) {\n continue;\n }\n if (\n accountPost.pendingApproval === true &&\n loadedFeedMap.has(getApprovalPublicationKey(accountPost))\n ) {\n continue;\n }\n // account post without cid already added, but now we have the cid\n if (accountPost.cid && loadedFeedMap.has(accountPost.index)) {\n const loadedFeedIndex = loadedFeedMap.get(accountPost.index);\n // update the feed with the accountPost.cid now that we have it\n loadedFeed[loadedFeedIndex] = accountPost;\n loadedFeedsChanged = true;\n continue;\n }\n if (loadedFeedMap.has(accountPost.index)) {\n continue;\n }\n // pending account post without cid already added\n if (!accountPost.cid && loadedFeedMap.has(accountPost.timestamp)) {\n continue;\n }\n if (append) {\n loadedFeed.push(accountPost);\n } else {\n loadedFeed.unshift(accountPost);\n }\n loadedFeedsChanged = true;\n }\n }\n return loadedFeedsChanged;\n};\n\nexport const getBufferedFeedsWithoutLoadedFeeds = (bufferedFeeds: Feeds, loadedFeeds: Feeds) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const loadedFeedsPosts: { [key: string]: Set<string> } = {};\n for (const feedName in loadedFeeds) {\n loadedFeedsPosts[feedName] = new Set();\n for (const post of loadedFeeds[feedName]) {\n loadedFeedsPosts[feedName].add(post.cid);\n }\n }\n\n const newBufferedFeeds: Feeds = {};\n for (const feedName in bufferedFeeds) {\n newBufferedFeeds[feedName] = [];\n let bufferedFeedPostChanged = false;\n for (const [i, post] of bufferedFeeds[feedName].entries()) {\n if (loadedFeedsPosts[feedName]?.has(post.cid)) {\n continue;\n }\n newBufferedFeeds[feedName].push(post);\n if (\n !bufferedFeedPostChanged &&\n (newBufferedFeeds[feedName][i]?.cid !== bufferedFeeds[feedName][i]?.cid ||\n (newBufferedFeeds[feedName][i]?.updatedAt || 0) >\n (bufferedFeeds[feedName][i]?.updatedAt || 0))\n ) {\n bufferedFeedPostChanged = true;\n }\n }\n if (\n !bufferedFeedPostChanged &&\n newBufferedFeeds[feedName].length === bufferedFeeds[feedName].length\n ) {\n newBufferedFeeds[feedName] = bufferedFeeds[feedName];\n }\n }\n return newBufferedFeeds;\n};\n\nexport const getUpdatedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n updatedFeeds: Feeds,\n loadedFeeds: Feeds,\n accounts: Accounts,\n) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const updatedFeedsPosts: { [feedName: string]: { [postCid: string]: any } } = {};\n for (const feedName in updatedFeeds) {\n updatedFeedsPosts[feedName] = {};\n for (const [index, updatedPost] of updatedFeeds[feedName].entries()) {\n updatedFeedsPosts[feedName][updatedPost.cid] = { index, updatedPost };\n }\n }\n\n const newUpdatedFeeds: Feeds = { ...updatedFeeds };\n for (const feedName in filteredSortedFeeds) {\n const pkc = accounts[feedsOptions[feedName]?.accountId]?.pkc;\n const updatedFeed = [...(updatedFeeds[feedName] || [])];\n const onlyHasNewPosts = updatedFeed.length === 0;\n let updatedFeedChanged = false;\n\n // add new posts from loadedFeed posts\n while (updatedFeed.length < loadedFeeds[feedName].length) {\n updatedFeed[updatedFeed.length] = loadedFeeds[feedName][updatedFeed.length];\n updatedFeedChanged = true;\n }\n\n // add updated post from filteredSortedFeed\n if (!onlyHasNewPosts) {\n const promises = [];\n for (const post of filteredSortedFeeds[feedName]) {\n if (updatedFeedsPosts[feedName]?.[post.cid]) {\n const { index, updatedPost } = updatedFeedsPosts[feedName][post.cid];\n // faster to validate comments async\n promises.push(\n (async () => {\n if (\n (post.updatedAt || 0) > (updatedPost.updatedAt || 0) &&\n (await commentIsValid(post, { validateReplies: false }, pkc))\n ) {\n updatedFeed[index] = post;\n updatedFeedChanged = true;\n }\n })(),\n );\n }\n }\n await Promise.all(promises);\n }\n\n if (updatedFeedChanged) {\n newUpdatedFeeds[feedName] = updatedFeed;\n }\n }\n return newUpdatedFeeds;\n};\n\n// find with communities have posts newer (or ranked higher) than the loaded feeds\n// can be used to display \"new posts in x, y, z subs\" alert, like on twitter\nexport const getFeedsCommunityKeysWithNewerPosts = (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n previousFeedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] },\n) => {\n const feedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] } = {};\n for (const feedName in loadedFeeds) {\n const loadedFeed = loadedFeeds[feedName];\n const cidsInLoadedFeed = new Set();\n for (const post of loadedFeed) {\n cidsInLoadedFeed.add(post.cid);\n }\n const communityKeysWithNewerPostsSet = new Set<string>();\n for (const [i, post] of filteredSortedFeeds[feedName].entries()) {\n if (i >= loadedFeed.length) {\n break;\n }\n // if any post in filteredSortedFeeds ranks higher than the loaded feed count, it's a newer post\n if (!cidsInLoadedFeed.has(post.cid)) {\n const postCommunityAddress = getCommentCommunityAddress(post);\n if (postCommunityAddress) {\n getMatchingCommunityRefKeys(\n getFeedCommunityRefs(feedsOptions[feedName] || {}),\n postCommunityAddress,\n ).forEach((communityKey) => communityKeysWithNewerPostsSet.add(communityKey));\n }\n }\n }\n const communityKeysWithNewerPosts = [...communityKeysWithNewerPostsSet];\n\n // don't update the array if the data is the same to avoid rerenders\n const previousCommunityKeysWithNewerPosts =\n previousFeedsCommunityKeysWithNewerPosts[feedName] || [];\n if (\n communityKeysWithNewerPosts.length === previousCommunityKeysWithNewerPosts.length &&\n communityKeysWithNewerPosts.toString() === previousCommunityKeysWithNewerPosts.toString()\n ) {\n feedsCommunityKeysWithNewerPosts[feedName] =\n previousFeedsCommunityKeysWithNewerPosts[feedName];\n } else {\n feedsCommunityKeysWithNewerPosts[feedName] = communityKeysWithNewerPosts;\n }\n }\n return feedsCommunityKeysWithNewerPosts;\n};\n\n// find how many posts are left in each communities in a buffereds feeds\nexport const getFeedsCommunitiesPostCounts = (feedsOptions: FeedsOptions, feeds: Feeds) => {\n const feedsCommunitiesPostCounts: FeedsCommunitiesPostCounts = {};\n for (const feedName in feedsOptions) {\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n feedsCommunitiesPostCounts[feedName] = {};\n for (const communityKey of communityKeys) {\n feedsCommunitiesPostCounts[feedName][communityKey] = 0;\n }\n for (const comment of feeds[feedName] || []) {\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress) {\n getMatchingCommunityRefKeys(communityRefs, commentCommunityAddress).forEach(\n (communityKey) => {\n feedsCommunitiesPostCounts[feedName][communityKey] =\n (feedsCommunitiesPostCounts[feedName][communityKey] || 0) + 1;\n },\n );\n }\n }\n }\n return feedsCommunitiesPostCounts;\n};\n\n/**\n * Get which feeds have more posts, i.e. have not reached the final page of all subs\n */\nexport const getFeedsHaveMore = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n) => {\n const feedsHaveMore: { [feedName: string]: boolean } = {};\n feedsLoop: for (const feedName in feedsOptions) {\n // if the feed still has buffered posts, then it still has more\n if (bufferedFeeds[feedName]?.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, modQueue } = feedsOptions[feedName];\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n communityKeysLoop: for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const community = communities[communityKey];\n const communityRef = communityRefs[communityIndex];\n const isBlockedCommunity = Object.keys(accounts[accountId]?.blockedAddresses || {}).some(\n (blockedAddress) =>\n communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community),\n );\n\n // don't consider the sub if the address is blocked\n if (isBlockedCommunity) {\n continue communityKeysLoop;\n }\n\n // if at least 1 community hasn't loaded yet, then the feed still has more\n if (!community?.updatedAt) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n // if at least 1 community has posts cache expired, then the feed still has more\n if (communityPostsCacheExpired(community)) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\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 // 'continue' to ignore it for now\n if (!firstPageCid) {\n continue communityKeysLoop;\n }\n const pages = getCommunityPages(community, sortType, communitiesPages, pageType, accountId);\n // if first page isn't loaded yet, then the feed still has more\n if (!pages.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n const lastPage = pages[pages.length - 1];\n if (lastPage.nextCid) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n }\n\n // if buffered feeds are empty and no last page of any community has a next page, then has more is false\n feedsHaveMore[feedName] = false;\n }\n return feedsHaveMore;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunities = (feedsOptions: FeedsOptions, communities: Communities) => {\n // find all feeds communities\n const feedsCommunityAddresses = new Set<string>();\n Object.keys(feedsOptions).forEach((i) =>\n getFeedCommunityKeys(feedsOptions[i]).forEach((a) => feedsCommunityAddresses.add(a)),\n );\n\n // use map for performance increase when checking size\n const feedsCommunities = new Map<string, Community>();\n for (const communityAddress of feedsCommunityAddresses) {\n feedsCommunities.set(communityAddress, communities[communityAddress]);\n }\n return feedsCommunities;\n};\n\nexport const feedsCommunitiesChanged = (\n previousFeedsCommunities: Map<string, Community>,\n feedsCommunities: Map<string, Community>,\n) => {\n if (previousFeedsCommunities.size !== feedsCommunities.size) {\n return true;\n }\n for (let communityAddress of previousFeedsCommunities.keys()) {\n // check if the object is still the same\n if (previousFeedsCommunities.get(communityAddress) !== feedsCommunities.get(communityAddress)) {\n return true;\n }\n }\n return false;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesFirstPageCids = (\n feedsCommunities: Map<string, Community>,\n): string[] => {\n // find all the feeds communities first page cids\n const feedsCommunitiesFirstPageCids = new Set<string>();\n for (const community of feedsCommunities.values()) {\n if (!community?.posts && !community?.modQueue) {\n continue;\n }\n\n // check pages\n if (community.posts?.pages) {\n for (const page of Object.values<CommunityPage>(community.posts.pages)) {\n if (page?.nextCid) {\n feedsCommunitiesFirstPageCids.add(page?.nextCid);\n }\n }\n }\n\n // check pageCids\n if (community.posts?.pageCids) {\n for (const pageCid of Object.values<string>(community.posts.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n\n // TODO: would be more performant to only check modQueue if there's a feedOptions with modQueue\n if (community.modQueue?.pageCids) {\n for (const pageCid of Object.values<string>(community.modQueue.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n }\n\n return [...feedsCommunitiesFirstPageCids].sort();\n};\n\n// get all communities posts pages first post updatedAts, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesPostsPagesFirstUpdatedAts = (\n feedsCommunities: Map<string, Community>,\n): string => {\n let feedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\n for (const community of feedsCommunities.values()) {\n for (const page of Object.values<CommunityPage>(community?.posts?.pages || {})) {\n if (page?.comments?.[0]?.updatedAt) {\n feedsCommunitiesPostsPagesFirstUpdatedAts +=\n page.comments[0].cid + page.comments[0].updatedAt;\n }\n }\n }\n return feedsCommunitiesPostsPagesFirstUpdatedAts;\n};\n\n// get number of feeds community that are loaded\nexport const getFeedsCommunitiesLoadedCount = (\n feedsCommunities: Map<string, Community>,\n): number => {\n let count = 0;\n for (const community of feedsCommunities.values()) {\n if (community?.updatedAt) {\n count++;\n }\n }\n return count;\n};\n\nexport const getAccountsBlockedAddresses = (accounts: Accounts) => {\n const blockedAddressesSet = new Set<string>();\n for (const { blockedAddresses } of Object.values(accounts)) {\n for (const address in blockedAddresses) {\n if (blockedAddresses[address]) {\n blockedAddressesSet.add(address);\n }\n }\n }\n return [...blockedAddressesSet].sort();\n};\n\nexport const accountsBlockedAddressesChanged = (\n previousAccountsBlockedAddresses: { [address: string]: boolean }[],\n accountsBlockedAddresses: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedAddresses.length !== accountsBlockedAddresses.length) {\n return true;\n }\n for (const i in previousAccountsBlockedAddresses) {\n // check if the object is still the same\n if (previousAccountsBlockedAddresses[i] !== accountsBlockedAddresses[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedAddresses = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedAddresses: string[],\n previousBlockedAddresses: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedAddresses = blockedAddresses\n .filter((x) => !previousBlockedAddresses.includes(x))\n .concat(previousBlockedAddresses.filter((x) => !blockedAddresses.includes(x)));\n\n // if changed blocked addresses arent used in the feeds, do nothing\n for (const address of changedBlockedAddresses) {\n for (const feedName in feedsOptions) {\n const feedOptions = feedsOptions[feedName];\n if (\n getMatchingCommunityRefKeys(getFeedCommunityRefs(feedOptions), address).some(\n (communityKey) => getFeedCommunityKeys(feedOptions).includes(communityKey),\n )\n ) {\n return true;\n }\n }\n }\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedAddressesSet = new Set(changedBlockedAddresses);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.author?.address && changedBlockedAddressesSet.has(post.author.address)) {\n return true;\n }\n }\n }\n\n return false;\n};\n\nexport const getAccountsBlockedCids = (accounts: Accounts) => {\n const blockedCidsSet = new Set<string>();\n for (const { blockedCids } of Object.values(accounts)) {\n for (const address in blockedCids) {\n if (blockedCids[address]) {\n blockedCidsSet.add(address);\n }\n }\n }\n return [...blockedCidsSet].sort();\n};\n\nexport const accountsBlockedCidsChanged = (\n previousAccountsBlockedCids: { [address: string]: boolean }[],\n accountsBlockedCids: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedCids.length !== accountsBlockedCids.length) {\n return true;\n }\n for (const i in previousAccountsBlockedCids) {\n // check if the object is still the same\n if (previousAccountsBlockedCids[i] !== accountsBlockedCids[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedCids = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedCids: string[],\n previousBlockedCids: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedCids = blockedCids\n .filter((x) => !previousBlockedCids.includes(x))\n .concat(previousBlockedCids.filter((x) => !blockedCids.includes(x)));\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedCidsSet = new Set(changedBlockedCids);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.cid && changedBlockedCidsSet.has(post?.cid)) {\n return true;\n }\n }\n }\n\n return false;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d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Ac,YAAY,EAC1B,UAAU,QAAQ;;CA+CnB,CAAC;AAGF,eAAO,MAAM,gBAAgB,GAAI,cAAc,mBAAmB,EAAE,UAAU,QAAQ,yBASrF,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,uBAAuB,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3C,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,YAYpC,CAAC;AAGF,eAAO,MAAM,6BAA6B,GAAI,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,EA4BzF,CAAC;AAGF,eAAO,MAAM,2CAA2C,GACtD,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAClC,MAWF,CAAC;AAGF,eAAO,MAAM,2BAA2B,GAAI,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAQjF,CAAC;AAGF,eAAO,MAAM,sBAAsB,GAAI,SAAS,OAAO,EAAE,aAAa,kBAAkB,WA0EvF,CAAC"}
@@ -119,6 +119,19 @@ const alwaysStreamPage = (feedOptions) => {
119
119
  // always stream top level replies and/or flat
120
120
  return feedOptions.commentDepth > 0 && !feedOptions.flat ? false : true;
121
121
  };
122
+ const getApprovalPublicationKey = (comment) => {
123
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
124
+ return [
125
+ (_a = comment.timestamp) !== null && _a !== void 0 ? _a : "",
126
+ (_b = comment.parentCid) !== null && _b !== void 0 ? _b : "",
127
+ (_c = comment.postCid) !== null && _c !== void 0 ? _c : "",
128
+ (_d = comment.communityAddress) !== null && _d !== void 0 ? _d : "",
129
+ (_f = (_e = comment.author) === null || _e === void 0 ? void 0 : _e.address) !== null && _f !== void 0 ? _f : "",
130
+ (_g = comment.title) !== null && _g !== void 0 ? _g : "",
131
+ (_h = comment.content) !== null && _h !== void 0 ? _h : "",
132
+ (_j = comment.link) !== null && _j !== void 0 ? _j : "",
133
+ ].join("\0");
134
+ };
122
135
  export const getLoadedFeeds = (feedsOptions, loadedFeeds, bufferedFeeds, accounts) => __awaiter(void 0, void 0, void 0, function* () {
123
136
  var _a;
124
137
  const loadedFeedsMissingReplies = {};
@@ -200,6 +213,9 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
200
213
  accountCidToReply.set(r.cid, r);
201
214
  }
202
215
  let loadedFeed = loadedFeeds[feedName] || [];
216
+ const approvedPublicationKeys = new Set(loadedFeed
217
+ .filter((reply) => reply.pendingApproval !== true)
218
+ .map((reply) => getApprovalPublicationKey(reply)));
203
219
  // prune stale local-account entries and replace when cid matches but index changed
204
220
  const prunedLoadedFeed = [];
205
221
  for (const reply of loadedFeed) {
@@ -207,6 +223,11 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
207
223
  prunedLoadedFeed.push(reply);
208
224
  continue;
209
225
  }
226
+ if (reply.pendingApproval === true &&
227
+ approvedPublicationKeys.has(getApprovalPublicationKey(reply))) {
228
+ loadedFeedsChanged = true;
229
+ continue;
230
+ }
210
231
  if (!validAccountIndices.has(reply.index)) {
211
232
  loadedFeedsChanged = true;
212
233
  continue;
@@ -231,16 +252,23 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
231
252
  loadedFeed.forEach((reply, loadedFeedIndex) => {
232
253
  if (reply.cid)
233
254
  loadedFeedMap.set(reply.cid, loadedFeedIndex);
234
- if (reply.index)
255
+ if (typeof reply.index === "number")
235
256
  loadedFeedMap.set(reply.index, loadedFeedIndex);
236
257
  if (!reply.cid)
237
258
  loadedFeedMap.set(reply.timestamp, loadedFeedIndex);
259
+ if (reply.pendingApproval !== true) {
260
+ loadedFeedMap.set(getApprovalPublicationKey(reply), loadedFeedIndex);
261
+ }
238
262
  });
239
263
  for (const accountReply of accountReplies) {
240
264
  // account reply with cid already added
241
265
  if (accountReply.cid && loadedFeedMap.has(accountReply.cid)) {
242
266
  continue;
243
267
  }
268
+ if (accountReply.pendingApproval === true &&
269
+ loadedFeedMap.has(getApprovalPublicationKey(accountReply))) {
270
+ continue;
271
+ }
244
272
  // account reply without cid already added, but now we have the cid
245
273
  if (accountReply.cid && loadedFeedMap.has(accountReply.index)) {
246
274
  const loadedFeedIndex = loadedFeedMap.get(accountReply.index);
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/replies/utils.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,aAAa,MAAM,sBAAsB,CAAC;AACjD,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,YAAiC,EACjC,QAAkB,EAClB,YAA0B,EAC1B,QAAkB,EAClB,EAAE;IACF,sBAAsB;IACtB,IAAI,KAAK,GAAU,EAAE,CAAC;IACtB,KAAK,MAAM,QAAQ,IAAI,YAAY,EAAE,CAAC;QACpC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QAE/E,2BAA2B;QAC3B,IAAI,mBAAmB,GAAG,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QAErC,QAAQ,GAAG,sBAAsB,CAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEnE,2CAA2C;QAC3C,IAAI,OAAO,EAAE,CAAC;YACZ,uCAAuC;YACvC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,OA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AAC,CAAA,OAAA,OAAA,OAAO,CAAC,OAAO,4CAAE,QAAQ,4CAAE,OAAO,CAAA;QACnC,CAAC,CAAA,OAAA,OAAA,OAAO,CAAC,OAAO,4CAAE,KAAK,4CAAE,GAAG,MAAI,OAAA,OAAA,OAAO,CAAC,OAAO,4CAAE,QAAQ,4CAAE,GAAG,CAAA,CAAC,EAC/D,CAAC;QACD,QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,yEAAyE;IACzE,4FAA4F;IAC5F,8FAA8F;IAC9F,6BAA6B;IAC7B,mCAAmC;IACnC,MAAM;IACN,WAAW;IACX,yGAAyG;IACzG,kCAAkC;IAClC,wCAAwC;IACxC,QAAQ;IACR,MAAM;IACN,IAAI;IACJ,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import assert from \"assert\";\nimport {\n Feed,\n Feeds,\n RepliesFeedOptions,\n RepliesFeedsOptions,\n Comment,\n Comments,\n Account,\n Accounts,\n RepliesPage,\n RepliesPages,\n} from \"../../types\";\nimport { getRepliesPages, getRepliesFirstPageCid } from \"../replies-pages\";\nimport repliesSorter from \"../feeds/feed-sorter\";\nimport accountsStore from \"../accounts\";\nimport { flattenCommentsPages, commentIsValid, removeInvalidComments } from \"../../lib/utils\";\nimport { areEquivalentCommunityAddresses } from \"../../lib/community-address\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:stores\");\n\n/**\n * Calculate the feeds from all the loaded replies pages, filter and sort them\n */\nexport const getFilteredSortedFeeds = (\n feedsOptions: RepliesFeedsOptions,\n comments: Comments,\n repliesPages: RepliesPages,\n accounts: Accounts,\n) => {\n // calculate each feed\n let feeds: Feeds = {};\n for (const feedName in feedsOptions) {\n let { commentCid, sortType, accountId, filter, flat } = feedsOptions[feedName];\n\n // find all fetched replies\n let bufferedFeedReplies = [];\n const comment = comments[commentCid];\n\n sortType = getSortTypeFromComment(comment, feedsOptions[feedName]);\n\n // comment has loaded and cache not expired\n if (comment) {\n // use comment preloaded replies if any\n const preloadedReplies = getPreloadedReplies(comment, sortType);\n if (preloadedReplies) {\n for (const reply of preloadedReplies) {\n // replies are manually validated, could have fake communityAddress\n if (!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress)) {\n break;\n }\n bufferedFeedReplies.push(reply);\n }\n }\n\n // add all replies from comment replies pages\n const _repliesPages = getRepliesPages(comment, sortType, repliesPages);\n for (const repliesPage of _repliesPages) {\n if (repliesPage?.comments) {\n for (const reply of repliesPage.comments) {\n // replies are manually validated, could have fake communityAddress\n if (\n !areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress)\n ) {\n break;\n }\n bufferedFeedReplies.push(reply);\n }\n }\n }\n }\n\n if (flat) {\n bufferedFeedReplies = flattenCommentsPages({ comments: bufferedFeedReplies });\n }\n\n // sort the feed before filtering to get more accurate results\n const sortedBufferedFeedReplies = repliesSorter.sort(sortType, bufferedFeedReplies);\n\n // filter the feed\n const filteredSortedBufferedFeedReplies = [];\n for (const reply of sortedBufferedFeedReplies) {\n // TODO: maybe skip if comment community address, comment cid or comment author is blocked?\n\n // feedOptions filter function\n if (filter && !filter.filter(reply)) {\n continue;\n }\n\n filteredSortedBufferedFeedReplies.push(reply);\n }\n\n feeds[feedName] = filteredSortedBufferedFeedReplies;\n }\n return feeds;\n};\n\nconst getPreloadedReplies = (comment: Comment, sortType: string) => {\n let preloadedReplies = comment.replies?.pages?.[sortType]?.comments;\n if (preloadedReplies) {\n return preloadedReplies;\n }\n // TODO: should we check pageCids? it's possible to have pageCids\n // and use 'best' preloadedReplies, if they have no nextCid (all replies are preloaded)\n // changing this might bug out nested immediate react renders\n // only check on comment.depth: 0 for now\n const hasPageCids = Object.keys(comment.replies?.pageCids || {}).length !== 0;\n if (hasPageCids && comment.depth === 0) {\n return;\n }\n const pages: any[] = Object.values(comment.replies?.pages || {});\n if (!pages.length) {\n return;\n }\n const nextCids = pages.map((page: any) => page?.nextCid).filter((nextCid) => !!nextCid);\n if (nextCids.length > 0) {\n return;\n }\n // if has a preloaded page, but no pageCids and no nextCids, it means all replies fit in a single preloaded page\n // so any sort type can be used, and later be resorted by the client\n if (pages[0]?.comments?.length) {\n return pages[0].comments;\n }\n};\n\nconst previousPageNumbers: { [feedName: string]: number } = {};\nconst pageNumberIncreased = (\n feedName: string,\n pageNumber: number,\n loadedFeed: Comment[],\n bufferedFeed: Comment[],\n) => {\n const isFirstPage = !loadedFeed && bufferedFeed?.length;\n // first page should always update\n // pageNumber has changed should always update\n if (isFirstPage || previousPageNumbers[feedName] !== pageNumber) {\n previousPageNumbers[feedName] = pageNumber;\n return true;\n }\n return false;\n};\n\nconst alwaysStreamPage = (feedOptions: RepliesFeedOptions) => {\n // feedOptions.streamPage set to true means always stream page\n if (feedOptions.streamPage) {\n return true;\n }\n // always stream top level replies and/or flat\n return feedOptions.commentDepth > 0 && !feedOptions.flat ? false : true;\n};\n\nexport const getLoadedFeeds = async (\n feedsOptions: RepliesFeedsOptions,\n loadedFeeds: Feeds,\n bufferedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const loadedFeedsMissingReplies: Feeds = {};\n for (const feedName in feedsOptions) {\n const { pageNumber, repliesPerPage, accountId, streamPage } = feedsOptions[feedName];\n\n // TODO: fix design issue, pageNumber shouldnt be increased when loadMore is called and repliesPerPage not reached\n // if not always streaming replies, and page number didn't increase, skip updating\n // so UI isn't displaced when new nested replies are added\n if (\n !alwaysStreamPage(feedsOptions[feedName]) &&\n !pageNumberIncreased(feedName, pageNumber, loadedFeeds[feedName], bufferedFeeds[feedName])\n ) {\n continue;\n }\n\n const pkc = accounts[accountId]?.pkc;\n const loadedFeedReplyCount = pageNumber * repliesPerPage;\n const currentLoadedFeed = loadedFeeds[feedName] || [];\n // don't count account replies\n const missingRepliesCount =\n loadedFeedReplyCount - currentLoadedFeed.filter((reply) => reply.index === undefined).length;\n\n // get new replies from buffered feed\n const bufferedFeed = bufferedFeeds[feedName] || [];\n\n let missingReplies: any[] = [];\n for (const reply of bufferedFeed) {\n if (missingReplies.length >= missingRepliesCount) {\n missingReplies = await removeInvalidComments(\n missingReplies,\n { validateReplies: false },\n pkc,\n );\n // only stop if there were no invalid comments\n if (missingReplies.length >= missingRepliesCount) {\n break;\n }\n }\n missingReplies.push(reply);\n }\n\n // the current loaded feed already exist and doesn't need new replies\n if (missingReplies.length === 0 && loadedFeeds[feedName]) {\n continue;\n }\n loadedFeedsMissingReplies[feedName] = missingReplies;\n }\n\n let newLoadedFeeds: Feeds = {};\n for (const feedName in loadedFeedsMissingReplies) {\n newLoadedFeeds[feedName] = [\n ...(loadedFeeds[feedName] || []),\n ...loadedFeedsMissingReplies[feedName],\n ];\n }\n\n // add account comments\n newLoadedFeeds = { ...loadedFeeds, ...newLoadedFeeds };\n const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, newLoadedFeeds);\n\n // do nothing if there are no missing replies\n if (Object.keys(loadedFeedsMissingReplies).length === 0 && !accountCommentsChangedFeeds) {\n return loadedFeeds;\n }\n return newLoadedFeeds;\n};\n\nexport const addAccountsComments = (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds) => {\n let loadedFeedsChanged = false;\n const accountsComments = accountsStore.getState().accountsComments || {};\n for (const feedName in feedsOptions) {\n const {\n accountId,\n accountComments: accountCommentsOptions,\n commentCid,\n postCid,\n commentDepth,\n flat,\n } = feedsOptions[feedName];\n const { newerThan, append } = accountCommentsOptions || {};\n if (!newerThan) {\n continue;\n }\n const newerThanTimestamp =\n newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;\n const isNewerThan = (reply: Comment) => reply.timestamp > newerThanTimestamp;\n\n const accountComments = accountsComments[accountId] || [];\n const accountReplies = accountComments.filter((reply) => {\n if (!isNewerThan(reply)) {\n return false;\n }\n if (flat) {\n // if flat, add all account replies with greater comment depth\n return reply.postCid === postCid && reply.depth > commentDepth;\n }\n return reply.parentCid === commentCid;\n });\n const validAccountIndices = new Set(accountReplies.map((r) => r.index));\n const accountCidToReply = new Map<string, Comment>();\n for (const r of accountReplies) {\n if (r.cid) accountCidToReply.set(r.cid, r);\n }\n\n let loadedFeed = loadedFeeds[feedName] || [];\n // prune stale local-account entries and replace when cid matches but index changed\n const prunedLoadedFeed: Comment[] = [];\n for (const reply of loadedFeed) {\n if (reply.index === undefined) {\n prunedLoadedFeed.push(reply);\n continue;\n }\n if (!validAccountIndices.has(reply.index)) {\n loadedFeedsChanged = true;\n continue;\n }\n if (reply.cid) {\n const freshAccountReply = accountCidToReply.get(reply.cid);\n if (freshAccountReply && freshAccountReply.index !== reply.index) {\n prunedLoadedFeed.push(freshAccountReply);\n loadedFeedsChanged = true;\n continue;\n }\n }\n prunedLoadedFeed.push(reply);\n }\n loadedFeed = loadedFeeds[feedName] = prunedLoadedFeed;\n\n if (!accountReplies.length) {\n continue;\n }\n // if a loaded comment doesn't have a cid, then it's pending\n // and pending account comments should always have unique timestamps\n const loadedFeedMap = new Map();\n loadedFeed.forEach((reply, loadedFeedIndex) => {\n if (reply.cid) loadedFeedMap.set(reply.cid, loadedFeedIndex);\n if (reply.index) loadedFeedMap.set(reply.index, loadedFeedIndex);\n if (!reply.cid) loadedFeedMap.set(reply.timestamp, loadedFeedIndex);\n });\n for (const accountReply of accountReplies) {\n // account reply with cid already added\n if (accountReply.cid && loadedFeedMap.has(accountReply.cid)) {\n continue;\n }\n // account reply without cid already added, but now we have the cid\n if (accountReply.cid && loadedFeedMap.has(accountReply.index)) {\n const loadedFeedIndex = loadedFeedMap.get(accountReply.index);\n // update the feed with the accountReply.cid now that we have it\n loadedFeed[loadedFeedIndex] = accountReply;\n loadedFeedsChanged = true;\n continue;\n }\n if (loadedFeedMap.has(accountReply.index)) {\n continue;\n }\n // pending account reply without cid already added\n if (!accountReply.cid && loadedFeedMap.has(accountReply.timestamp)) {\n continue;\n }\n if (append) {\n loadedFeed.push(accountReply);\n } else {\n loadedFeed.unshift(accountReply);\n }\n loadedFeedsChanged = true;\n }\n }\n return loadedFeedsChanged;\n};\n\nexport const getBufferedFeedsWithoutLoadedFeeds = (bufferedFeeds: Feeds, loadedFeeds: Feeds) => {\n // contruct a list of replies already loaded to remove them from buffered feeds\n const loadedFeedsReplies: { [key: string]: Set<string> } = {};\n for (const feedName in loadedFeeds) {\n loadedFeedsReplies[feedName] = new Set();\n for (const reply of loadedFeeds[feedName]) {\n loadedFeedsReplies[feedName].add(reply.cid);\n }\n }\n\n const newBufferedFeeds: Feeds = {};\n for (const feedName in bufferedFeeds) {\n newBufferedFeeds[feedName] = [];\n let bufferedFeedReplyChanged = false;\n for (const [i, reply] of bufferedFeeds[feedName].entries()) {\n if (loadedFeedsReplies[feedName]?.has(reply.cid)) {\n continue;\n }\n newBufferedFeeds[feedName].push(reply);\n if (\n !bufferedFeedReplyChanged &&\n (newBufferedFeeds[feedName][i]?.cid !== bufferedFeeds[feedName][i]?.cid ||\n (newBufferedFeeds[feedName][i]?.updatedAt || 0) >\n (bufferedFeeds[feedName][i]?.updatedAt || 0))\n ) {\n bufferedFeedReplyChanged = true;\n }\n }\n if (\n !bufferedFeedReplyChanged &&\n newBufferedFeeds[feedName].length === bufferedFeeds[feedName].length\n ) {\n newBufferedFeeds[feedName] = bufferedFeeds[feedName];\n }\n }\n return newBufferedFeeds;\n};\n\nexport const getUpdatedFeeds = async (\n feedsOptions: RepliesFeedsOptions,\n filteredSortedFeeds: Feeds,\n updatedFeeds: Feeds,\n loadedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const newUpdatedFeeds: Feeds = { ...updatedFeeds };\n const feedNames = new Set([\n ...Object.keys(filteredSortedFeeds || {}),\n ...Object.keys(loadedFeeds || {}),\n ...Object.keys(updatedFeeds || {}),\n ]);\n for (const feedName of feedNames) {\n const pkc = accounts[feedsOptions[feedName]?.accountId]?.pkc;\n const loadedFeed = loadedFeeds[feedName] || [];\n const previousUpdatedFeed = updatedFeeds[feedName] || [];\n const updatedFeed = [...loadedFeed];\n let updatedFeedChanged = false;\n\n // Keep updated feeds in lock-step with loaded feeds so local deletions\n // (e.g. abandoned pending replies) disappear without requiring a feed reset.\n if (previousUpdatedFeed.length !== updatedFeed.length) {\n updatedFeedChanged = true;\n }\n\n const filteredRepliesByCid = new Map<string, Comment>();\n for (const reply of filteredSortedFeeds[feedName] || []) {\n if (reply?.cid) {\n filteredRepliesByCid.set(reply.cid, reply);\n }\n }\n\n for (let i = 0; i < updatedFeed.length; i++) {\n const loadedReply = updatedFeed[i];\n if (!loadedReply?.cid) {\n continue;\n }\n\n const previousUpdatedReply = previousUpdatedFeed[i];\n if (\n previousUpdatedReply?.cid === loadedReply.cid &&\n (previousUpdatedReply.updatedAt || 0) > (loadedReply.updatedAt || 0)\n ) {\n updatedFeed[i] = previousUpdatedReply;\n updatedFeedChanged = true;\n }\n\n const candidateReply = filteredRepliesByCid.get(loadedReply.cid);\n if (!candidateReply) {\n continue;\n }\n if ((candidateReply.updatedAt || 0) <= (updatedFeed[i]?.updatedAt || 0)) {\n continue;\n }\n if (!(await commentIsValid(candidateReply, { validateReplies: false }, pkc))) {\n continue;\n }\n updatedFeed[i] = candidateReply;\n updatedFeedChanged = true;\n }\n\n if (updatedFeedChanged) {\n newUpdatedFeeds[feedName] = updatedFeed;\n continue;\n }\n\n if (!updatedFeeds[feedName]) {\n newUpdatedFeeds[feedName] = updatedFeed;\n }\n }\n return newUpdatedFeeds;\n};\n\n// find how many replies are in each comments in a buffereds feeds\n// NOTE: not useful, could use feed.length, copied over from useFeed and easier to keep it\nexport const getFeedsReplyCounts = (feedsOptions: RepliesFeedsOptions, feeds: Feeds) => {\n const feedsReplyCounts: { [feedName: string]: number } = {};\n for (const feedName in feedsOptions) {\n feedsReplyCounts[feedName] = feeds[feedName]?.length || 0;\n }\n return feedsReplyCounts;\n};\n\n/**\n * Get which feeds have more replies, i.e. have not reached the final page of all comments\n */\nexport const getFeedsHaveMore = (\n feedsOptions: RepliesFeedsOptions,\n bufferedFeeds: Feeds,\n comments: Comments,\n repliesPages: RepliesPages,\n accounts: Accounts,\n) => {\n const feedsHaveMore: { [feedName: string]: boolean } = {};\n for (const feedName in feedsOptions) {\n // if the feed still has buffered replies, then it still has more\n if (bufferedFeeds[feedName]?.length) {\n feedsHaveMore[feedName] = true;\n continue;\n }\n\n let { commentCid, sortType, onlyIfCached } = feedsOptions[feedName];\n\n // TODO: maybe skip if comment cid is blocked?\n\n const comment = comments[commentCid];\n // if at least comment hasn't loaded yet, then the feed still has more\n if (!comment?.updatedAt) {\n feedsHaveMore[feedName] = !onlyIfCached;\n continue;\n }\n\n sortType = getSortTypeFromComment(comment, feedsOptions[feedName]);\n\n const firstPageCid = getRepliesFirstPageCid(comment, sortType);\n // TODO: if a loaded comment 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 'best', or should we just ignore it?\n // 'continue' to ignore it for now\n if (!firstPageCid) {\n feedsHaveMore[feedName] = false;\n continue;\n }\n const pages = getRepliesPages(comment, sortType, repliesPages);\n // if first page isn't loaded yet, then the feed still has more\n if (!pages.length) {\n feedsHaveMore[feedName] = !onlyIfCached;\n continue;\n }\n const lastPage = pages[pages.length - 1];\n if (lastPage.nextCid) {\n feedsHaveMore[feedName] = !onlyIfCached;\n continue;\n }\n\n // if buffered feeds are empty and no last page of any comment has a next page, then has more is false\n feedsHaveMore[feedName] = false;\n }\n return feedsHaveMore;\n};\n\n// get all comments replies pages cids of all feeds, use to check if a commentsStore change should trigger updateFeeds\nexport const getFeedsComments = (feedsOptions: RepliesFeedsOptions, comments: Comments) => {\n const feedsComments = new Map<string, Comment>();\n for (const feedName in feedsOptions) {\n feedsComments.set(\n feedsOptions[feedName].commentCid,\n comments[feedsOptions[feedName].commentCid],\n );\n }\n return feedsComments;\n};\n\nexport const feedsCommentsChanged = (\n previousFeedsComments: Map<string, Comment>,\n feedsComments: Map<string, Comment>,\n) => {\n if (previousFeedsComments.size !== feedsComments.size) {\n return true;\n }\n for (let commentCid of previousFeedsComments.keys()) {\n // check if the object is still the same\n if (previousFeedsComments.get(commentCid) !== feedsComments.get(commentCid)) {\n return true;\n }\n }\n return false;\n};\n\n// get all comments replies pages cids of all feeds, use to check if a commentsStore change should trigger updateFeeds\nexport const getFeedsCommentsFirstPageCids = (feedsComments: Map<string, Comment>): string[] => {\n // find all the feeds comments first page cids\n const feedsCommentsFirstPageCids = new Set<string>();\n for (const comment of feedsComments.values()) {\n if (!comment?.replies) {\n continue;\n }\n\n // check pages\n if (comment.replies.pages) {\n for (const page of Object.values<RepliesPage>(comment.replies.pages)) {\n if (page?.nextCid) {\n feedsCommentsFirstPageCids.add(page?.nextCid);\n }\n }\n }\n\n // check pageCids\n if (comment.replies.pageCids) {\n for (const pageCid of Object.values<string>(comment.replies.pageCids)) {\n if (pageCid) {\n feedsCommentsFirstPageCids.add(pageCid);\n }\n }\n }\n }\n\n return [...feedsCommentsFirstPageCids].sort();\n};\n\n// get all comments replies pages first reply updatedAts, use to check if a commentsStore change should trigger updateFeeds\nexport const getFeedsCommentsRepliesPagesFirstUpdatedAts = (\n feedsComments: Map<string, Comment>,\n): string => {\n let feedsCommentsRepliesPagesFirstUpdatedAts = \"\";\n for (const comment of feedsComments.values()) {\n for (const page of Object.values<RepliesPage>(comment?.replies?.pages || {})) {\n if (page?.comments?.[0]?.updatedAt) {\n feedsCommentsRepliesPagesFirstUpdatedAts +=\n page.comments[0].cid + page.comments[0].updatedAt;\n }\n }\n }\n return feedsCommentsRepliesPagesFirstUpdatedAts;\n};\n\n// get number of feeds comments that are loaded\nexport const getFeedsCommentsLoadedCount = (feedsComments: Map<string, Comment>): number => {\n let count = 0;\n for (const comment of feedsComments.values()) {\n if (comment?.updatedAt) {\n count++;\n }\n }\n return count;\n};\n\n// selected sort type could be missing from comment, or not optimized\nexport const getSortTypeFromComment = (comment: Comment, feedOptions: RepliesFeedOptions) => {\n let { sortType, flat } = feedOptions;\n\n if (!comment) {\n return sortType;\n }\n\n // 'topAll' and 'best' are similar enough to be used interchangeably\n if (\n sortType === \"best\" &&\n !comment.replies?.pages?.best &&\n !comment.replies?.pageCids?.best &&\n (comment.replies?.pages?.topAll || comment.replies?.pageCids?.topAll)\n ) {\n sortType = \"topAll\";\n } else if (\n sortType === \"topAll\" &&\n !comment.replies?.pages?.topAll &&\n !comment.replies?.pageCids?.topAll &&\n (comment.replies?.pages?.best || comment.replies?.pageCids?.best)\n ) {\n sortType = \"best\";\n }\n\n // if 'new' sort type and flat: true, use 'newFlat'\n else if (\n sortType === \"new\" &&\n flat &&\n (comment.replies?.pages?.newFlat || comment.replies?.pageCids?.newFlat)\n ) {\n sortType = \"newFlat\";\n }\n // if 'old' sort type and flat: true, use 'oldFlat'\n else if (\n sortType === \"old\" &&\n flat &&\n (comment.replies?.pages?.oldFlat || comment.replies?.pageCids?.oldFlat)\n ) {\n sortType = \"oldFlat\";\n }\n\n // if 'newFlat' is missing, use 'new'\n else if (\n sortType === \"newFlat\" &&\n !comment.replies?.pages?.newFlat &&\n !comment.replies?.pageCids?.newFlat &&\n (comment.replies?.pages?.new || comment.replies?.pageCids?.new)\n ) {\n sortType = \"new\";\n }\n // if 'oldFlat' is missing, use 'old'\n else if (\n sortType === \"oldFlat\" &&\n !comment.replies?.pages?.oldFlat &&\n !comment.replies?.pageCids?.oldFlat &&\n (comment.replies?.pages?.old || comment.replies?.pageCids?.old)\n ) {\n sortType = \"old\";\n }\n\n // TODO: if sort type doesn't exist on comment, maybe use first existing?\n // else if (!comment.replies?.pages?.[sortType] && !comment.replies?.pageCids?.[sortType]) {\n // const firstPageSortType = comment.replies?.pages && Object.keys(comment.replies.pages)[0]\n // if (firstPageSortType) {\n // sortType = firstPageSortType\n // }\n // else {\n // const firstPageCidSortType = comment.replies?.pageCids && Object.keys(comment.replies.pageCids)[0]\n // if (firstPageCidSortType) {\n // sortType = firstPageCidSortType\n // }\n // }\n // }\n return sortType;\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/replies/utils.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,EAAE,eAAe,EAAE,sBAAsB,E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AA4F;IAC5F,8FAA8F;IAC9F,6BAA6B;IAC7B,mCAAmC;IACnC,MAAM;IACN,WAAW;IACX,yGAAyG;IACzG,kCAAkC;IAClC,wCAAwC;IACxC,QAAQ;IACR,MAAM;IACN,IAAI;IACJ,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import assert from \"assert\";\nimport {\n Feed,\n Feeds,\n RepliesFeedOptions,\n RepliesFeedsOptions,\n Comment,\n Comments,\n Account,\n Accounts,\n RepliesPage,\n RepliesPages,\n} from \"../../types\";\nimport { getRepliesPages, getRepliesFirstPageCid } from \"../replies-pages\";\nimport repliesSorter from \"../feeds/feed-sorter\";\nimport accountsStore from \"../accounts\";\nimport { flattenCommentsPages, commentIsValid, removeInvalidComments } from \"../../lib/utils\";\nimport { areEquivalentCommunityAddresses } from \"../../lib/community-address\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:stores\");\n\n/**\n * Calculate the feeds from all the loaded replies pages, filter and sort them\n */\nexport const getFilteredSortedFeeds = (\n feedsOptions: RepliesFeedsOptions,\n comments: Comments,\n repliesPages: RepliesPages,\n accounts: Accounts,\n) => {\n // calculate each feed\n let feeds: Feeds = {};\n for (const feedName in feedsOptions) {\n let { commentCid, sortType, accountId, filter, flat } = feedsOptions[feedName];\n\n // find all fetched replies\n let bufferedFeedReplies = [];\n const comment = comments[commentCid];\n\n sortType = getSortTypeFromComment(comment, feedsOptions[feedName]);\n\n // comment has loaded and cache not expired\n if (comment) {\n // use comment preloaded replies if any\n const preloadedReplies = getPreloadedReplies(comment, sortType);\n if (preloadedReplies) {\n for (const reply of preloadedReplies) {\n // replies are manually validated, could have fake communityAddress\n if (!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress)) {\n break;\n }\n bufferedFeedReplies.push(reply);\n }\n }\n\n // add all replies from comment replies pages\n const _repliesPages = getRepliesPages(comment, sortType, repliesPages);\n for (const repliesPage of _repliesPages) {\n if (repliesPage?.comments) {\n for (const reply of repliesPage.comments) {\n // replies are manually validated, could have fake communityAddress\n if (\n !areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress)\n ) {\n break;\n }\n bufferedFeedReplies.push(reply);\n }\n }\n }\n }\n\n if (flat) {\n bufferedFeedReplies = flattenCommentsPages({ comments: bufferedFeedReplies });\n }\n\n // sort the feed before filtering to get more accurate results\n const sortedBufferedFeedReplies = repliesSorter.sort(sortType, bufferedFeedReplies);\n\n // filter the feed\n const filteredSortedBufferedFeedReplies = [];\n for (const reply of sortedBufferedFeedReplies) {\n // TODO: maybe skip if comment community address, comment cid or comment author is blocked?\n\n // feedOptions filter function\n if (filter && !filter.filter(reply)) {\n continue;\n }\n\n filteredSortedBufferedFeedReplies.push(reply);\n }\n\n feeds[feedName] = filteredSortedBufferedFeedReplies;\n }\n return feeds;\n};\n\nconst getPreloadedReplies = (comment: Comment, sortType: string) => {\n let preloadedReplies = comment.replies?.pages?.[sortType]?.comments;\n if (preloadedReplies) {\n return preloadedReplies;\n }\n // TODO: should we check pageCids? it's possible to have pageCids\n // and use 'best' preloadedReplies, if they have no nextCid (all replies are preloaded)\n // changing this might bug out nested immediate react renders\n // only check on comment.depth: 0 for now\n const hasPageCids = Object.keys(comment.replies?.pageCids || {}).length !== 0;\n if (hasPageCids && comment.depth === 0) {\n return;\n }\n const pages: any[] = Object.values(comment.replies?.pages || {});\n if (!pages.length) {\n return;\n }\n const nextCids = pages.map((page: any) => page?.nextCid).filter((nextCid) => !!nextCid);\n if (nextCids.length > 0) {\n return;\n }\n // if has a preloaded page, but no pageCids and no nextCids, it means all replies fit in a single preloaded page\n // so any sort type can be used, and later be resorted by the client\n if (pages[0]?.comments?.length) {\n return pages[0].comments;\n }\n};\n\nconst previousPageNumbers: { [feedName: string]: number } = {};\nconst pageNumberIncreased = (\n feedName: string,\n pageNumber: number,\n loadedFeed: Comment[],\n bufferedFeed: Comment[],\n) => {\n const isFirstPage = !loadedFeed && bufferedFeed?.length;\n // first page should always update\n // pageNumber has changed should always update\n if (isFirstPage || previousPageNumbers[feedName] !== pageNumber) {\n previousPageNumbers[feedName] = pageNumber;\n return true;\n }\n return false;\n};\n\nconst alwaysStreamPage = (feedOptions: RepliesFeedOptions) => {\n // feedOptions.streamPage set to true means always stream page\n if (feedOptions.streamPage) {\n return true;\n }\n // always stream top level replies and/or flat\n return feedOptions.commentDepth > 0 && !feedOptions.flat ? false : true;\n};\n\nconst getApprovalPublicationKey = (comment: Comment) =>\n [\n comment.timestamp ?? \"\",\n comment.parentCid ?? \"\",\n comment.postCid ?? \"\",\n comment.communityAddress ?? \"\",\n comment.author?.address ?? \"\",\n comment.title ?? \"\",\n comment.content ?? \"\",\n comment.link ?? \"\",\n ].join(\"\\0\");\n\nexport const getLoadedFeeds = async (\n feedsOptions: RepliesFeedsOptions,\n loadedFeeds: Feeds,\n bufferedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const loadedFeedsMissingReplies: Feeds = {};\n for (const feedName in feedsOptions) {\n const { pageNumber, repliesPerPage, accountId, streamPage } = feedsOptions[feedName];\n\n // TODO: fix design issue, pageNumber shouldnt be increased when loadMore is called and repliesPerPage not reached\n // if not always streaming replies, and page number didn't increase, skip updating\n // so UI isn't displaced when new nested replies are added\n if (\n !alwaysStreamPage(feedsOptions[feedName]) &&\n !pageNumberIncreased(feedName, pageNumber, loadedFeeds[feedName], bufferedFeeds[feedName])\n ) {\n continue;\n }\n\n const pkc = accounts[accountId]?.pkc;\n const loadedFeedReplyCount = pageNumber * repliesPerPage;\n const currentLoadedFeed = loadedFeeds[feedName] || [];\n // don't count account replies\n const missingRepliesCount =\n loadedFeedReplyCount - currentLoadedFeed.filter((reply) => reply.index === undefined).length;\n\n // get new replies from buffered feed\n const bufferedFeed = bufferedFeeds[feedName] || [];\n\n let missingReplies: any[] = [];\n for (const reply of bufferedFeed) {\n if (missingReplies.length >= missingRepliesCount) {\n missingReplies = await removeInvalidComments(\n missingReplies,\n { validateReplies: false },\n pkc,\n );\n // only stop if there were no invalid comments\n if (missingReplies.length >= missingRepliesCount) {\n break;\n }\n }\n missingReplies.push(reply);\n }\n\n // the current loaded feed already exist and doesn't need new replies\n if (missingReplies.length === 0 && loadedFeeds[feedName]) {\n continue;\n }\n loadedFeedsMissingReplies[feedName] = missingReplies;\n }\n\n let newLoadedFeeds: Feeds = {};\n for (const feedName in loadedFeedsMissingReplies) {\n newLoadedFeeds[feedName] = [\n ...(loadedFeeds[feedName] || []),\n ...loadedFeedsMissingReplies[feedName],\n ];\n }\n\n // add account comments\n newLoadedFeeds = { ...loadedFeeds, ...newLoadedFeeds };\n const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, newLoadedFeeds);\n\n // do nothing if there are no missing replies\n if (Object.keys(loadedFeedsMissingReplies).length === 0 && !accountCommentsChangedFeeds) {\n return loadedFeeds;\n }\n return newLoadedFeeds;\n};\n\nexport const addAccountsComments = (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds) => {\n let loadedFeedsChanged = false;\n const accountsComments = accountsStore.getState().accountsComments || {};\n for (const feedName in feedsOptions) {\n const {\n accountId,\n accountComments: accountCommentsOptions,\n commentCid,\n postCid,\n commentDepth,\n flat,\n } = feedsOptions[feedName];\n const { newerThan, append } = accountCommentsOptions || {};\n if (!newerThan) {\n continue;\n }\n const newerThanTimestamp =\n newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;\n const isNewerThan = (reply: Comment) => reply.timestamp > newerThanTimestamp;\n\n const accountComments = accountsComments[accountId] || [];\n const accountReplies = accountComments.filter((reply) => {\n if (!isNewerThan(reply)) {\n return false;\n }\n if (flat) {\n // if flat, add all account replies with greater comment depth\n return reply.postCid === postCid && reply.depth > commentDepth;\n }\n return reply.parentCid === commentCid;\n });\n const validAccountIndices = new Set(accountReplies.map((r) => r.index));\n const accountCidToReply = new Map<string, Comment>();\n for (const r of accountReplies) {\n if (r.cid) accountCidToReply.set(r.cid, r);\n }\n\n let loadedFeed = loadedFeeds[feedName] || [];\n const approvedPublicationKeys = new Set(\n loadedFeed\n .filter((reply) => reply.pendingApproval !== true)\n .map((reply) => getApprovalPublicationKey(reply)),\n );\n // prune stale local-account entries and replace when cid matches but index changed\n const prunedLoadedFeed: Comment[] = [];\n for (const reply of loadedFeed) {\n if (reply.index === undefined) {\n prunedLoadedFeed.push(reply);\n continue;\n }\n if (\n reply.pendingApproval === true &&\n approvedPublicationKeys.has(getApprovalPublicationKey(reply))\n ) {\n loadedFeedsChanged = true;\n continue;\n }\n if (!validAccountIndices.has(reply.index)) {\n loadedFeedsChanged = true;\n continue;\n }\n if (reply.cid) {\n const freshAccountReply = accountCidToReply.get(reply.cid);\n if (freshAccountReply && freshAccountReply.index !== reply.index) {\n prunedLoadedFeed.push(freshAccountReply);\n loadedFeedsChanged = true;\n continue;\n }\n }\n prunedLoadedFeed.push(reply);\n }\n loadedFeed = loadedFeeds[feedName] = prunedLoadedFeed;\n\n if (!accountReplies.length) {\n continue;\n }\n // if a loaded comment doesn't have a cid, then it's pending\n // and pending account comments should always have unique timestamps\n const loadedFeedMap = new Map();\n loadedFeed.forEach((reply, loadedFeedIndex) => {\n if (reply.cid) loadedFeedMap.set(reply.cid, loadedFeedIndex);\n if (typeof reply.index === \"number\") loadedFeedMap.set(reply.index, loadedFeedIndex);\n if (!reply.cid) loadedFeedMap.set(reply.timestamp, loadedFeedIndex);\n if (reply.pendingApproval !== true) {\n loadedFeedMap.set(getApprovalPublicationKey(reply), loadedFeedIndex);\n }\n });\n for (const accountReply of accountReplies) {\n // account reply with cid already added\n if (accountReply.cid && loadedFeedMap.has(accountReply.cid)) {\n continue;\n }\n if (\n accountReply.pendingApproval === true &&\n loadedFeedMap.has(getApprovalPublicationKey(accountReply))\n ) {\n continue;\n }\n // account reply without cid already added, but now we have the cid\n if (accountReply.cid && loadedFeedMap.has(accountReply.index)) {\n const loadedFeedIndex = loadedFeedMap.get(accountReply.index);\n // update the feed with the accountReply.cid now that we have it\n loadedFeed[loadedFeedIndex] = accountReply;\n loadedFeedsChanged = true;\n continue;\n }\n if (loadedFeedMap.has(accountReply.index)) {\n continue;\n }\n // pending account reply without cid already added\n if (!accountReply.cid && loadedFeedMap.has(accountReply.timestamp)) {\n continue;\n }\n if (append) {\n loadedFeed.push(accountReply);\n } else {\n loadedFeed.unshift(accountReply);\n }\n loadedFeedsChanged = true;\n }\n }\n return loadedFeedsChanged;\n};\n\nexport const getBufferedFeedsWithoutLoadedFeeds = (bufferedFeeds: Feeds, loadedFeeds: Feeds) => {\n // contruct a list of replies already loaded to remove them from buffered feeds\n const loadedFeedsReplies: { [key: string]: Set<string> } = {};\n for (const feedName in loadedFeeds) {\n loadedFeedsReplies[feedName] = new Set();\n for (const reply of loadedFeeds[feedName]) {\n loadedFeedsReplies[feedName].add(reply.cid);\n }\n }\n\n const newBufferedFeeds: Feeds = {};\n for (const feedName in bufferedFeeds) {\n newBufferedFeeds[feedName] = [];\n let bufferedFeedReplyChanged = false;\n for (const [i, reply] of bufferedFeeds[feedName].entries()) {\n if (loadedFeedsReplies[feedName]?.has(reply.cid)) {\n continue;\n }\n newBufferedFeeds[feedName].push(reply);\n if (\n !bufferedFeedReplyChanged &&\n (newBufferedFeeds[feedName][i]?.cid !== bufferedFeeds[feedName][i]?.cid ||\n (newBufferedFeeds[feedName][i]?.updatedAt || 0) >\n (bufferedFeeds[feedName][i]?.updatedAt || 0))\n ) {\n bufferedFeedReplyChanged = true;\n }\n }\n if (\n !bufferedFeedReplyChanged &&\n newBufferedFeeds[feedName].length === bufferedFeeds[feedName].length\n ) {\n newBufferedFeeds[feedName] = bufferedFeeds[feedName];\n }\n }\n return newBufferedFeeds;\n};\n\nexport const getUpdatedFeeds = async (\n feedsOptions: RepliesFeedsOptions,\n filteredSortedFeeds: Feeds,\n updatedFeeds: Feeds,\n loadedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const newUpdatedFeeds: Feeds = { ...updatedFeeds };\n const feedNames = new Set([\n ...Object.keys(filteredSortedFeeds || {}),\n ...Object.keys(loadedFeeds || {}),\n ...Object.keys(updatedFeeds || {}),\n ]);\n for (const feedName of feedNames) {\n const pkc = accounts[feedsOptions[feedName]?.accountId]?.pkc;\n const loadedFeed = loadedFeeds[feedName] || [];\n const previousUpdatedFeed = updatedFeeds[feedName] || [];\n const updatedFeed = [...loadedFeed];\n let updatedFeedChanged = false;\n\n // Keep updated feeds in lock-step with loaded feeds so local deletions\n // (e.g. abandoned pending replies) disappear without requiring a feed reset.\n if (previousUpdatedFeed.length !== updatedFeed.length) {\n updatedFeedChanged = true;\n }\n\n const filteredRepliesByCid = new Map<string, Comment>();\n for (const reply of filteredSortedFeeds[feedName] || []) {\n if (reply?.cid) {\n filteredRepliesByCid.set(reply.cid, reply);\n }\n }\n\n for (let i = 0; i < updatedFeed.length; i++) {\n const loadedReply = updatedFeed[i];\n if (!loadedReply?.cid) {\n continue;\n }\n\n const previousUpdatedReply = previousUpdatedFeed[i];\n if (\n previousUpdatedReply?.cid === loadedReply.cid &&\n (previousUpdatedReply.updatedAt || 0) > (loadedReply.updatedAt || 0)\n ) {\n updatedFeed[i] = previousUpdatedReply;\n updatedFeedChanged = true;\n }\n\n const candidateReply = filteredRepliesByCid.get(loadedReply.cid);\n if (!candidateReply) {\n continue;\n }\n if ((candidateReply.updatedAt || 0) <= (updatedFeed[i]?.updatedAt || 0)) {\n continue;\n }\n if (!(await commentIsValid(candidateReply, { validateReplies: false }, pkc))) {\n continue;\n }\n updatedFeed[i] = candidateReply;\n updatedFeedChanged = true;\n }\n\n if (updatedFeedChanged) {\n newUpdatedFeeds[feedName] = updatedFeed;\n continue;\n }\n\n if (!updatedFeeds[feedName]) {\n newUpdatedFeeds[feedName] = updatedFeed;\n }\n }\n return newUpdatedFeeds;\n};\n\n// find how many replies are in each comments in a buffereds feeds\n// NOTE: not useful, could use feed.length, copied over from useFeed and easier to keep it\nexport const getFeedsReplyCounts = (feedsOptions: RepliesFeedsOptions, feeds: Feeds) => {\n const feedsReplyCounts: { [feedName: string]: number } = {};\n for (const feedName in feedsOptions) {\n feedsReplyCounts[feedName] = feeds[feedName]?.length || 0;\n }\n return feedsReplyCounts;\n};\n\n/**\n * Get which feeds have more replies, i.e. have not reached the final page of all comments\n */\nexport const getFeedsHaveMore = (\n feedsOptions: RepliesFeedsOptions,\n bufferedFeeds: Feeds,\n comments: Comments,\n repliesPages: RepliesPages,\n accounts: Accounts,\n) => {\n const feedsHaveMore: { [feedName: string]: boolean } = {};\n for (const feedName in feedsOptions) {\n // if the feed still has buffered replies, then it still has more\n if (bufferedFeeds[feedName]?.length) {\n feedsHaveMore[feedName] = true;\n continue;\n }\n\n let { commentCid, sortType, onlyIfCached } = feedsOptions[feedName];\n\n // TODO: maybe skip if comment cid is blocked?\n\n const comment = comments[commentCid];\n // if at least comment hasn't loaded yet, then the feed still has more\n if (!comment?.updatedAt) {\n feedsHaveMore[feedName] = !onlyIfCached;\n continue;\n }\n\n sortType = getSortTypeFromComment(comment, feedsOptions[feedName]);\n\n const firstPageCid = getRepliesFirstPageCid(comment, sortType);\n // TODO: if a loaded comment 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 'best', or should we just ignore it?\n // 'continue' to ignore it for now\n if (!firstPageCid) {\n feedsHaveMore[feedName] = false;\n continue;\n }\n const pages = getRepliesPages(comment, sortType, repliesPages);\n // if first page isn't loaded yet, then the feed still has more\n if (!pages.length) {\n feedsHaveMore[feedName] = !onlyIfCached;\n continue;\n }\n const lastPage = pages[pages.length - 1];\n if (lastPage.nextCid) {\n feedsHaveMore[feedName] = !onlyIfCached;\n continue;\n }\n\n // if buffered feeds are empty and no last page of any comment has a next page, then has more is false\n feedsHaveMore[feedName] = false;\n }\n return feedsHaveMore;\n};\n\n// get all comments replies pages cids of all feeds, use to check if a commentsStore change should trigger updateFeeds\nexport const getFeedsComments = (feedsOptions: RepliesFeedsOptions, comments: Comments) => {\n const feedsComments = new Map<string, Comment>();\n for (const feedName in feedsOptions) {\n feedsComments.set(\n feedsOptions[feedName].commentCid,\n comments[feedsOptions[feedName].commentCid],\n );\n }\n return feedsComments;\n};\n\nexport const feedsCommentsChanged = (\n previousFeedsComments: Map<string, Comment>,\n feedsComments: Map<string, Comment>,\n) => {\n if (previousFeedsComments.size !== feedsComments.size) {\n return true;\n }\n for (let commentCid of previousFeedsComments.keys()) {\n // check if the object is still the same\n if (previousFeedsComments.get(commentCid) !== feedsComments.get(commentCid)) {\n return true;\n }\n }\n return false;\n};\n\n// get all comments replies pages cids of all feeds, use to check if a commentsStore change should trigger updateFeeds\nexport const getFeedsCommentsFirstPageCids = (feedsComments: Map<string, Comment>): string[] => {\n // find all the feeds comments first page cids\n const feedsCommentsFirstPageCids = new Set<string>();\n for (const comment of feedsComments.values()) {\n if (!comment?.replies) {\n continue;\n }\n\n // check pages\n if (comment.replies.pages) {\n for (const page of Object.values<RepliesPage>(comment.replies.pages)) {\n if (page?.nextCid) {\n feedsCommentsFirstPageCids.add(page?.nextCid);\n }\n }\n }\n\n // check pageCids\n if (comment.replies.pageCids) {\n for (const pageCid of Object.values<string>(comment.replies.pageCids)) {\n if (pageCid) {\n feedsCommentsFirstPageCids.add(pageCid);\n }\n }\n }\n }\n\n return [...feedsCommentsFirstPageCids].sort();\n};\n\n// get all comments replies pages first reply updatedAts, use to check if a commentsStore change should trigger updateFeeds\nexport const getFeedsCommentsRepliesPagesFirstUpdatedAts = (\n feedsComments: Map<string, Comment>,\n): string => {\n let feedsCommentsRepliesPagesFirstUpdatedAts = \"\";\n for (const comment of feedsComments.values()) {\n for (const page of Object.values<RepliesPage>(comment?.replies?.pages || {})) {\n if (page?.comments?.[0]?.updatedAt) {\n feedsCommentsRepliesPagesFirstUpdatedAts +=\n page.comments[0].cid + page.comments[0].updatedAt;\n }\n }\n }\n return feedsCommentsRepliesPagesFirstUpdatedAts;\n};\n\n// get number of feeds comments that are loaded\nexport const getFeedsCommentsLoadedCount = (feedsComments: Map<string, Comment>): number => {\n let count = 0;\n for (const comment of feedsComments.values()) {\n if (comment?.updatedAt) {\n count++;\n }\n }\n return count;\n};\n\n// selected sort type could be missing from comment, or not optimized\nexport const getSortTypeFromComment = (comment: Comment, feedOptions: RepliesFeedOptions) => {\n let { sortType, flat } = feedOptions;\n\n if (!comment) {\n return sortType;\n }\n\n // 'topAll' and 'best' are similar enough to be used interchangeably\n if (\n sortType === \"best\" &&\n !comment.replies?.pages?.best &&\n !comment.replies?.pageCids?.best &&\n (comment.replies?.pages?.topAll || comment.replies?.pageCids?.topAll)\n ) {\n sortType = \"topAll\";\n } else if (\n sortType === \"topAll\" &&\n !comment.replies?.pages?.topAll &&\n !comment.replies?.pageCids?.topAll &&\n (comment.replies?.pages?.best || comment.replies?.pageCids?.best)\n ) {\n sortType = \"best\";\n }\n\n // if 'new' sort type and flat: true, use 'newFlat'\n else if (\n sortType === \"new\" &&\n flat &&\n (comment.replies?.pages?.newFlat || comment.replies?.pageCids?.newFlat)\n ) {\n sortType = \"newFlat\";\n }\n // if 'old' sort type and flat: true, use 'oldFlat'\n else if (\n sortType === \"old\" &&\n flat &&\n (comment.replies?.pages?.oldFlat || comment.replies?.pageCids?.oldFlat)\n ) {\n sortType = \"oldFlat\";\n }\n\n // if 'newFlat' is missing, use 'new'\n else if (\n sortType === \"newFlat\" &&\n !comment.replies?.pages?.newFlat &&\n !comment.replies?.pageCids?.newFlat &&\n (comment.replies?.pages?.new || comment.replies?.pageCids?.new)\n ) {\n sortType = \"new\";\n }\n // if 'oldFlat' is missing, use 'old'\n else if (\n sortType === \"oldFlat\" &&\n !comment.replies?.pages?.oldFlat &&\n !comment.replies?.pageCids?.oldFlat &&\n (comment.replies?.pages?.old || comment.replies?.pageCids?.old)\n ) {\n sortType = \"old\";\n }\n\n // TODO: if sort type doesn't exist on comment, maybe use first existing?\n // else if (!comment.replies?.pages?.[sortType] && !comment.replies?.pageCids?.[sortType]) {\n // const firstPageSortType = comment.replies?.pages && Object.keys(comment.replies.pages)[0]\n // if (firstPageSortType) {\n // sortType = firstPageSortType\n // }\n // else {\n // const firstPageCidSortType = comment.replies?.pageCids && Object.keys(comment.replies.pageCids)[0]\n // if (firstPageCidSortType) {\n // sortType = firstPageCidSortType\n // }\n // }\n // }\n return sortType;\n};\n"]}
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
- "version": "0.1.2",
16
+ "version": "0.1.4",
17
17
  "packageManager": "yarn@4.13.0",
18
18
  "files": [
19
19
  "dist"
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@bitsocial/bso-resolver": "0.0.6",
48
- "@pkcprotocol/pkc-js": "0.0.19",
48
+ "@pkcprotocol/pkc-js": "0.0.23",
49
49
  "@pkcprotocol/pkc-logger": "0.1.0",
50
50
  "assert": "2.0.0",
51
51
  "ethers": "5.8.0",