@bitsocial/bitsocial-react-hooks 0.1.5 → 0.1.6

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 CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.1.6](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.5...v0.1.6) (2026-05-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** resolve axios dependabot alerts ([f05eac0](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/f05eac02887067fe1413d39aa7fbe21b593c01aa))
7
+ * **deps:** resolve dependabot alerts ([805ac34](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/805ac34b43cbf139c2ff8d479450a45338070ec9))
8
+ * **replies:** keep newly published account replies visible ([96ab074](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/96ab074a85222b838cc71c8c091aae2ece6039da))
9
+ * **tests:** stop account hook suite OOM ([1e217d6](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/1e217d6a11008cdd25b83ed0ef2d3e7d5c95e537))
10
+
11
+
12
+
1
13
  ## [0.1.5](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.4...v0.1.5) (2026-05-02)
2
14
 
3
15
 
package/README.md CHANGED
@@ -1019,8 +1019,8 @@ 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
1022
+ // published account replies are kept in useReplies until the canonical replies
1023
+ // feed refreshes past the reply timestamp; after that exhausted feed, account-only
1024
1024
  // published replies are hidden unless the canonical feed includes their cid
1025
1025
  ```
1026
1026
 
@@ -1302,8 +1302,9 @@ const useRepliesOptions = {
1302
1302
  accountComments: { newerThan: Infinity, append: false },
1303
1303
  };
1304
1304
 
1305
- // accountComments keeps pending local replies visible, but published account
1306
- // replies must resolve through the canonical replies feed after it is exhausted
1305
+ // accountComments keeps pending and just-published local replies visible, but
1306
+ // published account replies must resolve through the canonical replies feed
1307
+ // after that feed refreshes past them and is exhausted
1307
1308
 
1308
1309
  const Reply = ({ reply, updatedReply }) => {
1309
1310
  const { replies, updatedReplies, bufferedReplies, hasMore, loadMore } = useReplies({
@@ -1,6 +1,8 @@
1
- declare function renderHook<Result, Props>(callback: (props: Props) => Result, options?: {
1
+ type RenderHookOptions<Props> = {
2
2
  initialProps?: Props;
3
- }): {
3
+ trackHistory?: boolean;
4
+ };
5
+ declare function renderHook<Result, Props>(callback: (props: Props) => Result, options?: RenderHookOptions<Props>): {
4
6
  result: {
5
7
  current: Result | null;
6
8
  all: Result[];
@@ -22,7 +24,14 @@ declare const testUtils: {
22
24
  resetStores: () => Promise<void>;
23
25
  resetDatabasesAndStores: () => Promise<void>;
24
26
  createWaitFor: (rendered: any, waitForOptions?: WaitForOptions) => (waitForFunction: Function) => Promise<void>;
25
- renderHookWithHistory: typeof renderHook;
27
+ renderHookWithHistory: <Result, Props>(callback: (props: Props) => Result, options?: RenderHookOptions<Props>) => {
28
+ result: {
29
+ current: Result | null;
30
+ all: Result[];
31
+ };
32
+ rerender: (rerenderCallbackProps: Props) => void;
33
+ unmount: () => void;
34
+ };
26
35
  silenceWaitForWarning: boolean;
27
36
  };
28
37
  export default testUtils;
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/lib/test-utils.ts"],"names":[],"mappings":"AAqBA,iBAAS,UAAU,CAAC,MAAM,EAAE,KAAK,EAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,EAClC,OAAO,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,KAAK,CAAA;CAAE;;iBAGA,MAAM,GAAG,IAAI;aAAa,MAAM,EAAE;;sCAc3B,KAAK;;EAO/C;AA6DD,KAAK,cAAc,GAAG;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAsEF,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,QAAA,MAAM,SAAS;;;;;;;;8BAvEkB,GAAG,mBAAmB,cAAc,uBAI3B,QAAQ;;;CA+EjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/lib/test-utils.ts"],"names":[],"mappings":"AAiBA,KAAK,iBAAiB,CAAC,KAAK,IAAI;IAC9B,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAMF,iBAAS,UAAU,CAAC,MAAM,EAAE,KAAK,EAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,EAClC,OAAO,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC;;iBAGA,MAAM,GAAG,IAAI;aAAa,MAAM,EAAE;;sCAgB3B,KAAK;;EAO/C;AA6DD,KAAK,cAAc,GAAG;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAuEF,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,QAAA,MAAM,SAAS;;;;;;;;8BAxEkB,GAAG,mBAAmB,cAAc,uBAI3B,QAAQ;4BA6DnB,MAAM,EAAE,KAAK,YAChC,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,YACxB,iBAAiB,CAAC,KAAK,CAAC;;;;;;;;;CAiBnC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -33,12 +33,14 @@ import { resetRepliesPagesStore, resetRepliesPagesDatabaseAndStore } from "../st
33
33
  // result.current via useEffect, which breaks polling-based waitFor patterns
34
34
  // when Zustand store updates trigger re-renders outside act().
35
35
  function renderHook(callback, options) {
36
- const _a = options || {}, { initialProps } = _a, renderOptions = __rest(_a, ["initialProps"]);
36
+ const _a = options || {}, { initialProps, trackHistory = false } = _a, renderOptions = __rest(_a, ["initialProps", "trackHistory"]);
37
37
  const result = { current: null, all: [] };
38
38
  function TestComponent({ renderCallbackProps }) {
39
39
  const pendingResult = callback(renderCallbackProps);
40
40
  result.current = pendingResult;
41
- result.all.push(pendingResult);
41
+ if (trackHistory) {
42
+ result.all.push(pendingResult);
43
+ }
42
44
  return null;
43
45
  }
44
46
  const { rerender: baseRerender, unmount } = render(React.createElement(TestComponent, { renderCallbackProps: initialProps }), renderOptions);
@@ -163,9 +165,7 @@ const resetDatabasesAndStores = () => __awaiter(void 0, void 0, void 0, function
163
165
  // always accounts last because it has async initialization
164
166
  yield resetAccountsDatabaseAndStore();
165
167
  });
166
- // renderHookWithHistory is kept for backward compatibility but our custom
167
- // renderHook already tracks result.all, so this is just a passthrough.
168
- const renderHookWithHistory = renderHook;
168
+ const renderHookWithHistory = (callback, options) => renderHook(callback, Object.assign(Object.assign({}, options), { trackHistory: true }));
169
169
  export { renderHook };
170
170
  const testUtils = {
171
171
  silenceTestWasNotWrappedInActWarning,
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/lib/test-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EACL,0BAA0B,EAC1B,qCAAqC,GACtC,MAAM,6BAA6B,CAAC;AACrC,OA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AAuB,GAAG,GAAS,EAAE;IACzC,MAAM,iCAAiC,EAAE,CAAC;IAC1C,MAAM,4BAA4B,EAAE,CAAC;IACrC,MAAM,oCAAoC,EAAE,CAAC;IAC7C,MAAM,qCAAqC,EAAE,CAAC;IAC9C,MAAM,0BAA0B,EAAE,CAAC;IACnC,MAAM,gCAAgC,EAAE,CAAC;IACzC,MAAM,6BAA6B,EAAE,CAAC;IACtC,2DAA2D;IAC3D,MAAM,6BAA6B,EAAE,CAAC;AACxC,CAAC,CAAA,CAAC;AAEF,0EAA0E;AAC1E,uEAAuE;AACvE,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,SAAS,GAAG;IAChB,oCAAoC;IACpC,sCAAsC;IACtC,4BAA4B;IAC5B,oBAAoB;IACpB,UAAU;IACV,WAAW;IACX,uBAAuB;IACvB,aAAa;IACb,qBAAqB;IACrB,4DAA4D;IAC5D,qBAAqB,EAAE,KAAK;CAC7B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { render, act as tlAct } from \"@testing-library/react\";\nimport React from \"react\";\nimport { resetCommentsStore, resetCommentsDatabaseAndStore } from \"../stores/comments\";\nimport { resetCommunitiesStore, resetCommunitiesDatabaseAndStore } from \"../stores/communities\";\nimport { resetAccountsStore, resetAccountsDatabaseAndStore } from \"../stores/accounts\";\nimport { resetFeedsStore, resetFeedsDatabaseAndStore } from \"../stores/feeds\";\nimport {\n resetCommunitiesPagesStore,\n resetCommunitiesPagesDatabaseAndStore,\n} from \"../stores/communities-pages\";\nimport {\n resetAuthorsCommentsStore,\n resetAuthorsCommentsDatabaseAndStore,\n} from \"../stores/authors-comments\";\nimport { resetRepliesStore, resetRepliesDatabaseAndStore } from \"../stores/replies\";\nimport { resetRepliesPagesStore, resetRepliesPagesDatabaseAndStore } from \"../stores/replies-pages\";\n\n// Custom renderHook that sets result.current synchronously during render,\n// matching @testing-library/react-hooks behavior. RTL v16's renderHook defers\n// result.current via useEffect, which breaks polling-based waitFor patterns\n// when Zustand store updates trigger re-renders outside act().\nfunction renderHook<Result, Props>(\n callback: (props: Props) => Result,\n options?: { initialProps?: Props },\n) {\n const { initialProps, ...renderOptions } = options || {};\n const result = { current: null as Result | null, all: [] as Result[] };\n\n function TestComponent({ renderCallbackProps }: { renderCallbackProps: Props }) {\n const pendingResult = callback(renderCallbackProps);\n result.current = pendingResult;\n result.all.push(pendingResult);\n return null;\n }\n\n const { rerender: baseRerender, unmount } = render(\n React.createElement(TestComponent, { renderCallbackProps: initialProps as Props }),\n renderOptions as any,\n );\n\n function rerender(rerenderCallbackProps: Props) {\n return baseRerender(\n React.createElement(TestComponent, { renderCallbackProps: rerenderCallbackProps }),\n );\n }\n\n return { result, rerender, unmount };\n}\n\nconst restorables: any = [];\n\nconst silenceUpdateUnmountedComponentWarning = () => {\n const originalError = console.error;\n console.error = (...args) => {\n if (/Can't perform a React state update on an unmounted component/.test(args[0])) {\n return;\n }\n originalError.call(console, ...args);\n };\n const restore = () => {\n console.error = originalError;\n };\n restorables.push(restore);\n return restore;\n};\n\nconst silenceTestWasNotWrappedInActWarning = () => {\n const originalError = console.error;\n console.error = (...args) => {\n if (/inside a test was not wrapped in act/.test(args[0])) {\n return;\n }\n originalError.call(console, ...args);\n };\n const restore = () => {\n console.error = originalError;\n };\n restorables.push(restore);\n return restore;\n};\n\n// this warning is usually good to have, so don't include it in silenceReactWarnings\nconst silenceOverlappingActWarning = () => {\n const originalError = console.error;\n console.error = (...args) => {\n if (/overlapping act\\(\\) calls/.test(args[0])) {\n return;\n }\n originalError.call(console, ...args);\n };\n const restore = () => {\n console.error = originalError;\n };\n restorables.push(restore);\n return restore;\n};\n\nconst silenceReactWarnings = () => {\n silenceUpdateUnmountedComponentWarning();\n silenceTestWasNotWrappedInActWarning();\n};\n\nconst restoreAll = () => {\n for (const restore of restorables) {\n restore();\n }\n};\n\ntype WaitForOptions = {\n timeout?: number;\n interval?: number;\n};\nconst createWaitFor = (rendered: any, waitForOptions?: WaitForOptions) => {\n if (!rendered?.result) {\n throw Error(`createWaitFor invalid 'rendered' argument`);\n }\n const waitFor = async (waitForFunction: Function) => {\n const stackTraceLimit = Error.stackTraceLimit;\n Error.stackTraceLimit = 10;\n const errorWithUsefulStackTrace = new Error(\"waitFor\");\n Error.stackTraceLimit = stackTraceLimit;\n\n if (typeof waitForFunction !== \"function\") {\n throw Error(`waitFor invalid 'waitForFunction' argument`);\n }\n // @ts-ignore\n if (typeof waitForFunction.then === \"function\") {\n throw Error(`waitFor 'waitForFunction' can't be async`);\n }\n const { timeout = 2000, interval = 50 } = waitForOptions || {};\n const start = Date.now();\n while (true) {\n // flush pending React/Zustand state updates before each check\n await tlAct(async () => {});\n try {\n if (waitForFunction()) return;\n } catch {\n // condition threw (e.g. accessing property on undefined), keep waiting\n }\n if (Date.now() - start >= timeout) {\n errorWithUsefulStackTrace.message = `Timed out in waitFor after ${timeout}ms. ${waitForFunction.toString()}`;\n if (!testUtils.silenceWaitForWarning) {\n console.warn(errorWithUsefulStackTrace);\n }\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n };\n return waitFor;\n};\n\n// always reset the least important store first, because a store even can affect another store\nconst resetStores = async () => {\n await resetRepliesPagesStore();\n await resetRepliesStore();\n await resetAuthorsCommentsStore();\n await resetCommunitiesPagesStore();\n await resetFeedsStore();\n await resetCommunitiesStore();\n await resetCommentsStore();\n // always accounts last because it has async initialization\n await resetAccountsStore();\n};\n\nconst resetDatabasesAndStores = async () => {\n await resetRepliesPagesDatabaseAndStore();\n await resetRepliesDatabaseAndStore();\n await resetAuthorsCommentsDatabaseAndStore();\n await resetCommunitiesPagesDatabaseAndStore();\n await resetFeedsDatabaseAndStore();\n await resetCommunitiesDatabaseAndStore();\n await resetCommentsDatabaseAndStore();\n // always accounts last because it has async initialization\n await resetAccountsDatabaseAndStore();\n};\n\n// renderHookWithHistory is kept for backward compatibility but our custom\n// renderHook already tracks result.all, so this is just a passthrough.\nconst renderHookWithHistory = renderHook;\n\nexport { renderHook };\n\nconst testUtils = {\n silenceTestWasNotWrappedInActWarning,\n silenceUpdateUnmountedComponentWarning,\n silenceOverlappingActWarning,\n silenceReactWarnings,\n restoreAll,\n resetStores,\n resetDatabasesAndStores,\n createWaitFor,\n renderHookWithHistory,\n // can be useful to silence warnings in tests that use retry\n silenceWaitForWarning: false,\n};\n\nexport default testUtils;\n"]}
1
+ {"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/lib/test-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EACL,0BAA0B,EAC1B,qCAAqC,GACtC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,yBAAyB,EACzB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,sBAAsB,EAAE,iCAAiC,EAAE,MAAM,yBAAyB,CAAC;AAOpG,0EAA0E;AAC1E,8EAA8E;AAC9E,4EAA4E;AAC5E,+DAA+D;AAC/D,SAAS,UAAU,CACjB,QAAkC,EAClC,OAAkC;IAElC,MAAM,KAA2D,OAAO,IAAI,EAAE,EAAxE,EAAE,YAAY,EAAE,YAAY,GAAG,KAAK,OAAoC,EAA/B,aAAa,cAAtD,gCA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GAAG,CAC5B,QAAkC,EAClC,OAAkC,EAClC,EAAE,CAAC,UAAU,CAAC,QAAQ,kCAAO,OAAO,KAAE,YAAY,EAAE,IAAI,IAAG,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,SAAS,GAAG;IAChB,oCAAoC;IACpC,sCAAsC;IACtC,4BAA4B;IAC5B,oBAAoB;IACpB,UAAU;IACV,WAAW;IACX,uBAAuB;IACvB,aAAa;IACb,qBAAqB;IACrB,4DAA4D;IAC5D,qBAAqB,EAAE,KAAK;CAC7B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import { render, act as tlAct } from \"@testing-library/react\";\nimport React from \"react\";\nimport { resetCommentsStore, resetCommentsDatabaseAndStore } from \"../stores/comments\";\nimport { resetCommunitiesStore, resetCommunitiesDatabaseAndStore } from \"../stores/communities\";\nimport { resetAccountsStore, resetAccountsDatabaseAndStore } from \"../stores/accounts\";\nimport { resetFeedsStore, resetFeedsDatabaseAndStore } from \"../stores/feeds\";\nimport {\n resetCommunitiesPagesStore,\n resetCommunitiesPagesDatabaseAndStore,\n} from \"../stores/communities-pages\";\nimport {\n resetAuthorsCommentsStore,\n resetAuthorsCommentsDatabaseAndStore,\n} from \"../stores/authors-comments\";\nimport { resetRepliesStore, resetRepliesDatabaseAndStore } from \"../stores/replies\";\nimport { resetRepliesPagesStore, resetRepliesPagesDatabaseAndStore } from \"../stores/replies-pages\";\n\ntype RenderHookOptions<Props> = {\n initialProps?: Props;\n trackHistory?: boolean;\n};\n\n// Custom renderHook that sets result.current synchronously during render,\n// matching @testing-library/react-hooks behavior. RTL v16's renderHook defers\n// result.current via useEffect, which breaks polling-based waitFor patterns\n// when Zustand store updates trigger re-renders outside act().\nfunction renderHook<Result, Props>(\n callback: (props: Props) => Result,\n options?: RenderHookOptions<Props>,\n) {\n const { initialProps, trackHistory = false, ...renderOptions } = options || {};\n const result = { current: null as Result | null, all: [] as Result[] };\n\n function TestComponent({ renderCallbackProps }: { renderCallbackProps: Props }) {\n const pendingResult = callback(renderCallbackProps);\n result.current = pendingResult;\n if (trackHistory) {\n result.all.push(pendingResult);\n }\n return null;\n }\n\n const { rerender: baseRerender, unmount } = render(\n React.createElement(TestComponent, { renderCallbackProps: initialProps as Props }),\n renderOptions as any,\n );\n\n function rerender(rerenderCallbackProps: Props) {\n return baseRerender(\n React.createElement(TestComponent, { renderCallbackProps: rerenderCallbackProps }),\n );\n }\n\n return { result, rerender, unmount };\n}\n\nconst restorables: any = [];\n\nconst silenceUpdateUnmountedComponentWarning = () => {\n const originalError = console.error;\n console.error = (...args) => {\n if (/Can't perform a React state update on an unmounted component/.test(args[0])) {\n return;\n }\n originalError.call(console, ...args);\n };\n const restore = () => {\n console.error = originalError;\n };\n restorables.push(restore);\n return restore;\n};\n\nconst silenceTestWasNotWrappedInActWarning = () => {\n const originalError = console.error;\n console.error = (...args) => {\n if (/inside a test was not wrapped in act/.test(args[0])) {\n return;\n }\n originalError.call(console, ...args);\n };\n const restore = () => {\n console.error = originalError;\n };\n restorables.push(restore);\n return restore;\n};\n\n// this warning is usually good to have, so don't include it in silenceReactWarnings\nconst silenceOverlappingActWarning = () => {\n const originalError = console.error;\n console.error = (...args) => {\n if (/overlapping act\\(\\) calls/.test(args[0])) {\n return;\n }\n originalError.call(console, ...args);\n };\n const restore = () => {\n console.error = originalError;\n };\n restorables.push(restore);\n return restore;\n};\n\nconst silenceReactWarnings = () => {\n silenceUpdateUnmountedComponentWarning();\n silenceTestWasNotWrappedInActWarning();\n};\n\nconst restoreAll = () => {\n for (const restore of restorables) {\n restore();\n }\n};\n\ntype WaitForOptions = {\n timeout?: number;\n interval?: number;\n};\nconst createWaitFor = (rendered: any, waitForOptions?: WaitForOptions) => {\n if (!rendered?.result) {\n throw Error(`createWaitFor invalid 'rendered' argument`);\n }\n const waitFor = async (waitForFunction: Function) => {\n const stackTraceLimit = Error.stackTraceLimit;\n Error.stackTraceLimit = 10;\n const errorWithUsefulStackTrace = new Error(\"waitFor\");\n Error.stackTraceLimit = stackTraceLimit;\n\n if (typeof waitForFunction !== \"function\") {\n throw Error(`waitFor invalid 'waitForFunction' argument`);\n }\n // @ts-ignore\n if (typeof waitForFunction.then === \"function\") {\n throw Error(`waitFor 'waitForFunction' can't be async`);\n }\n const { timeout = 2000, interval = 50 } = waitForOptions || {};\n const start = Date.now();\n while (true) {\n // flush pending React/Zustand state updates before each check\n await tlAct(async () => {});\n try {\n if (waitForFunction()) return;\n } catch {\n // condition threw (e.g. accessing property on undefined), keep waiting\n }\n if (Date.now() - start >= timeout) {\n errorWithUsefulStackTrace.message = `Timed out in waitFor after ${timeout}ms. ${waitForFunction.toString()}`;\n if (!testUtils.silenceWaitForWarning) {\n console.warn(errorWithUsefulStackTrace);\n }\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n };\n return waitFor;\n};\n\n// always reset the least important store first, because a store even can affect another store\nconst resetStores = async () => {\n await resetRepliesPagesStore();\n await resetRepliesStore();\n await resetAuthorsCommentsStore();\n await resetCommunitiesPagesStore();\n await resetFeedsStore();\n await resetCommunitiesStore();\n await resetCommentsStore();\n // always accounts last because it has async initialization\n await resetAccountsStore();\n};\n\nconst resetDatabasesAndStores = async () => {\n await resetRepliesPagesDatabaseAndStore();\n await resetRepliesDatabaseAndStore();\n await resetAuthorsCommentsDatabaseAndStore();\n await resetCommunitiesPagesDatabaseAndStore();\n await resetFeedsDatabaseAndStore();\n await resetCommunitiesDatabaseAndStore();\n await resetCommentsDatabaseAndStore();\n // always accounts last because it has async initialization\n await resetAccountsDatabaseAndStore();\n};\n\nconst renderHookWithHistory = <Result, Props>(\n callback: (props: Props) => Result,\n options?: RenderHookOptions<Props>,\n) => renderHook(callback, { ...options, trackHistory: true });\n\nexport { renderHook };\n\nconst testUtils = {\n silenceTestWasNotWrappedInActWarning,\n silenceUpdateUnmountedComponentWarning,\n silenceOverlappingActWarning,\n silenceReactWarnings,\n restoreAll,\n resetStores,\n resetDatabasesAndStores,\n createWaitFor,\n renderHookWithHistory,\n // can be useful to silence warnings in tests that use retry\n silenceWaitForWarning: false,\n};\n\nexport default testUtils;\n"]}
@@ -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,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"}
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;AAeF,QAAA,MAAM,YAAY,2EA2Sf,CAAC;AAkLJ,eAAO,MAAM,iCAAiC,GAC5C,SAAS,OAAO,EAChB,aAAa,OAAO,CAAC,kBAAkB,CAAC;;;CAoCzC,CAAC;AAKF,eAAO,MAAM,iBAAiB,qBAkB7B,CAAC;AAGF,eAAO,MAAM,4BAA4B,qBAGxC,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -39,6 +39,14 @@ export const feedOptionsToFeedName = (feedOptions) => {
39
39
  feedOptions = addDefaultFeedOptions(feedOptions);
40
40
  return `${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.accountId}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.commentCid}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.postCid}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.sortType}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.flat}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.onlyIfCached}-${(_a = feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.accountComments) === null || _a === void 0 ? void 0 : _a.newerThan}-${(_b = feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.accountComments) === null || _b === void 0 ? void 0 : _b.append}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.repliesPerPage}-${(_c = feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.filter) === null || _c === void 0 ? void 0 : _c.key}-${feedOptions === null || feedOptions === void 0 ? void 0 : feedOptions.streamPage}`;
41
41
  };
