@bitsocial/bitsocial-react-hooks 0.2.2 → 0.2.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.
Files changed (117) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +2 -0
  3. package/dist/hooks/accounts/accounts.d.ts.map +1 -1
  4. package/dist/hooks/accounts/accounts.js +35 -10
  5. package/dist/hooks/accounts/accounts.js.map +1 -1
  6. package/dist/hooks/actions/actions.d.ts.map +1 -1
  7. package/dist/hooks/actions/actions.js +166 -93
  8. package/dist/hooks/actions/actions.js.map +1 -1
  9. package/dist/hooks/authors/author-avatars.d.ts +2 -2
  10. package/dist/hooks/authors/author-avatars.d.ts.map +1 -1
  11. package/dist/hooks/authors/author-avatars.js +48 -20
  12. package/dist/hooks/authors/author-avatars.js.map +1 -1
  13. package/dist/hooks/authors/authors.d.ts.map +1 -1
  14. package/dist/hooks/authors/authors.js +68 -22
  15. package/dist/hooks/authors/authors.js.map +1 -1
  16. package/dist/hooks/comments.d.ts.map +1 -1
  17. package/dist/hooks/comments.js +54 -3
  18. package/dist/hooks/comments.js.map +1 -1
  19. package/dist/hooks/communities.d.ts.map +1 -1
  20. package/dist/hooks/communities.js +41 -12
  21. package/dist/hooks/communities.js.map +1 -1
  22. package/dist/hooks/feeds/feeds.d.ts.map +1 -1
  23. package/dist/hooks/feeds/feeds.js +47 -11
  24. package/dist/hooks/feeds/feeds.js.map +1 -1
  25. package/dist/hooks/pkc-rpc.d.ts.map +1 -1
  26. package/dist/hooks/pkc-rpc.js +33 -20
  27. package/dist/hooks/pkc-rpc.js.map +1 -1
  28. package/dist/hooks/replies.d.ts.map +1 -1
  29. package/dist/hooks/replies.js +30 -4
  30. package/dist/hooks/replies.js.map +1 -1
  31. package/dist/index.d.ts +6 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/lib/debug-utils.d.ts +4 -4
  36. package/dist/lib/debug-utils.d.ts.map +1 -1
  37. package/dist/lib/debug-utils.js +56 -11
  38. package/dist/lib/debug-utils.js.map +1 -1
  39. package/dist/lib/localforage-lru/localforage-lru.d.ts +1 -0
  40. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -1
  41. package/dist/lib/localforage-lru/localforage-lru.js +48 -10
  42. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -1
  43. package/dist/lib/page-sorts.d.ts +6 -0
  44. package/dist/lib/page-sorts.d.ts.map +1 -1
  45. package/dist/lib/page-sorts.js +45 -9
  46. package/dist/lib/page-sorts.js.map +1 -1
  47. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -1
  48. package/dist/lib/pkc-js/pkc-js-mock-content.js +5 -1
  49. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
  50. package/dist/lib/utils/utils.d.ts.map +1 -1
  51. package/dist/lib/utils/utils.js +24 -16
  52. package/dist/lib/utils/utils.js.map +1 -1
  53. package/dist/lib/validator.d.ts +1 -1
  54. package/dist/lib/validator.d.ts.map +1 -1
  55. package/dist/lib/validator.js +7 -1
  56. package/dist/lib/validator.js.map +1 -1
  57. package/dist/stores/accounts/account-generator.d.ts +1 -0
  58. package/dist/stores/accounts/account-generator.d.ts.map +1 -1
  59. package/dist/stores/accounts/account-generator.js +12 -4
  60. package/dist/stores/accounts/account-generator.js.map +1 -1
  61. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -1
  62. package/dist/stores/accounts/accounts-actions-internal.js +24 -6
  63. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
  64. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
  65. package/dist/stores/accounts/accounts-actions.js +339 -98
  66. package/dist/stores/accounts/accounts-actions.js.map +1 -1
  67. package/dist/stores/accounts/accounts-database.d.ts +1 -0
  68. package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
  69. package/dist/stores/accounts/accounts-database.js +82 -15
  70. package/dist/stores/accounts/accounts-database.js.map +1 -1
  71. package/dist/stores/accounts/accounts-store.d.ts +1 -1
  72. package/dist/stores/accounts/accounts-store.d.ts.map +1 -1
  73. package/dist/stores/accounts/accounts-store.js +1 -1
  74. package/dist/stores/accounts/accounts-store.js.map +1 -1
  75. package/dist/stores/accounts/utils.d.ts +5 -1
  76. package/dist/stores/accounts/utils.d.ts.map +1 -1
  77. package/dist/stores/accounts/utils.js +58 -0
  78. package/dist/stores/accounts/utils.js.map +1 -1
  79. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -1
  80. package/dist/stores/authors-comments/authors-comments-store.js +39 -12
  81. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
  82. package/dist/stores/comments/comments-store.d.ts +2 -0
  83. package/dist/stores/comments/comments-store.d.ts.map +1 -1
  84. package/dist/stores/comments/comments-store.js +170 -21
  85. package/dist/stores/comments/comments-store.js.map +1 -1
  86. package/dist/stores/communities/communities-store.d.ts.map +1 -1
  87. package/dist/stores/communities/communities-store.js +27 -7
  88. package/dist/stores/communities/communities-store.js.map +1 -1
  89. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
  90. package/dist/stores/communities-pages/communities-pages-store.js +60 -8
  91. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
  92. package/dist/stores/feeds/feed-sorter.d.ts +5 -2
  93. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
  94. package/dist/stores/feeds/feed-sorter.js +15 -4
  95. package/dist/stores/feeds/feed-sorter.js.map +1 -1
  96. package/dist/stores/feeds/feeds-store.d.ts +3 -0
  97. package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
  98. package/dist/stores/feeds/feeds-store.js +36 -26
  99. package/dist/stores/feeds/feeds-store.js.map +1 -1
  100. package/dist/stores/feeds/utils.d.ts +16 -0
  101. package/dist/stores/feeds/utils.d.ts.map +1 -1
  102. package/dist/stores/feeds/utils.js +82 -26
  103. package/dist/stores/feeds/utils.js.map +1 -1
  104. package/dist/stores/replies/replies-store.d.ts.map +1 -1
  105. package/dist/stores/replies/replies-store.js +32 -6
  106. package/dist/stores/replies/replies-store.js.map +1 -1
  107. package/dist/stores/replies/utils.d.ts +3 -2
  108. package/dist/stores/replies/utils.d.ts.map +1 -1
  109. package/dist/stores/replies/utils.js +38 -5
  110. package/dist/stores/replies/utils.js.map +1 -1
  111. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
  112. package/dist/stores/replies-pages/replies-pages-store.js +68 -13
  113. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
  114. package/dist/types.d.ts +11 -2
  115. package/dist/types.d.ts.map +1 -1
  116. package/dist/types.js.map +1 -1
  117. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"accounts-store.js","sourceRoot":"","sources":["../../../src/stores/accounts/accounts-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAC5D,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AACnD,OAAO,gBAAgB,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAgB/D,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,uBAAuB,MAAM,6BAA6B,CAAC;AACvE,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,SAAS,CAAC;AAEjB,6CAA6C;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAQ,EAAE,CAAC;AAoBjC,MAAM,aAAa,GAAG,WAAW,CAAgB,CAAC,QAAkB,EAAE,QAAkB,EAAE,EAAE,CAAC,CAAC;IAC5F,QAAQ,EAAE,EA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AAO,CAAC,GAAG,CAAC;QAChB,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE;QACpF,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE;KAC7E,CAAC,CAAC;IACH,MAAM,kBAAkB,EAAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import assert from \"../../lib/assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport accountsDatabase from \"./accounts-database\";\nimport accountGenerator from \"./account-generator\";\nimport { preloadAccountChainLibraries } from \"../../lib/chain\";\nimport {\n AccountNamesToAccountIds,\n Account,\n Accounts,\n AccountsActions,\n Comment,\n AccountsVotes,\n AccountsEdits,\n AccountsEditsSummaries,\n AccountComment,\n AccountsComments,\n AccountsCommentsIndexes,\n AccountsCommentsReplies,\n CommentCidsToAccountsComments,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport * as accountsActions from \"./accounts-actions\";\nimport * as accountsActionsInternal from \"./accounts-actions-internal\";\nimport localForage from \"localforage\";\nimport {\n getAccountsCommentsIndexes,\n getCommentCidsToAccountsComments,\n getInitAccountCommentsToUpdate,\n} from \"./utils\";\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\ntype AccountsState = {\n accounts: Accounts;\n accountIds: string[];\n activeAccountId: string | undefined;\n accountNamesToAccountIds: AccountNamesToAccountIds;\n accountsComments: AccountsComments;\n accountsCommentsIndexes: AccountsCommentsIndexes;\n commentCidsToAccountsComments: CommentCidsToAccountsComments;\n accountsCommentsUpdating: { [commentCid: string]: boolean };\n accountsCommentsReplies: AccountsCommentsReplies;\n accountsVotes: AccountsVotes;\n accountsEdits: AccountsEdits;\n accountsEditsSummaries: AccountsEditsSummaries;\n accountsEditsLoaded: { [accountId: string]: boolean };\n accountsActions: { [functionName: string]: Function };\n accountsActionsInternal: { [functionName: string]: Function };\n};\n\nconst accountsStore = createStore<AccountsState>((setState: Function, getState: Function) => ({\n accounts: {},\n accountIds: [],\n activeAccountId: undefined,\n accountNamesToAccountIds: {},\n accountsComments: {},\n accountsCommentsIndexes: {},\n commentCidsToAccountsComments: {},\n accountsCommentsUpdating: {},\n accountsCommentsReplies: {},\n accountsVotes: {},\n accountsEdits: {},\n accountsEditsSummaries: {},\n accountsEditsLoaded: {},\n accountsActions,\n accountsActionsInternal,\n}));\n\n// load accounts from database once on load\nconst initializeAccountsStore = async () => {\n await accountsDatabase.migrate();\n\n let accountIds: string[] | undefined;\n let activeAccountId: string | undefined;\n let accounts: Accounts;\n let accountNamesToAccountIds: AccountNamesToAccountIds | undefined;\n accountIds = (await accountsDatabase.accountsMetadataDatabase.getItem(\"accountIds\")) || undefined;\n // get accounts from database if any\n if (accountIds?.length) {\n [activeAccountId, accounts, accountNamesToAccountIds] = await Promise.all<any>([\n accountsDatabase.accountsMetadataDatabase.getItem(\"activeAccountId\"),\n accountsDatabase.getAccounts(accountIds),\n accountsDatabase.accountsMetadataDatabase.getItem(\"accountNamesToAccountIds\"),\n ]);\n }\n // no accounts in database, create a default account\n else {\n const defaultAccount = await accountGenerator.generateDefaultAccount();\n await accountsDatabase.addAccount(defaultAccount);\n accounts = { [defaultAccount.id]: defaultAccount };\n [accountIds, activeAccountId, accountNamesToAccountIds] = await Promise.all<any>([\n accountsDatabase.accountsMetadataDatabase.getItem(\"accountIds\"),\n accountsDatabase.accountsMetadataDatabase.getItem(\"activeAccountId\"),\n accountsDatabase.accountsMetadataDatabase.getItem(\"accountNamesToAccountIds\"),\n ]);\n assert(\n accountIds && activeAccountId && accountNamesToAccountIds,\n `accountsStore error creating a default account during initialization accountsMetadataDatabase.accountIds '${accountIds}' accountsMetadataDatabase.activeAccountId '${activeAccountId}' accountsMetadataDatabase.accountNamesToAccountIds '${JSON.stringify(\n accountNamesToAccountIds,\n )}'`,\n );\n }\n const [accountsComments, accountsVotes, accountsCommentsReplies, accountsEditsSummaries] =\n await Promise.all<any>([\n accountsDatabase.getAccountsComments(accountIds),\n accountsDatabase.getAccountsVotes(accountIds),\n accountsDatabase.getAccountsCommentsReplies(accountIds),\n accountsDatabase.getAccountsEditsSummaries(accountIds),\n ]);\n const commentCidsToAccountsComments = getCommentCidsToAccountsComments(accountsComments);\n const accountsCommentsIndexes = getAccountsCommentsIndexes(accountsComments);\n accountsStore.setState((state) => ({\n accounts,\n accountIds,\n activeAccountId,\n accountNamesToAccountIds,\n accountsComments,\n accountsCommentsIndexes,\n commentCidsToAccountsComments,\n accountsVotes,\n accountsCommentsReplies,\n // Keep accountsEditsSummaries hot while accountsEdits stays cold until accountsEditsLoaded flips true.\n accountsEdits: Object.fromEntries(accountIds.map((accountId) => [accountId, {}])),\n accountsEditsSummaries,\n accountsEditsLoaded: Object.fromEntries(accountIds.map((accountId) => [accountId, false])),\n }));\n\n // start looking for updates for all accounts comments in database\n for (const { accountComment, accountId } of getInitAccountCommentsToUpdate(accountsComments)) {\n accountsStore\n .getState()\n .accountsActionsInternal.startUpdatingAccountCommentOnCommentUpdateEvents(\n accountComment,\n accounts[accountId],\n accountComment.index,\n )\n .catch((error: unknown) =>\n log.error(\n \"accountsStore.initializeAccountsStore startUpdatingAccountCommentOnCommentUpdateEvents error\",\n {\n accountComment,\n accountCommentIndex: accountComment.index,\n accounts,\n error,\n },\n ),\n );\n }\n};\n\n// @ts-ignore\nconst isInitializing = () => !!window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZING;\nconst waitForInitialized = async () => {\n while (isInitializing()) {\n // uncomment to debug accounts init\n // console.warn(`can't reset accounts store while initializing, waiting 100ms`)\n await new Promise((r) => setTimeout(r, 100));\n }\n};\n\n(async () => {\n // don't initialize on load multiple times when loading the file multiple times during karma tests\n // @ts-ignore\n if (window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZED_ONCE) {\n return;\n }\n\n // @ts-ignore\n window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZED_ONCE = true;\n // @ts-ignore\n window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZING = true;\n\n preloadAccountChainLibraries();\n log(\"accounts store initializing started\");\n try {\n await initializeAccountsStore();\n } catch (error) {\n // initializing can fail in tests when store is being reset at the same time as databases are being deleted\n log.error(\"accountsStore.initializeAccountsStore error\", {\n accountsStore: accountsStore.getState(),\n error,\n });\n } finally {\n // @ts-ignore\n delete window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZING;\n }\n log(\"accounts store initializing finished\");\n})();\n\n// reset store in between tests\nconst originalState = accountsStore.getState();\n// async function because some stores have async init\nexport const resetAccountsStore = async () => {\n // don't reset while initializing, it could happen during quick successive tests\n await waitForInitialized();\n\n log(\"accounts store reset started\");\n\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n accountsStore.getState().accountsActionsInternal.resetLazyAccountHistoryLoaders?.();\n // destroy all component subscriptions to the store\n accountsStore.destroy();\n // restore original state\n accountsStore.setState(originalState);\n // init the store\n await initializeAccountsStore();\n\n log(\"accounts store reset finished\");\n};\n\n// reset database and store in between tests\nexport const resetAccountsDatabaseAndStore = async () => {\n // don't reset while initializing, it could happen during quick successive tests\n await waitForInitialized();\n\n await Promise.all([\n localForage.createInstance({ name: \"bitsocialReactHooks-accountsMetadata\" }).clear(),\n localForage.createInstance({ name: \"bitsocialReactHooks-accounts\" }).clear(),\n ]);\n await resetAccountsStore();\n};\n\nexport default accountsStore;\n"]}
