@bitsocial/bitsocial-react-hooks 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +213 -0
- package/README.md +6 -0
- package/dist/stores/replies/replies-store.d.ts.map +1 -1
- package/dist/stores/replies/replies-store.js +9 -2
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.d.ts +11 -2
- package/dist/stores/replies/utils.d.ts.map +1 -1
- package/dist/stores/replies/utils.js +24 -6
- package/dist/stores/replies/utils.js.map +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
## [0.1.5](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.4...v0.1.5) (2026-05-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **ci:** fetch tags for release notes ([6d22e9f](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/6d22e9f154621124757aef393dd8717657042c0a))
|
|
7
|
+
* **replies:** hide purged account replies ([570a5f2](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/570a5f24dbbb370c6d2ced6a2f6aff8fcfb053e2))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## [0.1.4](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.3...v0.1.4) (2026-04-30)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **ci:** create GitHub release after publish ([26562d5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/26562d5100e7108ba4c505df99d4aaed4594d4fb))
|
|
17
|
+
* **stores:** dedupe pending comments after approval ([1fe46f7](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/1fe46f7279a2d758dca30f0117fff62a2ab44a46))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [0.1.3](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.2...v0.1.3) (2026-04-29)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* **accounts:** use explicit RPC fallbacks for ETH defaults ([b0c9907](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b0c9907ae50139434ba86adf151b3d90de093d2c))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [0.1.2](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/d95bed5a75b832fbbfc980b34ead43d8e6848fba...v0.1.2) (2026-04-20)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **accounts-store:** add fetching link dimensions state ([15cf17f](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/15cf17f29a56334024e09c3a05b60e513df30d59))
|
|
36
|
+
* **accounts-store:** add fetching link dimensions state ([f226408](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f226408dc7ef44d442c0341fdba3834068e8030f))
|
|
37
|
+
* **accounts-store:** dont mutate subscriptions array ([a3088a3](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a3088a3a1605aee31fbc6539e5bcb115116a80cf))
|
|
38
|
+
* **accounts-store:** instantly return account comment index from usePublishComment ([3e16386](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/3e1638684a157191e41eb3251232c4570835b4ec))
|
|
39
|
+
* **accounts-store:** only fetch 10 comment updates on init, it slows down fetching comments/subs ([e45f527](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/e45f52713d3ca1cb6831cb40525d4d30129a35d2))
|
|
40
|
+
* **accounts-store:** subscribe and block actions add to db async, so feedback is more instant ([d551fd5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d551fd58ac5e048d240954993792fe3e7325a3b5))
|
|
41
|
+
* **accounts-store:** validate replies notifications properly ([9e7b06b](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/9e7b06b846b514b11c66c704a71ee8da9ddce296))
|
|
42
|
+
* **accounts:** address account history review regressions ([fbe9c3d](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/fbe9c3d37853ceb360cbe1c560ccc6690a1716f6))
|
|
43
|
+
* **accounts:** address final account history review findings ([7feb65d](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/7feb65d5f351c4a231f3cc9f34e7c6710b6f7cc2))
|
|
44
|
+
* **accounts:** align pending comment failure state with plebbit-js ([#48](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/48)) ([a9f7111](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a9f71118667184095b064d54f2d427636acfb049))
|
|
45
|
+
* **accounts:** compact legacy stored account comments ([#44](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/44)) ([5f90193](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/5f90193153cb7d0d1be5105e6cb45e8a8bb35300))
|
|
46
|
+
* **accounts:** deeply compact stored account comments ([#46](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/46)) ([f2f8b4c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f2f8b4cc82fad6d07aa8f3c0d22f42fa5e1046fb))
|
|
47
|
+
* **accounts:** defer moderation rollback until edit is stored ([b59b8a0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b59b8a07aa47a3501e052f548fa7f69105040c82))
|
|
48
|
+
* **accounts:** optimistically remove pending comment on abandon delete ([bde1501](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/bde1501c703ae474c6de3b46cd05511fd3d8900e))
|
|
49
|
+
* **accounts:** preserve legacy publication field names ([#29](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/29)) ([dc23dca](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/dc23dca88055c13a52f6ee6106a25cc64f105210))
|
|
50
|
+
* **accounts:** roll back failed optimistic comment edits ([#34](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/34)) ([45aa5f6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/45aa5f6baa8bc7be7348bec45f941a93e3535743))
|
|
51
|
+
* **accounts:** rollback terminal comment edit challenge failures ([#35](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/35)) ([d8af0ad](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d8af0adffb8d4debe0a20b8805667093c77f3fad)), closes [#33](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/33)
|
|
52
|
+
* **accounts:** simplify account history query naming ([38a67e3](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/38a67e349a7346393b2cb4946676663c6804f023))
|
|
53
|
+
* **accounts:** stabilize account history e2e paths ([b9705b6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b9705b65e959b0bedba21dbb8a0c340c183f069e))
|
|
54
|
+
* **accounts:** start comment moderation publish earlier ([10ef375](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/10ef375402a4009685906386f939cf019d9f9550))
|
|
55
|
+
* **accounts:** stop auto-generating sol wallets ([2eab3dc](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/2eab3dce70703e65f324db1834f8fd1ebf8b5b6c)), closes [#20](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/20)
|
|
56
|
+
* **accounts:** stop stale moderation edits from sticking ([f8af7b6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f8af7b652dc924b4392105cc4166ab01486bd79f))
|
|
57
|
+
* **accounts:** switch default eth rpc to publicnode ([85d3ee4](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/85d3ee498d33080c223e5dde0ce011145a58e7f7))
|
|
58
|
+
* **actions:** add exports and test ([b298a50](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b298a505f49b4db103aaffd258195d2df9a07ab5))
|
|
59
|
+
* **actions:** ignore stale usePublishComment updates after abandon ([cb0ad7e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/cb0ad7ecb2735c98ccd5764c0901aae6ebf16b16))
|
|
60
|
+
* **actions:** implement usePublishCommentModeration ([1a8a5c1](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/1a8a5c1074c581bf0f2aa9832195d79e5e48bf56))
|
|
61
|
+
* address community refactor follow-up bugs ([#24](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/24)) ([1c38324](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/1c383246951879a56a4870a205003d5ddf06cbc2)), closes [#22](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/22)
|
|
62
|
+
* **authors-comments-store:** scrolling comments stalls sometimes ([173b214](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/173b21424bf38ff389cec9cb47620784888ef194))
|
|
63
|
+
* **authors-comments:** tolerate React 19 batching off-by-one in discover lastCommentCid test ([20676f8](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/20676f8e80993d974eb11b86b1f4dac0a5854cfd))
|
|
64
|
+
* **authors:** align author name resolution with pkc-js ([#53](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/53)) ([3294f39](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/3294f391958b68804b444555f9883106081d8c94))
|
|
65
|
+
* **authors:** support .bso author address resolution ([35da119](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/35da11928797495073ae52bede4df62c72e6872b)), closes [#21](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/21)
|
|
66
|
+
* **authors:** undefined useAuthorAddress with argument accountComment before challenge verification ([6ec824e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/6ec824eaadb7dacc024b7fc74d2a97174075647c))
|
|
67
|
+
* **build:** remove consumer patch requirements ([#50](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/50)) ([cd76e12](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/cd76e12f362fbe6bd27c8f688ef4bec2838efb92))
|
|
68
|
+
* **build:** support TypeScript 6 compiler checks ([29cd3e6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/29cd3e6f58a0188dbed6db75840f0689df630cd1))
|
|
69
|
+
* **chain:** auto generated wallets had timestamps in ms, not seconds ([24f2373](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/24f2373f9f8cfadadac58e2afa027637b670b879))
|
|
70
|
+
* **ci:** align browser e2e pkc options ([b29ca70](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b29ca70187535e6f0f81c27d38337a8f07a51c3c))
|
|
71
|
+
* **ci:** avoid husky during yarn install ([a3c2184](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a3c218401f36262e706a64a7dbaef010e605e653))
|
|
72
|
+
* **ci:** disable husky during yarn install to prevent git dependency postinstall failure ([9dd99f7](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/9dd99f7fb062ae709afcec6afc39f864b8e1e63b))
|
|
73
|
+
* **ci:** drop legacy yarn install flags ([5921bde](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/5921bded2f869ba9f6cd983a4ee7e346dd0f8dfc))
|
|
74
|
+
* **ci:** push dist auto-commit from branch instead of detached HEAD ([57a3921](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/57a39219cdf3db1cbc310836290ecf9b18becf72))
|
|
75
|
+
* **ci:** reduce e2e debug output ([ce7eeb1](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ce7eeb11bab3475b7ebbd71b0f55adb34312ae50))
|
|
76
|
+
* **ci:** remove setup-node yarn cache ([ec3a133](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ec3a1336f852f82cebb5cf2678a11fe8a5e18b21))
|
|
77
|
+
* **ci:** replace tsgo with tsc in type-check script ([5b2144d](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/5b2144d0ba9b8df380280b7bdc828ba5c6b5232e))
|
|
78
|
+
* **ci:** retry yarn install with cache clean on corrupt tar extraction ([434bec2](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/434bec2fd4ef4d4bd183900d555dea6800e2a0de))
|
|
79
|
+
* **ci:** skip non-e2e build scripts during checks install ([c7f18d9](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/c7f18d94380a572a985d919d5949dc372aee18ab))
|
|
80
|
+
* **ci:** use --network-concurrency 1 to avoid yarn v1 parallel tar extraction race ([2073797](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/2073797468bbeef8c813b060f7162a49e9f2b943))
|
|
81
|
+
* **comments:** address PR 31 review follow-ups ([#32](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/32)) ([0b0d635](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/0b0d6359520abebbd1116dfeafabd270b773342f))
|
|
82
|
+
* **comments:** new comments shouldnt show updating state for 5 minutes ([1691bdf](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/1691bdfb087da23e8c14592500788b3f099782b2))
|
|
83
|
+
* **comments:** plebbit.createComment throws adds useComment().error ([8ff7aba](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/8ff7aba2a1133d1de80775de7370a36a497abce7))
|
|
84
|
+
* **comments:** resolve pending mod-queue comments without updatedAt in useComment path ([7236fc4](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/7236fc422d09189862cd9ffeb0417d07b73c6893)), closes [#8](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/8)
|
|
85
|
+
* **communities:** unwrap stats cid content ([#51](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/51)) ([39d4d7a](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/39d4d7ab99b991ce21815b5718ee5c5c89eee111))
|
|
86
|
+
* correct property exclusion in useEditedComment comparison logic ([f1c6af5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f1c6af5b1d8de111bb79d2c782d9142d9c5fd644))
|
|
87
|
+
* **deps:** patch minimatch security override ([3264934](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/3264934d5815b362ba583da11279a9af3f38e87d))
|
|
88
|
+
* **deps:** remediate dependabot alerts via ethers upgrade and transitive resolutions ([ecf5c6e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ecf5c6e67b6c78f0bb68d1d8a5de135d1cce4244))
|
|
89
|
+
* **deps:** resolve Dependabot alerts for protobufjs and follow-redirects ([3b993b6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/3b993b6a92a50b7ae17e109d4844bf0be9b611ae))
|
|
90
|
+
* **deps:** resolve dependabot transitive vulnerabilities ([8403967](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/84039678ddab805c4a9be7b4c627ba9f927967fd))
|
|
91
|
+
* **deps:** resolve lodash dependabot alerts ([6db0e8e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/6db0e8e3e1186e92c0590cee9d9bf319af436f22))
|
|
92
|
+
* **e2e:** add auto-cleanup to custom renderHook to prevent root leaks ([fe274a6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/fe274a675b8086bb97624152a862c60ed3c6c7aa))
|
|
93
|
+
* **e2e:** bypass RTL auto-cleanup by managing React root directly ([f7bf6e5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f7bf6e54aa9386f874b238d9ef72e1c6ce6a59a5))
|
|
94
|
+
* **e2e:** migrate vitest-e2e config to Vitest 4 browser provider API ([23907ff](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/23907ff4bdb26743b426705a2f6db84506eb07dc))
|
|
95
|
+
* **e2e:** test comment validation directly via commentIsValid ([00743c4](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/00743c41a0cbbb88d29dccf21f45b69c16b8850c))
|
|
96
|
+
* **e2e:** unmount beforeEach root before creating new one in validate comments ([f1185c0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f1185c00e8102c5c8e5d7a19e7cd7828a14b688e))
|
|
97
|
+
* **e2e:** use custom renderHook in browser tests to avoid React 19 unmounted root error ([b541452](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b5414520852cf65f4347d45238d75caddb574de2))
|
|
98
|
+
* **feed-stores:** hasMore is true when feed cache expires ([ec1dd54](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ec1dd542d5b045f9a27eca54614212b0c6e0f458))
|
|
99
|
+
* **feeds:** crash when switching accounts ([c7450a9](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/c7450a9c1fed135375777406c4b821f9627c738f))
|
|
100
|
+
* **feeds:** evict approved posts from mod queue feeds ([b1682b1](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b1682b1054bc818424658205f02e7a4ad6ef5600)), closes [#17](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/17)
|
|
101
|
+
* **feeds:** feeds fetch infinite pages when subplebbit.fetchedAt cache expires ([6606b68](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/6606b68420bf47d4fbd01470788d90a16b2c93c3))
|
|
102
|
+
* **feeds:** filter stale public posts out of pending approval feeds ([a1b77b2](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a1b77b209692272fc50a3497d704c1135413c89e)), closes [#18](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/18)
|
|
103
|
+
* **feeds:** hot score needs Math.abs or negative score is ignored ([d41b6a2](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d41b6a277dd487beb7a6bc48a7c655eff0285290))
|
|
104
|
+
* **feeds:** refresh subplebbit snapshots on feed reset ([b98fb82](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b98fb823318491690734febaeabb9ddf1c2950dc)), closes [#19](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/19)
|
|
105
|
+
* filter API is now {filter: Function: key: string} ([bb91724](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/bb91724d01c49f87da5599c37799ad6a933ba780))
|
|
106
|
+
* fix subplebbit blocking issue ([e7c5031](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/e7c50315e70ac5e574e10c0fe20472c24f1ff195))
|
|
107
|
+
* harden hook error paths and cleanup leaks ([09fc6ea](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/09fc6ea47fcfc0ea3d8d01c6d2c85ac386002179))
|
|
108
|
+
* **hooks:** mirror moderation flags into commentModeration ([a16a1b5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a16a1b5c4af610a7bbf75716c942862c4424920f)), closes [#11](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/11)
|
|
109
|
+
* **lint:** resolve yarn lint issues ([ec7c43a](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ec7c43a286225f9969b9700f2fe15f46481d513b))
|
|
110
|
+
* **mock-content:** use real private key ([590e168](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/590e1682e901f9de60eefbb3b3dc14655c0c065d))
|
|
111
|
+
* **moderation:** add live e2e coverage and sourcemaps ([dac0604](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/dac0604195cb85fa035aea8f64457666d5b10f04))
|
|
112
|
+
* **pkc-js:** normalize short address params ([60e02c2](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/60e02c2fed9629208123cd47663fb919fe663a7f))
|
|
113
|
+
* **plebbit-rpc:** add initial rpc settings state ([64b6451](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/64b64514de4814727dfa418d4e71d3cf293531c0))
|
|
114
|
+
* **plebbit-rpc:** update usePlebbitRpcSettings to new api ([375677c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/375677c489f9d3f85b841e819b76c674f4d5b745))
|
|
115
|
+
* **replies store:** sync updated feeds with local reply deletions ([7f9318f](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/7f9318f235aec04590e2b936bde9e2a47695bdf1))
|
|
116
|
+
* **replies:** tolerate async page fetch timing in sort type best fallback test ([8438da0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/8438da05be82c659ce3c05a086dc57b7cb5f7068))
|
|
117
|
+
* restore CI after address refactor follow-ups ([68e0289](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/68e0289739b0c17f40272fe9e7dd064697c01dc8))
|
|
118
|
+
* restore publication mock types for ci type-check ([231547e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/231547ee864a0eada541aeb4a939522dc4f5d4b5))
|
|
119
|
+
* **states:** non chainproviders clients are showing as 'resolving-address' state ([edc5d85](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/edc5d85713f63281f0d1aaecabf89c8e35589046))
|
|
120
|
+
* **states:** show updating states when posts cache is expired ([9809e94](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/9809e948eff14428314c368404c43a98d51c7114))
|
|
121
|
+
* **subplebbits:** plebbit.createSubplebbit throws adds useSubplebbit().error ([6750688](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/675068878177771ee8233e68aa4d4a933fba82f9))
|
|
122
|
+
* **subplebbits:** update subplebbit stats on subplebbit change ([d24b67e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d24b67eccb765e833c5430b674e0342e2500e859))
|
|
123
|
+
* **subplebbit:** treat .eth and .bso subplebbit addresses as equivalent ([d56c73b](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d56c73b10efaa0a12623cadd43c757cac204efd9)), closes [#12](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/12)
|
|
124
|
+
* **test:** prevent replies.test.ts cascade from prototype pollution and timing races ([ef9ce90](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ef9ce907fc3a67a33cab1e938afef888a446d095)), closes [#5](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/5)
|
|
125
|
+
* **tests:** correct assignment-as-comparison, unused waitFor2, and mock restore bugs ([3a7f2fe](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/3a7f2fedd38d56aae57a7cc5b8b5cc79fdff13eb))
|
|
126
|
+
* **tests:** relax transient plebbit rpc state assertion ([f1ee69d](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f1ee69ddbbef1e03b272512e18d3ef34c37f52c2))
|
|
127
|
+
* **test:** stabilize filtered multi-community feed assertion ([07bc14c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/07bc14c0e47194c0d088f5cc3300def3a3dc9db7))
|
|
128
|
+
* **test:** stabilize initial hot feed assertion ([01344a4](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/01344a492bbfe422c7b2bdd51e52edfd7e29e37c))
|
|
129
|
+
* **tests:** wait for appended reply before asserting order ([aeb7e6b](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/aeb7e6b4858f188277e89b5dfe1f7afc412c2a09))
|
|
130
|
+
* **test:** use high custom ports for test IPFS nodes to avoid conflicts ([d0d8862](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d0d8862b46b78c6211e50497953117cb05dfece8))
|
|
131
|
+
* **test:** wait for parent comment indexing before publishing reply ([3a300f9](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/3a300f9de17266c36293ebfb862251b4ff93437f))
|
|
132
|
+
* **test:** wait for updatedAt instead of timestamp for parent indexing ([aecf86f](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/aecf86f6ad6eb6bbfbd91cecfe690cea2906ac31))
|
|
133
|
+
* **types:** declare window defaults for account generator ([a08cb1a](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a08cb1ad7313d27cffb7b8f0f2a6b395d23e76e4))
|
|
134
|
+
* **utils:** incorrect import ([b74cc63](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b74cc63f9622fb4d0d52cb2e30c321d6aff955c2))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### Features
|
|
138
|
+
|
|
139
|
+
* **accounts-store:** add default sol chain provider ([c660709](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/c660709eaa602c4f70e9ac5a20ac1c6ee6b29a1e))
|
|
140
|
+
* **accounts-store:** generate eth and sol wallets based on the plebbit private key ([def94d0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/def94d0addb936a869b0e24324105dbd496ea281))
|
|
141
|
+
* **accounts-store:** implement comment.linkHtmlTagName ([2edeb5c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/2edeb5c20b274f717e28c2e4c4c0fd4e99a2a697))
|
|
142
|
+
* **accounts-store:** migrate account db ([450858c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/450858c243d8c1191d444bd1571ef07dedb2f2fc))
|
|
143
|
+
* **accounts-store:** validate replies pages for notifications ([b97761f](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b97761fcb33825063d3c3c8c72eb453e06b09514))
|
|
144
|
+
* **accounts:** add abandonPublish and hard-delete account comments ([fe5e5b7](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/fe5e5b786a7d1b87d06e6895753fb075028cf988)), closes [plebbit/plebbit-react-hooks#2](https://github.com/plebbit/plebbit-react-hooks/issues/2) [#7](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/7)
|
|
145
|
+
* **accounts:** dedupe equivalent .eth and .bso account subplebbits under canonical .bso key ([09967e8](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/09967e87cdf12c52e3be642d34bccc1123624a4d)), closes [#16](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/16)
|
|
146
|
+
* **account:** wire bso-resolver into pkc ([3138d4c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/3138d4c1f35d72dc9de0ce4def38dd463d0c6a9f))
|
|
147
|
+
* add onlyIfCached to hooks to improve performance ([b01838c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b01838c5bd1fe904cb938a18ac8a5eb119a91b6b))
|
|
148
|
+
* **authors:** add .sol to useResolvedAuthorAddress ([0a3df5c](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/0a3df5c93f4b046c940b02219c13b75ae108fabe))
|
|
149
|
+
* **authors:** add setAuthorAvatarsWhitelistedTokenAddresses ([21dd181](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/21dd181a8afa71babcf2a4559d0dd45484b502bd))
|
|
150
|
+
* **chain:** validate wallet timestamp must be less than Date.now() / 1000 ([9e70b9a](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/9e70b9a91addd93c4f6a8a3796efa36adfd2635f))
|
|
151
|
+
* **comments:** add auto update controls and refresh ([#31](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/31)) ([15cf2df](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/15cf2df879f5ab4a9bc224c203504a864c962f9b))
|
|
152
|
+
* **comments:** implement useValidateComment ([b337c52](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b337c520222c71409352aa07ef44b6924fec73ba))
|
|
153
|
+
* **comments:** useComment can use comment from replies pages ([f259741](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f2597418aec9ac2be14cee3b9790ef7fa2f884e2))
|
|
154
|
+
* **feeds-store:** add validatePages: false ([9b11dd8](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/9b11dd888f319ad038a24c9b1da373858ce00417))
|
|
155
|
+
* **feeds-store:** if no next cid and no page cids, use preloaded page of any sort type ([5a24836](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/5a24836e0ce8e4a5a514184e6c4f45e85b394d3a))
|
|
156
|
+
* **feeds:** add old and best sort ([e5b30dc](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/e5b30dcd62f1f355bc3ce52555e7f71ea4cae06b))
|
|
157
|
+
* **feeds:** implement auto set correct time for topAll and controversialAll when newerThan is set ([4f33f77](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/4f33f772d94060072c65fbbd2b7ebacae8f59c06))
|
|
158
|
+
* **feeds:** implement useFeed modQueue pendingApproval ([5135645](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/51356455aae0420a855f3fd1f53c2bc589e4a3c3))
|
|
159
|
+
* **feeds:** implement useFeed().bufferedFeed ([7efd7f8](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/7efd7f888d0053b8e5ec385ded0d546046f90c0f))
|
|
160
|
+
* **feeds:** implement useFeed().reset() ([773df5a](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/773df5ad8d8477849e0effceaa57f7b1a28e1082))
|
|
161
|
+
* **feeds:** implement useFeed().updatedFeeds ([f9c08b0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f9c08b0dcf5a234f1755ea6cfd9a612f9502a733))
|
|
162
|
+
* **feeds:** implement useFeed({accountComments}) ([7064e8f](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/7064e8f84d54ab7be573023c753b70e737ff9e3b))
|
|
163
|
+
* **feeds:** implement useFeed({newerThan: seconds}) ([571861a](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/571861a1aaadc2eca9b3edc93444fbc33acbe084))
|
|
164
|
+
* **feeds:** implement useFeeds().subplebbitAddressesWithNewerPosts ([b32bdf6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b32bdf6a820bf68aac84423ffc4adec9d9ebaad3))
|
|
165
|
+
* **feeds:** support in-place time-window expansion ([e3526ef](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/e3526efd55678d1278cc882b2edbbaa0352be9f2))
|
|
166
|
+
* **hooks:** require explicit community objects ([#49](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/49)) ([c46ddc0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/c46ddc05834d934c5c4fc849ba42d414d8174460))
|
|
167
|
+
* **mock:** add `purged` moderation field to mock and tests ([f813f94](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f813f9480a203ea06d9bc44af98027dba789ba3f)), closes [#1](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/1)
|
|
168
|
+
* **plebbit-rpc:** implement usePlebbitRpcSettings ([ae28916](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ae28916952b17625db64b40583fd9f7d7189f590))
|
|
169
|
+
* **protocol:** migrate hooks library to pkc-js ([153df23](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/153df23a533131f9e8942fadd12a6337694ff646))
|
|
170
|
+
* **replies-pages-store:** implement replies pages store ([d3d98f4](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d3d98f4e5612983e38ccb465af59e4d87123d8a4))
|
|
171
|
+
* **replies-store:** if no nextCid, all replies are preloaded and use any sort type ([15782c2](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/15782c25a81cde42e7afd51452151926ce8e1b61))
|
|
172
|
+
* **replies-store:** implement replies-store ([b244273](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b2442732d854a9df972fb67b93e82fdb10730d42))
|
|
173
|
+
* **replies:** add account comments to usereplies ([dc7f658](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/dc7f658d1518973eceeb0998d313a45be8ae1ce0))
|
|
174
|
+
* **replies:** add replies pages clients fetching state ([f071225](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f071225bab8540bf6e993e5383999e87ff2e479b))
|
|
175
|
+
* **replies:** implement flat ([b5a387b](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b5a387b6beb1dcfff8212f393790fa89df1a74d7))
|
|
176
|
+
* **replies:** implement useReplies().bufferedReplies ([e0d4213](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/e0d4213014ded7995e6b989628d91b4ec0851802))
|
|
177
|
+
* **replies:** implement useReplies().updatedReplies ([63dd2e8](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/63dd2e8dd0869ae464fc927ba36e95da399d415b))
|
|
178
|
+
* **replies:** implement useReplies({validateOptimistically}) ([5b6e22b](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/5b6e22b3ef0e3187bec8d9ee09d6f827d10145e8))
|
|
179
|
+
* **states:** useClientsStates gets comment and subplebbit updating states ([c341a25](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/c341a25f3f99186f1c4383f06c2f616ad0fc0999))
|
|
180
|
+
* **states:** useClientsStates when publishing ([ac21c96](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ac21c96bb9b8fd302713d469190e8c3860aa62cb))
|
|
181
|
+
* **states:** useSubplebbitsStates ([84c7a42](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/84c7a426d7a3f802b1c2cbda89f8b89e34407e35))
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
### Performance Improvements
|
|
185
|
+
|
|
186
|
+
* **accounts-store:** use entries instead of keys ([42d6b15](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/42d6b15360601df4b16fa89e485890510a9b1dc8))
|
|
187
|
+
* **accounts:** slim account history storage and query hot paths ([4a85fbc](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/4a85fbce10afb957a9d292c57e70f8ea2f741645))
|
|
188
|
+
* **ci:** parallelize e2e suites and inline dist publish in main workflow ([6d40eec](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/6d40eecf2e514bdd6d98f5b67f1c2992f3f2a8d0)), closes [#6](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/6)
|
|
189
|
+
* **feeds-store:** dont use subplebbit relative sorting anymore as it gives bad feed results ([b8201c9](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/b8201c924e57285c33080f1b8f36e3032d8987f1))
|
|
190
|
+
* **feeds:** expire subplebbits cache 1h after fetch (for feeds only) ([f7c87b0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f7c87b00bb7be6cdab77d63e40e7f73aacce1a8b))
|
|
191
|
+
* **feeds:** optimize buffered feeds that dont change ([1acd1fd](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/1acd1fd8182b20d9f34306fc79088a3a3bc3e64d))
|
|
192
|
+
* improve perf ([7cb055e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/7cb055e6c6b055708f85648ce9584ec0f9556614))
|
|
193
|
+
* **replies:** add cached-only mode to useReplies ([#37](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/37)) ([125df99](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/125df993e522ac438f18b290911dc501cc79b125))
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
### Reverts
|
|
197
|
+
|
|
198
|
+
* Revert "update to rpcOptions instead of port" ([0ca7d53](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/0ca7d5306fe82cefee8c32fc9480cd429d961021))
|
|
199
|
+
* Revert "change plebbit data path to /tmp for electron. May eliminate SQLite IO errors" ([bcf1a94](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/bcf1a94e01376996f25a5be5a901c9e8071df97e))
|
|
200
|
+
* Revert "use latest signer schema" ([26690be](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/26690bebda858bdb8111eab786dd1cd06563099c))
|
|
201
|
+
* Revert "update plebbit-js" ([a4c63e3](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a4c63e37cf0e5f5fdeedd1f34de6d0fe26a9dfd0))
|
|
202
|
+
* Revert "fix undefined plebbit.dataPath before setAccount" ([d95bed5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/d95bed5a75b832fbbfc980b34ead43d8e6848fba))
|
|
203
|
+
* dont use real signer for mock content, didnt work ([629c2f2](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/629c2f2a6f76129eb51e7e66b82517d1aaee2458))
|
|
204
|
+
* not necessary to mock ens ([ba1dc84](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/ba1dc849341232de72e80f2b6406aa6dfc73538c))
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
### BREAKING CHANGES
|
|
208
|
+
|
|
209
|
+
* useFeed({filter}) and useAuthorComments({filter}) are now {filter: Function, key:
|
|
210
|
+
string}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
package/README.md
CHANGED
|
@@ -1019,6 +1019,9 @@ const { replies } = useReplies({
|
|
|
1019
1019
|
|
|
1020
1020
|
// pending local account comments are reconciled with their approved network version
|
|
1021
1021
|
// so the same post or reply is not shown twice after moderation approval
|
|
1022
|
+
// published account replies are only kept in useReplies while the canonical
|
|
1023
|
+
// replies feed may still contain them; after the feed is exhausted, account-only
|
|
1024
|
+
// published replies are hidden unless the canonical feed includes their cid
|
|
1022
1025
|
```
|
|
1023
1026
|
|
|
1024
1027
|
#### Determine if a comment is your own
|
|
@@ -1299,6 +1302,9 @@ const useRepliesOptions = {
|
|
|
1299
1302
|
accountComments: { newerThan: Infinity, append: false },
|
|
1300
1303
|
};
|
|
1301
1304
|
|
|
1305
|
+
// accountComments keeps pending local replies visible, but published account
|
|
1306
|
+
// replies must resolve through the canonical replies feed after it is exhausted
|
|
1307
|
+
|
|
1302
1308
|
const Reply = ({ reply, updatedReply }) => {
|
|
1303
1309
|
const { replies, updatedReplies, bufferedReplies, hasMore, loadMore } = useReplies({
|
|
1304
1310
|
...useRepliesOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replies-store.d.ts","sourceRoot":"","sources":["../../../src/stores/replies/replies-store.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,OAAO,EAGP,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,aAAa,CAAC;AAwBrB,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAKxC,MAAM,MAAM,YAAY,GAAG;IACzB,YAAY,EAAE,mBAAmB,CAAC;IAClC,aAAa,EAAE,KAAK,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;IACnB,YAAY,EAAE,KAAK,CAAC;IACpB,wBAAwB,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACzD,aAAa,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,eAAe,EAAE,QAAQ,CAAC;IAC1B,6BAA6B,EAAE,QAAQ,CAAC;IACxC,uBAAuB,EAAE,QAAQ,CAAC;IAClC,SAAS,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC;AAgBF,eAAO,MAAM,qBAAqB,GAAI,aAAa,OAAO,CAAC,kBAAkB,CAAC,WAG7E,CAAC;AAOF,QAAA,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"replies-store.d.ts","sourceRoot":"","sources":["../../../src/stores/replies/replies-store.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,OAAO,EAGP,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,aAAa,CAAC;AAwBrB,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAKxC,MAAM,MAAM,YAAY,GAAG;IACzB,YAAY,EAAE,mBAAmB,CAAC;IAClC,aAAa,EAAE,KAAK,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;IACnB,YAAY,EAAE,KAAK,CAAC;IACpB,wBAAwB,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACzD,aAAa,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,eAAe,EAAE,QAAQ,CAAC;IAC1B,6BAA6B,EAAE,QAAQ,CAAC;IACxC,uBAAuB,EAAE,QAAQ,CAAC;IAClC,SAAS,EAAE,QAAQ,CAAC;IACpB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC;AAgBF,eAAO,MAAM,qBAAqB,GAAI,aAAa,OAAO,CAAC,kBAAkB,CAAC,WAG7E,CAAC;AAOF,QAAA,MAAM,YAAY,2EAySf,CAAC;AAkLJ,eAAO,MAAM,iCAAiC,GAC5C,SAAS,OAAO,EAChB,aAAa,OAAO,CAAC,kBAAkB,CAAC;;;CAkCzC,CAAC;AAKF,eAAO,MAAM,iBAAiB,qBAkB7B,CAAC;AAGF,eAAO,MAAM,4BAA4B,qBAGxC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -193,7 +193,14 @@ const repliesStore = createStore((setState, getState) => ({
|
|
|
193
193
|
// calculate new feeds
|
|
194
194
|
const filteredSortedFeeds = getFilteredSortedFeeds(feedsOptions, comments, repliesPages, accounts);
|
|
195
195
|
const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(filteredSortedFeeds, previousState.loadedFeeds);
|
|
196
|
-
const
|
|
196
|
+
const canonicalLoadedFeeds = yield getLoadedFeeds(feedsOptions, previousState.loadedFeeds, bufferedFeedsWithoutPreviousLoadedFeeds, accounts, { addAccountComments: false });
|
|
197
|
+
const canonicalBufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(bufferedFeedsWithoutPreviousLoadedFeeds, canonicalLoadedFeeds);
|
|
198
|
+
const canonicalFeedsHaveMore = getFeedsHaveMore(feedsOptions, canonicalBufferedFeeds, comments, repliesPages, accounts);
|
|
199
|
+
const loadedFeedsWithAccountComments = Object.assign({}, canonicalLoadedFeeds);
|
|
200
|
+
const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, loadedFeedsWithAccountComments, canonicalFeedsHaveMore);
|
|
201
|
+
const loadedFeeds = accountCommentsChangedFeeds
|
|
202
|
+
? loadedFeedsWithAccountComments
|
|
203
|
+
: canonicalLoadedFeeds;
|
|
197
204
|
// after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds
|
|
198
205
|
const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(bufferedFeedsWithoutPreviousLoadedFeeds, loadedFeeds);
|
|
199
206
|
const bufferedFeedsReplyCounts = getFeedsReplyCounts(feedsOptions, bufferedFeeds);
|
|
@@ -378,8 +385,8 @@ export const getRepliesFirstPageSkipValidation = (comment, feedOptions) => {
|
|
|
378
385
|
if (filteredSortedFeeds[feedName].length > repliesPerPage) {
|
|
379
386
|
bufferedFeeds[feedName] = filteredSortedFeeds[feedName].splice(repliesPerPage);
|
|
380
387
|
}
|
|
381
|
-
addAccountsComments(feedsOptions, filteredSortedFeeds);
|
|
382
388
|
const feedsHaveMore = getFeedsHaveMore(feedsOptions, bufferedFeeds, comments, repliesPages, accounts);
|
|
389
|
+
addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore);
|
|
383
390
|
return { replies: filteredSortedFeeds[feedName], hasMore: feedsHaveMore[feedName] };
|
|
384
391
|
};
|
|
385
392
|
// reset store in between tests
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replies-store.js","sourceRoot":"","sources":["../../../src/stores/replies/replies-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAA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C","sourcesContent":["import assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:stores\");\nimport {\n Feed,\n Feeds,\n Comment,\n Comments,\n Account,\n RepliesFeedOptions,\n RepliesFeedsOptions,\n RepliesPage,\n CommentsFilter,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport accountsStore from \"../accounts\";\nimport repliesCommentsStore from \"./replies-comments-store\";\nimport repliesPagesStore from \"../replies-pages\";\nimport {\n getFeedsCommentsFirstPageCids,\n getLoadedFeeds,\n getBufferedFeedsWithoutLoadedFeeds,\n getUpdatedFeeds,\n getFeedsReplyCounts,\n getFeedsHaveMore,\n feedsCommentsChanged,\n getFeedsComments,\n getFeedsCommentsLoadedCount,\n getFeedsCommentsRepliesPagesFirstUpdatedAts,\n getFilteredSortedFeeds,\n getSortTypeFromComment,\n addAccountsComments,\n} from \"./utils\";\n\n// reddit loads approximately 25 posts per page\n// while infinite scrolling\nexport const defaultRepliesPerPage = 25;\n\n// keep large buffer because fetching cids is slow\nconst commentRepliesLeftBeforeNextPage = 50;\n\nexport type RepliesState = {\n feedsOptions: RepliesFeedsOptions;\n bufferedFeeds: Feeds;\n loadedFeeds: Feeds;\n updatedFeeds: Feeds;\n bufferedFeedsReplyCounts: { [feedName: string]: number };\n feedsHaveMore: { [feedName: string]: boolean };\n addFeedsToStore: Function;\n addFeedToStoreOrUpdateComment: Function;\n incrementFeedPageNumber: Function;\n resetFeed: Function;\n updateFeeds: Function;\n};\n\nconst defaultAccountComments = { newerThan: Infinity, append: false };\nconst addDefaultFeedOptions = (feedOptions: any) => {\n feedOptions = { ...feedOptions };\n if (feedOptions.flat === undefined || feedOptions.flat === null) {\n feedOptions.flat = false;\n }\n feedOptions.onlyIfCached = feedOptions.onlyIfCached === true;\n if (feedOptions.accountComments === undefined || feedOptions.accountComments === null) {\n feedOptions.accountComments = defaultAccountComments;\n }\n feedOptions.repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n return feedOptions;\n};\n\nexport const feedOptionsToFeedName = (feedOptions: Partial<RepliesFeedOptions>) => {\n feedOptions = addDefaultFeedOptions(feedOptions);\n return `${feedOptions?.accountId}-${feedOptions?.commentCid}-${feedOptions?.postCid}-${feedOptions?.sortType}-${feedOptions?.flat}-${feedOptions?.onlyIfCached}-${feedOptions?.accountComments?.newerThan}-${feedOptions?.accountComments?.append}-${feedOptions?.repliesPerPage}-${feedOptions?.filter?.key}-${feedOptions?.streamPage}`;\n};\n\n// don't updateFeeds more than once per updateFeedsMinIntervalTime\nlet updateFeedsPending = false;\nlet updateFeedsAgain = false;\nconst updateFeedsMinIntervalTime = 100;\n\nconst repliesStore = createStore<RepliesState>((setState: Function, getState: Function) => ({\n feedsOptions: {},\n bufferedFeeds: {},\n loadedFeeds: {},\n updatedFeeds: {},\n bufferedFeedsReplyCounts: {},\n feedsHaveMore: {},\n\n addFeedsToStore(feedOptionsArray: RepliesFeedOptions[]) {\n if (!feedOptionsArray.length) {\n return;\n }\n const { feedsOptions: previousFeedsOptions } = getState();\n const newFeedsOptions: RepliesFeedsOptions = {};\n\n // get all newFeedsOptions\n for (let feedOptions of feedOptionsArray) {\n const feedName = feedOptionsToFeedName(feedOptions);\n // feed is in store already, do nothing\n // if the feed already exist but is at page 0, reset it to page 1\n if (previousFeedsOptions[feedName] && previousFeedsOptions[feedName].pageNumber !== 0) {\n continue;\n }\n\n feedOptions = addDefaultFeedOptions(feedOptions);\n\n // to add a buffered feed, add a feed with pageNumber 0\n feedOptions.pageNumber = 1;\n newFeedsOptions[feedName] = feedOptions;\n }\n\n // set new feedsOptions state (first loop already skips existing feeds)\n let feedsChanged = false;\n setState(({ feedsOptions }: RepliesState) => {\n if (!Object.keys(newFeedsOptions).length) return {};\n feedsChanged = true;\n return { feedsOptions: { ...feedsOptions, ...newFeedsOptions } };\n });\n if (feedsChanged) {\n log(\"repliesStore.addFeedsToStore\", newFeedsOptions);\n }\n return feedsChanged;\n },\n\n async addFeedToStoreOrUpdateComment(comment: Comment, feedOptions: RepliesFeedOptions) {\n // init here because must be called after async accounts store finished initializing\n initializeRepliesStore();\n\n // validate options\n assert(\n comment && comment.cid && typeof comment.cid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment comment.cid '${comment?.cid}' invalid`,\n );\n assert(\n feedOptions.commentCid && typeof feedOptions.commentCid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.commentCid '${feedOptions.commentCid}' invalid`,\n );\n assert(\n feedOptions.sortType && typeof feedOptions.sortType === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.sortType '${feedOptions.sortType}' invalid`,\n );\n const account = accountsStore.getState().accounts[feedOptions.accountId];\n assert(\n typeof account?.pkc?.createComment === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.accountId '${feedOptions.accountId}' invalid`,\n );\n assert(\n !feedOptions.repliesPerPage || typeof feedOptions.repliesPerPage === \"number\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.repliesPerPage '${feedOptions.repliesPerPage}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.filter === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.filter '${feedOptions.filter?.filter}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.key === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.key '${feedOptions.filter?.key}' invalid`,\n );\n\n // if replies feed aren't in store yet, add them recursively\n // TODO: optimize performance by only adding feeds that are in page 1, and add more on each page increase\n const commentsToAddToStoreOrUpdate: Comment[] = [];\n const feedsToAddToStore: RepliesFeedOptions[] = [];\n\n // use the sort type availabe on the comment when missing\n const sortType = getSortTypeFromComment(comment, feedOptions);\n\n const addRepliesFeedsToStoreRecursively = (comment: Comment) => {\n // NOTE: even a comment with no replies needs a feed, to know it has 0 replies and not displace the UI when a new replies appears\n commentsToAddToStoreOrUpdate.push(comment);\n feedsToAddToStore.push({\n ...feedOptions,\n commentCid: comment?.cid,\n commentDepth: comment?.depth,\n });\n\n // flat doesn't need nested feeds\n if (!feedOptions.flat) {\n for (const reply of comment.replies?.pages?.[sortType]?.comments || []) {\n addRepliesFeedsToStoreRecursively(reply);\n }\n }\n };\n addRepliesFeedsToStoreRecursively(comment);\n\n // add feeds to store and update feeds\n const { addFeedsToStore, updateFeeds } = getState();\n const feedsChanged = addFeedsToStore(feedsToAddToStore);\n // add comments to store (do it after addFeedsToStore because it can trigger updateFeeds)\n repliesCommentsStore\n .getState()\n .addCommentsToStoreOrUpdateComments(commentsToAddToStoreOrUpdate);\n if (feedsChanged) {\n log(\"repliesStore.addFeedToStoreOrUpdateComment\", {\n comment,\n feedOptions,\n sortType,\n feedsToAddToStore,\n commentsToAddToStoreOrUpdate,\n });\n updateFeeds();\n }\n },\n\n incrementFeedPageNumber(feedName: string) {\n const { feedsOptions, loadedFeeds, bufferedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`,\n );\n log(\"repliesStore.incrementFeedPageNumber\", { feedName });\n\n // TODO: fix design issue, pageNumber shouldnt be increased when loadMore is called and repliesPerPage not reached\n // assert(\n // feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <= loadedFeeds[feedName].length,\n // `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`\n // )\n if (\n feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <=\n loadedFeeds[feedName].length\n ) {\n assert(\n bufferedFeeds[feedName].length > 0,\n `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`,\n );\n }\n\n setState(({ feedsOptions, loadedFeeds }: any) => {\n // don't increment page number before the current page has loaded\n // if (feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage > loadedFeeds[feedName].length) {\n // return {}\n // }\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: feedsOptions[feedName].pageNumber + 1,\n };\n return { feedsOptions: { ...feedsOptions, [feedName]: feedOptions } };\n });\n\n // do not update feed at the same time as increment a page number or it might cause\n // a race condition, rather schedule a feed update\n updateFeeds();\n },\n\n resetFeed(feedName: string) {\n const { feedsOptions, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.resetFeed feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n feedsOptions[feedName].pageNumber >= 1,\n `repliesStore.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`,\n );\n log(\"repliesStore.resetFeed\", { feedName });\n\n setState(({ feedsOptions, loadedFeeds, updatedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: 1,\n };\n return {\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n loadedFeeds: { ...loadedFeeds, [feedName]: [] },\n updatedFeeds: { ...updatedFeeds, [feedName]: [] },\n };\n });\n\n updateFeeds();\n },\n\n // recalculate all feeds using new comments.replies.pages, repliesPagesStore and page numbers\n updateFeeds() {\n if (updateFeedsPending) {\n updateFeedsAgain = true;\n return;\n }\n updateFeedsPending = true;\n\n // don't update feeds more than once per updateFeedsMinIntervalTime\n const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;\n\n setTimeout(async () => {\n // get state from all stores\n const previousState = getState();\n const { feedsOptions, updateFeeds } = previousState;\n const { comments } = repliesCommentsStore.getState();\n const { repliesPages } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // calculate new feeds\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n filteredSortedFeeds,\n previousState.loadedFeeds,\n );\n const loadedFeeds = await getLoadedFeeds(\n feedsOptions,\n previousState.loadedFeeds,\n bufferedFeedsWithoutPreviousLoadedFeeds,\n accounts,\n );\n // after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds\n const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n loadedFeeds,\n );\n const bufferedFeedsReplyCounts = getFeedsReplyCounts(feedsOptions, bufferedFeeds);\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n const updatedFeeds = await getUpdatedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.updatedFeeds,\n loadedFeeds,\n accounts,\n );\n\n // set new feeds\n setState((state: any) => ({\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n }));\n log(\"repliesStore.updateFeeds\", {\n feedsOptions,\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n comments,\n repliesPages,\n });\n\n updateFeedsPending = false;\n\n // if updateFeeds was called while updateFeedsPending = true, call updateFeeds again\n if (updateFeedsAgain) {\n updateFeedsAgain = false;\n updateFeeds();\n }\n }, timeUntilNextUpdate);\n },\n}));\n\nlet repliesStoreInitialized = false;\nconst initializeRepliesStore = async () => {\n if (repliesStoreInitialized) {\n return;\n }\n repliesStoreInitialized = true;\n // TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommentsChange(comment)\n // subscribe to comments store changes\n repliesCommentsStore.subscribe(updateFeedsOnFeedsCommentsChange);\n // subscribe to bufferedFeedsReplyCounts change\n repliesStore.subscribe(addRepliesPagesOnLowBufferedFeedsReplyCounts);\n // subscribe to replies pages store changes\n repliesPagesStore.subscribe(updateFeedsOnFeedsRepliesPagesChange);\n // subscribe to accounts store changes\n accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);\n};\n\nlet previousRepliesPages: { [pageCid: string]: RepliesPage } = {};\nconst updateFeedsOnFeedsRepliesPagesChange = (repliesPagesStoreState: any) => {\n const { repliesPages } = repliesPagesStoreState;\n\n // no changes, do nothing\n if (repliesPages === previousRepliesPages) {\n return;\n }\n previousRepliesPages = repliesPages;\n\n // currently only the feeds use repliesPagesStore, so any change must\n // trigger a feed update, if in the future another hook uses the repliesPagesStore\n // we should check if the replies pages changed are actually used by the feeds before\n // triggering an update\n repliesStore.getState().updateFeeds();\n};\n\nlet previousBufferedFeedsReplyCountsPageCids: string[] = [];\nlet previousBufferedFeedsComments = new Map<string, Comments>();\nlet previousBufferedFeedsReplyCounts: { [feedName: string]: number } = {};\nconst addRepliesPagesOnLowBufferedFeedsReplyCounts = (repliesStoreState: any) => {\n const { bufferedFeedsReplyCounts, feedsOptions } = repliesStore.getState();\n const { comments } = repliesCommentsStore.getState();\n\n // if feeds comments have changed, we must try adding them even if buffered replies counts haven't changed\n const bufferedFeedsComments = getFeedsComments(feedsOptions, comments);\n const _feedsCommentsChanged = feedsCommentsChanged(\n previousBufferedFeedsComments,\n bufferedFeedsComments,\n );\n const bufferedFeedsReplyCountsChanged =\n previousBufferedFeedsReplyCounts !== bufferedFeedsReplyCounts;\n\n // if feeds comments havent changed and buffered replies counts also havent changed, do nothing\n if (!_feedsCommentsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsComments = bufferedFeedsComments;\n previousBufferedFeedsReplyCounts = bufferedFeedsReplyCounts;\n\n // in case feeds comments changed, but the first page cids haven't\n const bufferedFeedsReplyCountsPageCids = getFeedsCommentsFirstPageCids(bufferedFeedsComments);\n const bufferedFeedsReplyCountsPageCidsChanged =\n bufferedFeedsReplyCountsPageCids.toString() !==\n previousBufferedFeedsReplyCountsPageCids.toString();\n if (!bufferedFeedsReplyCountsPageCidsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsReplyCountsPageCids = bufferedFeedsReplyCountsPageCids;\n\n const { addNextRepliesPageToStore } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // bufferedFeedsReplyCounts have changed, check if any of them are low\n for (const feedName in bufferedFeedsReplyCounts) {\n if (feedsOptions[feedName].onlyIfCached) {\n continue;\n }\n const account = accounts[feedsOptions[feedName].accountId];\n const feedReplyCount = bufferedFeedsReplyCounts[feedName];\n let sortType = feedsOptions[feedName].sortType;\n const commentCid = feedsOptions[feedName].commentCid;\n\n // TODO: maybe skip if comment community address, comment cid or comment author is blocked?\n\n // comment hasn't loaded yet\n if (!comments[commentCid]) {\n continue;\n }\n\n sortType = getSortTypeFromComment(comments[commentCid], feedsOptions[feedName]);\n\n // comment replies count is low, fetch next replies page\n if (feedReplyCount <= commentRepliesLeftBeforeNextPage) {\n addNextRepliesPageToStore(comments[commentCid], sortType, account).catch((error: unknown) =>\n log.error(\"repliesStore repliesPagesStore.addNextRepliesPageToStore error\", {\n commentCid,\n comment: comments[commentCid],\n sortType,\n error,\n }),\n );\n }\n }\n};\n\nlet previousFeedsCommentsFirstPageCids: string[] = [];\nlet previousFeedsComments: Map<string, Comments> = new Map();\nlet previousFeedsCommentsLoadedCount = 0;\nlet previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\nconst updateFeedsOnFeedsCommentsChange = (repliesCommentsStoreState: any) => {\n const { comments } = repliesCommentsStoreState;\n const { feedsOptions, updateFeeds } = repliesStore.getState();\n\n // feeds comments haven't changed, do nothing\n const feedsComments = getFeedsComments(feedsOptions, comments);\n if (!feedsCommentsChanged(previousFeedsComments, feedsComments)) {\n return;\n }\n previousFeedsComments = feedsComments;\n\n // decide if feeds comments have changed by looking at all feeds comments page cids\n // (in case that a comment changed, but its first page cid didn't)\n const feedsCommentsFirstPageCids = getFeedsCommentsFirstPageCids(feedsComments);\n\n // first page cids haven't changed, do nothing\n if (feedsCommentsFirstPageCids.toString() === previousFeedsCommentsFirstPageCids.toString()) {\n // if no new feed comments have loaded, do nothing\n // in case a comment loads with no first page cid and first pages cids don't change, need to trigger hasMore update\n const feedsCommentsLoadedCount = getFeedsCommentsLoadedCount(feedsComments);\n if (feedsCommentsLoadedCount === previousFeedsCommentsLoadedCount) {\n // if comment.replies.pages haven't changed, do nothing\n const feedsCommentsRepliesPagesFirstUpdatedAts =\n getFeedsCommentsRepliesPagesFirstUpdatedAts(feedsComments);\n if (\n feedsCommentsRepliesPagesFirstUpdatedAts ===\n previousFeedsCommentsRepliesPagesFirstUpdatedAts\n ) {\n return;\n }\n\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = feedsCommentsRepliesPagesFirstUpdatedAts;\n }\n previousFeedsCommentsLoadedCount = feedsCommentsLoadedCount;\n }\n\n // feeds comments have changed, update feeds\n previousFeedsCommentsFirstPageCids = feedsCommentsFirstPageCids;\n updateFeeds();\n};\n\nlet previousAccountsCommentsCount = 0;\nlet previousAccountsCommentsCids = \"\";\nconst updateFeedsOnAccountsCommentsChange = (accountsStoreState: any) => {\n const { accountsComments } = accountsStoreState;\n const accountsCommentsCount = Object.values(accountsComments as Comment[][]).reduce(\n (count, accountComments) => count + accountComments.length,\n 0,\n );\n\n // no changes, do nothing\n if (accountsCommentsCount === previousAccountsCommentsCount) {\n // if cids haven't changed (account comments receive cids after pending), do nothing\n const accountsCommentsCids = Object.values(accountsComments as Comment[][]).reduce(\n (cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || \"\")),\n \"\",\n );\n if (accountsCommentsCids === previousAccountsCommentsCids) {\n return;\n }\n previousAccountsCommentsCids = accountsCommentsCids;\n }\n previousAccountsCommentsCount = accountsCommentsCount;\n\n // TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid\n repliesStore.getState().updateFeeds();\n};\n\n// needed to view replies instantly without waiting for zustant store react rerenders. must be synchronous\nexport const getRepliesFirstPageSkipValidation = (\n comment: Comment,\n feedOptions: Partial<RepliesFeedOptions>,\n) => {\n const feedName = `firstPageSkipValidation-${comment?.cid}`;\n const feedsOptions: any = { [feedName]: feedOptions };\n const { accounts } = accountsStore.getState();\n\n // don't use comments store, only use preloaded comment.replies.pages\n const comments = { [comment.cid]: comment };\n\n // don't use any reply pages, they can't provide instant loading like preloaded comment.replies.pages\n const repliesPages = {};\n\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n\n // only get first page and put next page in buffered\n const bufferedFeeds: Feeds = { [feedName]: [] };\n const repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n if (filteredSortedFeeds[feedName].length > repliesPerPage) {\n bufferedFeeds[feedName] = filteredSortedFeeds[feedName].splice(repliesPerPage);\n }\n addAccountsComments(feedsOptions, filteredSortedFeeds);\n\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n return { replies: filteredSortedFeeds[feedName], hasMore: feedsHaveMore[feedName] };\n};\n\n// reset store in between tests\nconst originalState = repliesStore.getState();\n// async function because some stores have async init\nexport const resetRepliesStore = async () => {\n previousBufferedFeedsReplyCounts = {};\n previousBufferedFeedsReplyCountsPageCids = [];\n previousBufferedFeedsComments = new Map();\n previousFeedsCommentsFirstPageCids = [];\n previousFeedsComments = new Map();\n previousFeedsCommentsLoadedCount = 0;\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\n previousRepliesPages = {};\n previousAccountsCommentsCount = 0;\n previousAccountsCommentsCids = \"\";\n updateFeedsPending = false;\n // destroy all component subscriptions to the store\n repliesStore.destroy();\n // restore original state\n repliesStore.setState(originalState);\n repliesCommentsStore.setState({ ...repliesCommentsStore.getState(), comments: {} });\n repliesStoreInitialized = false;\n};\n\n// reset database and store in between tests\nexport const resetRepliesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-repliesPages\" }).clear();\n await resetRepliesStore();\n};\n\nexport default repliesStore;\n"]}
|
|
1
|
+
{"version":3,"file":"replies-store.js","sourceRoot":"","sources":["../../../src/stores/replies/replies-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MA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AAC,CAAC;IACrC,oBAAoB,CAAC,QAAQ,iCAAM,oBAAoB,CAAC,QAAQ,EAAE,KAAE,QAAQ,EAAE,EAAE,IAAG,CAAC;IACpF,uBAAuB,GAAG,KAAK,CAAC;AAClC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAS,EAAE;IACrD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,kCAAkC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IAC1F,MAAM,iBAAiB,EAAE,CAAC;AAC5B,CAAC,CAAA,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import assert from \"assert\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:replies:stores\");\nimport {\n Feed,\n Feeds,\n Comment,\n Comments,\n Account,\n RepliesFeedOptions,\n RepliesFeedsOptions,\n RepliesPage,\n CommentsFilter,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport accountsStore from \"../accounts\";\nimport repliesCommentsStore from \"./replies-comments-store\";\nimport repliesPagesStore from \"../replies-pages\";\nimport {\n getFeedsCommentsFirstPageCids,\n getLoadedFeeds,\n getBufferedFeedsWithoutLoadedFeeds,\n getUpdatedFeeds,\n getFeedsReplyCounts,\n getFeedsHaveMore,\n feedsCommentsChanged,\n getFeedsComments,\n getFeedsCommentsLoadedCount,\n getFeedsCommentsRepliesPagesFirstUpdatedAts,\n getFilteredSortedFeeds,\n getSortTypeFromComment,\n addAccountsComments,\n} from \"./utils\";\n\n// reddit loads approximately 25 posts per page\n// while infinite scrolling\nexport const defaultRepliesPerPage = 25;\n\n// keep large buffer because fetching cids is slow\nconst commentRepliesLeftBeforeNextPage = 50;\n\nexport type RepliesState = {\n feedsOptions: RepliesFeedsOptions;\n bufferedFeeds: Feeds;\n loadedFeeds: Feeds;\n updatedFeeds: Feeds;\n bufferedFeedsReplyCounts: { [feedName: string]: number };\n feedsHaveMore: { [feedName: string]: boolean };\n addFeedsToStore: Function;\n addFeedToStoreOrUpdateComment: Function;\n incrementFeedPageNumber: Function;\n resetFeed: Function;\n updateFeeds: Function;\n};\n\nconst defaultAccountComments = { newerThan: Infinity, append: false };\nconst addDefaultFeedOptions = (feedOptions: any) => {\n feedOptions = { ...feedOptions };\n if (feedOptions.flat === undefined || feedOptions.flat === null) {\n feedOptions.flat = false;\n }\n feedOptions.onlyIfCached = feedOptions.onlyIfCached === true;\n if (feedOptions.accountComments === undefined || feedOptions.accountComments === null) {\n feedOptions.accountComments = defaultAccountComments;\n }\n feedOptions.repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n return feedOptions;\n};\n\nexport const feedOptionsToFeedName = (feedOptions: Partial<RepliesFeedOptions>) => {\n feedOptions = addDefaultFeedOptions(feedOptions);\n return `${feedOptions?.accountId}-${feedOptions?.commentCid}-${feedOptions?.postCid}-${feedOptions?.sortType}-${feedOptions?.flat}-${feedOptions?.onlyIfCached}-${feedOptions?.accountComments?.newerThan}-${feedOptions?.accountComments?.append}-${feedOptions?.repliesPerPage}-${feedOptions?.filter?.key}-${feedOptions?.streamPage}`;\n};\n\n// don't updateFeeds more than once per updateFeedsMinIntervalTime\nlet updateFeedsPending = false;\nlet updateFeedsAgain = false;\nconst updateFeedsMinIntervalTime = 100;\n\nconst repliesStore = createStore<RepliesState>((setState: Function, getState: Function) => ({\n feedsOptions: {},\n bufferedFeeds: {},\n loadedFeeds: {},\n updatedFeeds: {},\n bufferedFeedsReplyCounts: {},\n feedsHaveMore: {},\n\n addFeedsToStore(feedOptionsArray: RepliesFeedOptions[]) {\n if (!feedOptionsArray.length) {\n return;\n }\n const { feedsOptions: previousFeedsOptions } = getState();\n const newFeedsOptions: RepliesFeedsOptions = {};\n\n // get all newFeedsOptions\n for (let feedOptions of feedOptionsArray) {\n const feedName = feedOptionsToFeedName(feedOptions);\n // feed is in store already, do nothing\n // if the feed already exist but is at page 0, reset it to page 1\n if (previousFeedsOptions[feedName] && previousFeedsOptions[feedName].pageNumber !== 0) {\n continue;\n }\n\n feedOptions = addDefaultFeedOptions(feedOptions);\n\n // to add a buffered feed, add a feed with pageNumber 0\n feedOptions.pageNumber = 1;\n newFeedsOptions[feedName] = feedOptions;\n }\n\n // set new feedsOptions state (first loop already skips existing feeds)\n let feedsChanged = false;\n setState(({ feedsOptions }: RepliesState) => {\n if (!Object.keys(newFeedsOptions).length) return {};\n feedsChanged = true;\n return { feedsOptions: { ...feedsOptions, ...newFeedsOptions } };\n });\n if (feedsChanged) {\n log(\"repliesStore.addFeedsToStore\", newFeedsOptions);\n }\n return feedsChanged;\n },\n\n async addFeedToStoreOrUpdateComment(comment: Comment, feedOptions: RepliesFeedOptions) {\n // init here because must be called after async accounts store finished initializing\n initializeRepliesStore();\n\n // validate options\n assert(\n comment && comment.cid && typeof comment.cid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment comment.cid '${comment?.cid}' invalid`,\n );\n assert(\n feedOptions.commentCid && typeof feedOptions.commentCid === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.commentCid '${feedOptions.commentCid}' invalid`,\n );\n assert(\n feedOptions.sortType && typeof feedOptions.sortType === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.sortType '${feedOptions.sortType}' invalid`,\n );\n const account = accountsStore.getState().accounts[feedOptions.accountId];\n assert(\n typeof account?.pkc?.createComment === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.accountId '${feedOptions.accountId}' invalid`,\n );\n assert(\n !feedOptions.repliesPerPage || typeof feedOptions.repliesPerPage === \"number\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.repliesPerPage '${feedOptions.repliesPerPage}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.filter === \"function\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.filter '${feedOptions.filter?.filter}' invalid`,\n );\n assert(\n !feedOptions.filter || typeof feedOptions.filter?.key === \"string\",\n `repliesStore.addFeedToStoreOrUpdateComment feedOptions.filter.key '${feedOptions.filter?.key}' invalid`,\n );\n\n // if replies feed aren't in store yet, add them recursively\n // TODO: optimize performance by only adding feeds that are in page 1, and add more on each page increase\n const commentsToAddToStoreOrUpdate: Comment[] = [];\n const feedsToAddToStore: RepliesFeedOptions[] = [];\n\n // use the sort type availabe on the comment when missing\n const sortType = getSortTypeFromComment(comment, feedOptions);\n\n const addRepliesFeedsToStoreRecursively = (comment: Comment) => {\n // NOTE: even a comment with no replies needs a feed, to know it has 0 replies and not displace the UI when a new replies appears\n commentsToAddToStoreOrUpdate.push(comment);\n feedsToAddToStore.push({\n ...feedOptions,\n commentCid: comment?.cid,\n commentDepth: comment?.depth,\n });\n\n // flat doesn't need nested feeds\n if (!feedOptions.flat) {\n for (const reply of comment.replies?.pages?.[sortType]?.comments || []) {\n addRepliesFeedsToStoreRecursively(reply);\n }\n }\n };\n addRepliesFeedsToStoreRecursively(comment);\n\n // add feeds to store and update feeds\n const { addFeedsToStore, updateFeeds } = getState();\n const feedsChanged = addFeedsToStore(feedsToAddToStore);\n // add comments to store (do it after addFeedsToStore because it can trigger updateFeeds)\n repliesCommentsStore\n .getState()\n .addCommentsToStoreOrUpdateComments(commentsToAddToStoreOrUpdate);\n if (feedsChanged) {\n log(\"repliesStore.addFeedToStoreOrUpdateComment\", {\n comment,\n feedOptions,\n sortType,\n feedsToAddToStore,\n commentsToAddToStoreOrUpdate,\n });\n updateFeeds();\n }\n },\n\n incrementFeedPageNumber(feedName: string) {\n const { feedsOptions, loadedFeeds, bufferedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`,\n );\n log(\"repliesStore.incrementFeedPageNumber\", { feedName });\n\n // TODO: fix design issue, pageNumber shouldnt be increased when loadMore is called and repliesPerPage not reached\n // assert(\n // feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <= loadedFeeds[feedName].length,\n // `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`\n // )\n if (\n feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage <=\n loadedFeeds[feedName].length\n ) {\n assert(\n bufferedFeeds[feedName].length > 0,\n `repliesStore.incrementFeedPageNumber cannot increment feed page number before current page has loaded`,\n );\n }\n\n setState(({ feedsOptions, loadedFeeds }: any) => {\n // don't increment page number before the current page has loaded\n // if (feedsOptions[feedName].pageNumber * feedsOptions[feedName].repliesPerPage > loadedFeeds[feedName].length) {\n // return {}\n // }\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: feedsOptions[feedName].pageNumber + 1,\n };\n return { feedsOptions: { ...feedsOptions, [feedName]: feedOptions } };\n });\n\n // do not update feed at the same time as increment a page number or it might cause\n // a race condition, rather schedule a feed update\n updateFeeds();\n },\n\n resetFeed(feedName: string) {\n const { feedsOptions, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `repliesStore.resetFeed feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n feedsOptions[feedName].pageNumber >= 1,\n `repliesStore.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`,\n );\n log(\"repliesStore.resetFeed\", { feedName });\n\n setState(({ feedsOptions, loadedFeeds, updatedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: 1,\n };\n return {\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n loadedFeeds: { ...loadedFeeds, [feedName]: [] },\n updatedFeeds: { ...updatedFeeds, [feedName]: [] },\n };\n });\n\n updateFeeds();\n },\n\n // recalculate all feeds using new comments.replies.pages, repliesPagesStore and page numbers\n updateFeeds() {\n if (updateFeedsPending) {\n updateFeedsAgain = true;\n return;\n }\n updateFeedsPending = true;\n\n // don't update feeds more than once per updateFeedsMinIntervalTime\n const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;\n\n setTimeout(async () => {\n // get state from all stores\n const previousState = getState();\n const { feedsOptions, updateFeeds } = previousState;\n const { comments } = repliesCommentsStore.getState();\n const { repliesPages } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // calculate new feeds\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n filteredSortedFeeds,\n previousState.loadedFeeds,\n );\n const canonicalLoadedFeeds = await getLoadedFeeds(\n feedsOptions,\n previousState.loadedFeeds,\n bufferedFeedsWithoutPreviousLoadedFeeds,\n accounts,\n { addAccountComments: false },\n );\n const canonicalBufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n canonicalLoadedFeeds,\n );\n const canonicalFeedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n canonicalBufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n const loadedFeedsWithAccountComments = { ...canonicalLoadedFeeds };\n const accountCommentsChangedFeeds = addAccountsComments(\n feedsOptions,\n loadedFeedsWithAccountComments,\n canonicalFeedsHaveMore,\n );\n const loadedFeeds = accountCommentsChangedFeeds\n ? loadedFeedsWithAccountComments\n : canonicalLoadedFeeds;\n // after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds\n const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n loadedFeeds,\n );\n const bufferedFeedsReplyCounts = getFeedsReplyCounts(feedsOptions, bufferedFeeds);\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n const updatedFeeds = await getUpdatedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.updatedFeeds,\n loadedFeeds,\n accounts,\n );\n\n // set new feeds\n setState((state: any) => ({\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n }));\n log(\"repliesStore.updateFeeds\", {\n feedsOptions,\n bufferedFeeds,\n loadedFeeds,\n bufferedFeedsReplyCounts,\n updatedFeeds,\n feedsHaveMore,\n comments,\n repliesPages,\n });\n\n updateFeedsPending = false;\n\n // if updateFeeds was called while updateFeedsPending = true, call updateFeeds again\n if (updateFeedsAgain) {\n updateFeedsAgain = false;\n updateFeeds();\n }\n }, timeUntilNextUpdate);\n },\n}));\n\nlet repliesStoreInitialized = false;\nconst initializeRepliesStore = async () => {\n if (repliesStoreInitialized) {\n return;\n }\n repliesStoreInitialized = true;\n // TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommentsChange(comment)\n // subscribe to comments store changes\n repliesCommentsStore.subscribe(updateFeedsOnFeedsCommentsChange);\n // subscribe to bufferedFeedsReplyCounts change\n repliesStore.subscribe(addRepliesPagesOnLowBufferedFeedsReplyCounts);\n // subscribe to replies pages store changes\n repliesPagesStore.subscribe(updateFeedsOnFeedsRepliesPagesChange);\n // subscribe to accounts store changes\n accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);\n};\n\nlet previousRepliesPages: { [pageCid: string]: RepliesPage } = {};\nconst updateFeedsOnFeedsRepliesPagesChange = (repliesPagesStoreState: any) => {\n const { repliesPages } = repliesPagesStoreState;\n\n // no changes, do nothing\n if (repliesPages === previousRepliesPages) {\n return;\n }\n previousRepliesPages = repliesPages;\n\n // currently only the feeds use repliesPagesStore, so any change must\n // trigger a feed update, if in the future another hook uses the repliesPagesStore\n // we should check if the replies pages changed are actually used by the feeds before\n // triggering an update\n repliesStore.getState().updateFeeds();\n};\n\nlet previousBufferedFeedsReplyCountsPageCids: string[] = [];\nlet previousBufferedFeedsComments = new Map<string, Comments>();\nlet previousBufferedFeedsReplyCounts: { [feedName: string]: number } = {};\nconst addRepliesPagesOnLowBufferedFeedsReplyCounts = (repliesStoreState: any) => {\n const { bufferedFeedsReplyCounts, feedsOptions } = repliesStore.getState();\n const { comments } = repliesCommentsStore.getState();\n\n // if feeds comments have changed, we must try adding them even if buffered replies counts haven't changed\n const bufferedFeedsComments = getFeedsComments(feedsOptions, comments);\n const _feedsCommentsChanged = feedsCommentsChanged(\n previousBufferedFeedsComments,\n bufferedFeedsComments,\n );\n const bufferedFeedsReplyCountsChanged =\n previousBufferedFeedsReplyCounts !== bufferedFeedsReplyCounts;\n\n // if feeds comments havent changed and buffered replies counts also havent changed, do nothing\n if (!_feedsCommentsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsComments = bufferedFeedsComments;\n previousBufferedFeedsReplyCounts = bufferedFeedsReplyCounts;\n\n // in case feeds comments changed, but the first page cids haven't\n const bufferedFeedsReplyCountsPageCids = getFeedsCommentsFirstPageCids(bufferedFeedsComments);\n const bufferedFeedsReplyCountsPageCidsChanged =\n bufferedFeedsReplyCountsPageCids.toString() !==\n previousBufferedFeedsReplyCountsPageCids.toString();\n if (!bufferedFeedsReplyCountsPageCidsChanged && !bufferedFeedsReplyCountsChanged) {\n return;\n }\n previousBufferedFeedsReplyCountsPageCids = bufferedFeedsReplyCountsPageCids;\n\n const { addNextRepliesPageToStore } = repliesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // bufferedFeedsReplyCounts have changed, check if any of them are low\n for (const feedName in bufferedFeedsReplyCounts) {\n if (feedsOptions[feedName].onlyIfCached) {\n continue;\n }\n const account = accounts[feedsOptions[feedName].accountId];\n const feedReplyCount = bufferedFeedsReplyCounts[feedName];\n let sortType = feedsOptions[feedName].sortType;\n const commentCid = feedsOptions[feedName].commentCid;\n\n // TODO: maybe skip if comment community address, comment cid or comment author is blocked?\n\n // comment hasn't loaded yet\n if (!comments[commentCid]) {\n continue;\n }\n\n sortType = getSortTypeFromComment(comments[commentCid], feedsOptions[feedName]);\n\n // comment replies count is low, fetch next replies page\n if (feedReplyCount <= commentRepliesLeftBeforeNextPage) {\n addNextRepliesPageToStore(comments[commentCid], sortType, account).catch((error: unknown) =>\n log.error(\"repliesStore repliesPagesStore.addNextRepliesPageToStore error\", {\n commentCid,\n comment: comments[commentCid],\n sortType,\n error,\n }),\n );\n }\n }\n};\n\nlet previousFeedsCommentsFirstPageCids: string[] = [];\nlet previousFeedsComments: Map<string, Comments> = new Map();\nlet previousFeedsCommentsLoadedCount = 0;\nlet previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\nconst updateFeedsOnFeedsCommentsChange = (repliesCommentsStoreState: any) => {\n const { comments } = repliesCommentsStoreState;\n const { feedsOptions, updateFeeds } = repliesStore.getState();\n\n // feeds comments haven't changed, do nothing\n const feedsComments = getFeedsComments(feedsOptions, comments);\n if (!feedsCommentsChanged(previousFeedsComments, feedsComments)) {\n return;\n }\n previousFeedsComments = feedsComments;\n\n // decide if feeds comments have changed by looking at all feeds comments page cids\n // (in case that a comment changed, but its first page cid didn't)\n const feedsCommentsFirstPageCids = getFeedsCommentsFirstPageCids(feedsComments);\n\n // first page cids haven't changed, do nothing\n if (feedsCommentsFirstPageCids.toString() === previousFeedsCommentsFirstPageCids.toString()) {\n // if no new feed comments have loaded, do nothing\n // in case a comment loads with no first page cid and first pages cids don't change, need to trigger hasMore update\n const feedsCommentsLoadedCount = getFeedsCommentsLoadedCount(feedsComments);\n if (feedsCommentsLoadedCount === previousFeedsCommentsLoadedCount) {\n // if comment.replies.pages haven't changed, do nothing\n const feedsCommentsRepliesPagesFirstUpdatedAts =\n getFeedsCommentsRepliesPagesFirstUpdatedAts(feedsComments);\n if (\n feedsCommentsRepliesPagesFirstUpdatedAts ===\n previousFeedsCommentsRepliesPagesFirstUpdatedAts\n ) {\n return;\n }\n\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = feedsCommentsRepliesPagesFirstUpdatedAts;\n }\n previousFeedsCommentsLoadedCount = feedsCommentsLoadedCount;\n }\n\n // feeds comments have changed, update feeds\n previousFeedsCommentsFirstPageCids = feedsCommentsFirstPageCids;\n updateFeeds();\n};\n\nlet previousAccountsCommentsCount = 0;\nlet previousAccountsCommentsCids = \"\";\nconst updateFeedsOnAccountsCommentsChange = (accountsStoreState: any) => {\n const { accountsComments } = accountsStoreState;\n const accountsCommentsCount = Object.values(accountsComments as Comment[][]).reduce(\n (count, accountComments) => count + accountComments.length,\n 0,\n );\n\n // no changes, do nothing\n if (accountsCommentsCount === previousAccountsCommentsCount) {\n // if cids haven't changed (account comments receive cids after pending), do nothing\n const accountsCommentsCids = Object.values(accountsComments as Comment[][]).reduce(\n (cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || \"\")),\n \"\",\n );\n if (accountsCommentsCids === previousAccountsCommentsCids) {\n return;\n }\n previousAccountsCommentsCids = accountsCommentsCids;\n }\n previousAccountsCommentsCount = accountsCommentsCount;\n\n // TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid\n repliesStore.getState().updateFeeds();\n};\n\n// needed to view replies instantly without waiting for zustant store react rerenders. must be synchronous\nexport const getRepliesFirstPageSkipValidation = (\n comment: Comment,\n feedOptions: Partial<RepliesFeedOptions>,\n) => {\n const feedName = `firstPageSkipValidation-${comment?.cid}`;\n const feedsOptions: any = { [feedName]: feedOptions };\n const { accounts } = accountsStore.getState();\n\n // don't use comments store, only use preloaded comment.replies.pages\n const comments = { [comment.cid]: comment };\n\n // don't use any reply pages, they can't provide instant loading like preloaded comment.replies.pages\n const repliesPages = {};\n\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n comments,\n repliesPages,\n accounts,\n );\n\n // only get first page and put next page in buffered\n const bufferedFeeds: Feeds = { [feedName]: [] };\n const repliesPerPage = feedOptions.repliesPerPage || defaultRepliesPerPage;\n if (filteredSortedFeeds[feedName].length > repliesPerPage) {\n bufferedFeeds[feedName] = filteredSortedFeeds[feedName].splice(repliesPerPage);\n }\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n comments,\n repliesPages,\n accounts,\n );\n addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore);\n return { replies: filteredSortedFeeds[feedName], hasMore: feedsHaveMore[feedName] };\n};\n\n// reset store in between tests\nconst originalState = repliesStore.getState();\n// async function because some stores have async init\nexport const resetRepliesStore = async () => {\n previousBufferedFeedsReplyCounts = {};\n previousBufferedFeedsReplyCountsPageCids = [];\n previousBufferedFeedsComments = new Map();\n previousFeedsCommentsFirstPageCids = [];\n previousFeedsComments = new Map();\n previousFeedsCommentsLoadedCount = 0;\n previousFeedsCommentsRepliesPagesFirstUpdatedAts = \"\";\n previousRepliesPages = {};\n previousAccountsCommentsCount = 0;\n previousAccountsCommentsCids = \"\";\n updateFeedsPending = false;\n // destroy all component subscriptions to the store\n repliesStore.destroy();\n // restore original state\n repliesStore.setState(originalState);\n repliesCommentsStore.setState({ ...repliesCommentsStore.getState(), comments: {} });\n repliesStoreInitialized = false;\n};\n\n// reset database and store in between tests\nexport const resetRepliesDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-repliesPages\" }).clear();\n await resetRepliesStore();\n};\n\nexport default repliesStore;\n"]}
|
|
@@ -3,8 +3,16 @@ import { Feeds, RepliesFeedOptions, RepliesFeedsOptions, Comment, Comments, Acco
|
|
|
3
3
|
* Calculate the feeds from all the loaded replies pages, filter and sort them
|
|
4
4
|
*/
|
|
5
5
|
export declare const getFilteredSortedFeeds: (feedsOptions: RepliesFeedsOptions, comments: Comments, repliesPages: RepliesPages, accounts: Accounts) => Feeds;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
type GetLoadedFeedsOptions = {
|
|
7
|
+
addAccountComments?: boolean;
|
|
8
|
+
feedsHaveMore?: {
|
|
9
|
+
[feedName: string]: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const getLoadedFeeds: (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds, bufferedFeeds: Feeds, accounts: Accounts, options?: GetLoadedFeedsOptions) => Promise<Feeds>;
|
|
13
|
+
export declare const addAccountsComments: (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds, feedsHaveMore?: {
|
|
14
|
+
[feedName: string]: boolean;
|
|
15
|
+
}) => boolean;
|
|
8
16
|
export declare const getBufferedFeedsWithoutLoadedFeeds: (bufferedFeeds: Feeds, loadedFeeds: Feeds) => Feeds;
|
|
9
17
|
export declare const getUpdatedFeeds: (feedsOptions: RepliesFeedsOptions, filteredSortedFeeds: Feeds, updatedFeeds: Feeds, loadedFeeds: Feeds, accounts: Accounts) => Promise<Feeds>;
|
|
10
18
|
export declare const getFeedsReplyCounts: (feedsOptions: RepliesFeedsOptions, feeds: Feeds) => {
|
|
@@ -22,4 +30,5 @@ export declare const getFeedsCommentsFirstPageCids: (feedsComments: Map<string,
|
|
|
22
30
|
export declare const getFeedsCommentsRepliesPagesFirstUpdatedAts: (feedsComments: Map<string, Comment>) => string;
|
|
23
31
|
export declare const getFeedsCommentsLoadedCount: (feedsComments: Map<string, Comment>) => number;
|
|
24
32
|
export declare const getSortTypeFromComment: (comment: Comment, feedOptions: RepliesFeedOptions) => string;
|
|
33
|
+
export {};
|
|
25
34
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/replies/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,EACL,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,QAAQ,EAER,QAAQ,EAER,YAAY,EACb,MAAM,aAAa,CAAC;AASrB;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,cAAc,mBAAmB,EACjC,UAAU,QAAQ,EAClB,cAAc,YAAY,EAC1B,UAAU,QAAQ,UAmEnB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/replies/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,EACL,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,QAAQ,EAER,QAAQ,EAER,YAAY,EACb,MA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M,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"}
|
|
@@ -132,7 +132,15 @@ const getApprovalPublicationKey = (comment) => {
|
|
|
132
132
|
(_j = comment.link) !== null && _j !== void 0 ? _j : "",
|
|
133
133
|
].join("\0");
|
|
134
134
|
};
|
|
135
|
-
|
|
135
|
+
const isActivePublishingState = (publishingState) => publishingState === "pending" ||
|
|
136
|
+
(publishingState === null || publishingState === void 0 ? void 0 : publishingState.startsWith("publishing")) ||
|
|
137
|
+
(publishingState === null || publishingState === void 0 ? void 0 : publishingState.startsWith("waiting-")) ||
|
|
138
|
+
(publishingState === null || publishingState === void 0 ? void 0 : publishingState.startsWith("fetching-link-dimensions"));
|
|
139
|
+
const isPublishedAccountReply = (reply) => typeof (reply === null || reply === void 0 ? void 0 : reply.index) === "number" &&
|
|
140
|
+
!!reply.cid &&
|
|
141
|
+
reply.pendingApproval !== true &&
|
|
142
|
+
!isActivePublishingState(reply.publishingState);
|
|
143
|
+
export const getLoadedFeeds = (feedsOptions_1, loadedFeeds_1, bufferedFeeds_1, accounts_1, ...args_1) => __awaiter(void 0, [feedsOptions_1, loadedFeeds_1, bufferedFeeds_1, accounts_1, ...args_1], void 0, function* (feedsOptions, loadedFeeds, bufferedFeeds, accounts, options = {}) {
|
|
136
144
|
var _a;
|
|
137
145
|
const loadedFeedsMissingReplies = {};
|
|
138
146
|
for (const feedName in feedsOptions) {
|
|
@@ -177,14 +185,16 @@ export const getLoadedFeeds = (feedsOptions, loadedFeeds, bufferedFeeds, account
|
|
|
177
185
|
}
|
|
178
186
|
// add account comments
|
|
179
187
|
newLoadedFeeds = Object.assign(Object.assign({}, loadedFeeds), newLoadedFeeds);
|
|
180
|
-
const accountCommentsChangedFeeds =
|
|
188
|
+
const accountCommentsChangedFeeds = options.addAccountComments === false
|
|
189
|
+
? false
|
|
190
|
+
: addAccountsComments(feedsOptions, newLoadedFeeds, options.feedsHaveMore);
|
|
181
191
|
// do nothing if there are no missing replies
|
|
182
192
|
if (Object.keys(loadedFeedsMissingReplies).length === 0 && !accountCommentsChangedFeeds) {
|
|
183
193
|
return loadedFeeds;
|
|
184
194
|
}
|
|
185
195
|
return newLoadedFeeds;
|
|
186
196
|
});
|
|
187
|
-
export const addAccountsComments = (feedsOptions, loadedFeeds) => {
|
|
197
|
+
export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore) => {
|
|
188
198
|
let loadedFeedsChanged = false;
|
|
189
199
|
const accountsComments = accountsStore.getState().accountsComments || {};
|
|
190
200
|
for (const feedName in feedsOptions) {
|
|
@@ -195,8 +205,12 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
|
|
|
195
205
|
}
|
|
196
206
|
const newerThanTimestamp = newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;
|
|
197
207
|
const isNewerThan = (reply) => reply.timestamp > newerThanTimestamp;
|
|
208
|
+
const hidePublishedAccountReplies = (feedsHaveMore === null || feedsHaveMore === void 0 ? void 0 : feedsHaveMore[feedName]) === false;
|
|
198
209
|
const accountComments = accountsComments[accountId] || [];
|
|
199
210
|
const accountReplies = accountComments.filter((reply) => {
|
|
211
|
+
if (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
200
214
|
if (!isNewerThan(reply)) {
|
|
201
215
|
return false;
|
|
202
216
|
}
|
|
@@ -223,12 +237,12 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
|
|
|
223
237
|
prunedLoadedFeed.push(reply);
|
|
224
238
|
continue;
|
|
225
239
|
}
|
|
226
|
-
if (
|
|
227
|
-
approvedPublicationKeys.has(getApprovalPublicationKey(reply))) {
|
|
240
|
+
if (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {
|
|
228
241
|
loadedFeedsChanged = true;
|
|
229
242
|
continue;
|
|
230
243
|
}
|
|
231
|
-
if (
|
|
244
|
+
if (reply.pendingApproval === true &&
|
|
245
|
+
approvedPublicationKeys.has(getApprovalPublicationKey(reply))) {
|
|
232
246
|
loadedFeedsChanged = true;
|
|
233
247
|
continue;
|
|
234
248
|
}
|
|
@@ -240,6 +254,10 @@ export const addAccountsComments = (feedsOptions, loadedFeeds) => {
|
|
|
240
254
|
continue;
|
|
241
255
|
}
|
|
242
256
|
}
|
|
257
|
+
if (!validAccountIndices.has(reply.index)) {
|
|
258
|
+
loadedFeedsChanged = true;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
243
261
|
prunedLoadedFeed.push(reply);
|
|
244
262
|
}
|
|
245
263
|
loadedFeed = loadedFeeds[feedName] = prunedLoadedFeed;
|
|
@@ -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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QAAQ,GAAG,SAAS,CAAC;IACvB,CAAC;IAED,qCAAqC;SAChC,IACH,QAAQ,KAAK,SAAS;QACtB,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,KAAK,0CAAE,OAAO,CAAA;QAChC,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,QAAQ,0CAAE,OAAO,CAAA;QACnC,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,KAAK,0CAAE,GAAG,MAAI,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,QAAQ,0CAAE,GAAG,CAAA,CAAC,EAC/D,CAAC;QACD,QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,qCAAqC;SAChC,IACH,QAAQ,KAAK,SAAS;QACtB,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,KAAK,0CAAE,OAAO,CAAA;QAChC,CAAC,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\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"]}
|
|
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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AE,OAAO,CAAA,CAAC,EACvE,CAAC;QACD,QAAQ,GAAG,SAAS,CAAC;IACvB,CAAC;IAED,qCAAqC;SAChC,IACH,QAAQ,KAAK,SAAS;QACtB,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,KAAK,0CAAE,OAAO,CAAA;QAChC,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,QAAQ,0CAAE,OAAO,CAAA;QACnC,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,KAAK,0CAAE,GAAG,MAAI,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,QAAQ,0CAAE,GAAG,CAAA,CAAC,EAC/D,CAAC;QACD,QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,qCAAqC;SAChC,IACH,QAAQ,KAAK,SAAS;QACtB,CAAC,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,KAAK,0CAAE,OAAO,CAAA;QAChC,CAAC,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\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\nconst isActivePublishingState = (publishingState?: string) =>\n publishingState === \"pending\" ||\n publishingState?.startsWith(\"publishing\") ||\n publishingState?.startsWith(\"waiting-\") ||\n publishingState?.startsWith(\"fetching-link-dimensions\");\n\nconst isPublishedAccountReply = (reply: Comment) =>\n typeof reply?.index === \"number\" &&\n !!reply.cid &&\n reply.pendingApproval !== true &&\n !isActivePublishingState(reply.publishingState);\n\ntype GetLoadedFeedsOptions = {\n addAccountComments?: boolean;\n feedsHaveMore?: { [feedName: string]: boolean };\n};\n\nexport const getLoadedFeeds = async (\n feedsOptions: RepliesFeedsOptions,\n loadedFeeds: Feeds,\n bufferedFeeds: Feeds,\n accounts: Accounts,\n options: GetLoadedFeedsOptions = {},\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 =\n options.addAccountComments === false\n ? false\n : addAccountsComments(feedsOptions, newLoadedFeeds, options.feedsHaveMore);\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 = (\n feedsOptions: RepliesFeedsOptions,\n loadedFeeds: Feeds,\n feedsHaveMore?: { [feedName: string]: boolean },\n) => {\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 const hidePublishedAccountReplies = feedsHaveMore?.[feedName] === false;\n\n const accountComments = accountsComments[accountId] || [];\n const accountReplies = accountComments.filter((reply) => {\n if (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {\n return false;\n }\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 (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {\n loadedFeedsChanged = true;\n continue;\n }\n if (\n reply.pendingApproval === true &&\n approvedPublicationKeys.has(getApprovalPublicationKey(reply))\n ) {\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 if (!validAccountIndices.has(reply.index)) {\n loadedFeedsChanged = true;\n continue;\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,9 +13,10 @@
|
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.5",
|
|
17
17
|
"packageManager": "yarn@4.13.0",
|
|
18
18
|
"files": [
|
|
19
|
+
"CHANGELOG.md",
|
|
19
20
|
"dist"
|
|
20
21
|
],
|
|
21
22
|
"main": "dist/index.js",
|
|
@@ -41,7 +42,8 @@
|
|
|
41
42
|
"lint": "oxlint src/**/*.{js,ts,tsx}",
|
|
42
43
|
"prettier": "oxfmt src/**/*.{js,ts,tsx} test/**/*.{js,ts,tsx} config/**/*.{js,ts,tsx}",
|
|
43
44
|
"type-check": "node ./node_modules/typescript/bin/tsc --noEmit --project config/tsconfig.json",
|
|
44
|
-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
|
|
45
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
46
|
+
"changelog:release-notes": "node scripts/changelog-release-notes.mjs"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
47
49
|
"@bitsocial/bso-resolver": "0.0.6",
|