42
+ const getFeedsUpdatedAts = (feedsOptions, comments) => {
43
+ var _a;
44
+ const feedsUpdatedAts = {};
45
+ for (const feedName in feedsOptions) {
46
+ feedsUpdatedAts[feedName] = (_a = comments[feedsOptions[feedName].commentCid]) === null || _a === void 0 ? void 0 : _a.updatedAt;
47
+ }
48
+ return feedsUpdatedAts;
49
+ };
42
50
  // don't updateFeeds more than once per updateFeedsMinIntervalTime
43
51
  let updateFeedsPending = false;
44
52
  let updateFeedsAgain = false;
@@ -196,8 +204,9 @@ const repliesStore = createStore((setState, getState) => ({
196
204
  const canonicalLoadedFeeds = yield getLoadedFeeds(feedsOptions, previousState.loadedFeeds, bufferedFeedsWithoutPreviousLoadedFeeds, accounts, { addAccountComments: false });
197
205
  const canonicalBufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(bufferedFeedsWithoutPreviousLoadedFeeds, canonicalLoadedFeeds);
198
206
  const canonicalFeedsHaveMore = getFeedsHaveMore(feedsOptions, canonicalBufferedFeeds, comments, repliesPages, accounts);
207
+ const canonicalFeedsUpdatedAts = getFeedsUpdatedAts(feedsOptions, comments);
199
208
  const loadedFeedsWithAccountComments = Object.assign({}, canonicalLoadedFeeds);
200
- const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, loadedFeedsWithAccountComments, canonicalFeedsHaveMore);
209
+ const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, loadedFeedsWithAccountComments, canonicalFeedsHaveMore, canonicalFeedsUpdatedAts);
201
210
  const loadedFeeds = accountCommentsChangedFeeds
202
211
  ? loadedFeedsWithAccountComments
203
212
  : canonicalLoadedFeeds;
@@ -386,7 +395,9 @@ export const getRepliesFirstPageSkipValidation = (comment, feedOptions) => {
386
395
  bufferedFeeds[feedName] = filteredSortedFeeds[feedName].splice(repliesPerPage);
387
396
  }
388
397
  const feedsHaveMore = getFeedsHaveMore(feedsOptions, bufferedFeeds, comments, repliesPages, accounts);
389
- addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore);
398
+ addAccountsComments(feedsOptions, filteredSortedFeeds, feedsHaveMore, {
399
+ [feedName]: comment.updatedAt,
400
+ });
390
401
  return { replies: filteredSortedFeeds[feedName], hasMore: feedsHaveMore[feedName] };