1
+ {"version":3,"file":"accounts-store.js","sourceRoot":"","sources":["../../../src/stores/accounts/accounts-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAC5D,OA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AS,CAAC,OAAO,CAAC,CAAC,QAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACpE,MAAA,MAAA,aAAa,CAAC,QAAQ,EAAE,CAAC,uBAAuB,EAAC,8BAA8B,kDAAI,CAAC;IACpF,mDAAmD;IACnD,aAAa,CAAC,OAAO,EAAE,CAAC;IACxB,yBAAyB;IACzB,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IACtC,iBAAiB;IACjB,MAAM,uBAAuB,EAAE,CAAC;IAEhC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AACvC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAS,EAAE;IACtD,gFAAgF;IAChF,MAAM,kBAAkB,EAAE,CAAC;IAE3B,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,sCAAsC,EAAE,CAAC,CAAC,KAAK,EAAE;QACpF,WAAW,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE;KAC7E,CAAC,CAAC;IACH,MAAM,kBAAkB,EAAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import assert from \"../../lib/assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport accountsDatabase from \"./accounts-database\";\nimport accountGenerator from \"./account-generator\";\nimport { preloadAccountChainLibraries } from \"../../lib/chain\";\nimport {\n AccountNamesToAccountIds,\n Account,\n Accounts,\n AccountsActions,\n Comment,\n AccountsVotes,\n AccountsEdits,\n AccountsEditsSummaries,\n AccountComment,\n AccountsComments,\n AccountsCommentsIndexes,\n AccountsCommentsReplies,\n CommentCidsToAccountsComments,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport * as accountsActions from \"./accounts-actions\";\nimport * as accountsActionsInternal from \"./accounts-actions-internal\";\nimport localForage from \"localforage\";\nimport {\n getAccountsCommentsIndexes,\n getCommentCidsToAccountsComments,\n getInitAccountCommentsToUpdate,\n} from \"./utils\";\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\ntype AccountsState = {\n accounts: Accounts;\n accountIds: string[];\n activeAccountId: string | undefined;\n accountNamesToAccountIds: AccountNamesToAccountIds;\n accountsComments: AccountsComments;\n accountsCommentsIndexes: AccountsCommentsIndexes;\n commentCidsToAccountsComments: CommentCidsToAccountsComments;\n // keyed by `${accountId}:${commentCid}`\n accountsCommentsUpdating: { [accountIdAndCommentCid: string]: boolean };\n accountsCommentsReplies: AccountsCommentsReplies;\n accountsVotes: AccountsVotes;\n accountsEdits: AccountsEdits;\n accountsEditsSummaries: AccountsEditsSummaries;\n accountsEditsLoaded: { [accountId: string]: boolean };\n accountsActions: { [functionName: string]: Function };\n accountsActionsInternal: { [functionName: string]: Function };\n};\n\nconst accountsStore = createStore<AccountsState>((setState: Function, getState: Function) => ({\n accounts: {},\n accountIds: [],\n activeAccountId: undefined,\n accountNamesToAccountIds: {},\n accountsComments: {},\n accountsCommentsIndexes: {},\n commentCidsToAccountsComments: {},\n accountsCommentsUpdating: {},\n accountsCommentsReplies: {},\n accountsVotes: {},\n accountsEdits: {},\n accountsEditsSummaries: {},\n accountsEditsLoaded: {},\n accountsActions,\n accountsActionsInternal,\n}));\n\n// load accounts from database once on load\nconst initializeAccountsStore = async () => {\n await accountsDatabase.migrate();\n\n let accountIds: string[] | undefined;\n let activeAccountId: string | undefined;\n let accounts: Accounts;\n let accountNamesToAccountIds: AccountNamesToAccountIds | undefined;\n accountIds = (await accountsDatabase.repairAccountsMetadata()) || undefined;\n // get accounts from database if any\n if (accountIds?.length) {\n [activeAccountId, accounts, accountNamesToAccountIds] = await Promise.all<any>([\n accountsDatabase.accountsMetadataDatabase.getItem(\"activeAccountId\"),\n accountsDatabase.getAccounts(accountIds),\n accountsDatabase.accountsMetadataDatabase.getItem(\"accountNamesToAccountIds\"),\n ]);\n }\n // no accounts in database, create a default account\n else {\n const defaultAccount = await accountGenerator.generateDefaultAccount();\n await accountsDatabase.addAccount(defaultAccount);\n accounts = { [defaultAccount.id]: defaultAccount };\n [accountIds, activeAccountId, accountNamesToAccountIds] = await Promise.all<any>([\n accountsDatabase.accountsMetadataDatabase.getItem(\"accountIds\"),\n accountsDatabase.accountsMetadataDatabase.getItem(\"activeAccountId\"),\n accountsDatabase.accountsMetadataDatabase.getItem(\"accountNamesToAccountIds\"),\n ]);\n assert(\n accountIds && activeAccountId && accountNamesToAccountIds,\n `accountsStore error creating a default account during initialization accountsMetadataDatabase.accountIds '${accountIds}' accountsMetadataDatabase.activeAccountId '${activeAccountId}' accountsMetadataDatabase.accountNamesToAccountIds '${JSON.stringify(\n accountNamesToAccountIds,\n )}'`,\n );\n }\n const [accountsComments, accountsVotes, accountsCommentsReplies, accountsEditsSummaries] =\n await Promise.all<any>([\n accountsDatabase.getAccountsComments(accountIds),\n accountsDatabase.getAccountsVotes(accountIds),\n accountsDatabase.getAccountsCommentsReplies(accountIds),\n accountsDatabase.getAccountsEditsSummaries(accountIds),\n ]);\n const commentCidsToAccountsComments = getCommentCidsToAccountsComments(accountsComments);\n const accountsCommentsIndexes = getAccountsCommentsIndexes(accountsComments);\n accountsStore.setState((state) => ({\n accounts,\n accountIds,\n activeAccountId,\n accountNamesToAccountIds,\n accountsComments,\n accountsCommentsIndexes,\n commentCidsToAccountsComments,\n accountsVotes,\n accountsCommentsReplies,\n // Keep accountsEditsSummaries hot while accountsEdits stays cold until accountsEditsLoaded flips true.\n accountsEdits: Object.fromEntries(accountIds.map((accountId) => [accountId, {}])),\n accountsEditsSummaries,\n accountsEditsLoaded: Object.fromEntries(accountIds.map((accountId) => [accountId, false])),\n }));\n\n // start looking for updates for all accounts comments in database\n for (const { accountComment, accountId } of getInitAccountCommentsToUpdate(accountsComments)) {\n accountsStore\n .getState()\n .accountsActionsInternal.startUpdatingAccountCommentOnCommentUpdateEvents(\n accountComment,\n accounts[accountId],\n accountComment.index,\n )\n .catch((error: unknown) =>\n log.error(\n \"accountsStore.initializeAccountsStore startUpdatingAccountCommentOnCommentUpdateEvents error\",\n {\n accountComment,\n accountCommentIndex: accountComment.index,\n accounts,\n error,\n },\n ),\n );\n }\n};\n\n// @ts-ignore\nconst isInitializing = () => !!window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZING;\nconst waitForInitialized = async () => {\n while (isInitializing()) {\n // uncomment to debug accounts init\n // console.warn(`can't reset accounts store while initializing, waiting 100ms`)\n await new Promise((r) => setTimeout(r, 100));\n }\n};\n\n(async () => {\n // don't initialize on load multiple times when loading the file multiple times during karma tests\n // @ts-ignore\n if (window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZED_ONCE) {\n return;\n }\n\n // @ts-ignore\n window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZED_ONCE = true;\n // @ts-ignore\n window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZING = true;\n\n preloadAccountChainLibraries();\n log(\"accounts store initializing started\");\n try {\n await initializeAccountsStore();\n } catch (error) {\n // initializing can fail in tests when store is being reset at the same time as databases are being deleted\n log.error(\"accountsStore.initializeAccountsStore error\", {\n accountsStore: accountsStore.getState(),\n error,\n });\n } finally {\n // @ts-ignore\n delete window.BITSOCIAL_REACT_HOOKS_ACCOUNTS_STORE_INITIALIZING;\n }\n log(\"accounts store initializing finished\");\n})();\n\n// reset store in between tests\nconst originalState = accountsStore.getState();\n// async function because some stores have async init\nexport const resetAccountsStore = async () => {\n // don't reset while initializing, it could happen during quick successive tests\n await waitForInitialized();\n\n log(\"accounts store reset started\");\n\n // remove all event listeners\n listeners.forEach((listener: any) => listener.removeAllListeners());\n accountsStore.getState().accountsActionsInternal.resetLazyAccountHistoryLoaders?.();\n // destroy all component subscriptions to the store\n accountsStore.destroy();\n // restore original state\n accountsStore.setState(originalState);\n // init the store\n await initializeAccountsStore();\n\n log(\"accounts store reset finished\");\n};\n\n// reset database and store in between tests\nexport const resetAccountsDatabaseAndStore = async () => {\n // don't reset while initializing, it could happen during quick successive tests\n await waitForInitialized();\n\n await Promise.all([\n localForage.createInstance({ name: \"bitsocialReactHooks-accountsMetadata\" }).clear(),\n localForage.createInstance({ name: \"bitsocialReactHooks-accounts\" }).clear(),\n ]);\n await resetAccountsStore();\n};\n\nexport default accountsStore;\n"]}
@@ -1,4 +1,4 @@
1
- import { Account, Communities, AccountComment, AccountsComments, AccountsCommentsIndexes, AccountCommentsIndex, CommentCidsToAccountsComments, Comment, AccountEdit, AccountEditsSummary } from "../../types.js";
1
+ import { Account, Communities, AccountComment, AccountsComments, AccountsCommentsIndexes, AccountCommentsIndex, CommentCidsToAccountsComments, Comment, AccountEdit, AccountEditsSummary, AccountVote } from "../../types.js";
2
2
  export declare const getAccountCommunities: (account: Account, communities: Communities) => any;
3
3
  export declare const getCommentCidsToAccountsComments: (accountsComments: AccountsComments) => CommentCidsToAccountsComments;
4
4
  export declare const sanitizeAccountCommentForState: (comment: Comment) => any;
@@ -23,8 +23,10 @@ export declare const getInitAccountCommentsToUpdate: (accountsComments: Accounts
23
23
  accountId: string;
24
24
  }[];
25
25
  export declare const getAccountCommentDepth: (comment: Comment) => number | undefined;
26
+ export declare const getAccountCommentPostCid: (comment: Comment, ...additionalParentCandidates: (Comment | undefined)[]) => string | undefined;
26
27
  export declare const getFreshestLoadedComment: (commentCid: string, ...additionalCandidates: (Comment | undefined)[]) => Comment | undefined;
27
28
  export declare const addShortAddressesToAccountComment: (comment: Comment) => Comment;
29
+ export declare const addShortCommunityAddressToAccountPublication: <Publication extends AccountVote | AccountEdit | undefined>(publication: Publication) => Publication;
28
30
  declare const utils: {
29
31
  getAccountCommunities: (account: Account, communities: Communities) => any;
30
32
  getCommentCidsToAccountsComments: (accountsComments: AccountsComments) => CommentCidsToAccountsComments;
@@ -44,8 +46,10 @@ declare const utils: {
44
46
  accountId: string;
45
47
  }[];
46
48
  getAccountCommentDepth: (comment: Comment) => number | undefined;
49
+ getAccountCommentPostCid: (comment: Comment, ...additionalParentCandidates: (Comment | undefined)[]) => string | undefined;
47
50
  getFreshestLoadedComment: (commentCid: string, ...additionalCandidates: (Comment | undefined)[]) => Comment | undefined;
48
51
  addShortAddressesToAccountComment: (comment: Comment) => Comment;
52
+ addShortCommunityAddressToAccountPublication: <Publication extends AccountVote | AccountEdit | undefined>(publication: Publication) => Publication;
49
53
  promiseAny: <T>(promises: Promise<T>[]) => Promise<T>;
50
54
  };
51
55
  export default utils;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,6BAA6B,EAC7B,OAAO,EACP,WAAW,EACX,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAsBrB,eAAO,MAAM,qBAAqB,GAAI,SAAS,OAAO,EAAE,aAAa,WAAW,QAiB/E,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAAI,kBAAkB,gBAAgB,kCAalF,CAAC;AA0FF,eAAO,MAAM,8BAA8B,GAAI,SAAS,OAAO,QAuB9D,CAAC;AAEF,eAAO,MAAM,4BAA4B,GAAI,SAAS,OAAO,QAoB5D,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,iBAAiB,cAAc,EAAE,GAAG,SAAS,KAC5C,oBAoBF,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,kBAAkB,gBAAgB,4BAM5E,CAAC;AAYF,eAAO,MAAM,qCAAqC,6BAA6B,CAAC;AAsBhF,eAAO,MAAM,6BAA6B,GAAI,cAAc,WAAW,EAAE,GAAG,SAAS;;CAsBpF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,cAAc;IACpD,CAAC,4BA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,CAAC,CAAC;CAkTzD,CAAC;AAEF,eAAe,KAAK,CAAC"}
@@ -406,6 +406,34 @@ export const getAccountCommentDepth = (comment) => {
406
406
  // if can't find the parent comment depth anywhere, don't include it with the account comment
407
407
  // it will be added automatically when challenge verification is received
408
408
  };