391
402
  };
392
403
  // 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,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAY3D,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,6BAA6B,EAC7B,cAAc,EACd,kCAAkC,EAClC,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,2BAA2B,EAC3B,2CAA2C,EAC3C,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,SAAS,CAAC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kc-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"]}
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,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAY3D,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,6BAA6B,EAC7B,cAAc,EACd,kCAAkC,EAClC,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,2BAA2B,EAC3B,2CAA2C,EAC3C,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAEjB,+CAA+C;AAC/C,2BAA2B;AAC3B,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC,kDAAkD;AAClD,MAAM,gCAAgC,GAAG,EAAE,CAAC;AAgB5C,MAAM,sBAAsB,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACtE,MAAM,qBAAqB,GAAG,CAAC,WAAgB,EAAE,EAAE;IACjD,WAAW,qBAAQ,WAAW,CAAE,CAAC;IACjC,IAAI,WAAW,CAAC,IAAI,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAChE,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e,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\nconst getFeedsUpdatedAts = (feedsOptions: RepliesFeedsOptions, comments: Comments) => {\n const feedsUpdatedAts: { [feedName: string]: number | undefined } = {};\n for (const feedName in feedsOptions) {\n feedsUpdatedAts[feedName] = comments[feedsOptions[feedName].commentCid]?.updatedAt;\n }\n return feedsUpdatedAts;\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 canonicalFeedsUpdatedAts = getFeedsUpdatedAts(feedsOptions, comments);\n const loadedFeedsWithAccountComments = { ...canonicalLoadedFeeds };\n const accountCommentsChangedFeeds = addAccountsComments(\n feedsOptions,\n loadedFeedsWithAccountComments,\n canonicalFeedsHaveMore,\n canonicalFeedsUpdatedAts,\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 [feedName]: comment.updatedAt,\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"]}
@@ -8,10 +8,15 @@ type GetLoadedFeedsOptions = {
8
8
  feedsHaveMore?: {
9
9
  [feedName: string]: boolean;
10
10
  };
11
+ feedsUpdatedAts?: {
12
+ [feedName: string]: number | undefined;
13
+ };
11
14
  };
12
15
  export declare const getLoadedFeeds: (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds, bufferedFeeds: Feeds, accounts: Accounts, options?: GetLoadedFeedsOptions) => Promise<Feeds>;
13
16
  export declare const addAccountsComments: (feedsOptions: RepliesFeedsOptions, loadedFeeds: Feeds, feedsHaveMore?: {
14
17
  [feedName: string]: boolean;
18
+ }, feedsUpdatedAts?: {
19
+ [feedName: string]: number | undefined;
15
20
  }) => boolean;
16
21
  export declare const getBufferedFeedsWithoutLoadedFeeds: (bufferedFeeds: Feeds, loadedFeeds: Feeds) => Feeds;
17
22
  export declare const getUpdatedFeeds: (feedsOptions: RepliesFeedsOptions, filteredSortedFeeds: Feeds, updatedFeeds: Feeds, loadedFeeds: Feeds, accounts: Accounts) => Promise<Feeds>;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../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AO,MAAM,sBAAsB,GAAI,SAAS,OAAO,EAAE,aAAa,kBAAkB,WA0EvF,CAAC"}
@@ -140,6 +140,12 @@ const isPublishedAccountReply = (reply) => typeof (reply === null || reply === v
140
140
  !!reply.cid &&
141
141
  reply.pendingApproval !== true &&
142
142
  !isActivePublishingState(reply.publishingState);
143
+ const canonicalFeedRefreshedAfterReply = (reply, feedUpdatedAt) => typeof feedUpdatedAt !== "number" ||
144
+ typeof reply.timestamp !== "number" ||
145
+ feedUpdatedAt > reply.timestamp;
146
+ const shouldHidePublishedAccountReply = (reply, hidePublishedAccountReplies, feedUpdatedAt) => hidePublishedAccountReplies &&
147
+ isPublishedAccountReply(reply) &&
148
+ canonicalFeedRefreshedAfterReply(reply, feedUpdatedAt);
143
149
  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 = {}) {
144
150
  var _a;
145
151
  const loadedFeedsMissingReplies = {};
@@ -187,14 +193,14 @@ export const getLoadedFeeds = (feedsOptions_1, loadedFeeds_1, bufferedFeeds_1, a
187
193
  newLoadedFeeds = Object.assign(Object.assign({}, loadedFeeds), newLoadedFeeds);
188
194
  const accountCommentsChangedFeeds = options.addAccountComments === false
189
195
  ? false
190
- : addAccountsComments(feedsOptions, newLoadedFeeds, options.feedsHaveMore);
196
+ : addAccountsComments(feedsOptions, newLoadedFeeds, options.feedsHaveMore, options.feedsUpdatedAts);
191
197
  // do nothing if there are no missing replies
192
198
  if (Object.keys(loadedFeedsMissingReplies).length === 0 && !accountCommentsChangedFeeds) {
193
199
  return loadedFeeds;
194
200
  }
195
201
  return newLoadedFeeds;
196
202
  });
197
- export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore) => {
203
+ export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore, feedsUpdatedAts) => {
198
204
  let loadedFeedsChanged = false;
199
205
  const accountsComments = accountsStore.getState().accountsComments || {};
200
206
  for (const feedName in feedsOptions) {
@@ -206,9 +212,10 @@ export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore) =>
206
212
  const newerThanTimestamp = newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;
207
213
  const isNewerThan = (reply) => reply.timestamp > newerThanTimestamp;
208
214
  const hidePublishedAccountReplies = (feedsHaveMore === null || feedsHaveMore === void 0 ? void 0 : feedsHaveMore[feedName]) === false;
215
+ const feedUpdatedAt = feedsUpdatedAts === null || feedsUpdatedAts === void 0 ? void 0 : feedsUpdatedAts[feedName];
209
216
  const accountComments = accountsComments[accountId] || [];
210
217
  const accountReplies = accountComments.filter((reply) => {
211
- if (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {
218
+ if (shouldHidePublishedAccountReply(reply, hidePublishedAccountReplies, feedUpdatedAt)) {
212
219
  return false;
213
220
  }
214
221
  if (!isNewerThan(reply)) {
@@ -237,7 +244,7 @@ export const addAccountsComments = (feedsOptions, loadedFeeds, feedsHaveMore) =>
237
244
  prunedLoadedFeed.push(reply);
238
245
  continue;
239
246
  }
240
- if (hidePublishedAccountReplies && isPublishedAccountReply(reply)) {
247
+ if (shouldHidePublishedAccountReply(reply, hidePublishedAccountReplies, feedUpdatedAt)) {
241
248
  loadedFeedsChanged = true;
242
249
  continue;
243
250
  }
@@ -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,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,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"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/replies/utils.ts"],"names":[],"mappings":";;;;;;;;;AAaA,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,aAAa,MAAM,sBAAsB,CAAC;AACjD,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,YAAiC,EACjC,QAAkB,EAClB,YAA0B,EAC1B,QAAkB,EAClB,EAAE;IACF,sBAAsB;IACtB,IAAI,KAAK,GAAU,EAAE,CAAC;IACtB,KAAK,MAAM,QAAQ,IAAI,YAAY,EAAE,CAAC;QACpC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QAE/E,2BAA2B;QAC3B,IAAI,mBAAmB,GAAG,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QAErC,QAAQ,GAAG,sBAAsB,CAAC,OAAO,EAA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AAA,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\nconst canonicalFeedRefreshedAfterReply = (reply: Comment, feedUpdatedAt?: number) =>\n typeof feedUpdatedAt !== \"number\" ||\n typeof reply.timestamp !== \"number\" ||\n feedUpdatedAt > reply.timestamp;\n\nconst shouldHidePublishedAccountReply = (\n reply: Comment,\n hidePublishedAccountReplies: boolean,\n feedUpdatedAt?: number,\n) =>\n hidePublishedAccountReplies &&\n isPublishedAccountReply(reply) &&\n canonicalFeedRefreshedAfterReply(reply, feedUpdatedAt);\n\ntype GetLoadedFeedsOptions = {\n addAccountComments?: boolean;\n feedsHaveMore?: { [feedName: string]: boolean };\n feedsUpdatedAts?: { [feedName: string]: number | undefined };\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(\n feedsOptions,\n newLoadedFeeds,\n options.feedsHaveMore,\n options.feedsUpdatedAts,\n );\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 feedsUpdatedAts?: { [feedName: string]: number | undefined },\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 const feedUpdatedAt = feedsUpdatedAts?.[feedName];\n\n const accountComments = accountsComments[accountId] || [];\n const accountReplies = accountComments.filter((reply) => {\n if (shouldHidePublishedAccountReply(reply, hidePublishedAccountReplies, feedUpdatedAt)) {\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 (shouldHidePublishedAccountReply(reply, hidePublishedAccountReplies, feedUpdatedAt)) {\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,7 +13,7 @@
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
- "version": "0.1.5",
16
+ "version": "0.1.6",
17
17
  "packageManager": "yarn@4.13.0",
18
18
  "files": [
19
19
  "CHANGELOG.md",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@bitsocial/bso-resolver": "0.0.6",
50
- "@pkcprotocol/pkc-js": "0.0.23",
50
+ "@pkcprotocol/pkc-js": "0.0.24",
51
51
  "@pkcprotocol/pkc-logger": "0.1.0",
52
52
  "assert": "2.0.0",
53
53
  "ethers": "5.8.0",
@@ -58,7 +58,7 @@
58
58
  "peer-id": "0.16.0",
59
59
  "quick-lru": "5.1.1",
60
60
  "uint8arrays": "3.1.1",
61
- "uuid": "11.1.0",
61
+ "uuid": "14.0.0",
62
62
  "viem": "2.45.0",
63
63
  "zustand": "4.0.0"
64
64
  },
@@ -67,8 +67,10 @@
67
67
  },
68
68
  "resolutions": {
69
69
  "follow-redirects": "1.16.0",
70
+ "postcss": "8.5.10",
70
71
  "protobufjs": "7.5.5",
71
- "axios": "1.15.0",
72
+ "uuid": "14.0.0",
73
+ "axios": "1.15.2",
72
74
  "vite": "8.0.7",
73
75
  "tar": "7.5.11",
74
76
  "undici": "7.24.0",