409
+ // the cid of the post a pending account comment belongs to, when the caches know its parent
410
+ export const getAccountCommentPostCid = (comment, ...additionalParentCandidates) => {
411
+ // never replace the value the caller published with
412
+ if (comment.postCid) {
413
+ return comment.postCid;
414
+ }
415
+ // a post's own postCid is its cid, which doesn't exist until challenge verification
416
+ if (!comment.parentCid) {
417
+ return;
418
+ }
419
+ const parentComments = [
420
+ commentsStore.getState().comments[comment.parentCid],
421
+ repliesPagesStore.getState().comments[comment.parentCid],
422
+ communitiesPagesStore.getState().comments[comment.parentCid],
423
+ ...additionalParentCandidates,
424
+ ];
425
+ for (const parentComment of parentComments) {
426
+ if (typeof (parentComment === null || parentComment === void 0 ? void 0 : parentComment.postCid) === "string" && parentComment.postCid) {
427
+ return parentComment.postCid;
428
+ }
429
+ // the parent is the post
430
+ if ((parentComment === null || parentComment === void 0 ? void 0 : parentComment.depth) === 0) {
431
+ return comment.parentCid;
432
+ }
433
+ }
434
+ // if can't find the thread root anywhere, don't include it with the account comment
435
+ // it will be added automatically when challenge verification is received
436
+ };
409
437
  export const getFreshestLoadedComment = (commentCid, ...additionalCandidates) => {
410
438
  const candidates = [
411
439
  commentsStore.getState().comments[commentCid],
@@ -435,6 +463,34 @@ export const addShortAddressesToAccountComment = (comment) => {
435
463
  catch (e) { }
436
464
  return comment;
437
465
  };
466
+ // Account votes and edits are stored as their publish options, without the short community address
467
+ // account comments get when they are created. Derive it when they are read instead of storing it,
468
+ // so history stored by earlier versions has it too and no stored record is rewritten. Votes and
469
+ // edits are stored without their author, so there is no author.shortAddress to add.
470
+ // Cached per record so a record that didn't change keeps its identity between renders.
471
+ const accountPublicationsWithShortCommunityAddress = new WeakMap();
472
+ export const addShortCommunityAddressToAccountPublication = (publication) => {
473
+ if (!publication ||
474
+ typeof publication.communityAddress !== "string" ||
475
+ publication.shortCommunityAddress) {
476
+ return publication;
477
+ }
478
+ let publicationWithShortCommunityAddress = accountPublicationsWithShortCommunityAddress.get(publication);
479
+ if (!publicationWithShortCommunityAddress) {
480
+ publicationWithShortCommunityAddress = publication;
481
+ try {
482
+ const shortCommunityAddress = PkcJs.PKC.getShortAddress({
483
+ address: publication.communityAddress,
484
+ });
485
+ if (shortCommunityAddress) {
486
+ publicationWithShortCommunityAddress = Object.assign(Object.assign({}, publication), { shortCommunityAddress });
487
+ }
488
+ }
489
+ catch (_a) { }
490
+ accountPublicationsWithShortCommunityAddress.set(publication, publicationWithShortCommunityAddress);
491
+ }
492
+ return publicationWithShortCommunityAddress;
493
+ };
438
494
  const utils = {
439
495
  getAccountCommunities,
440
496
  getCommentCidsToAccountsComments,
@@ -447,8 +503,10 @@ const utils = {
447
503
  fetchCommentLinkDimensions,
448
504
  getInitAccountCommentsToUpdate,
449
505
  getAccountCommentDepth,
506
+ getAccountCommentPostCid,
450
507
  getFreshestLoadedComment,
451
508
  addShortAddressesToAccountComment,
509
+ addShortCommunityAddressToAccountPublication,
452
510
  promiseAny,
453
511
  };
454
512
  export default utils;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAaA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAC5D,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,EAAE,2BAA2B,EA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AAC,SAAS,CAAC,GAAG,2BAA2B,CAAC,QAAQ,CAAC;QAC5E,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,QAAQ,EACd,SAAS,CACV,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,OAAgB,EAAE,EAAE;IACpE,OAAO,qBAAQ,OAAO,CAAE,CAAC;IACzB,IAAI,CAAC;QACH,OAAO,CAAC,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;YACxD,OAAO,EAAE,OAAO,CAAC,gBAAgB;SAClC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IACd,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,qBAAQ,OAAO,CAAC,MAAM,CAAE,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;YACtD,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO;SAChC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;IACd,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG;IACZ,qBAAqB;IACrB,gCAAgC;IAChC,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,4BAA4B;IAC5B,6BAA6B;IAC7B,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,sBAAsB;IACtB,wBAAwB;IACxB,iCAAiC;IACjC,UAAU;CACX,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import {\n Account,\n Role,\n Communities,\n AccountComment,\n AccountsComments,\n AccountsCommentsIndexes,\n AccountCommentsIndex,\n CommentCidsToAccountsComments,\n Comment,\n AccountEdit,\n AccountEditsSummary,\n} from \"../../types\";\nimport assert from \"../../lib/assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport commentsStore from \"../comments\";\nimport repliesPagesStore from \"../replies-pages\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport repliesCommentsStore from \"../replies/replies-comments-store\";\nimport PkcJs from \"../../lib/pkc-js\";\nimport { getCommentVoteCountsVersion } from \"../../lib/utils/optimistic-vote-counts\";\n\nconst getAuthorAddressRolesFromCommunities = (authorAddress: string, communities: Communities) => {\n const roles: { [communityAddress: string]: Role } = {};\n for (const communityAddress in communities) {\n const role = communities[communityAddress]?.roles?.[authorAddress];\n if (role) {\n roles[communityAddress] = role;\n }\n }\n return roles;\n};\n\nexport const getAccountCommunities = (account: Account, communities: Communities) => {\n assert(\n account?.author?.address && typeof account?.author?.address === \"string\",\n `accountsStore utils getAccountCommunities invalid account.author.address '${account?.author?.address}'`,\n );\n assert(\n communities && typeof communities === \"object\",\n `accountsStore utils getAccountCommunities invalid communities '${communities}'`,\n );\n\n const roles = getAuthorAddressRolesFromCommunities(account.author.address, communities);\n const accountCommunities = { ...account.communities };\n for (const communityAddress in roles) {\n accountCommunities[communityAddress] = { ...accountCommunities[communityAddress] };\n accountCommunities[communityAddress].role = roles[communityAddress];\n }\n return accountCommunities;\n};\n\nexport const getCommentCidsToAccountsComments = (accountsComments: AccountsComments) => {\n const commentCidsToAccountsComments: CommentCidsToAccountsComments = {};\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n if (accountComment.cid) {\n commentCidsToAccountsComments[accountComment.cid] = {\n accountId,\n accountCommentIndex: accountComment.index,\n };\n }\n }\n }\n return commentCidsToAccountsComments;\n};\n\nconst cloneWithoutFunctions = (value: any): any => {\n if (Array.isArray(value)) {\n return value\n .map((entry) => cloneWithoutFunctions(entry))\n .filter((entry) => entry !== undefined);\n }\n if (!value || typeof value !== \"object\") {\n return typeof value === \"function\" ? undefined : value;\n }\n\n const clonedValue: Record<string, any> = {};\n for (const key in value) {\n if (typeof value[key] === \"function\") {\n continue;\n }\n const clonedChild = cloneWithoutFunctions(value[key]);\n if (clonedChild !== undefined) {\n clonedValue[key] = clonedChild;\n }\n }\n return clonedValue;\n};\n\nconst compactStoredCommentAuthor = (author: any) => {\n if (!author || typeof author !== \"object\") {\n return undefined;\n }\n\n const compactAuthor = cloneWithoutFunctions({\n address: author.address,\n shortAddress: author.shortAddress,\n displayName: author.displayName,\n avatar: author.avatar,\n flair: author.flair,\n });\n\n return compactAuthor && Object.keys(compactAuthor).length > 0 ? compactAuthor : undefined;\n};\n\nconst compactStoredOriginalComment = (originalComment: any) => {\n if (!originalComment || typeof originalComment !== \"object\") {\n return undefined;\n }\n\n const compactOriginalComment = cloneWithoutFunctions({\n cid: originalComment.cid,\n content: originalComment.content,\n title: originalComment.title,\n link: originalComment.link,\n linkWidth: originalComment.linkWidth,\n linkHeight: originalComment.linkHeight,\n linkHtmlTagName: originalComment.linkHtmlTagName,\n thumbnailUrl: originalComment.thumbnailUrl,\n media: originalComment.media,\n spoiler: originalComment.spoiler,\n nsfw: originalComment.nsfw,\n deleted: originalComment.deleted,\n removed: originalComment.removed,\n reason: originalComment.reason,\n quotedCids: originalComment.quotedCids,\n parentCid: originalComment.parentCid,\n postCid: originalComment.postCid,\n communityAddress: originalComment.communityAddress,\n timestamp: originalComment.timestamp,\n author: compactStoredCommentAuthor(originalComment.author),\n });\n\n return compactOriginalComment && Object.keys(compactOriginalComment).length > 0\n ? compactOriginalComment\n : undefined;\n};\n\nconst compactStoredReplies = (replies: any) => {\n if (!replies || typeof replies !== \"object\") {\n return undefined;\n }\n\n const compactReplies = cloneWithoutFunctions(\n Object.fromEntries(\n Object.entries(replies).filter(\n ([replyKey]) => replyKey !== \"pages\" && replyKey !== \"clients\",\n ),\n ),\n );\n\n return compactReplies && Object.keys(compactReplies).length > 0 ? compactReplies : undefined;\n};\n\nexport const sanitizeAccountCommentForState = (comment: Comment) => {\n const sanitizedComment = cloneWithoutFunctions({\n ...comment,\n signer: undefined,\n raw: undefined,\n replies: comment?.replies\n ? Object.fromEntries(\n Object.entries(comment.replies).filter(([replyKey]) => replyKey !== \"pages\"),\n )\n : comment?.replies,\n });\n\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies?.pages) {\n sanitizedComment.replies = { ...sanitizedComment.replies };\n delete sanitizedComment.replies.pages;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n return sanitizedComment;\n};\n\nexport const sanitizeStoredAccountComment = (comment: Comment) => {\n const preprocessedComment = {\n ...comment,\n signer: undefined,\n clients: undefined,\n raw: undefined,\n replies: compactStoredReplies(comment?.replies),\n original: comment?.edit ? compactStoredOriginalComment(comment.original) : undefined,\n };\n const sanitizedComment = cloneWithoutFunctions(preprocessedComment);\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n if (sanitizedComment?.original && Object.keys(sanitizedComment.original).length === 0) {\n delete sanitizedComment.original;\n }\n return sanitizedComment;\n};\n\nexport const getAccountCommentsIndex = (\n accountComments: AccountComment[] | undefined,\n): AccountCommentsIndex => {\n const index: AccountCommentsIndex = {\n byCommunityAddress: {},\n byParentCid: {},\n };\n for (const accountComment of accountComments || []) {\n if (accountComment.communityAddress) {\n if (!index.byCommunityAddress[accountComment.communityAddress]) {\n index.byCommunityAddress[accountComment.communityAddress] = [];\n }\n index.byCommunityAddress[accountComment.communityAddress].push(accountComment.index);\n }\n if (accountComment.parentCid) {\n if (!index.byParentCid[accountComment.parentCid]) {\n index.byParentCid[accountComment.parentCid] = [];\n }\n index.byParentCid[accountComment.parentCid].push(accountComment.index);\n }\n }\n return index;\n};\n\nexport const getAccountsCommentsIndexes = (accountsComments: AccountsComments) => {\n const indexes: AccountsCommentsIndexes = {};\n for (const accountId in accountsComments) {\n indexes[accountId] = getAccountCommentsIndex(accountsComments[accountId]);\n }\n return indexes;\n};\n\nconst accountEditNonPropertyNames = new Set([\n \"author\",\n \"signer\",\n \"clientId\",\n \"commentCid\",\n \"communityAddress\",\n \"communityAddress\",\n \"timestamp\",\n]);\n\nexport const COMMENT_MODERATION_AUTHOR_SUMMARY_KEY = \"commentModeration.author\";\n\nconst normalizeAccountEditForSummary = (accountEdit: AccountEdit) => {\n const normalizedAccountEdit = { ...accountEdit };\n const commentModeration = normalizedAccountEdit.commentModeration;\n if (commentModeration && typeof commentModeration === \"object\") {\n const { author, ...commentModerationProperties } = commentModeration;\n Object.assign(normalizedAccountEdit, commentModerationProperties);\n if (Object.prototype.hasOwnProperty.call(commentModeration, \"author\")) {\n normalizedAccountEdit[COMMENT_MODERATION_AUTHOR_SUMMARY_KEY] = author;\n }\n delete normalizedAccountEdit.commentModeration;\n }\n const communityEdit = normalizedAccountEdit.communityEdit ?? normalizedAccountEdit.communityEdit;\n if (communityEdit && typeof communityEdit === \"object\") {\n Object.assign(normalizedAccountEdit, communityEdit);\n }\n delete normalizedAccountEdit.communityEdit;\n delete normalizedAccountEdit.communityEdit;\n return normalizedAccountEdit;\n};\n\nexport const getAccountEditPropertySummary = (accountEdits: AccountEdit[] | undefined) => {\n const accountEditPropertySummary: AccountEditsSummary[string] = {};\n for (const accountEdit of accountEdits || []) {\n const normalizedAccountEdit = normalizeAccountEditForSummary(accountEdit);\n for (const propertyName in normalizedAccountEdit) {\n if (\n (normalizedAccountEdit[propertyName] === undefined &&\n propertyName !== COMMENT_MODERATION_AUTHOR_SUMMARY_KEY) ||\n accountEditNonPropertyNames.has(propertyName)\n ) {\n continue;\n }\n const previousTimestamp = accountEditPropertySummary[propertyName]?.timestamp || 0;\n if ((normalizedAccountEdit.timestamp || 0) >= previousTimestamp) {\n accountEditPropertySummary[propertyName] = {\n timestamp: normalizedAccountEdit.timestamp,\n value: normalizedAccountEdit[propertyName],\n };\n }\n }\n }\n return accountEditPropertySummary;\n};\n\nexport const getAccountsEditsSummary = (accountEdits: {\n [commentCidOrCommunityAddress: string]: AccountEdit[];\n}) => {\n const summary: AccountEditsSummary = {};\n for (const target in accountEdits || {}) {\n summary[target] = getAccountEditPropertySummary(accountEdits[target]);\n }\n return summary;\n};\n\ninterface CommentLinkDimensions {\n linkWidth?: number;\n linkHeight?: number;\n linkHtmlTagName?: \"img\" | \"video\" | \"audio\";\n}\n\n// polyfill Promise.any, exported for test coverage of empty-array branch\nconst promiseAny = <T>(promises: Promise<T>[]): Promise<T> =>\n new Promise((res, rej) => {\n let count = promises.length;\n if (count === 0) return rej(Error(\"all promises rejected\"));\n promises.forEach((p) =>\n Promise.resolve(p)\n .then(res)\n .catch((e) => {\n if (--count === 0) rej(Error(\"all promises rejected\"));\n }),\n );\n });\n\nexport const fetchCommentLinkDimensions = async (link: string): Promise<CommentLinkDimensions> => {\n if (!link) {\n return {};\n }\n\n const fetchImageDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const image = new Image();\n image.onload = () => {\n // don't accept 0px value\n if (!image.width || !image.height) {\n return reject(Error(`failed fetching image dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: image.width,\n linkHeight: image.height,\n linkHtmlTagName: \"img\",\n });\n\n // remove image from memory\n try {\n image.src = \"\";\n } catch (e) {}\n };\n image.onerror = (error) => {\n reject(Error(`failed fetching image dimensions for url '${url}'`));\n };\n\n // max loading time\n const timeout = 10000;\n setTimeout(\n () =>\n reject(Error(`failed fetching image dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n image.src = url;\n });\n\n const fetchVideoDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const video = document.createElement(\"video\");\n video.muted = true;\n video.loop = false;\n video.addEventListener(\"loadeddata\", () => {\n // don't accept 0px value\n if (!video.videoWidth || !video.videoHeight) {\n return reject(Error(`failed fetching video dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: video.videoWidth,\n linkHeight: video.videoHeight,\n linkHtmlTagName: \"video\",\n });\n // prevent video from playing\n try {\n video.pause();\n } catch (e) {}\n // prevent video from loading\n try {\n video.src = \"\";\n } catch (e) {}\n });\n video.addEventListener(\"error\", (error) => {\n reject(Error(`failed fetching video dimensions for url '${url}'`));\n });\n\n // max loading time\n const timeout = 30000;\n setTimeout(\n () =>\n reject(Error(`failed fetching video dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n video.src = url;\n });\n\n const fetchAudio = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const audio = document.createElement(\"audio\");\n audio.addEventListener(\"loadeddata\", () => {\n resolve({\n linkHtmlTagName: \"audio\",\n });\n try {\n audio.pause();\n } catch {}\n try {\n audio.src = \"\";\n } catch {}\n });\n audio.addEventListener(\"error\", () =>\n reject(Error(`failed fetching audio html tag name for url '${url}'`)),\n );\n\n const timeout = 20000;\n setTimeout(\n () =>\n reject(\n Error(`failed fetching audio html tag name for url '${url}' timeout '${timeout}'`),\n ),\n timeout,\n );\n\n audio.src = url;\n });\n\n try {\n if (new URL(link).protocol !== \"https:\") {\n throw Error(`failed fetching comment.link dimensions for link '${link}' not https protocol`);\n }\n // an <audio> element also loads a video file's audio track, often before the <video> element\n // decodes a frame, so the audio result only counts once the image and video probes both failed\n const audio = fetchAudio(link);\n audio.catch(() => {});\n const dimensions = await promiseAny([\n fetchImageDimensions(link),\n fetchVideoDimensions(link),\n ]).catch(() => audio);\n return dimensions;\n } catch (error: any) {\n log.error(\"fetchCommentLinkDimensions error\", { error, link });\n return {};\n }\n};\n\nexport const getInitAccountCommentsToUpdate = (accountsComments: AccountsComments) => {\n const accountCommentsToUpdate: { accountComment: AccountComment; accountId: string }[] = [];\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n accountCommentsToUpdate.push({ accountComment, accountId });\n }\n }\n\n // update newer comments first, more likely to have notifications\n accountCommentsToUpdate.sort((a, b) => b.accountComment.timestamp - a.accountComment.timestamp);\n\n // updating too many comments during init slows down fetching comments/subs\n if (accountCommentsToUpdate.length > 10) {\n accountCommentsToUpdate.length = 10;\n }\n\n // TODO: add some algo to fetch all notifications (even old), but not on init\n // during downtimes when we're not fetching anything else\n return accountCommentsToUpdate;\n};\n\nexport const getAccountCommentDepth = (comment: Comment) => {\n if (!comment.parentCid) {\n return 0;\n }\n let parentCommentDepth = commentsStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = repliesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = communitiesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n // if can't find the parent comment depth anywhere, don't include it with the account comment\n // it will be added automatically when challenge verification is received\n};\n\nexport const getFreshestLoadedComment = (\n commentCid: string,\n ...additionalCandidates: (Comment | undefined)[]\n): Comment | undefined => {\n const candidates = [\n commentsStore.getState().comments[commentCid],\n repliesPagesStore.getState().comments[commentCid],\n communitiesPagesStore.getState().comments[commentCid],\n repliesCommentsStore.getState().comments[commentCid],\n ...additionalCandidates,\n ];\n return candidates.reduce<Comment | undefined>(\n (freshest, candidate) =>\n getCommentVoteCountsVersion(candidate) > getCommentVoteCountsVersion(freshest)\n ? candidate\n : freshest,\n undefined,\n );\n};\n\nexport const addShortAddressesToAccountComment = (comment: Comment) => {\n comment = { ...comment };\n try {\n comment.shortCommunityAddress = PkcJs.PKC.getShortAddress({\n address: comment.communityAddress,\n });\n } catch (e) {}\n try {\n comment.author = { ...comment.author };\n comment.author.shortAddress = PkcJs.PKC.getShortAddress({\n address: comment.author.address,\n });\n } catch (e) {}\n return comment;\n};\n\nconst utils = {\n getAccountCommunities,\n getCommentCidsToAccountsComments,\n getAccountCommentsIndex,\n getAccountsCommentsIndexes,\n sanitizeAccountCommentForState,\n sanitizeStoredAccountComment,\n getAccountEditPropertySummary,\n getAccountsEditsSummary,\n fetchCommentLinkDimensions,\n getInitAccountCommentsToUpdate,\n getAccountCommentDepth,\n getFreshestLoadedComment,\n addShortAddressesToAccountComment,\n promiseAny,\n};\n\nexport default utils;\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/accounts/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAcA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAC5D,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,qBAAqB,MAAM,sBAAsB,CAAC;AACzD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAC;AAErF,MAAM,oCAAoC,GAAG,CAAC,aAAqB,EAAE,WAAwB,EAAE,EAAE;;IAC/F,MAAM,KAAK,GAAyC,EAAE,CAAC;IACvD,KAAK,MAAM,gBAAgB,IAAI,WAAW,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAA,MAAA,WAAW,CAAC,gBAAgB,CAAC,0CAAE,KAAK,0CAAG,aAAa,CAAC,CAAC;QACnE,IAAI,IAAI,EAAE,CAAC;YACT,KAAK,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAgB,EAAE,WAAwB,EAAE,EAAE;;IAClF,MAAM,CACJ,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,0CAAE,OAAO,KAAI,OAAO,CAAA,MAAA,OAAO,aAAP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AAI,OAAO,EAAe,CAAC;AAChF,MAAM,CAAC,MAAM,4CAA4C,GAAG,CAG1D,WAAwB,EACX,EAAE;IACf,IACE,CAAC,WAAW;QACZ,OAAO,WAAW,CAAC,gBAAgB,KAAK,QAAQ;QAChD,WAAW,CAAC,qBAAqB,EACjC,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,IAAI,oCAAoC,GACtC,4CAA4C,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAChE,IAAI,CAAC,oCAAoC,EAAE,CAAC;QAC1C,oCAAoC,GAAG,WAAW,CAAC;QACnD,IAAI,CAAC;YACH,MAAM,qBAAqB,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC;gBACtD,OAAO,EAAE,WAAW,CAAC,gBAAgB;aACtC,CAAC,CAAC;YACH,IAAI,qBAAqB,EAAE,CAAC;gBAC1B,oCAAoC,mCAAQ,WAAW,KAAE,qBAAqB,GAAE,CAAC;YACnF,CAAC;QACH,CAAC;QAAC,WAAM,CAAC,CAAA,CAAC;QACV,4CAA4C,CAAC,GAAG,CAC9C,WAAW,EACX,oCAAoC,CACrC,CAAC;IACJ,CAAC;IACD,OAAO,oCAAoC,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG;IACZ,qBAAqB;IACrB,gCAAgC;IAChC,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,4BAA4B;IAC5B,6BAA6B;IAC7B,uBAAuB;IACvB,0BAA0B;IAC1B,8BAA8B;IAC9B,sBAAsB;IACtB,wBAAwB;IACxB,wBAAwB;IACxB,iCAAiC;IACjC,4CAA4C;IAC5C,UAAU;CACX,CAAC;AAEF,eAAe,KAAK,CAAC","sourcesContent":["import {\n Account,\n Role,\n Communities,\n AccountComment,\n AccountsComments,\n AccountsCommentsIndexes,\n AccountCommentsIndex,\n CommentCidsToAccountsComments,\n Comment,\n AccountEdit,\n AccountEditsSummary,\n AccountVote,\n} from \"../../types\";\nimport assert from \"../../lib/assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:accounts:stores\");\nimport commentsStore from \"../comments\";\nimport repliesPagesStore from \"../replies-pages\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport repliesCommentsStore from \"../replies/replies-comments-store\";\nimport PkcJs from \"../../lib/pkc-js\";\nimport { getCommentVoteCountsVersion } from \"../../lib/utils/optimistic-vote-counts\";\n\nconst getAuthorAddressRolesFromCommunities = (authorAddress: string, communities: Communities) => {\n const roles: { [communityAddress: string]: Role } = {};\n for (const communityAddress in communities) {\n const role = communities[communityAddress]?.roles?.[authorAddress];\n if (role) {\n roles[communityAddress] = role;\n }\n }\n return roles;\n};\n\nexport const getAccountCommunities = (account: Account, communities: Communities) => {\n assert(\n account?.author?.address && typeof account?.author?.address === \"string\",\n `accountsStore utils getAccountCommunities invalid account.author.address '${account?.author?.address}'`,\n );\n assert(\n communities && typeof communities === \"object\",\n `accountsStore utils getAccountCommunities invalid communities '${communities}'`,\n );\n\n const roles = getAuthorAddressRolesFromCommunities(account.author.address, communities);\n const accountCommunities = { ...account.communities };\n for (const communityAddress in roles) {\n accountCommunities[communityAddress] = { ...accountCommunities[communityAddress] };\n accountCommunities[communityAddress].role = roles[communityAddress];\n }\n return accountCommunities;\n};\n\nexport const getCommentCidsToAccountsComments = (accountsComments: AccountsComments) => {\n const commentCidsToAccountsComments: CommentCidsToAccountsComments = {};\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n if (accountComment.cid) {\n commentCidsToAccountsComments[accountComment.cid] = {\n accountId,\n accountCommentIndex: accountComment.index,\n };\n }\n }\n }\n return commentCidsToAccountsComments;\n};\n\nconst cloneWithoutFunctions = (value: any): any => {\n if (Array.isArray(value)) {\n return value\n .map((entry) => cloneWithoutFunctions(entry))\n .filter((entry) => entry !== undefined);\n }\n if (!value || typeof value !== \"object\") {\n return typeof value === \"function\" ? undefined : value;\n }\n\n const clonedValue: Record<string, any> = {};\n for (const key in value) {\n if (typeof value[key] === \"function\") {\n continue;\n }\n const clonedChild = cloneWithoutFunctions(value[key]);\n if (clonedChild !== undefined) {\n clonedValue[key] = clonedChild;\n }\n }\n return clonedValue;\n};\n\nconst compactStoredCommentAuthor = (author: any) => {\n if (!author || typeof author !== \"object\") {\n return undefined;\n }\n\n const compactAuthor = cloneWithoutFunctions({\n address: author.address,\n shortAddress: author.shortAddress,\n displayName: author.displayName,\n avatar: author.avatar,\n flair: author.flair,\n });\n\n return compactAuthor && Object.keys(compactAuthor).length > 0 ? compactAuthor : undefined;\n};\n\nconst compactStoredOriginalComment = (originalComment: any) => {\n if (!originalComment || typeof originalComment !== \"object\") {\n return undefined;\n }\n\n const compactOriginalComment = cloneWithoutFunctions({\n cid: originalComment.cid,\n content: originalComment.content,\n title: originalComment.title,\n link: originalComment.link,\n linkWidth: originalComment.linkWidth,\n linkHeight: originalComment.linkHeight,\n linkHtmlTagName: originalComment.linkHtmlTagName,\n thumbnailUrl: originalComment.thumbnailUrl,\n media: originalComment.media,\n spoiler: originalComment.spoiler,\n nsfw: originalComment.nsfw,\n deleted: originalComment.deleted,\n removed: originalComment.removed,\n reason: originalComment.reason,\n quotedCids: originalComment.quotedCids,\n parentCid: originalComment.parentCid,\n postCid: originalComment.postCid,\n communityAddress: originalComment.communityAddress,\n timestamp: originalComment.timestamp,\n author: compactStoredCommentAuthor(originalComment.author),\n });\n\n return compactOriginalComment && Object.keys(compactOriginalComment).length > 0\n ? compactOriginalComment\n : undefined;\n};\n\nconst compactStoredReplies = (replies: any) => {\n if (!replies || typeof replies !== \"object\") {\n return undefined;\n }\n\n const compactReplies = cloneWithoutFunctions(\n Object.fromEntries(\n Object.entries(replies).filter(\n ([replyKey]) => replyKey !== \"pages\" && replyKey !== \"clients\",\n ),\n ),\n );\n\n return compactReplies && Object.keys(compactReplies).length > 0 ? compactReplies : undefined;\n};\n\nexport const sanitizeAccountCommentForState = (comment: Comment) => {\n const sanitizedComment = cloneWithoutFunctions({\n ...comment,\n signer: undefined,\n raw: undefined,\n replies: comment?.replies\n ? Object.fromEntries(\n Object.entries(comment.replies).filter(([replyKey]) => replyKey !== \"pages\"),\n )\n : comment?.replies,\n });\n\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies?.pages) {\n sanitizedComment.replies = { ...sanitizedComment.replies };\n delete sanitizedComment.replies.pages;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n return sanitizedComment;\n};\n\nexport const sanitizeStoredAccountComment = (comment: Comment) => {\n const preprocessedComment = {\n ...comment,\n signer: undefined,\n clients: undefined,\n raw: undefined,\n replies: compactStoredReplies(comment?.replies),\n original: comment?.edit ? compactStoredOriginalComment(comment.original) : undefined,\n };\n const sanitizedComment = cloneWithoutFunctions(preprocessedComment);\n if (!sanitizedComment || typeof sanitizedComment !== \"object\") {\n return sanitizedComment;\n }\n if (sanitizedComment?.replies && Object.keys(sanitizedComment.replies).length === 0) {\n delete sanitizedComment.replies;\n }\n if (sanitizedComment?.original && Object.keys(sanitizedComment.original).length === 0) {\n delete sanitizedComment.original;\n }\n return sanitizedComment;\n};\n\nexport const getAccountCommentsIndex = (\n accountComments: AccountComment[] | undefined,\n): AccountCommentsIndex => {\n const index: AccountCommentsIndex = {\n byCommunityAddress: {},\n byParentCid: {},\n };\n for (const accountComment of accountComments || []) {\n if (accountComment.communityAddress) {\n if (!index.byCommunityAddress[accountComment.communityAddress]) {\n index.byCommunityAddress[accountComment.communityAddress] = [];\n }\n index.byCommunityAddress[accountComment.communityAddress].push(accountComment.index);\n }\n if (accountComment.parentCid) {\n if (!index.byParentCid[accountComment.parentCid]) {\n index.byParentCid[accountComment.parentCid] = [];\n }\n index.byParentCid[accountComment.parentCid].push(accountComment.index);\n }\n }\n return index;\n};\n\nexport const getAccountsCommentsIndexes = (accountsComments: AccountsComments) => {\n const indexes: AccountsCommentsIndexes = {};\n for (const accountId in accountsComments) {\n indexes[accountId] = getAccountCommentsIndex(accountsComments[accountId]);\n }\n return indexes;\n};\n\nconst accountEditNonPropertyNames = new Set([\n \"author\",\n \"signer\",\n \"clientId\",\n \"commentCid\",\n \"communityAddress\",\n \"communityAddress\",\n \"timestamp\",\n]);\n\nexport const COMMENT_MODERATION_AUTHOR_SUMMARY_KEY = \"commentModeration.author\";\n\nconst normalizeAccountEditForSummary = (accountEdit: AccountEdit) => {\n const normalizedAccountEdit = { ...accountEdit };\n const commentModeration = normalizedAccountEdit.commentModeration;\n if (commentModeration && typeof commentModeration === \"object\") {\n const { author, ...commentModerationProperties } = commentModeration;\n Object.assign(normalizedAccountEdit, commentModerationProperties);\n if (Object.prototype.hasOwnProperty.call(commentModeration, \"author\")) {\n normalizedAccountEdit[COMMENT_MODERATION_AUTHOR_SUMMARY_KEY] = author;\n }\n delete normalizedAccountEdit.commentModeration;\n }\n const communityEdit = normalizedAccountEdit.communityEdit ?? normalizedAccountEdit.communityEdit;\n if (communityEdit && typeof communityEdit === \"object\") {\n Object.assign(normalizedAccountEdit, communityEdit);\n }\n delete normalizedAccountEdit.communityEdit;\n delete normalizedAccountEdit.communityEdit;\n return normalizedAccountEdit;\n};\n\nexport const getAccountEditPropertySummary = (accountEdits: AccountEdit[] | undefined) => {\n const accountEditPropertySummary: AccountEditsSummary[string] = {};\n for (const accountEdit of accountEdits || []) {\n const normalizedAccountEdit = normalizeAccountEditForSummary(accountEdit);\n for (const propertyName in normalizedAccountEdit) {\n if (\n (normalizedAccountEdit[propertyName] === undefined &&\n propertyName !== COMMENT_MODERATION_AUTHOR_SUMMARY_KEY) ||\n accountEditNonPropertyNames.has(propertyName)\n ) {\n continue;\n }\n const previousTimestamp = accountEditPropertySummary[propertyName]?.timestamp || 0;\n if ((normalizedAccountEdit.timestamp || 0) >= previousTimestamp) {\n accountEditPropertySummary[propertyName] = {\n timestamp: normalizedAccountEdit.timestamp,\n value: normalizedAccountEdit[propertyName],\n };\n }\n }\n }\n return accountEditPropertySummary;\n};\n\nexport const getAccountsEditsSummary = (accountEdits: {\n [commentCidOrCommunityAddress: string]: AccountEdit[];\n}) => {\n const summary: AccountEditsSummary = {};\n for (const target in accountEdits || {}) {\n summary[target] = getAccountEditPropertySummary(accountEdits[target]);\n }\n return summary;\n};\n\ninterface CommentLinkDimensions {\n linkWidth?: number;\n linkHeight?: number;\n linkHtmlTagName?: \"img\" | \"video\" | \"audio\";\n}\n\n// polyfill Promise.any, exported for test coverage of empty-array branch\nconst promiseAny = <T>(promises: Promise<T>[]): Promise<T> =>\n new Promise((res, rej) => {\n let count = promises.length;\n if (count === 0) return rej(Error(\"all promises rejected\"));\n promises.forEach((p) =>\n Promise.resolve(p)\n .then(res)\n .catch((e) => {\n if (--count === 0) rej(Error(\"all promises rejected\"));\n }),\n );\n });\n\nexport const fetchCommentLinkDimensions = async (link: string): Promise<CommentLinkDimensions> => {\n if (!link) {\n return {};\n }\n\n const fetchImageDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const image = new Image();\n image.onload = () => {\n // don't accept 0px value\n if (!image.width || !image.height) {\n return reject(Error(`failed fetching image dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: image.width,\n linkHeight: image.height,\n linkHtmlTagName: \"img\",\n });\n\n // remove image from memory\n try {\n image.src = \"\";\n } catch (e) {}\n };\n image.onerror = (error) => {\n reject(Error(`failed fetching image dimensions for url '${url}'`));\n };\n\n // max loading time\n const timeout = 10000;\n setTimeout(\n () =>\n reject(Error(`failed fetching image dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n image.src = url;\n });\n\n const fetchVideoDimensions = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const video = document.createElement(\"video\");\n video.muted = true;\n video.loop = false;\n video.addEventListener(\"loadeddata\", () => {\n // don't accept 0px value\n if (!video.videoWidth || !video.videoHeight) {\n return reject(Error(`failed fetching video dimensions for url '${url}'`));\n }\n resolve({\n linkWidth: video.videoWidth,\n linkHeight: video.videoHeight,\n linkHtmlTagName: \"video\",\n });\n // prevent video from playing\n try {\n video.pause();\n } catch (e) {}\n // prevent video from loading\n try {\n video.src = \"\";\n } catch (e) {}\n });\n video.addEventListener(\"error\", (error) => {\n reject(Error(`failed fetching video dimensions for url '${url}'`));\n });\n\n // max loading time\n const timeout = 30000;\n setTimeout(\n () =>\n reject(Error(`failed fetching video dimensions for url '${url}' timeout '${timeout}'`)),\n timeout,\n );\n\n // start loading\n video.src = url;\n });\n\n const fetchAudio = (url: string) =>\n new Promise<CommentLinkDimensions>((resolve, reject) => {\n const audio = document.createElement(\"audio\");\n audio.addEventListener(\"loadeddata\", () => {\n resolve({\n linkHtmlTagName: \"audio\",\n });\n try {\n audio.pause();\n } catch {}\n try {\n audio.src = \"\";\n } catch {}\n });\n audio.addEventListener(\"error\", () =>\n reject(Error(`failed fetching audio html tag name for url '${url}'`)),\n );\n\n const timeout = 20000;\n setTimeout(\n () =>\n reject(\n Error(`failed fetching audio html tag name for url '${url}' timeout '${timeout}'`),\n ),\n timeout,\n );\n\n audio.src = url;\n });\n\n try {\n if (new URL(link).protocol !== \"https:\") {\n throw Error(`failed fetching comment.link dimensions for link '${link}' not https protocol`);\n }\n // an <audio> element also loads a video file's audio track, often before the <video> element\n // decodes a frame, so the audio result only counts once the image and video probes both failed\n const audio = fetchAudio(link);\n audio.catch(() => {});\n const dimensions = await promiseAny([\n fetchImageDimensions(link),\n fetchVideoDimensions(link),\n ]).catch(() => audio);\n return dimensions;\n } catch (error: any) {\n log.error(\"fetchCommentLinkDimensions error\", { error, link });\n return {};\n }\n};\n\nexport const getInitAccountCommentsToUpdate = (accountsComments: AccountsComments) => {\n const accountCommentsToUpdate: { accountComment: AccountComment; accountId: string }[] = [];\n for (const accountId in accountsComments) {\n for (const accountComment of accountsComments[accountId]) {\n accountCommentsToUpdate.push({ accountComment, accountId });\n }\n }\n\n // update newer comments first, more likely to have notifications\n accountCommentsToUpdate.sort((a, b) => b.accountComment.timestamp - a.accountComment.timestamp);\n\n // updating too many comments during init slows down fetching comments/subs\n if (accountCommentsToUpdate.length > 10) {\n accountCommentsToUpdate.length = 10;\n }\n\n // TODO: add some algo to fetch all notifications (even old), but not on init\n // during downtimes when we're not fetching anything else\n return accountCommentsToUpdate;\n};\n\nexport const getAccountCommentDepth = (comment: Comment) => {\n if (!comment.parentCid) {\n return 0;\n }\n let parentCommentDepth = commentsStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = repliesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n parentCommentDepth = communitiesPagesStore.getState().comments[comment.parentCid]?.depth;\n if (typeof parentCommentDepth === \"number\") {\n return parentCommentDepth + 1;\n }\n // if can't find the parent comment depth anywhere, don't include it with the account comment\n // it will be added automatically when challenge verification is received\n};\n\n// the cid of the post a pending account comment belongs to, when the caches know its parent\nexport const getAccountCommentPostCid = (\n comment: Comment,\n ...additionalParentCandidates: (Comment | undefined)[]\n): string | undefined => {\n // never replace the value the caller published with\n if (comment.postCid) {\n return comment.postCid;\n }\n // a post's own postCid is its cid, which doesn't exist until challenge verification\n if (!comment.parentCid) {\n return;\n }\n const parentComments = [\n commentsStore.getState().comments[comment.parentCid],\n repliesPagesStore.getState().comments[comment.parentCid],\n communitiesPagesStore.getState().comments[comment.parentCid],\n ...additionalParentCandidates,\n ];\n for (const parentComment of parentComments) {\n if (typeof parentComment?.postCid === \"string\" && parentComment.postCid) {\n return parentComment.postCid;\n }\n // the parent is the post\n if (parentComment?.depth === 0) {\n return comment.parentCid;\n }\n }\n // if can't find the thread root anywhere, don't include it with the account comment\n // it will be added automatically when challenge verification is received\n};\n\nexport const getFreshestLoadedComment = (\n commentCid: string,\n ...additionalCandidates: (Comment | undefined)[]\n): Comment | undefined => {\n const candidates = [\n commentsStore.getState().comments[commentCid],\n repliesPagesStore.getState().comments[commentCid],\n communitiesPagesStore.getState().comments[commentCid],\n repliesCommentsStore.getState().comments[commentCid],\n ...additionalCandidates,\n ];\n return candidates.reduce<Comment | undefined>(\n (freshest, candidate) =>\n getCommentVoteCountsVersion(candidate) > getCommentVoteCountsVersion(freshest)\n ? candidate\n : freshest,\n undefined,\n );\n};\n\nexport const addShortAddressesToAccountComment = (comment: Comment) => {\n comment = { ...comment };\n try {\n comment.shortCommunityAddress = PkcJs.PKC.getShortAddress({\n address: comment.communityAddress,\n });\n } catch (e) {}\n try {\n comment.author = { ...comment.author };\n comment.author.shortAddress = PkcJs.PKC.getShortAddress({\n address: comment.author.address,\n });\n } catch (e) {}\n return comment;\n};\n\n// Account votes and edits are stored as their publish options, without the short community address\n// account comments get when they are created. Derive it when they are read instead of storing it,\n// so history stored by earlier versions has it too and no stored record is rewritten. Votes and\n// edits are stored without their author, so there is no author.shortAddress to add.\n// Cached per record so a record that didn't change keeps its identity between renders.\nconst accountPublicationsWithShortCommunityAddress = new WeakMap<object, any>();\nexport const addShortCommunityAddressToAccountPublication = <\n Publication extends AccountVote | AccountEdit | undefined,\n>(\n publication: Publication,\n): Publication => {\n if (\n !publication ||\n typeof publication.communityAddress !== \"string\" ||\n publication.shortCommunityAddress\n ) {\n return publication;\n }\n let publicationWithShortCommunityAddress =\n accountPublicationsWithShortCommunityAddress.get(publication);\n if (!publicationWithShortCommunityAddress) {\n publicationWithShortCommunityAddress = publication;\n try {\n const shortCommunityAddress = PkcJs.PKC.getShortAddress({\n address: publication.communityAddress,\n });\n if (shortCommunityAddress) {\n publicationWithShortCommunityAddress = { ...publication, shortCommunityAddress };\n }\n } catch {}\n accountPublicationsWithShortCommunityAddress.set(\n publication,\n publicationWithShortCommunityAddress,\n );\n }\n return publicationWithShortCommunityAddress;\n};\n\nconst utils = {\n getAccountCommunities,\n getCommentCidsToAccountsComments,\n getAccountCommentsIndex,\n getAccountsCommentsIndexes,\n sanitizeAccountCommentForState,\n sanitizeStoredAccountComment,\n getAccountEditPropertySummary,\n getAccountsEditsSummary,\n fetchCommentLinkDimensions,\n getInitAccountCommentsToUpdate,\n getAccountCommentDepth,\n getAccountCommentPostCid,\n getFreshestLoadedComment,\n addShortAddressesToAccountComment,\n addShortCommunityAddressToAccountPublication,\n promiseAny,\n};\n\nexport default utils;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"authors-comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/authors-comments/authors-comments-store.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,qBAAqB,EAGrB,OAAO,EACR,MAAM,aAAa,CAAC;AAWrB,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,KAAK,oBAAoB,GAAG;IAE1B,OAAO,EAAE;QAAE,CAAC,kBAAkB,EAAE,MAAM,GAAG,qBAAqB,CAAA;KAAE,CAAC;IACjE,cAAc,EAAE;QAAE,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,EAAE,CAAA;KAAE,CAAC;IAC5D,uBAAuB,EAAE;QAAE,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACnE,mBAAmB,EAAE;QAAE,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IAC9D,sBAAsB,EAAE;QAAE,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IACxE,sBAAsB,EAAE;QAAE,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC7D,eAAe,EAAE;QAAE,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IACjE,wBAAwB,EAAE,QAAQ,CAAC;IACnC,yBAAyB,EAAE,QAAQ,CAAC;IACpC,mBAAmB,EAAE,QAAQ,CAAC;IAC9B,qBAAqB,EAAE,QAA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qBAAqB,EAAE,QAAQ,CAAC;IAChC,oBAAoB,EAAE,QAAQ,CAAC;IAC/B,iBAAiB,EAAE,QAAQ,CAAC;CAC7B,CAAC;AAEF,QAAA,MAAM,oBAAoB,mFAwRzB,CAAC;AAoOF,eAAO,MAAM,yBAAyB,qBAUrC,CAAC;AAGF,eAAO,MAAM,oCAAoC,qBAEhD,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -182,6 +182,13 @@ const authorsCommentsStore = createStore((setState, getState) => ({
182
182
  }));
183
183
  },
184
184
  }));
185
+ // This store watches the comments it fetches for the rest of the session, so it waits for the
186
+ // update addCommentToStore requests on open, and a frozen useComment that leaves cannot end it.
187
+ const addCommentToCommentsStore = (commentCid, account) => {
188
+ const { addOpeningUpdateWaiter, addCommentToStore } = commentsStore.getState();
189
+ addOpeningUpdateWaiter(commentCid, "authorsCommentsStore");
190
+ return addCommentToStore(commentCid, account);
191
+ };
185
192
  // if nextCommentCidsToFetch or shouldFetchNextComment changed, fetch the next comment
186
193
  const fetchCommentOnShouldFetchOrNextCidChange = (options) => (state) => {
187
194
  const nextCommentCidToFetch = state.nextCommentCidsToFetch[options.authorAddress];
@@ -194,35 +201,51 @@ const fetchCommentOnShouldFetchOrNextCidChange = (options) => (state) => {
194
201
  return;
195
202
  }
196
203
  // when comment has fetched, update loadedComments, bufferedComments and shouldFetchNextComment
197
- if (!authorCommentCidsFetching[nextCommentCidToFetch]) {
198
- authorCommentCidsFetching[nextCommentCidToFetch] = true;
204
+ const authorCommentKey = getAuthorCommentKey(options.authorAddress, nextCommentCidToFetch);
205
+ if (!authorCommentCidsFetching[authorCommentKey]) {
206
+ authorCommentCidsFetching[authorCommentKey] = true;
199
207
  commentsStore.subscribe(updateCommentsOnCommentsChange(options, nextCommentCidToFetch));
200
208
  }
201
209
  // start fetching comment
202
210
  const account = accountsStore.getState().accounts[options.accountId];
203
- const addCommentToStore = commentsStore.getState().addCommentToStore;
204
- addCommentToStore(nextCommentCidToFetch, account).catch((error) => log.error("authorsCommentsStore fetchCommentOnShouldFetchOrNextCidChange addCommentToStore error", { error, nextCommentCidToFetch, account }));
211
+ addCommentToCommentsStore(nextCommentCidToFetch, account).catch((error) => log.error("authorsCommentsStore fetchCommentOnShouldFetchOrNextCidChange addCommentToStore error", { error, nextCommentCidToFetch, account }));
205
212
  };
213
+ // the chains of 2 authors can reach the same cid, and each chain must handle it (e.g. end on a
214
+ // comment by another author), so fetching listeners and previous comments are keyed per author
215
+ const getAuthorCommentKey = (authorAddress, commentCid) => `${authorAddress} ${commentCid}`;
206
216
  // if commentStore changed, update loadedComments, bufferedCommentCids, shouldFetchNextComment and nextCommentCidsToFetch
207
217
  let previousComments = new QuickLru({ maxSize: 10000 });
208
218
  let authorCommentCidsFetching = {};
209
219
  let communityLastCommentCidsFetching = {};
210
220
  const updateCommentsOnCommentsChange = (options, commentCid) => (state) => {
211
- var _a, _b, _c;
221
+ var _a, _b, _c, _d;
222
+ const authorCommentKey = getAuthorCommentKey(options.authorAddress, commentCid);
212
223
  // not a next cid, do nothing
213
- if (!authorCommentCidsFetching[commentCid]) {
224
+ if (!authorCommentCidsFetching[authorCommentKey]) {
214
225
  return;
215
226
  }
216
227
  const comment = state.comments[commentCid];
217
228
  // comment hasn't changed, do nothing
218
- if (!(comment === null || comment === void 0 ? void 0 : comment.timestamp) || comment === previousComments.get(commentCid)) {
229
+ if (!(comment === null || comment === void 0 ? void 0 : comment.timestamp) || comment === previousComments.get(authorCommentKey)) {
219
230
  return;
220
231
  }
221
232
  // comment author address is incorrect, do nothing
222
233
  if (((_a = comment.author) === null || _a === void 0 ? void 0 : _a.address) !== options.authorAddress) {
234
+ // a next cid by another author can't continue the author's comments, so nothing is left to
235
+ // fetch, otherwise the chain would wait on it forever
236
+ if (commentCid === authorsCommentsStore.getState().nextCommentCidsToFetch[options.authorAddress]) {
237
+ log.error("authorsCommentsStore next comment cid has a different author address", {
238
+ commentCid,
239
+ authorAddress: options.authorAddress,
240
+ commentAuthorAddress: (_b = comment.author) === null || _b === void 0 ? void 0 : _b.address,
241
+ });
242
+ authorsCommentsStore.setState((state) => ({
243
+ nextCommentCidsToFetch: Object.assign(Object.assign({}, state.nextCommentCidsToFetch), { [options.authorAddress]: undefined }),
244
+ }));
245
+ }
223
246
  return;
224
247
  }
225
- previousComments.set(commentCid, comment);
248
+ previousComments.set(authorCommentKey, comment);
226
249
  const { addBufferedCommentCid, bufferedCommentCids, updateLoadedComments, setNextCommentCidsToFetch, nextCommentCidsToFetch, } = authorsCommentsStore.getState();
227
250
  // the comment is a new comment, add it to buffered comment cids
228
251
  if (!bufferedCommentCids[options.authorAddress].has(commentCid)) {
@@ -236,7 +259,7 @@ const updateCommentsOnCommentsChange = (options, commentCid) => (state) => {
236
259
  // one of the comment changed, must update loaded comments
237
260
  updateLoadedComments();
238
261
  // the changed comment might have a new author.community.lastCommentCid, try to fetch it
239
- const communityLastCommentCid = (_c = (_b = comment.author) === null || _b === void 0 ? void 0 : _b.community) === null || _c === void 0 ? void 0 : _c.lastCommentCid;
262
+ const communityLastCommentCid = (_d = (_c = comment.author) === null || _c === void 0 ? void 0 : _c.community) === null || _d === void 0 ? void 0 : _d.lastCommentCid;
240
263
  if (communityLastCommentCid) {
241
264
  // when last comment has fetched, update lastCommentCid
242
265
  if (!communityLastCommentCidsFetching[communityLastCommentCid]) {
@@ -245,7 +268,7 @@ const updateCommentsOnCommentsChange = (options, commentCid) => (state) => {
245
268
  }
246
269
  // start fetching lastCommentCid
247
270
  const account = accountsStore.getState().accounts[options.accountId];
248
- state.addCommentToStore(communityLastCommentCid, account).catch((error) => log.error("authorsCommentsStore updateCommentsOnCommentsChange addCommentToStore error", {
271
+ addCommentToCommentsStore(communityLastCommentCid, account).catch((error) => log.error("authorsCommentsStore updateCommentsOnCommentsChange addCommentToStore error", {
249
272
  error,
250
273
  communityLastCommentCid,
251
274
  account,
@@ -312,8 +335,12 @@ const setLastCommentCidOnCommentsChange = (options, commentCid) => (state) => {
312
335
  setLastCommentCid(options.authorAddress, commentCid);
313
336
  // add the last comment to loadedComments
314
337
  updateLoadedComments();
315
- // start a new linked list of comments to fetch using the lastComment.author.previousCommentCid
316
- if ((_b = comment.author) === null || _b === void 0 ? void 0 : _b.previousCommentCid) {
338
+ // start a new linked list of comments to fetch using the lastComment.author.previousCommentCid,
339
+ // unless the list already continues from there, e.g. the lastComment is the one it started from
340
+ const previousCommentCid = (_b = comment.author) === null || _b === void 0 ? void 0 : _b.previousCommentCid;
341
+ if (previousCommentCid &&
342
+ previousCommentCid !==
343
+ authorsCommentsStore.getState().nextCommentCidsToFetch[options.authorAddress]) {
317
344
  setNextCommentCidsToFetch(options.authorAddress, comment);
318
345
  }
319
346
  };