@bitsocial/bitsocial-react-hooks 0.1.50 → 0.1.51

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,12 @@
1
+ ## [0.1.51](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.50...v0.1.51) (2026-10-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **feeds:** keep a community's order for a sort file under a built-in name (release 0.1.51) ([a06f8e5](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a06f8e59a9024b409948be3f4f4da0a5e7506787))
7
+
8
+
9
+
1
10
  ## [0.1.50](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.49...v0.1.50) (2026-10-14)
2
11
 
3
12
 
package/README.md CHANGED
@@ -170,7 +170,7 @@ useBufferedFeeds({feedsOptions: UseFeedOptions[]}) // preload or buffer feeds in
170
170
  `useFeed().reset()` clears the current feed and refreshes the latest community snapshots before rebuilding it.
171
171
  `useFeed().expandTimeWindow(newerThan)` broadens `newerThan` in place without constructing a different sort name, so older posts can be appended without replacing the feed instance.
172
172
 
173
- Feed and reply sort names are defined by each community record, not by a fixed hooks allowlist. Omit `sortType` to use the preloaded page, or discover the requestable names with `getAvailablePostSortTypes(community)` and `getAvailableReplySortTypes(comment)`. pkc-js preloads a single sort and only publishes `pageCids` once that page overflows, so when every post or reply fits in the preloaded page the standard sorts (`hot`, `new`, `active` and `top*` for posts; `best`, `new`, `old`, `newFlat` and `oldFlat` for replies) are also requestable and are sorted client-side from that page, including the time window of `top*` timeframe sorts. `getPostPageSortType(community, sortType)` and `getReplyPageSortType(comment, sortType)` return the page that serves a sort. A requested sort that is neither published nor computable client-side is not silently replaced with another sort. Hooks preserve protocol page order for unknown custom sorts because their scoring algorithm is not available to the client.
173
+ Feed and reply sort names are defined by each community record, not by a fixed hooks allowlist. Omit `sortType` to use the preloaded page, or discover the requestable names with `getAvailablePostSortTypes(community)` and `getAvailableReplySortTypes(comment)`. pkc-js preloads a single sort and only publishes `pageCids` once that page overflows, so when every post or reply fits in the preloaded page the standard sorts (`hot`, `new`, `active` and `top*` for posts; `best`, `new`, `old`, `newFlat` and `oldFlat` for replies) are also requestable and are sorted client-side from that page, including the time window of `top*` timeframe sorts. `getPostPageSortType(community, sortType)` and `getReplyPageSortType(comment, sortType)` return the page that serves a sort. A requested sort that is neither published nor computable client-side is not silently replaced with another sort. Hooks preserve protocol page order for unknown custom sorts because their scoring algorithm is not available to the client. The same applies to a sort file that a community publishes under a built-in name (for example a keyword no-bump `active`), which `community.pageSorts.posts[sortType]` reveals through a different `name` or options of its own: a single-community feed reading that sort's pages keeps the community's page order, while a feed merging several communities still orders them with the built-in sorter of that name.
174
174
 
175
175
  #### Actions Hooks
176
176
 
@@ -7,6 +7,7 @@ export declare const getPreloadedPostSortType: (community?: Community) => string
7
7
  export declare const getPreloadedReplySortType: (comment?: Comment) => string | undefined;
8
8
  export declare const resolvePostSortType: (community: Community | undefined, requestedSortType?: string) => string | undefined;
9
9
  export declare const resolveReplySortType: (comment: Comment | undefined, requestedSortType?: string) => string | undefined;
10
+ export declare const isBuiltInPostSortType: (community: Community | undefined, sortType: string | undefined) => boolean;
10
11
  export declare const getPostPageSortType: (community: Community | undefined, requestedSortType?: string) => string | undefined;
11
12
  export declare const getReplyPageSortType: (comment: Comment | undefined, requestedSortType?: string) => string | undefined;
12
13
  //# sourceMappingURL=page-sorts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"page-sorts.d.ts","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AA4C9C,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,OAA8C,CAAC;AAElG,eAAO,MAAM,uBAAuB,GAAI,WAAW,MAAM,KAAG,MAAM,GAAG,SAGpE,CAAC;AAyHF,eAAO,MAAM,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AAyB,GAAI,UAAU,OAAO,KAAG,MAAM,GAAG,SAC3B,CAAC;AAE7C,eAAO,MAAM,mBAAmB,GAC9B,WAAW,SAAS,GAAG,SAAS,EAChC,oBAAoB,MAAM,KACzB,MAAM,GAAG,SAC+E,CAAC;AAE5F,eAAO,MAAM,oBAAoB,GAC/B,SAAS,OAAO,GAAG,SAAS,EAC5B,oBAAoB,MAAM,KACzB,MAAM,GAAG,SAKT,CAAC;AAkBJ,eAAO,MAAM,qBAAqB,GAChC,WAAW,SAAS,GAAG,SAAS,EAChC,UAAU,MAAM,GAAG,SAAS,KAC3B,OASF,CAAC;AAIF,eAAO,MAAM,mBAAmB,GAC9B,WAAW,SAAS,GAAG,SAAS,EAChC,oBAAoB,MAAM,KACzB,MAAM,GAAG,SACgF,CAAC;AAE7F,eAAO,MAAM,oBAAoB,GAC/B,SAAS,OAAO,GAAG,SAAS,EAC5B,oBAAoB,MAAM,KACzB,MAAM,GAAG,SAC+E,CAAC"}
@@ -138,6 +138,28 @@ export const getPreloadedPostSortType = (community) => getPreloadedPageSortType(
138
138
  export const getPreloadedReplySortType = (comment) => getPreloadedPageSortType(comment === null || comment === void 0 ? void 0 : comment.replies);
139
139
  export const resolvePostSortType = (community, requestedSortType) => resolvePageSortType(community === null || community === void 0 ? void 0 : community.posts, requestedSortType, CLIENT_SORTABLE_POST_SORT_TYPES);
140
140
  export const resolveReplySortType = (comment, requestedSortType) => resolvePageSortType(comment === null || comment === void 0 ? void 0 : comment.replies, requestedSortType, getClientSortableReplySortTypes(comment));
141
+ // the options pkc-js applies to every sort; any other published option belongs to the sort file itself
142
+ const RESERVED_PAGE_SORT_OPTIONS = new Set([
143
+ "maxAge",
144
+ "pinnedFirst",
145
+ "excludeRemovedComments",
146
+ "excludeDeletedComments",
147
+ "excludeCommentPendingApproval",
148
+ "excludeCommentWithApprovedFalse",
149
+ "excludeCommentsWithDifferentCommunityAddress",
150
+ ]);
151
+ // a community configured with `settings.pages` publishes `community.pageSorts`, naming the file behind
152
+ // each key; a package or path file published under a built-in key (e.g. a keyword no-bump `active`)
153
+ // orders its pages by a score the client sorters do not reproduce. A node may also register such a
154
+ // file under the built-in name itself, which its own options (e.g. `noBumpKeywords`) still reveal.
155
+ // Unconfigured communities publish no `pageSorts`, so their keys are the built-ins.
156
+ export const isBuiltInPostSortType = (community, sortType) => {
157
+ var _a, _b;
158
+ const publishedPageSort = sortType ? (_b = (_a = community === null || community === void 0 ? void 0 : community.pageSorts) === null || _a === void 0 ? void 0 : _a.posts) === null || _b === void 0 ? void 0 : _b[sortType] : undefined;
159
+ return (!publishedPageSort ||
160
+ (publishedPageSort.name === sortType &&
161
+ Object.keys(publishedPageSort.publicOptions || {}).every((option) => RESERVED_PAGE_SORT_OPTIONS.has(option))));
162
+ };
141
163
  // the `community.posts` page sort that serves a request, e.g. the preloaded `hot` page when a
142
164
  // single-page community serves `active` client-side; undefined when the sort cannot be served
143
165
  export const getPostPageSortType = (community, requestedSortType) => getPageSortTypeToRead(community === null || community === void 0 ? void 0 : community.posts, resolvePostSortType(community, requestedSortType));
@@ -1 +1 @@
1
- {"version":3,"file":"page-sorts.js","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AASA,oGAAoG;AACpG,iGAAiG;AACjG,qGAAqG;AACrG,MAAM,+BAA+B,GAAG;IACtC,KAAK;IACL,KAAK;IACL,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,SAAS;IACT,UAAU;IACV,SAAS;IACT,QAAQ;CACT,CAAC;AACF,MAAM,gCAAgC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEtF,kGAAkG;AAClG,yFAAyF;AACzF,MAAM,+BAA+B,GAAG,CAAC,OAAiB,EAAY,EAAE;IACtE,MAAM,MAAM,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,MAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK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,OAAO,EAAE,+BAA+B,CAAC,OAAO,CAAC,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,SAAqB,EAAsB,EAAE,CACpF,wBAAwB,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,OAAiB,EAAsB,EAAE,CACjF,wBAAwB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAgC,EAChC,iBAA0B,EACN,EAAE,CACtB,mBAAmB,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,EAAE,iBAAiB,EAAE,+BAA+B,CAAC,CAAC;AAE5F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA4B,EAC5B,iBAA0B,EACN,EAAE,CACtB,mBAAmB,CACjB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAChB,iBAAiB,EACjB,+BAA+B,CAAC,OAAO,CAAC,CACzC,CAAC;AAEJ,8FAA8F;AAC9F,8FAA8F;AAC9F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAgC,EAChC,iBAA0B,EACN,EAAE,CACtB,qBAAqB,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,EAAE,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAE7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA4B,EAC5B,iBAA0B,EACN,EAAE,CACtB,qBAAqB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC","sourcesContent":["import { Comment, Community } from \"../types\";\n\ntype PagesRecord = {\n pages?: Record<string, unknown>;\n pageCids?: Record<string, unknown>;\n};\n\ntype PreloadedPage = { comments?: unknown; nextCid?: string } | undefined;\n\n// Standard pkc-js sorts (pkc-js src/pages/util.ts) whose scoring the feed sorter reproduces. pkc-js\n// preloads a single sort and only publishes pageCids once that page overflows, so a record whose\n// comments all fit in the preloaded page can serve any of these by re-sorting that page client-side.\nconst CLIENT_SORTABLE_POST_SORT_TYPES = [\n \"hot\",\n \"new\",\n \"active\",\n \"topHour\",\n \"topDay\",\n \"topWeek\",\n \"topMonth\",\n \"topYear\",\n \"topAll\",\n];\nconst CLIENT_SORTABLE_REPLY_SORT_TYPES = [\"best\", \"new\", \"old\", \"newFlat\", \"oldFlat\"];\n\n// pkc-js only publishes flat sorts for a post's replies (REPLY_REPLIES_SORT_TYPES has none), so a\n// nested reply must not advertise them while its replies still fit in the preloaded page\nconst getClientSortableReplySortTypes = (comment?: Comment): string[] => {\n const isPost = comment?.depth !== undefined ? comment.depth === 0 : !comment?.parentCid;\n return isPost\n ? CLIENT_SORTABLE_REPLY_SORT_TYPES\n : CLIENT_SORTABLE_REPLY_SORT_TYPES.filter((sortType) => !isFlatSortType(sortType));\n};\n\n// pkc-js TIMEFRAMES_TO_SECONDS, applied client-side when a timeframe sort is computed from a\n// preloaded page instead of a page the community windowed itself\nconst SORT_TIMEFRAMES_SECONDS: Record<string, number> = {\n Hour: 3600,\n Day: 86400,\n Week: 604800,\n Month: 2629746,\n Year: 31557600,\n};\n\nexport const isFlatSortType = (sortType?: string): boolean => Boolean(sortType?.endsWith(\"Flat\"));\n\nexport const getSortTimeframeSeconds = (sortType?: string): number | undefined => {\n const timeframe = sortType?.match(/^(?:top|controversial)(Hour|Day|Week|Month|Year)$/)?.[1];\n return timeframe ? SORT_TIMEFRAMES_SECONDS[timeframe] : undefined;\n};\n\nconst getPublishedPageSortTypes = (record?: PagesRecord): string[] => {\n const sortTypes = new Set<string>();\n for (const sortType of Object.keys(record?.pages || {})) {\n if (sortType) sortTypes.add(sortType);\n }\n for (const sortType of Object.keys(record?.pageCids || {})) {\n if (sortType) sortTypes.add(sortType);\n }\n return [...sortTypes];\n};\n\n// preloaded pages holding the record's complete comment set: no page continues with a nextCid and\n// no pageCids are published (pkc-js publishes pageCids for every sort once the preloaded page overflows)\nconst getCompletePreloadedPageSortTypes = (record?: PagesRecord): string[] => {\n if (Object.keys(record?.pageCids || {}).length > 0) {\n return [];\n }\n const pages = record?.pages || {};\n const sortTypes = Object.keys(pages).filter((sortType) =>\n Array.isArray((pages[sortType] as PreloadedPage)?.comments),\n );\n if (\n !sortTypes.length ||\n sortTypes.some((sortType) => (pages[sortType] as PreloadedPage)?.nextCid)\n ) {\n return [];\n }\n // a page windowed by a timeframe sort only holds that window, never the complete set\n return sortTypes.filter((sortType) => !getSortTimeframeSeconds(sortType));\n};\n\n// a flat sort flattens the whole reply tree, so every nested reply chain must be complete too\nconst hasCompleteReplyTree = (page: PreloadedPage): boolean =>\n ((page?.comments as Comment[] | undefined) || []).every((comment) => {\n const completeSortTypes = getCompletePreloadedPageSortTypes(comment?.replies);\n if (!completeSortTypes.length) {\n // no preloaded replies is only complete when the comment reports none, and a continued or\n // paged chain is never complete\n return !(comment?.replyCount > 0) && !Object.keys(comment?.replies?.pages || {}).length;\n }\n const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));\n return hierarchicalSortType === undefined\n ? true\n : hasCompleteReplyTree(comment.replies.pages[hierarchicalSortType]);\n });\n\n// a flat page cannot rebuild the reply tree, so it only serves flat sorts; a hierarchical page\n// serves flat sorts only when its nested reply chains are complete\nconst getClientSortableSortTypes = (\n record: PagesRecord | undefined,\n clientSortableSortTypes: string[],\n): string[] => {\n const completeSortTypes = getCompletePreloadedPageSortTypes(record);\n if (!completeSortTypes.length) {\n return [];\n }\n const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));\n if (hierarchicalSortType === undefined) {\n return clientSortableSortTypes.filter(isFlatSortType);\n }\n const canFlatten =\n completeSortTypes.some(isFlatSortType) ||\n hasCompleteReplyTree(record?.pages?.[hierarchicalSortType] as PreloadedPage);\n return canFlatten\n ? clientSortableSortTypes\n : clientSortableSortTypes.filter((sortType) => !isFlatSortType(sortType));\n};\n\nconst getAvailablePageSortTypes = (\n record: PagesRecord | undefined,\n clientSortableSortTypes: string[],\n): string[] => {\n const sortTypes = getPublishedPageSortTypes(record);\n for (const sortType of getClientSortableSortTypes(record, clientSortableSortTypes)) {\n if (!sortTypes.includes(sortType)) sortTypes.push(sortType);\n }\n return sortTypes;\n};\n\nconst getPreloadedPageSortType = (record?: PagesRecord): string | undefined => {\n const preloadedSortType = Object.keys(record?.pages || {}).find(Boolean);\n return preloadedSortType || getPublishedPageSortTypes(record)[0];\n};\n\nconst resolvePageSortType = (\n record: PagesRecord | undefined,\n requestedSortType: string | undefined,\n clientSortableSortTypes: string[],\n): string | undefined => {\n if (requestedSortType !== undefined) {\n return getAvailablePageSortTypes(record, clientSortableSortTypes).includes(requestedSortType)\n ? requestedSortType\n : undefined;\n }\n return getPreloadedPageSortType(record);\n};\n\n// the page that serves a resolved sort: its published page, or the complete preloaded page the\n// client re-sorts (a flat sort prefers a complete flat page, else flattens a hierarchical one)\nconst getPageSortTypeToRead = (\n record: PagesRecord | undefined,\n sortType: string | undefined,\n): string | undefined => {\n if (sortType === undefined) {\n return undefined;\n }\n if (getPublishedPageSortTypes(record).includes(sortType)) {\n return sortType;\n }\n const completeSortTypes = getCompletePreloadedPageSortTypes(record);\n const hierarchicalSortType = completeSortTypes.find(\n (preloadedSortType) => !isFlatSortType(preloadedSortType),\n );\n if (isFlatSortType(sortType)) {\n return completeSortTypes.find(isFlatSortType) ?? hierarchicalSortType;\n }\n return hierarchicalSortType;\n};\n\nexport const getAvailablePostSortTypes = (community?: Community): string[] =>\n getAvailablePageSortTypes(community?.posts, CLIENT_SORTABLE_POST_SORT_TYPES);\n\nexport const getAvailableReplySortTypes = (comment?: Comment): string[] =>\n getAvailablePageSortTypes(comment?.replies, getClientSortableReplySortTypes(comment));\n\nexport const getPreloadedPostSortType = (community?: Community): string | undefined =>\n getPreloadedPageSortType(community?.posts);\n\nexport const getPreloadedReplySortType = (comment?: Comment): string | undefined =>\n getPreloadedPageSortType(comment?.replies);\n\nexport const resolvePostSortType = (\n community: Community | undefined,\n requestedSortType?: string,\n): string | undefined =>\n resolvePageSortType(community?.posts, requestedSortType, CLIENT_SORTABLE_POST_SORT_TYPES);\n\nexport const resolveReplySortType = (\n comment: Comment | undefined,\n requestedSortType?: string,\n): string | undefined =>\n resolvePageSortType(\n comment?.replies,\n requestedSortType,\n getClientSortableReplySortTypes(comment),\n );\n\n// the `community.posts` page sort that serves a request, e.g. the preloaded `hot` page when a\n// single-page community serves `active` client-side; undefined when the sort cannot be served\nexport const getPostPageSortType = (\n community: Community | undefined,\n requestedSortType?: string,\n): string | undefined =>\n getPageSortTypeToRead(community?.posts, resolvePostSortType(community, requestedSortType));\n\nexport const getReplyPageSortType = (\n comment: Comment | undefined,\n requestedSortType?: string,\n): string | undefined =>\n getPageSortTypeToRead(comment?.replies, resolveReplySortType(comment, requestedSortType));\n"]}
1
+ {"version":3,"file":"page-sorts.js","sourceRoot":"","sources":["../../src/lib/page-sorts.ts"],"names":[],"mappings":"AASA,oGAAoG;AACpG,iGAAiG;AACjG,qGAAqG;AACrG,MAAM,+BAA+B,GAAG;IACtC,KAAK;IACL,KAAK;IACL,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,SAAS;IACT,UAAU;IACV,SAAS;IACT,QAAQ;CACT,CAAC;AACF,MAAM,gCAAgC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAEtF,kGAAkG;AAClG,yFAAyF;AACzF,MAAM,+BAA+B,GAAG,CAAC,OAAiB,EAAY,EAAE;IACtE,MAAM,MAAM,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,MAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,KAAK,C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AAiB;QAClB,CAAC,iBAAiB,CAAC,IAAI,KAAK,QAAQ;YAClC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAClE,0BAA0B,CAAC,GAAG,CAAC,MAAM,CAAC,CACvC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC;AAEF,8FAA8F;AAC9F,8FAA8F;AAC9F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAAgC,EAChC,iBAA0B,EACN,EAAE,CACtB,qBAAqB,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,EAAE,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAE7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA4B,EAC5B,iBAA0B,EACN,EAAE,CACtB,qBAAqB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC","sourcesContent":["import { Comment, Community } from \"../types\";\n\ntype PagesRecord = {\n pages?: Record<string, unknown>;\n pageCids?: Record<string, unknown>;\n};\n\ntype PreloadedPage = { comments?: unknown; nextCid?: string } | undefined;\n\n// Standard pkc-js sorts (pkc-js src/pages/util.ts) whose scoring the feed sorter reproduces. pkc-js\n// preloads a single sort and only publishes pageCids once that page overflows, so a record whose\n// comments all fit in the preloaded page can serve any of these by re-sorting that page client-side.\nconst CLIENT_SORTABLE_POST_SORT_TYPES = [\n \"hot\",\n \"new\",\n \"active\",\n \"topHour\",\n \"topDay\",\n \"topWeek\",\n \"topMonth\",\n \"topYear\",\n \"topAll\",\n];\nconst CLIENT_SORTABLE_REPLY_SORT_TYPES = [\"best\", \"new\", \"old\", \"newFlat\", \"oldFlat\"];\n\n// pkc-js only publishes flat sorts for a post's replies (REPLY_REPLIES_SORT_TYPES has none), so a\n// nested reply must not advertise them while its replies still fit in the preloaded page\nconst getClientSortableReplySortTypes = (comment?: Comment): string[] => {\n const isPost = comment?.depth !== undefined ? comment.depth === 0 : !comment?.parentCid;\n return isPost\n ? CLIENT_SORTABLE_REPLY_SORT_TYPES\n : CLIENT_SORTABLE_REPLY_SORT_TYPES.filter((sortType) => !isFlatSortType(sortType));\n};\n\n// pkc-js TIMEFRAMES_TO_SECONDS, applied client-side when a timeframe sort is computed from a\n// preloaded page instead of a page the community windowed itself\nconst SORT_TIMEFRAMES_SECONDS: Record<string, number> = {\n Hour: 3600,\n Day: 86400,\n Week: 604800,\n Month: 2629746,\n Year: 31557600,\n};\n\nexport const isFlatSortType = (sortType?: string): boolean => Boolean(sortType?.endsWith(\"Flat\"));\n\nexport const getSortTimeframeSeconds = (sortType?: string): number | undefined => {\n const timeframe = sortType?.match(/^(?:top|controversial)(Hour|Day|Week|Month|Year)$/)?.[1];\n return timeframe ? SORT_TIMEFRAMES_SECONDS[timeframe] : undefined;\n};\n\nconst getPublishedPageSortTypes = (record?: PagesRecord): string[] => {\n const sortTypes = new Set<string>();\n for (const sortType of Object.keys(record?.pages || {})) {\n if (sortType) sortTypes.add(sortType);\n }\n for (const sortType of Object.keys(record?.pageCids || {})) {\n if (sortType) sortTypes.add(sortType);\n }\n return [...sortTypes];\n};\n\n// preloaded pages holding the record's complete comment set: no page continues with a nextCid and\n// no pageCids are published (pkc-js publishes pageCids for every sort once the preloaded page overflows)\nconst getCompletePreloadedPageSortTypes = (record?: PagesRecord): string[] => {\n if (Object.keys(record?.pageCids || {}).length > 0) {\n return [];\n }\n const pages = record?.pages || {};\n const sortTypes = Object.keys(pages).filter((sortType) =>\n Array.isArray((pages[sortType] as PreloadedPage)?.comments),\n );\n if (\n !sortTypes.length ||\n sortTypes.some((sortType) => (pages[sortType] as PreloadedPage)?.nextCid)\n ) {\n return [];\n }\n // a page windowed by a timeframe sort only holds that window, never the complete set\n return sortTypes.filter((sortType) => !getSortTimeframeSeconds(sortType));\n};\n\n// a flat sort flattens the whole reply tree, so every nested reply chain must be complete too\nconst hasCompleteReplyTree = (page: PreloadedPage): boolean =>\n ((page?.comments as Comment[] | undefined) || []).every((comment) => {\n const completeSortTypes = getCompletePreloadedPageSortTypes(comment?.replies);\n if (!completeSortTypes.length) {\n // no preloaded replies is only complete when the comment reports none, and a continued or\n // paged chain is never complete\n return !(comment?.replyCount > 0) && !Object.keys(comment?.replies?.pages || {}).length;\n }\n const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));\n return hierarchicalSortType === undefined\n ? true\n : hasCompleteReplyTree(comment.replies.pages[hierarchicalSortType]);\n });\n\n// a flat page cannot rebuild the reply tree, so it only serves flat sorts; a hierarchical page\n// serves flat sorts only when its nested reply chains are complete\nconst getClientSortableSortTypes = (\n record: PagesRecord | undefined,\n clientSortableSortTypes: string[],\n): string[] => {\n const completeSortTypes = getCompletePreloadedPageSortTypes(record);\n if (!completeSortTypes.length) {\n return [];\n }\n const hierarchicalSortType = completeSortTypes.find((sortType) => !isFlatSortType(sortType));\n if (hierarchicalSortType === undefined) {\n return clientSortableSortTypes.filter(isFlatSortType);\n }\n const canFlatten =\n completeSortTypes.some(isFlatSortType) ||\n hasCompleteReplyTree(record?.pages?.[hierarchicalSortType] as PreloadedPage);\n return canFlatten\n ? clientSortableSortTypes\n : clientSortableSortTypes.filter((sortType) => !isFlatSortType(sortType));\n};\n\nconst getAvailablePageSortTypes = (\n record: PagesRecord | undefined,\n clientSortableSortTypes: string[],\n): string[] => {\n const sortTypes = getPublishedPageSortTypes(record);\n for (const sortType of getClientSortableSortTypes(record, clientSortableSortTypes)) {\n if (!sortTypes.includes(sortType)) sortTypes.push(sortType);\n }\n return sortTypes;\n};\n\nconst getPreloadedPageSortType = (record?: PagesRecord): string | undefined => {\n const preloadedSortType = Object.keys(record?.pages || {}).find(Boolean);\n return preloadedSortType || getPublishedPageSortTypes(record)[0];\n};\n\nconst resolvePageSortType = (\n record: PagesRecord | undefined,\n requestedSortType: string | undefined,\n clientSortableSortTypes: string[],\n): string | undefined => {\n if (requestedSortType !== undefined) {\n return getAvailablePageSortTypes(record, clientSortableSortTypes).includes(requestedSortType)\n ? requestedSortType\n : undefined;\n }\n return getPreloadedPageSortType(record);\n};\n\n// the page that serves a resolved sort: its published page, or the complete preloaded page the\n// client re-sorts (a flat sort prefers a complete flat page, else flattens a hierarchical one)\nconst getPageSortTypeToRead = (\n record: PagesRecord | undefined,\n sortType: string | undefined,\n): string | undefined => {\n if (sortType === undefined) {\n return undefined;\n }\n if (getPublishedPageSortTypes(record).includes(sortType)) {\n return sortType;\n }\n const completeSortTypes = getCompletePreloadedPageSortTypes(record);\n const hierarchicalSortType = completeSortTypes.find(\n (preloadedSortType) => !isFlatSortType(preloadedSortType),\n );\n if (isFlatSortType(sortType)) {\n return completeSortTypes.find(isFlatSortType) ?? hierarchicalSortType;\n }\n return hierarchicalSortType;\n};\n\nexport const getAvailablePostSortTypes = (community?: Community): string[] =>\n getAvailablePageSortTypes(community?.posts, CLIENT_SORTABLE_POST_SORT_TYPES);\n\nexport const getAvailableReplySortTypes = (comment?: Comment): string[] =>\n getAvailablePageSortTypes(comment?.replies, getClientSortableReplySortTypes(comment));\n\nexport const getPreloadedPostSortType = (community?: Community): string | undefined =>\n getPreloadedPageSortType(community?.posts);\n\nexport const getPreloadedReplySortType = (comment?: Comment): string | undefined =>\n getPreloadedPageSortType(comment?.replies);\n\nexport const resolvePostSortType = (\n community: Community | undefined,\n requestedSortType?: string,\n): string | undefined =>\n resolvePageSortType(community?.posts, requestedSortType, CLIENT_SORTABLE_POST_SORT_TYPES);\n\nexport const resolveReplySortType = (\n comment: Comment | undefined,\n requestedSortType?: string,\n): string | undefined =>\n resolvePageSortType(\n comment?.replies,\n requestedSortType,\n getClientSortableReplySortTypes(comment),\n );\n\n// the options pkc-js applies to every sort; any other published option belongs to the sort file itself\nconst RESERVED_PAGE_SORT_OPTIONS = new Set([\n \"maxAge\",\n \"pinnedFirst\",\n \"excludeRemovedComments\",\n \"excludeDeletedComments\",\n \"excludeCommentPendingApproval\",\n \"excludeCommentWithApprovedFalse\",\n \"excludeCommentsWithDifferentCommunityAddress\",\n]);\n\n// a community configured with `settings.pages` publishes `community.pageSorts`, naming the file behind\n// each key; a package or path file published under a built-in key (e.g. a keyword no-bump `active`)\n// orders its pages by a score the client sorters do not reproduce. A node may also register such a\n// file under the built-in name itself, which its own options (e.g. `noBumpKeywords`) still reveal.\n// Unconfigured communities publish no `pageSorts`, so their keys are the built-ins.\nexport const isBuiltInPostSortType = (\n community: Community | undefined,\n sortType: string | undefined,\n): boolean => {\n const publishedPageSort = sortType ? community?.pageSorts?.posts?.[sortType] : undefined;\n return (\n !publishedPageSort ||\n (publishedPageSort.name === sortType &&\n Object.keys(publishedPageSort.publicOptions || {}).every((option) =>\n RESERVED_PAGE_SORT_OPTIONS.has(option),\n ))\n );\n};\n\n// the `community.posts` page sort that serves a request, e.g. the preloaded `hot` page when a\n// single-page community serves `active` client-side; undefined when the sort cannot be served\nexport const getPostPageSortType = (\n community: Community | undefined,\n requestedSortType?: string,\n): string | undefined =>\n getPageSortTypeToRead(community?.posts, resolvePostSortType(community, requestedSortType));\n\nexport const getReplyPageSortType = (\n comment: Comment | undefined,\n requestedSortType?: string,\n): string | undefined =>\n getPageSortTypeToRead(comment?.replies, resolveReplySortType(comment, requestedSortType));\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,eAAO,MAAM,GAAG,QAAkD,CAAC;AACnE,OAAO,EAAW,QAAQ,EAAW,MAAM,aAAa,CAAC;AAqBzD,eAAO,MAAM,SAAS,EAAE,GAAQ,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAC1C,iBAAiB,EAAE,QAAQ,CAAC;IAC5B,sBAAsB,EAAE,QAAQ,CAAC;IACjC,qBAAqB,EAAE,QAAQ,CAAC;IAChC,cAAc,EAAE,QAAQ,CAAC;CAC1B,CAAC;AAuDF,QAAA,MAAM,aAAa,4EAmdjB,CAAC;AA8BH,eAAO,MAAM,kBAAkB,qBAsC9B,CAAC;AAGF,eAAO,MAAM,6BAA6B,qBAGzC,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"comments-store.d.ts","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,eAAO,MAAM,GAAG,QAAkD,CAAC;AACnE,OAAO,EAAW,QAAQ,EAAW,MAAM,aAAa,CAAC;AAqBzD,eAAO,MAAM,SAAS,EAAE,GAAQ,CAAC;AAEjC,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAC1C,iBAAiB,EAAE,QAAQ,CAAC;IAC5B,sBAAsB,EAAE,QAAQ,CAAC;IACjC,qBAAqB,EAAE,QAAQ,CAAC;IAChC,cAAc,EAAE,QAAQ,CAAC;CAC1B,CAAC;AAuDF,QAAA,MAAM,aAAa,4EAodjB,CAAC;AA8BH,eAAO,MAAM,kBAAkB,qBAsC9B,CAAC;AAGF,eAAO,MAAM,6BAA6B,qBAGzC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -285,12 +285,13 @@ const commentsStore = createStore((setState, getState) => {
285
285
  return false;
286
286
  });
287
287
  };
288
- // Waits for the update cycle that startUpdate() begins. pkc-js runs one update loop per CID:
289
- // when another instance already updates this comment (for example the account's own reply,
290
- // whose update subscribes to its post), update() mirrors that shared loop instead of starting
291
- // a cycle, and the loop only emits again on its next poll, up to a minute later on a quiet
292
- // community. A shared loop that already has a CommentUpdate is current, so a cycle that
293
- // attaches to it settles as soon as update() returns.
288
+ // Waits for the update cycle that startUpdate() begins or joins. pkc-js runs one update loop
289
+ // per CID: when another instance already updates this comment (for example the account's own
290
+ // reply, whose update subscribes to its post), update() mirrors that shared loop instead of
291
+ // starting a cycle, and when auto-update subscribers keep this comment updating, update() does
292
+ // nothing. Either loop only emits again on its next poll, up to a minute later on a quiet
293
+ // community, but its latest CommentUpdate is current, so joining a loop that has already
294
+ // settled settles as soon as update() returns.
294
295
  const waitForCommentUpdateCycle = (commentCid, comment, startUpdate) => new Promise((resolve, reject) => {
295
296
  var _a, _b, _c;
296
297
  let settled = false;
@@ -1 +1 @@
1
- {"version":3,"file":"comments-store.js","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,MAAM,gBAAgB,GAAG,cAAc,CAAC,cAAc,CAAC;IACrD,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AACH,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAEnE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,iBAAiB,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAExE,IAAI,oBAAoB,GAA+B,EAAE,CAAC;AAC1D,MAAM,YAAY,GAAsC,EAAE,CAAC;AAC3D,MAAM,mBAAmB,GAA2D,EAAE,CAAC;AACvF,MAAM,4BAA4B,GAE9B,EAAE,CAAC;AACP,MAAM,0BAA0B,GAAsC,EAAE,CAAC;AACzE,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CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IACD,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,6BAA6B;IAC7B,MAAM,OAAO,CAAC,GAAG,CACf,SAAS,CAAC,GAAG,CAAC,CAAO,QAAa,EAAE,EAAE;;QACpC,IAAI,CAAC;YACH,IAAI,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAA,KAAK,UAAU,EAAE,CAAC;gBACzC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxB,CAAC;QACH,CAAC;QAAC,WAAM,CAAC,CAAA,CAAC;QACV,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,kBAAkB,wDAAI,CAAC;IACnC,CAAC,CAAA,CAAC,CACH,CAAC;IACF,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IAErB,mDAAmD;IACnD,aAAa,CAAC,OAAO,EAAE,CAAC;IACxB,yBAAyB;IACzB,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC,CAAA,CAAC;AAEF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAS,EAAE;IACtD,MAAM,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;IACtF,MAAM,kBAAkB,EAAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import localForageLru from \"../../lib/localforage-lru\";\nconst commentsDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-comments\",\n size: 5000,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nexport const log = Logger(\"bitsocial-react-hooks:comments:stores\");\nimport { Comment, Comments, Account } from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport repliesPagesStore from \"../replies-pages\";\nimport { normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\n\nlet pkcGetCommentPending: { [key: string]: boolean } = {};\nconst liveComments: { [commentCid: string]: Comment } = {};\nconst liveCommentPromises: { [commentCid: string]: Promise<Comment> | undefined } = {};\nconst commentAutoUpdateSubscribers: {\n [commentCid: string]: { [subscriberId: string]: true };\n} = {};\nconst stopCommentAfterNextUpdate: { [commentCid: string]: boolean } = {};\nconst sparseCommentFollowupRequested: { [commentCid: string]: boolean } = {};\n// set when the current update attempt emitted an error, until the next attempt starts\nconst commentUpdateAttemptFailed: { [commentCid: string]: boolean } = {};\nconst initializedComments = new WeakSet<object>();\nconst trackedListeners = new WeakSet<object>();\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\nexport type CommentsState = {\n comments: Comments;\n errors: { [commentCid: string]: Error[] };\n addCommentToStore: Function;\n startCommentAutoUpdate: Function;\n stopCommentAutoUpdate: Function;\n refreshComment: Function;\n};\n\nconst removeCommentListener = (comment: any, event: string, listener: (...args: any[]) => void) => {\n if (typeof comment?.off === \"function\") {\n comment.off(event, listener);\n return;\n }\n if (typeof comment?.removeListener === \"function\") {\n comment.removeListener(event, listener);\n }\n};\n\nconst getCommentAutoUpdateSubscribersCount = (commentCid: string) =>\n Object.keys(commentAutoUpdateSubscribers[commentCid] || {}).length;\n\nconst hasCommentAutoUpdateSubscribers = (commentCid: string) =>\n getCommentAutoUpdateSubscribersCount(commentCid) > 0;\n\nconst mergeCommentData = (\n commentCid: string,\n ...commentDataList: (Comment | undefined)[]\n): Comment => {\n const mergedCommentData: Comment = { cid: commentCid };\n for (const commentData of commentDataList) {\n if (commentData && typeof commentData === \"object\") {\n Object.assign(mergedCommentData, utils.clone(commentData));\n }\n }\n mergedCommentData.cid = commentCid;\n return mergedCommentData;\n};\n\nconst releaseLiveComment = (commentCid: string, comment?: Comment) => {\n const liveComment = comment || liveComments[commentCid];\n if (liveComment) {\n const listenerIndex = listeners.indexOf(liveComment);\n if (listenerIndex !== -1) {\n listeners.splice(listenerIndex, 1);\n }\n }\n if (!comment || liveComments[commentCid] === liveComment) {\n delete liveComments[commentCid];\n }\n};\n\nconst maybeReleaseStoppedLiveComment = (commentCid: string, comment?: Comment) => {\n if (!comment || hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n if (liveComments[commentCid] !== comment) {\n return;\n }\n releaseLiveComment(commentCid, comment);\n};\n\nconst commentsStore = createStore<CommentsState>((setState: Function, getState: Function) => {\n const addCommentError = (commentCid: string, error: Error) => {\n setState((state: CommentsState) => {\n let commentErrors = state.errors[commentCid] || [];\n commentErrors = [...commentErrors, error];\n return { ...state, errors: { ...state.errors, [commentCid]: commentErrors } };\n });\n };\n\n const persistComment = async (commentCid: string, nextComment: Comment) => {\n const normalizedComment = normalizeCommentCommunityAddress(utils.clone(nextComment)) as Comment;\n // Store the update before the database write. pkc-js emits \"updatingstatechange\" right after\n // \"update\", so waiting on the write would let \"succeeded\" land on a CID-only entry, and a\n // frozen useComment would settle on that empty shell.\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: normalizedComment },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);\n\n await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\n\n return normalizedComment;\n };\n\n const clearCommentUpdateFollowup = (commentCid: string) => {\n delete sparseCommentFollowupRequested[commentCid];\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\n clearCommentUpdateFollowup(commentCid);\n const liveComment = comment || liveComments[commentCid];\n if (typeof liveComment?.stop !== \"function\") {\n return;\n }\n try {\n await liveComment.stop();\n } catch (error) {\n log.trace(\"comment.stop error\", { commentCid, comment: liveComment, error });\n }\n };\n\n const maybeStopCommentAfterOneShotUpdate = (commentCid: string, comment: Comment) => {\n if (!stopCommentAfterNextUpdate[commentCid]) {\n return;\n }\n delete stopCommentAfterNextUpdate[commentCid];\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n void stopLiveComment(commentCid, comment).finally(() => {\n maybeReleaseStoppedLiveComment(commentCid, comment);\n });\n };\n\n const toCommentUpdateError = (error: unknown) =>\n error instanceof Error ? error : Error(\"comment update failed\");\n\n const emitCommentError = (comment: Comment, error: Error) => {\n const emit = (comment as any)?.emit;\n if (typeof emit !== \"function\") {\n return;\n }\n try {\n emit.call(comment, \"error\", error);\n } catch (emitError) {\n if (emitError !== error) {\n log.trace(\"comment.update error event error\", { comment, error: emitError });\n }\n }\n };\n\n const handleCommentUpdateError = (commentCid: string, comment: Comment, error: unknown) => {\n const updateError = toCommentUpdateError(error);\n clearCommentUpdateFollowup(commentCid);\n\n if (!getState().errors[commentCid]?.includes(updateError)) {\n emitCommentError(comment, updateError);\n if (!getState().errors[commentCid]?.includes(updateError)) {\n addCommentError(commentCid, updateError);\n }\n }\n\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n return updateError;\n };\n\n const isSparseCommentUpdate = (comment: Comment) => !!comment?.timestamp && !comment?.updatedAt;\n\n // A CID-only comment update can settle after immutable IPFS data; one follow-up\n // update gives PKC a chance to load mutable community data such as replies.\n const shouldRequestSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n !sparseCommentFollowupRequested[commentCid] &&\n (stopCommentAfterNextUpdate[commentCid] || hasCommentAutoUpdateSubscribers(commentCid)) &&\n isSparseCommentUpdate(comment);\n\n const shouldWaitForSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n sparseCommentFollowupRequested[commentCid] && isSparseCommentUpdate(comment);\n\n // pkc-js ends an update cycle that found no newer CommentUpdate with \"waiting-retry\". A\n // retriable failure also ends in \"waiting-retry\", after an error event, and must keep retrying.\n // Once the comment has a CommentUpdate, an error-free \"waiting-retry\" settles a one-shot update\n // or refresh; until then, keep waiting for the first one.\n const isUnchangedUpdateCycleEnd = (updatingState: string, commentCid: string, comment: Comment) =>\n updatingState === \"waiting-retry\" &&\n !commentUpdateAttemptFailed[commentCid] &&\n typeof comment?.updatedAt === \"number\";\n\n const initializeComment = (commentCid: string, comment: Comment, account: Account) => {\n if (initializedComments.has(comment as object)) {\n liveComments[commentCid] = comment;\n return;\n }\n initializedComments.add(comment as object);\n liveComments[commentCid] = comment;\n\n comment?.on?.(\"update\", async (updatedComment: Comment) => {\n updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment)) as Comment;\n await persistComment(commentCid, updatedComment);\n });\n\n comment?.on?.(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommentsState) => ({\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], updatingState },\n },\n }));\n\n if (\n updatingState === \"succeeded\" &&\n shouldRequestSparseCommentFollowup(commentCid, comment)\n ) {\n sparseCommentFollowupRequested[commentCid] = true;\n requestCommentUpdate(commentCid, comment, {\n stopAfterNextUpdate: !!stopCommentAfterNextUpdate[commentCid],\n });\n return;\n }\n\n if (\n updatingState === \"succeeded\" &&\n (comment.updatedAt || sparseCommentFollowupRequested[commentCid])\n ) {\n clearCommentUpdateFollowup(commentCid);\n }\n if (updatingState === \"failed\") {\n clearCommentUpdateFollowup(commentCid);\n }\n\n if (\n updatingState === \"succeeded\" ||\n updatingState === \"failed\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment)\n ) {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n if (updatingState !== \"waiting-retry\") {\n delete commentUpdateAttemptFailed[commentCid];\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\n commentUpdateAttemptFailed[commentCid] = true;\n addCommentError(commentCid, error);\n });\n\n // set clients on comment so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n comment?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommentsState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.comments[commentCid]) {\n return {};\n }\n const clients = { ...state.comments[commentCid]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], clients },\n },\n };\n });\n },\n );\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n // if comment.timestamp isn't defined, it means the next update will contain the timestamp and author\n // which is used in addCidToAccountComment\n if (!comment?.timestamp) {\n comment?.once?.(\"update\", () =>\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(comment)\n .catch((error: any) =>\n log.error(\"accountsActionsInternal.addCidToAccountComment error\", { comment, error }),\n ),\n );\n }\n\n if (!trackedListeners.has(comment as object)) {\n trackedListeners.add(comment as object);\n listeners.push(comment);\n }\n };\n\n const ensureLiveComment = async (commentCid: string, account: Account, commentData?: Comment) => {\n if (liveComments[commentCid]) {\n return liveComments[commentCid];\n }\n if (liveCommentPromises[commentCid]) {\n return liveCommentPromises[commentCid] as Promise<Comment>;\n }\n\n const liveCommentPromise = (async () => {\n const initialComment = normalizeCommentCommunityAddress(\n mergeCommentData(commentCid, commentData),\n );\n const liveComment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(initialComment),\n ) as Comment;\n initializeComment(commentCid, liveComment, account);\n return liveComment;\n })();\n liveCommentPromises[commentCid] = liveCommentPromise;\n\n try {\n return await liveCommentPromise;\n } finally {\n if (liveCommentPromises[commentCid] === liveCommentPromise) {\n delete liveCommentPromises[commentCid];\n }\n }\n };\n\n const requestCommentUpdate = (\n commentCid: string,\n comment: Comment,\n options?: { stopAfterNextUpdate?: boolean },\n ) => {\n if (options?.stopAfterNextUpdate) {\n stopCommentAfterNextUpdate[commentCid] = true;\n } else {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n\n // Resolves whether update() started or attached to an update loop.\n return comment?.update?.().then(\n () => true,\n (error: unknown) => {\n const updateError = handleCommentUpdateError(commentCid, comment, error);\n log.trace(\"comment.update error\", { commentCid, comment, error: updateError });\n return false;\n },\n );\n };\n\n // Waits for the update cycle that startUpdate() begins. pkc-js runs one update loop per CID:\n // when another instance already updates this comment (for example the account's own reply,\n // whose update subscribes to its post), update() mirrors that shared loop instead of starting\n // a cycle, and the loop only emits again on its next poll, up to a minute later on a quiet\n // community. A shared loop that already has a CommentUpdate is current, so a cycle that\n // attaches to it settles as soon as update() returns.\n const waitForCommentUpdateCycle = (\n commentCid: string,\n comment: Comment,\n startUpdate: () => Promise<boolean> | undefined,\n ) =>\n new Promise<Comment>((resolve, reject) => {\n let settled = false;\n const settle = () => {\n settled = true;\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n };\n const isSettledUpdatingState = (updatingState: string) =>\n updatingState === \"succeeded\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment);\n\n const onUpdatingStateChange = (updatingState: string) => {\n if (isSettledUpdatingState(updatingState)) {\n if (shouldWaitForSparseCommentFollowup(commentCid, comment)) {\n return;\n }\n settle();\n return;\n }\n if (updatingState === \"failed\") {\n settled = true;\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\n settled = true;\n cleanup();\n reject(error);\n };\n\n const cleanup = () => {\n removeCommentListener(comment, \"updatingstatechange\", onUpdatingStateChange);\n removeCommentListener(comment, \"error\", onError);\n };\n\n comment?.on?.(\"updatingstatechange\", onUpdatingStateChange);\n comment?.on?.(\"error\", onError);\n\n void startUpdate()?.then((updateStarted) => {\n if (\n !updateStarted ||\n settled ||\n typeof comment?.updatedAt !== \"number\" ||\n !isSettledUpdatingState(comment?.updatingState) ||\n shouldWaitForSparseCommentFollowup(commentCid, comment)\n ) {\n return;\n }\n // No event will end this cycle, so detach a one-shot update here as the event would.\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n settle();\n });\n });\n\n return {\n comments: {},\n errors: {},\n\n async addCommentToStore(commentCid: string, account: Account, commentData?: Comment) {\n const { comments } = getState();\n const pendingKey = commentCid + account.id;\n\n // comment is in store already, do nothing\n let comment: Comment | undefined = comments[commentCid];\n if (comment || pkcGetCommentPending[pendingKey]) {\n return;\n }\n pkcGetCommentPending[pendingKey] = true;\n\n try {\n // try to find comment in database\n comment = await getCommentFromDatabase(commentCid, account, commentData);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, commentData);\n comment = normalizeCommentCommunityAddress(comment);\n log(\"commentsStore.addCommentToStore\", { commentCid, comment, account });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n } else {\n comment = normalizeCommentCommunityAddress(comment);\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);\n\n comment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, comment, commentData),\n );\n }\n\n if (comment) {\n requestCommentUpdate(commentCid, comment, { stopAfterNextUpdate: true });\n }\n } catch (e: any) {\n addCommentError(commentCid, e);\n throw e;\n } finally {\n pkcGetCommentPending[pendingKey] = false;\n }\n },\n\n async startCommentAutoUpdate(\n commentCid: string,\n subscriberId: string,\n account: Account,\n commentData?: Comment,\n ) {\n const hadAutoUpdateSubscribers = hasCommentAutoUpdateSubscribers(commentCid);\n commentAutoUpdateSubscribers[commentCid] = {\n ...(commentAutoUpdateSubscribers[commentCid] || {}),\n [subscriberId]: true,\n };\n\n if (hadAutoUpdateSubscribers && liveComments[commentCid]) {\n return;\n }\n\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (!storedComment) {\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(liveComment) },\n }));\n }\n\n if (!hasCommentAutoUpdateSubscribers(commentCid)) {\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n return;\n }\n\n requestCommentUpdate(commentCid, liveComment);\n },\n\n async stopCommentAutoUpdate(commentCid: string, subscriberId: string) {\n if (commentAutoUpdateSubscribers[commentCid]) {\n delete commentAutoUpdateSubscribers[commentCid][subscriberId];\n if (Object.keys(commentAutoUpdateSubscribers[commentCid]).length === 0) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n }\n\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n\n delete stopCommentAfterNextUpdate[commentCid];\n const liveComment = liveComments[commentCid];\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n },\n\n async refreshComment(commentCid: string, account: Account, commentData?: Comment) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n return waitForCommentUpdateCycle(commentCid, liveComment, () =>\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n }),\n );\n },\n };\n});\n\nconst getCommentFromDatabase = async (\n commentCid: string,\n account: Account,\n initialCommentData?: Comment,\n) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(\n mergeCommentData(commentCid, commentData, initialCommentData),\n ),\n );\n return comment;\n } catch (e) {\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createComment(cachedComment)\", {\n cachedComment: commentData,\n error: e,\n });\n }\n};\n\n// reset store in between tests\nconst originalState = commentsStore.getState();\n// async function because some stores have async init\nexport const resetCommentsStore = async () => {\n pkcGetCommentPending = {};\n for (const commentCid in commentAutoUpdateSubscribers) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n for (const commentCid in stopCommentAfterNextUpdate) {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n for (const commentCid in sparseCommentFollowupRequested) {\n delete sparseCommentFollowupRequested[commentCid];\n }\n for (const commentCid in commentUpdateAttemptFailed) {\n delete commentUpdateAttemptFailed[commentCid];\n }\n for (const commentCid in liveCommentPromises) {\n delete liveCommentPromises[commentCid];\n }\n for (const commentCid in liveComments) {\n delete liveComments[commentCid];\n }\n\n // remove all event listeners\n await Promise.all(\n listeners.map(async (listener: any) => {\n try {\n if (typeof listener?.stop === \"function\") {\n await listener.stop();\n }\n } catch {}\n listener?.removeAllListeners?.();\n }),\n );\n listeners.length = 0;\n\n // destroy all component subscriptions to the store\n commentsStore.destroy();\n // restore original state\n commentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommentsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear();\n await resetCommentsStore();\n};\n\nexport default commentsStore;\n"]}
1
+ {"version":3,"file":"comments-store.js","sourceRoot":"","sources":["../../../src/stores/comments/comments-store.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,MAAM,gBAAgB,GAAG,cAAc,CAAC,cAAc,CAAC;IACrD,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AACH,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAC;AAEnE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,WAAW,MAAM,SAAS,CAAC;AAClC,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,O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AAE,CAAC;AAC7B,CAAC,CAAA,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import localForageLru from \"../../lib/localforage-lru\";\nconst commentsDatabase = localForageLru.createInstance({\n name: \"bitsocialReactHooks-comments\",\n size: 5000,\n});\nimport Logger from \"@pkcprotocol/pkc-logger\";\nexport const log = Logger(\"bitsocial-react-hooks:comments:stores\");\nimport { Comment, Comments, Account } from \"../../types\";\nimport utils from \"../../lib/utils\";\nimport createStore from \"zustand\";\nimport accountsStore from \"../accounts\";\nimport repliesPagesStore from \"../replies-pages\";\nimport { normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\n\nlet pkcGetCommentPending: { [key: string]: boolean } = {};\nconst liveComments: { [commentCid: string]: Comment } = {};\nconst liveCommentPromises: { [commentCid: string]: Promise<Comment> | undefined } = {};\nconst commentAutoUpdateSubscribers: {\n [commentCid: string]: { [subscriberId: string]: true };\n} = {};\nconst stopCommentAfterNextUpdate: { [commentCid: string]: boolean } = {};\nconst sparseCommentFollowupRequested: { [commentCid: string]: boolean } = {};\n// set when the current update attempt emitted an error, until the next attempt starts\nconst commentUpdateAttemptFailed: { [commentCid: string]: boolean } = {};\nconst initializedComments = new WeakSet<object>();\nconst trackedListeners = new WeakSet<object>();\n\n// reset all event listeners in between tests\nexport const listeners: any = [];\n\nexport type CommentsState = {\n comments: Comments;\n errors: { [commentCid: string]: Error[] };\n addCommentToStore: Function;\n startCommentAutoUpdate: Function;\n stopCommentAutoUpdate: Function;\n refreshComment: Function;\n};\n\nconst removeCommentListener = (comment: any, event: string, listener: (...args: any[]) => void) => {\n if (typeof comment?.off === \"function\") {\n comment.off(event, listener);\n return;\n }\n if (typeof comment?.removeListener === \"function\") {\n comment.removeListener(event, listener);\n }\n};\n\nconst getCommentAutoUpdateSubscribersCount = (commentCid: string) =>\n Object.keys(commentAutoUpdateSubscribers[commentCid] || {}).length;\n\nconst hasCommentAutoUpdateSubscribers = (commentCid: string) =>\n getCommentAutoUpdateSubscribersCount(commentCid) > 0;\n\nconst mergeCommentData = (\n commentCid: string,\n ...commentDataList: (Comment | undefined)[]\n): Comment => {\n const mergedCommentData: Comment = { cid: commentCid };\n for (const commentData of commentDataList) {\n if (commentData && typeof commentData === \"object\") {\n Object.assign(mergedCommentData, utils.clone(commentData));\n }\n }\n mergedCommentData.cid = commentCid;\n return mergedCommentData;\n};\n\nconst releaseLiveComment = (commentCid: string, comment?: Comment) => {\n const liveComment = comment || liveComments[commentCid];\n if (liveComment) {\n const listenerIndex = listeners.indexOf(liveComment);\n if (listenerIndex !== -1) {\n listeners.splice(listenerIndex, 1);\n }\n }\n if (!comment || liveComments[commentCid] === liveComment) {\n delete liveComments[commentCid];\n }\n};\n\nconst maybeReleaseStoppedLiveComment = (commentCid: string, comment?: Comment) => {\n if (!comment || hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n if (liveComments[commentCid] !== comment) {\n return;\n }\n releaseLiveComment(commentCid, comment);\n};\n\nconst commentsStore = createStore<CommentsState>((setState: Function, getState: Function) => {\n const addCommentError = (commentCid: string, error: Error) => {\n setState((state: CommentsState) => {\n let commentErrors = state.errors[commentCid] || [];\n commentErrors = [...commentErrors, error];\n return { ...state, errors: { ...state.errors, [commentCid]: commentErrors } };\n });\n };\n\n const persistComment = async (commentCid: string, nextComment: Comment) => {\n const normalizedComment = normalizeCommentCommunityAddress(utils.clone(nextComment)) as Comment;\n // Store the update before the database write. pkc-js emits \"updatingstatechange\" right after\n // \"update\", so waiting on the write would let \"succeeded\" land on a CID-only entry, and a\n // frozen useComment would settle on that empty shell.\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: normalizedComment },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);\n\n await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\n\n return normalizedComment;\n };\n\n const clearCommentUpdateFollowup = (commentCid: string) => {\n delete sparseCommentFollowupRequested[commentCid];\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\n clearCommentUpdateFollowup(commentCid);\n const liveComment = comment || liveComments[commentCid];\n if (typeof liveComment?.stop !== \"function\") {\n return;\n }\n try {\n await liveComment.stop();\n } catch (error) {\n log.trace(\"comment.stop error\", { commentCid, comment: liveComment, error });\n }\n };\n\n const maybeStopCommentAfterOneShotUpdate = (commentCid: string, comment: Comment) => {\n if (!stopCommentAfterNextUpdate[commentCid]) {\n return;\n }\n delete stopCommentAfterNextUpdate[commentCid];\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n void stopLiveComment(commentCid, comment).finally(() => {\n maybeReleaseStoppedLiveComment(commentCid, comment);\n });\n };\n\n const toCommentUpdateError = (error: unknown) =>\n error instanceof Error ? error : Error(\"comment update failed\");\n\n const emitCommentError = (comment: Comment, error: Error) => {\n const emit = (comment as any)?.emit;\n if (typeof emit !== \"function\") {\n return;\n }\n try {\n emit.call(comment, \"error\", error);\n } catch (emitError) {\n if (emitError !== error) {\n log.trace(\"comment.update error event error\", { comment, error: emitError });\n }\n }\n };\n\n const handleCommentUpdateError = (commentCid: string, comment: Comment, error: unknown) => {\n const updateError = toCommentUpdateError(error);\n clearCommentUpdateFollowup(commentCid);\n\n if (!getState().errors[commentCid]?.includes(updateError)) {\n emitCommentError(comment, updateError);\n if (!getState().errors[commentCid]?.includes(updateError)) {\n addCommentError(commentCid, updateError);\n }\n }\n\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n return updateError;\n };\n\n const isSparseCommentUpdate = (comment: Comment) => !!comment?.timestamp && !comment?.updatedAt;\n\n // A CID-only comment update can settle after immutable IPFS data; one follow-up\n // update gives PKC a chance to load mutable community data such as replies.\n const shouldRequestSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n !sparseCommentFollowupRequested[commentCid] &&\n (stopCommentAfterNextUpdate[commentCid] || hasCommentAutoUpdateSubscribers(commentCid)) &&\n isSparseCommentUpdate(comment);\n\n const shouldWaitForSparseCommentFollowup = (commentCid: string, comment: Comment) =>\n sparseCommentFollowupRequested[commentCid] && isSparseCommentUpdate(comment);\n\n // pkc-js ends an update cycle that found no newer CommentUpdate with \"waiting-retry\". A\n // retriable failure also ends in \"waiting-retry\", after an error event, and must keep retrying.\n // Once the comment has a CommentUpdate, an error-free \"waiting-retry\" settles a one-shot update\n // or refresh; until then, keep waiting for the first one.\n const isUnchangedUpdateCycleEnd = (updatingState: string, commentCid: string, comment: Comment) =>\n updatingState === \"waiting-retry\" &&\n !commentUpdateAttemptFailed[commentCid] &&\n typeof comment?.updatedAt === \"number\";\n\n const initializeComment = (commentCid: string, comment: Comment, account: Account) => {\n if (initializedComments.has(comment as object)) {\n liveComments[commentCid] = comment;\n return;\n }\n initializedComments.add(comment as object);\n liveComments[commentCid] = comment;\n\n comment?.on?.(\"update\", async (updatedComment: Comment) => {\n updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment)) as Comment;\n await persistComment(commentCid, updatedComment);\n });\n\n comment?.on?.(\"updatingstatechange\", (updatingState: string) => {\n setState((state: CommentsState) => ({\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], updatingState },\n },\n }));\n\n if (\n updatingState === \"succeeded\" &&\n shouldRequestSparseCommentFollowup(commentCid, comment)\n ) {\n sparseCommentFollowupRequested[commentCid] = true;\n requestCommentUpdate(commentCid, comment, {\n stopAfterNextUpdate: !!stopCommentAfterNextUpdate[commentCid],\n });\n return;\n }\n\n if (\n updatingState === \"succeeded\" &&\n (comment.updatedAt || sparseCommentFollowupRequested[commentCid])\n ) {\n clearCommentUpdateFollowup(commentCid);\n }\n if (updatingState === \"failed\") {\n clearCommentUpdateFollowup(commentCid);\n }\n\n if (\n updatingState === \"succeeded\" ||\n updatingState === \"failed\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment)\n ) {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n if (updatingState !== \"waiting-retry\") {\n delete commentUpdateAttemptFailed[commentCid];\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\n commentUpdateAttemptFailed[commentCid] = true;\n addCommentError(commentCid, error);\n });\n\n // set clients on comment so the frontend can display it, dont persist in db because a reload cancels updating\n utils.clientsOnStateChange(\n comment?.clients,\n (clientState: string, clientType: string, clientUrl: string, chainTicker?: string) => {\n setState((state: CommentsState) => {\n // make sure not undefined, sometimes happens in e2e tests\n if (!state.comments[commentCid]) {\n return {};\n }\n const clients = { ...state.comments[commentCid]?.clients };\n const client = { state: clientState };\n if (chainTicker) {\n const chainProviders = { ...clients[clientType][chainTicker], [clientUrl]: client };\n clients[clientType] = { ...clients[clientType], [chainTicker]: chainProviders };\n } else {\n clients[clientType] = { ...clients[clientType], [clientUrl]: client };\n }\n return {\n comments: {\n ...state.comments,\n [commentCid]: { ...state.comments[commentCid], clients },\n },\n };\n });\n },\n );\n\n // when publishing a comment, you don't yet know its CID\n // so when a new comment is fetched, check to see if it's your own\n // comment, and if yes, add the CID to your account comments database\n // if comment.timestamp isn't defined, it means the next update will contain the timestamp and author\n // which is used in addCidToAccountComment\n if (!comment?.timestamp) {\n comment?.once?.(\"update\", () =>\n accountsStore\n .getState()\n .accountsActionsInternal.addCidToAccountComment(comment)\n .catch((error: any) =>\n log.error(\"accountsActionsInternal.addCidToAccountComment error\", { comment, error }),\n ),\n );\n }\n\n if (!trackedListeners.has(comment as object)) {\n trackedListeners.add(comment as object);\n listeners.push(comment);\n }\n };\n\n const ensureLiveComment = async (commentCid: string, account: Account, commentData?: Comment) => {\n if (liveComments[commentCid]) {\n return liveComments[commentCid];\n }\n if (liveCommentPromises[commentCid]) {\n return liveCommentPromises[commentCid] as Promise<Comment>;\n }\n\n const liveCommentPromise = (async () => {\n const initialComment = normalizeCommentCommunityAddress(\n mergeCommentData(commentCid, commentData),\n );\n const liveComment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(initialComment),\n ) as Comment;\n initializeComment(commentCid, liveComment, account);\n return liveComment;\n })();\n liveCommentPromises[commentCid] = liveCommentPromise;\n\n try {\n return await liveCommentPromise;\n } finally {\n if (liveCommentPromises[commentCid] === liveCommentPromise) {\n delete liveCommentPromises[commentCid];\n }\n }\n };\n\n const requestCommentUpdate = (\n commentCid: string,\n comment: Comment,\n options?: { stopAfterNextUpdate?: boolean },\n ) => {\n if (options?.stopAfterNextUpdate) {\n stopCommentAfterNextUpdate[commentCid] = true;\n } else {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n\n // Resolves whether update() started or attached to an update loop.\n return comment?.update?.().then(\n () => true,\n (error: unknown) => {\n const updateError = handleCommentUpdateError(commentCid, comment, error);\n log.trace(\"comment.update error\", { commentCid, comment, error: updateError });\n return false;\n },\n );\n };\n\n // Waits for the update cycle that startUpdate() begins or joins. pkc-js runs one update loop\n // per CID: when another instance already updates this comment (for example the account's own\n // reply, whose update subscribes to its post), update() mirrors that shared loop instead of\n // starting a cycle, and when auto-update subscribers keep this comment updating, update() does\n // nothing. Either loop only emits again on its next poll, up to a minute later on a quiet\n // community, but its latest CommentUpdate is current, so joining a loop that has already\n // settled settles as soon as update() returns.\n const waitForCommentUpdateCycle = (\n commentCid: string,\n comment: Comment,\n startUpdate: () => Promise<boolean> | undefined,\n ) =>\n new Promise<Comment>((resolve, reject) => {\n let settled = false;\n const settle = () => {\n settled = true;\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n };\n const isSettledUpdatingState = (updatingState: string) =>\n updatingState === \"succeeded\" ||\n isUnchangedUpdateCycleEnd(updatingState, commentCid, comment);\n\n const onUpdatingStateChange = (updatingState: string) => {\n if (isSettledUpdatingState(updatingState)) {\n if (shouldWaitForSparseCommentFollowup(commentCid, comment)) {\n return;\n }\n settle();\n return;\n }\n if (updatingState === \"failed\") {\n settled = true;\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\n settled = true;\n cleanup();\n reject(error);\n };\n\n const cleanup = () => {\n removeCommentListener(comment, \"updatingstatechange\", onUpdatingStateChange);\n removeCommentListener(comment, \"error\", onError);\n };\n\n comment?.on?.(\"updatingstatechange\", onUpdatingStateChange);\n comment?.on?.(\"error\", onError);\n\n void startUpdate()?.then((updateStarted) => {\n if (\n !updateStarted ||\n settled ||\n typeof comment?.updatedAt !== \"number\" ||\n !isSettledUpdatingState(comment?.updatingState) ||\n shouldWaitForSparseCommentFollowup(commentCid, comment)\n ) {\n return;\n }\n // No event will end this cycle, so detach a one-shot update here as the event would.\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n settle();\n });\n });\n\n return {\n comments: {},\n errors: {},\n\n async addCommentToStore(commentCid: string, account: Account, commentData?: Comment) {\n const { comments } = getState();\n const pendingKey = commentCid + account.id;\n\n // comment is in store already, do nothing\n let comment: Comment | undefined = comments[commentCid];\n if (comment || pkcGetCommentPending[pendingKey]) {\n return;\n }\n pkcGetCommentPending[pendingKey] = true;\n\n try {\n // try to find comment in database\n comment = await getCommentFromDatabase(commentCid, account, commentData);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, commentData);\n comment = normalizeCommentCommunityAddress(comment);\n log(\"commentsStore.addCommentToStore\", { commentCid, comment, account });\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n } else {\n comment = normalizeCommentCommunityAddress(comment);\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(comment) },\n }));\n\n // add comment replies pages to repliesPagesStore so they can be used in useComment\n repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);\n\n comment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, comment, commentData),\n );\n }\n\n if (comment) {\n requestCommentUpdate(commentCid, comment, { stopAfterNextUpdate: true });\n }\n } catch (e: any) {\n addCommentError(commentCid, e);\n throw e;\n } finally {\n pkcGetCommentPending[pendingKey] = false;\n }\n },\n\n async startCommentAutoUpdate(\n commentCid: string,\n subscriberId: string,\n account: Account,\n commentData?: Comment,\n ) {\n const hadAutoUpdateSubscribers = hasCommentAutoUpdateSubscribers(commentCid);\n commentAutoUpdateSubscribers[commentCid] = {\n ...(commentAutoUpdateSubscribers[commentCid] || {}),\n [subscriberId]: true,\n };\n\n if (hadAutoUpdateSubscribers && liveComments[commentCid]) {\n return;\n }\n\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (!storedComment) {\n setState((state: CommentsState) => ({\n comments: { ...state.comments, [commentCid]: utils.clone(liveComment) },\n }));\n }\n\n if (!hasCommentAutoUpdateSubscribers(commentCid)) {\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n return;\n }\n\n requestCommentUpdate(commentCid, liveComment);\n },\n\n async stopCommentAutoUpdate(commentCid: string, subscriberId: string) {\n if (commentAutoUpdateSubscribers[commentCid]) {\n delete commentAutoUpdateSubscribers[commentCid][subscriberId];\n if (Object.keys(commentAutoUpdateSubscribers[commentCid]).length === 0) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n }\n\n if (hasCommentAutoUpdateSubscribers(commentCid)) {\n return;\n }\n\n delete stopCommentAfterNextUpdate[commentCid];\n const liveComment = liveComments[commentCid];\n await stopLiveComment(commentCid, liveComment);\n maybeReleaseStoppedLiveComment(commentCid, liveComment);\n },\n\n async refreshComment(commentCid: string, account: Account, commentData?: Comment) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n mergeCommentData(commentCid, storedComment, commentData),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n return waitForCommentUpdateCycle(commentCid, liveComment, () =>\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n }),\n );\n },\n };\n});\n\nconst getCommentFromDatabase = async (\n commentCid: string,\n account: Account,\n initialCommentData?: Comment,\n) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(\n await account.pkc.createComment(\n mergeCommentData(commentCid, commentData, initialCommentData),\n ),\n );\n return comment;\n } catch (e) {\n // need to log this always or it could silently fail in production and cache never be used\n console.error(\"failed pkc.createComment(cachedComment)\", {\n cachedComment: commentData,\n error: e,\n });\n }\n};\n\n// reset store in between tests\nconst originalState = commentsStore.getState();\n// async function because some stores have async init\nexport const resetCommentsStore = async () => {\n pkcGetCommentPending = {};\n for (const commentCid in commentAutoUpdateSubscribers) {\n delete commentAutoUpdateSubscribers[commentCid];\n }\n for (const commentCid in stopCommentAfterNextUpdate) {\n delete stopCommentAfterNextUpdate[commentCid];\n }\n for (const commentCid in sparseCommentFollowupRequested) {\n delete sparseCommentFollowupRequested[commentCid];\n }\n for (const commentCid in commentUpdateAttemptFailed) {\n delete commentUpdateAttemptFailed[commentCid];\n }\n for (const commentCid in liveCommentPromises) {\n delete liveCommentPromises[commentCid];\n }\n for (const commentCid in liveComments) {\n delete liveComments[commentCid];\n }\n\n // remove all event listeners\n await Promise.all(\n listeners.map(async (listener: any) => {\n try {\n if (typeof listener?.stop === \"function\") {\n await listener.stop();\n }\n } catch {}\n listener?.removeAllListeners?.();\n }),\n );\n listeners.length = 0;\n\n // destroy all component subscriptions to the store\n commentsStore.destroy();\n // restore original state\n commentsStore.setState(originalState);\n};\n\n// reset database and store in between tests\nexport const resetCommentsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-comments\" }).clear();\n await resetCommentsStore();\n};\n\nexport default commentsStore;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EAEP,KAAK,EAEL,Y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AC"}
@@ -14,7 +14,7 @@ import { communityPostsCacheExpired, commentIsValid, removeInvalidComments } fro
14
14
  import { getCommentCommunityAddress, normalizeCommentCommunityAddress } from "../../lib/pkc-compat.js";
15
15
  import { doesAddressMatchCommunityRef, getCommunityRefKeys, getMatchingCommunityRefKeys, } from "../../lib/community-ref.js";
16
16
  import Logger from "@pkcprotocol/pkc-logger";
17
- import { getPostPageSortType, getSortTimeframeSeconds, resolvePostSortType, } from "../../lib/page-sorts.js";
17
+ import { getPostPageSortType, getSortTimeframeSeconds, isBuiltInPostSortType, resolvePostSortType, } from "../../lib/page-sorts.js";
18
18
  const log = Logger("bitsocial-react-hooks:feeds:stores");
19
19
  const getFeedCommunityRefs = (feedOptions) => feedOptions.communities || [];
20
20
  const getFeedCommunityKeys = (feedOptions) => feedOptions.communityKeys || getCommunityRefKeys(getFeedCommunityRefs(feedOptions));
@@ -162,7 +162,18 @@ export const getFilteredSortedFeeds = (feedsOptions, communities, communitiesPag
162
162
  const uniqueResolvedDefaultSortTypes = new Set(resolvedDefaultSortTypes);
163
163
  const originalSortType = feedsOptions[feedName].sortType ||
164
164
  (uniqueResolvedDefaultSortTypes.size === 1 ? resolvedDefaultSortTypes[0] : undefined);
165
- const sortedBufferedFeedPosts = feedSorter.sort(originalSortType, bufferedFeedPosts);
165
+ // one community's pages of a sort already arrive in its order; re-sorting them with the built-in
166
+ // sorter of the same name would undo a sort the client cannot reproduce. A sort served from
167
+ // another sort's complete page still needs the client sort, and feeds merging several
168
+ // communities need a common order, so both keep using the built-in sorter.
169
+ const singleCommunity = communityKeys.length === 1 ? communities[communityKeys[0]] : undefined;
170
+ const keepCommunityOrder = !!singleCommunity &&
171
+ originalSortType !== undefined &&
172
+ getPostPageSortType(singleCommunity, originalSortType) === originalSortType &&
173
+ !isBuiltInPostSortType(singleCommunity, originalSortType);
174
+ const sortedBufferedFeedPosts = keepCommunityOrder
175
+ ? bufferedFeedPosts
176
+ : feedSorter.sort(originalSortType, bufferedFeedPosts);
166
177
  // filter the feed
167
178
  const filteredSortedBufferedFeedPosts = [];
168
179
  for (const post of sortedBufferedFeedPosts) {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":";;;;;;;;;AAeA,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAEL,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAEzD,MAAM,oBAAoB,GAAG,CAAC,WAAiC,EAAwB,EAAE,CACvF,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC;AAEhC,MAAM,oBAAoB,GAAG,CAAC,WAAiC,EAAE,EAAE,CACjE,WAAW,CAAC,aAAa,IAAI,mBAAmB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC;AAEtF,MAAM,mBAAmB,GAAG,CAAC,OAA4B,EAAE,EAAE,eAC3D,OAAA,IAAI,CAAC,GAAG,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,CAAC,EAAE,CAAC,CAAC,CAAA,EAAA,CAAC;AAEhE,MAAM,sBAA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IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import assert from \"assert\";\nimport {\n Comment,\n Feed,\n Feeds,\n FeedOptions,\n FeedsOptions,\n Community,\n Communities,\n Account,\n Accounts,\n CommunityPage,\n CommunitiesPages,\n FeedsCommunitiesPostCounts,\n} from \"../../types\";\nimport { getCommunityPages, getCommunityFirstPageCid } from \"../communities-pages\";\nimport accountsStore from \"../accounts\";\nimport feedSorter from \"./feed-sorter\";\nimport { communityPostsCacheExpired, commentIsValid, removeInvalidComments } from \"../../lib/utils\";\nimport { getCommentCommunityAddress, normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\nimport {\n CommunityLookupRef,\n doesAddressMatchCommunityRef,\n getCommunityRefKeys,\n getMatchingCommunityRefKeys,\n} from \"../../lib/community-ref\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport {\n getPostPageSortType,\n getSortTimeframeSeconds,\n resolvePostSortType,\n} from \"../../lib/page-sorts\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:stores\");\n\nconst getFeedCommunityRefs = (feedOptions: Partial<FeedOptions>): CommunityLookupRef[] =>\n feedOptions.communities || [];\n\nconst getFeedCommunityKeys = (feedOptions: Partial<FeedOptions>) =>\n feedOptions.communityKeys || getCommunityRefKeys(getFeedCommunityRefs(feedOptions));\n\nconst getCommentFreshness = (comment: Comment | undefined) =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\nconst commentMatchesModQueue = (comment: Comment | undefined, modQueue?: string[]) => {\n const modQueueName = modQueue?.[0];\n if (!modQueueName) {\n return true;\n }\n if (modQueueName === \"pendingApproval\") {\n return comment?.pendingApproval === true;\n }\n return true;\n};\n\nconst getFeedPost = (\n post: Comment,\n communityRef: CommunityLookupRef,\n community: Community,\n modQueue?: string[],\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n const normalizedPost = normalizeCommentCommunityAddress(post) as Comment;\n const freshestComment = post.cid\n ? normalizeCommentCommunityAddress(freshestComments?.[post.cid])\n : undefined;\n const postCommunityAddress = getCommentCommunityAddress(normalizedPost);\n if (!doesAddressMatchCommunityRef(postCommunityAddress, communityRef, community)) {\n return;\n }\n if (!commentMatchesModQueue(normalizedPost, modQueue)) {\n return;\n }\n if (\n !freshestComment ||\n getCommentFreshness(freshestComment) <= getCommentFreshness(normalizedPost)\n ) {\n return normalizedPost;\n }\n if (!commentMatchesModQueue(freshestComment, modQueue)) {\n return;\n }\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(freshestComment),\n communityRef,\n community,\n )\n ) {\n return;\n }\n return freshestComment;\n};\n\nconst reconcileLoadedModQueueFeed = (\n feedOptions: FeedOptions,\n loadedFeed: Feed,\n filteredSortedFeed: Feed,\n) => {\n if (!feedOptions?.modQueue?.[0] || !loadedFeed?.length) {\n return loadedFeed;\n }\n\n const filteredSortedFeedByCid = new Map<string, Comment>();\n for (const post of filteredSortedFeed) {\n if (post.cid) {\n filteredSortedFeedByCid.set(post.cid, post);\n }\n }\n\n let changed = false;\n const nextLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (!post.cid) {\n nextLoadedFeed.push(post);\n continue;\n }\n\n const sourcePost = filteredSortedFeedByCid.get(post.cid);\n if (!sourcePost) {\n changed = true;\n continue;\n }\n\n if (getCommentFreshness(sourcePost) > getCommentFreshness(post)) {\n nextLoadedFeed.push(sourcePost);\n changed = true;\n continue;\n }\n\n nextLoadedFeed.push(post);\n }\n\n return changed ? nextLoadedFeed : loadedFeed;\n};\n\n/**\n * Calculate the feeds from all the loaded community pages, filter and sort them\n */\nexport const getFilteredSortedFeeds = (\n feedsOptions: FeedsOptions,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n // calculate each feed\n let feeds: Feeds = {};\n for (const feedName in feedsOptions) {\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, filter, newerThan, modQueue } = feedsOptions[feedName];\n const newerThanTimestamp = newerThan ? Math.floor(Date.now() / 1000) - newerThan : undefined;\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // find all fetched posts\n const bufferedFeedPosts = [];\n\n // add each comment from each page, do not filter at this stage, filter after sorting\n for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const communityRef = communityRefs[communityIndex];\n // community hasn't loaded yet\n const community = communities[communityKey];\n if (!community || !communityRef) {\n continue;\n }\n\n // if cache is expired and has internet access, don't use, wait for next community update\n if (communityPostsCacheExpired(community) && window.navigator.onLine) {\n continue;\n }\n\n // use community preloaded posts if any\n const preloadedPosts = getPreloadedPosts(community, sortType);\n if (preloadedPosts) {\n const clientTimeframeTimestamp = getClientSortTimeframeTimestamp(community, sortType);\n for (const post of preloadedPosts) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(getCommentCommunityAddress(post), communityRef, community)\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (!nextPost) {\n continue;\n }\n // window the reconciled post: pinned is mutable moderation state, and like the pages a\n // community windows itself, pinned posts stay regardless of age\n if (\n clientTimeframeTimestamp !== undefined &&\n !nextPost.pinned &&\n nextPost.timestamp <= clientTimeframeTimestamp\n ) {\n continue;\n }\n bufferedFeedPosts.push(nextPost);\n }\n }\n\n // add all posts from community pages\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n accountId,\n );\n for (const communityPage of communityPages) {\n if (communityPage?.comments) {\n for (const post of communityPage.comments) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(post),\n communityRef,\n community,\n )\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (nextPost) {\n bufferedFeedPosts.push(nextPost);\n }\n }\n }\n }\n }\n\n // sort the feed before filtering to get more accurate results\n const resolvedDefaultSortTypes = communityKeys.map((communityKey) =>\n resolvePostSortType(communities[communityKey], feedsOptions[feedName].sortType),\n );\n const uniqueResolvedDefaultSortTypes = new Set(resolvedDefaultSortTypes);\n const originalSortType =\n feedsOptions[feedName].sortType ||\n (uniqueResolvedDefaultSortTypes.size === 1 ? resolvedDefaultSortTypes[0] : undefined);\n const sortedBufferedFeedPosts = feedSorter.sort(originalSortType, bufferedFeedPosts);\n\n // filter the feed\n const filteredSortedBufferedFeedPosts = [];\n for (const post of sortedBufferedFeedPosts) {\n // address is blocked\n if (\n accounts[accountId]?.blockedAddresses[getCommentCommunityAddress(post) || \"\"] ||\n (post.author?.address && accounts[accountId]?.blockedAddresses[post.author.address])\n ) {\n continue;\n }\n\n // comment cid is blocked\n if (accounts[accountId]?.blockedCids[post.cid]) {\n continue;\n }\n\n // if a feed has more than 1 sub, don't include pinned posts\n // TODO: add test to check if pinned are filtered\n if (post.pinned && communityKeys.length > 1) {\n continue;\n }\n\n // feedOptions filter function\n if (filter && !filter.filter(post)) {\n continue;\n }\n\n // filter posts older than newerThan option\n if (newerThanTimestamp) {\n if (originalSortType === \"active\") {\n if ((post.lastReplyTimestamp || post.timestamp) <= newerThanTimestamp) {\n continue;\n }\n } else {\n if (post.timestamp <= newerThanTimestamp) {\n continue;\n }\n }\n }\n\n filteredSortedBufferedFeedPosts.push(post);\n }\n\n feeds[feedName] = filteredSortedBufferedFeedPosts;\n }\n return feeds;\n};\n\nconst getPreloadedPosts = (community: Community, sortType?: string) => {\n const pageSortType = getPostPageSortType(community, sortType);\n if (!pageSortType) {\n return;\n }\n return community.posts?.pages?.[pageSortType]?.comments;\n};\n\n// a timeframe sort computed client-side from a complete preloaded page applies its own window,\n// like the pages a community publishes for that sort would\nconst getClientSortTimeframeTimestamp = (community: Community, sortType?: string) => {\n const timeframeSeconds = getSortTimeframeSeconds(sortType);\n if (!timeframeSeconds || getPostPageSortType(community, sortType) === sortType) {\n return;\n }\n return Math.floor(Date.now() / 1000) - timeframeSeconds;\n};\n\nexport const getLoadedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n bufferedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const nextLoadedFeeds: Feeds = { ...loadedFeeds };\n let loadedFeedsChanged = false;\n for (const feedName in feedsOptions) {\n const { pageNumber, postsPerPage, accountId } = feedsOptions[feedName];\n const pkc = accounts[accountId]?.pkc;\n const loadedFeedPostCount = pageNumber * postsPerPage;\n const currentLoadedFeed = reconcileLoadedModQueueFeed(\n feedsOptions[feedName],\n loadedFeeds[feedName] || [],\n filteredSortedFeeds[feedName] || [],\n );\n if (currentLoadedFeed !== loadedFeeds[feedName]) {\n nextLoadedFeeds[feedName] = currentLoadedFeed;\n loadedFeedsChanged = true;\n }\n const missingPostsCount =\n loadedFeedPostCount - currentLoadedFeed.filter((post) => post.index === undefined).length;\n\n // get new posts from buffered feed\n const bufferedFeed = bufferedFeeds[feedName] || [];\n\n let missingPosts: any[] = [];\n for (const post of bufferedFeed) {\n if (missingPosts.length >= missingPostsCount) {\n missingPosts = await removeInvalidComments(missingPosts, { validateReplies: false }, pkc);\n // only stop if there were no invalid comments\n if (missingPosts.length >= missingPostsCount) {\n break;\n }\n }\n missingPosts.push(post);\n }\n\n // the current loaded feed already exist and doesn't need new posts\n if (\n missingPosts.length === 0 &&\n loadedFeeds[feedName] &&\n currentLoadedFeed === loadedFeeds[feedName]\n ) {\n continue;\n }\n nextLoadedFeeds[feedName] = [...currentLoadedFeed, ...missingPosts];\n if (missingPosts.length > 0) {\n loadedFeedsChanged = true;\n }\n }\n\n // add account comments\n const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, nextLoadedFeeds);\n\n // do nothing if there are no missing posts\n if (!loadedFeedsChanged && !accountCommentsChangedFeeds) {\n return loadedFeeds;\n }\n return nextLoadedFeeds;\n};\n\nconst getApprovalPublicationKey = (comment: Comment) =>\n [\n comment.timestamp ?? \"\",\n comment.parentCid ?? \"\",\n comment.postCid ?? \"\",\n getCommentCommunityAddress(comment) ?? \"\",\n comment.author?.address ?? \"\",\n comment.title ?? \"\",\n comment.content ?? \"\",\n comment.link ?? \"\",\n ].join(\"\\0\");\n\nexport const addAccountsComments = (feedsOptions: FeedsOptions, loadedFeeds: Feeds) => {\n let loadedFeedsChanged = false;\n const accountsComments = accountsStore.getState().accountsComments || {};\n for (const feedName in feedsOptions) {\n const { accountId, accountComments: accountCommentsOptions } = feedsOptions[feedName];\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const { newerThan, append } = accountCommentsOptions || {};\n if (!newerThan) {\n continue;\n }\n const newerThanTimestamp =\n newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;\n const isNewerThan = (post: Comment) => post.timestamp > newerThanTimestamp;\n\n const accountComments = accountsComments[accountId] || [];\n const accountPosts = accountComments.filter((comment) => {\n // is a reply, not a post\n if (comment.parentCid || comment.depth > 0) {\n return false;\n }\n if (!isNewerThan(comment)) {\n return false;\n }\n return (\n getMatchingCommunityRefKeys(communityRefs, getCommentCommunityAddress(comment)).length > 0\n );\n });\n const validAccountIndices = new Set(accountPosts.map((p) => p.index));\n const accountCidToPost = new Map<string, Comment>();\n for (const p of accountPosts) {\n if (p.cid) accountCidToPost.set(p.cid, p);\n }\n\n let loadedFeed = loadedFeeds[feedName] || [];\n const approvedPublicationKeys = new Set(\n loadedFeed\n .filter((post) => post.pendingApproval !== true)\n .map((post) => getApprovalPublicationKey(post)),\n );\n // prune stale local-account entries and replace when cid matches but index changed\n const prunedLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (post.index === undefined) {\n prunedLoadedFeed.push(post);\n continue;\n }\n if (\n post.pendingApproval === true &&\n approvedPublicationKeys.has(getApprovalPublicationKey(post))\n ) {\n loadedFeedsChanged = true;\n continue;\n }\n if (!validAccountIndices.has(post.index)) {\n loadedFeedsChanged = true;\n continue;\n }\n if (post.cid) {\n const freshAccountPost = accountCidToPost.get(post.cid);\n if (freshAccountPost && freshAccountPost.index !== post.index) {\n prunedLoadedFeed.push(freshAccountPost);\n loadedFeedsChanged = true;\n continue;\n }\n }\n prunedLoadedFeed.push(post);\n }\n loadedFeed = loadedFeeds[feedName] = prunedLoadedFeed;\n\n if (!accountPosts.length) {\n continue;\n }\n // if a loaded comment doesn't have a cid, then it's pending\n // and pending account comments should always have unique timestamps\n const loadedFeedMap = new Map();\n loadedFeed.forEach((post, loadedFeedIndex) => {\n if (post.cid) loadedFeedMap.set(post.cid, loadedFeedIndex);\n if (typeof post.index === \"number\") loadedFeedMap.set(post.index, loadedFeedIndex);\n if (!post.cid) loadedFeedMap.set(post.timestamp, loadedFeedIndex);\n if (post.pendingApproval !== true) {\n loadedFeedMap.set(getApprovalPublicationKey(post), loadedFeedIndex);\n }\n });\n for (const accountPost of accountPosts) {\n // account post with cid already added\n if (accountPost.cid && loadedFeedMap.has(accountPost.cid)) {\n continue;\n }\n if (\n accountPost.pendingApproval === true &&\n loadedFeedMap.has(getApprovalPublicationKey(accountPost))\n ) {\n continue;\n }\n // account post without cid already added, but now we have the cid\n if (accountPost.cid && loadedFeedMap.has(accountPost.index)) {\n const loadedFeedIndex = loadedFeedMap.get(accountPost.index);\n // update the feed with the accountPost.cid now that we have it\n loadedFeed[loadedFeedIndex] = accountPost;\n loadedFeedsChanged = true;\n continue;\n }\n if (loadedFeedMap.has(accountPost.index)) {\n continue;\n }\n // pending account post without cid already added\n if (!accountPost.cid && loadedFeedMap.has(accountPost.timestamp)) {\n continue;\n }\n if (append) {\n loadedFeed.push(accountPost);\n } else {\n loadedFeed.unshift(accountPost);\n }\n loadedFeedsChanged = true;\n }\n }\n return loadedFeedsChanged;\n};\n\nexport const getBufferedFeedsWithoutLoadedFeeds = (bufferedFeeds: Feeds, loadedFeeds: Feeds) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const loadedFeedsPosts: { [key: string]: Set<string> } = {};\n for (const feedName in loadedFeeds) {\n loadedFeedsPosts[feedName] = new Set();\n for (const post of loadedFeeds[feedName]) {\n loadedFeedsPosts[feedName].add(post.cid);\n }\n }\n\n const newBufferedFeeds: Feeds = {};\n for (const feedName in bufferedFeeds) {\n newBufferedFeeds[feedName] = [];\n let bufferedFeedPostChanged = false;\n for (const [i, post] of bufferedFeeds[feedName].entries()) {\n if (loadedFeedsPosts[feedName]?.has(post.cid)) {\n continue;\n }\n newBufferedFeeds[feedName].push(post);\n if (\n !bufferedFeedPostChanged &&\n (newBufferedFeeds[feedName][i]?.cid !== bufferedFeeds[feedName][i]?.cid ||\n (newBufferedFeeds[feedName][i]?.updatedAt || 0) >\n (bufferedFeeds[feedName][i]?.updatedAt || 0))\n ) {\n bufferedFeedPostChanged = true;\n }\n }\n if (\n !bufferedFeedPostChanged &&\n newBufferedFeeds[feedName].length === bufferedFeeds[feedName].length\n ) {\n newBufferedFeeds[feedName] = bufferedFeeds[feedName];\n }\n }\n return newBufferedFeeds;\n};\n\nexport const getUpdatedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n updatedFeeds: Feeds,\n loadedFeeds: Feeds,\n accounts: Accounts,\n) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const updatedFeedsPosts: { [feedName: string]: { [postCid: string]: any } } = {};\n for (const feedName in updatedFeeds) {\n updatedFeedsPosts[feedName] = {};\n for (const [index, updatedPost] of updatedFeeds[feedName].entries()) {\n updatedFeedsPosts[feedName][updatedPost.cid] = { index, updatedPost };\n }\n }\n\n const newUpdatedFeeds: Feeds = { ...updatedFeeds };\n for (const feedName in filteredSortedFeeds) {\n const pkc = accounts[feedsOptions[feedName]?.accountId]?.pkc;\n const updatedFeed = [...(updatedFeeds[feedName] || [])];\n const onlyHasNewPosts = updatedFeed.length === 0;\n let updatedFeedChanged = false;\n\n // add new posts from loadedFeed posts\n while (updatedFeed.length < loadedFeeds[feedName].length) {\n updatedFeed[updatedFeed.length] = loadedFeeds[feedName][updatedFeed.length];\n updatedFeedChanged = true;\n }\n\n // add updated post from filteredSortedFeed\n if (!onlyHasNewPosts) {\n const promises = [];\n for (const post of filteredSortedFeeds[feedName]) {\n if (updatedFeedsPosts[feedName]?.[post.cid]) {\n const { index, updatedPost } = updatedFeedsPosts[feedName][post.cid];\n // faster to validate comments async\n promises.push(\n (async () => {\n if (\n (post.updatedAt || 0) > (updatedPost.updatedAt || 0) &&\n (await commentIsValid(post, { validateReplies: false }, pkc))\n ) {\n updatedFeed[index] = post;\n updatedFeedChanged = true;\n }\n })(),\n );\n }\n }\n await Promise.all(promises);\n }\n\n if (updatedFeedChanged) {\n newUpdatedFeeds[feedName] = updatedFeed;\n }\n }\n return newUpdatedFeeds;\n};\n\n// find with communities have posts newer (or ranked higher) than the loaded feeds\n// can be used to display \"new posts in x, y, z subs\" alert, like on twitter\nexport const getFeedsCommunityKeysWithNewerPosts = (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n previousFeedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] },\n) => {\n const feedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] } = {};\n for (const feedName in loadedFeeds) {\n const loadedFeed = loadedFeeds[feedName];\n const cidsInLoadedFeed = new Set();\n for (const post of loadedFeed) {\n cidsInLoadedFeed.add(post.cid);\n }\n const communityKeysWithNewerPostsSet = new Set<string>();\n for (const [i, post] of filteredSortedFeeds[feedName].entries()) {\n if (i >= loadedFeed.length) {\n break;\n }\n // if any post in filteredSortedFeeds ranks higher than the loaded feed count, it's a newer post\n if (!cidsInLoadedFeed.has(post.cid)) {\n const postCommunityAddress = getCommentCommunityAddress(post);\n if (postCommunityAddress) {\n getMatchingCommunityRefKeys(\n getFeedCommunityRefs(feedsOptions[feedName] || {}),\n postCommunityAddress,\n ).forEach((communityKey) => communityKeysWithNewerPostsSet.add(communityKey));\n }\n }\n }\n const communityKeysWithNewerPosts = [...communityKeysWithNewerPostsSet];\n\n // don't update the array if the data is the same to avoid rerenders\n const previousCommunityKeysWithNewerPosts =\n previousFeedsCommunityKeysWithNewerPosts[feedName] || [];\n if (\n communityKeysWithNewerPosts.length === previousCommunityKeysWithNewerPosts.length &&\n communityKeysWithNewerPosts.toString() === previousCommunityKeysWithNewerPosts.toString()\n ) {\n feedsCommunityKeysWithNewerPosts[feedName] =\n previousFeedsCommunityKeysWithNewerPosts[feedName];\n } else {\n feedsCommunityKeysWithNewerPosts[feedName] = communityKeysWithNewerPosts;\n }\n }\n return feedsCommunityKeysWithNewerPosts;\n};\n\n// find how many posts are left in each communities in a buffereds feeds\nexport const getFeedsCommunitiesPostCounts = (feedsOptions: FeedsOptions, feeds: Feeds) => {\n const feedsCommunitiesPostCounts: FeedsCommunitiesPostCounts = {};\n for (const feedName in feedsOptions) {\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n feedsCommunitiesPostCounts[feedName] = {};\n for (const communityKey of communityKeys) {\n feedsCommunitiesPostCounts[feedName][communityKey] = 0;\n }\n for (const comment of feeds[feedName] || []) {\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress) {\n getMatchingCommunityRefKeys(communityRefs, commentCommunityAddress).forEach(\n (communityKey) => {\n feedsCommunitiesPostCounts[feedName][communityKey] =\n (feedsCommunitiesPostCounts[feedName][communityKey] || 0) + 1;\n },\n );\n }\n }\n }\n return feedsCommunitiesPostCounts;\n};\n\n/**\n * Get which feeds have more posts, i.e. have not reached the final page of all subs\n */\nexport const getFeedsHaveMore = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n) => {\n const feedsHaveMore: { [feedName: string]: boolean } = {};\n feedsLoop: for (const feedName in feedsOptions) {\n // if the feed still has buffered posts, then it still has more\n if (bufferedFeeds[feedName]?.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, modQueue } = feedsOptions[feedName];\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n communityKeysLoop: for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const community = communities[communityKey];\n const communityRef = communityRefs[communityIndex];\n const isBlockedCommunity = Object.keys(accounts[accountId]?.blockedAddresses || {}).some(\n (blockedAddress) =>\n communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community),\n );\n\n // don't consider the sub if the address is blocked\n if (isBlockedCommunity) {\n continue communityKeysLoop;\n }\n\n // if at least 1 community hasn't loaded yet, then the feed still has more\n if (!community?.updatedAt) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n // if at least 1 community has posts cache expired, then the feed still has more\n if (communityPostsCacheExpired(community)) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n // 'continue' to ignore it for now\n if (!firstPageCid) {\n continue communityKeysLoop;\n }\n const pages = getCommunityPages(community, sortType, communitiesPages, pageType, accountId);\n // if first page isn't loaded yet, then the feed still has more\n if (!pages.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n const lastPage = pages[pages.length - 1];\n if (lastPage.nextCid) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n }\n\n // if buffered feeds are empty and no last page of any community has a next page, then has more is false\n feedsHaveMore[feedName] = false;\n }\n return feedsHaveMore;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunities = (feedsOptions: FeedsOptions, communities: Communities) => {\n // find all feeds communities\n const feedsCommunityAddresses = new Set<string>();\n Object.keys(feedsOptions).forEach((i) =>\n getFeedCommunityKeys(feedsOptions[i]).forEach((a) => feedsCommunityAddresses.add(a)),\n );\n\n // use map for performance increase when checking size\n const feedsCommunities = new Map<string, Community>();\n for (const communityAddress of feedsCommunityAddresses) {\n feedsCommunities.set(communityAddress, communities[communityAddress]);\n }\n return feedsCommunities;\n};\n\nexport const feedsCommunitiesChanged = (\n previousFeedsCommunities: Map<string, Community>,\n feedsCommunities: Map<string, Community>,\n) => {\n if (previousFeedsCommunities.size !== feedsCommunities.size) {\n return true;\n }\n for (let communityAddress of previousFeedsCommunities.keys()) {\n // check if the object is still the same\n if (previousFeedsCommunities.get(communityAddress) !== feedsCommunities.get(communityAddress)) {\n return true;\n }\n }\n return false;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesFirstPageCids = (\n feedsCommunities: Map<string, Community>,\n): string[] => {\n // find all the feeds communities first page cids\n const feedsCommunitiesFirstPageCids = new Set<string>();\n for (const community of feedsCommunities.values()) {\n if (!community?.posts && !community?.modQueue) {\n continue;\n }\n\n // check pages\n if (community.posts?.pages) {\n for (const page of Object.values<CommunityPage>(community.posts.pages)) {\n if (page?.nextCid) {\n feedsCommunitiesFirstPageCids.add(page?.nextCid);\n }\n }\n }\n\n // check pageCids\n if (community.posts?.pageCids) {\n for (const pageCid of Object.values<string>(community.posts.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n\n // TODO: would be more performant to only check modQueue if there's a feedOptions with modQueue\n if (community.modQueue?.pageCids) {\n for (const pageCid of Object.values<string>(community.modQueue.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n }\n\n return [...feedsCommunitiesFirstPageCids].sort();\n};\n\n// get all communities posts pages first post updatedAts, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesPostsPagesFirstUpdatedAts = (\n feedsCommunities: Map<string, Community>,\n): string => {\n let feedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\n for (const community of feedsCommunities.values()) {\n for (const page of Object.values<CommunityPage>(community?.posts?.pages || {})) {\n if (page?.comments?.[0]?.updatedAt) {\n feedsCommunitiesPostsPagesFirstUpdatedAts +=\n page.comments[0].cid + page.comments[0].updatedAt;\n }\n }\n }\n return feedsCommunitiesPostsPagesFirstUpdatedAts;\n};\n\n// get number of feeds community that are loaded\nexport const getFeedsCommunitiesLoadedCount = (\n feedsCommunities: Map<string, Community>,\n): number => {\n let count = 0;\n for (const community of feedsCommunities.values()) {\n if (community?.updatedAt) {\n count++;\n }\n }\n return count;\n};\n\nexport const getAccountsBlockedAddresses = (accounts: Accounts) => {\n const blockedAddressesSet = new Set<string>();\n for (const { blockedAddresses } of Object.values(accounts)) {\n for (const address in blockedAddresses) {\n if (blockedAddresses[address]) {\n blockedAddressesSet.add(address);\n }\n }\n }\n return [...blockedAddressesSet].sort();\n};\n\nexport const accountsBlockedAddressesChanged = (\n previousAccountsBlockedAddresses: { [address: string]: boolean }[],\n accountsBlockedAddresses: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedAddresses.length !== accountsBlockedAddresses.length) {\n return true;\n }\n for (const i in previousAccountsBlockedAddresses) {\n // check if the object is still the same\n if (previousAccountsBlockedAddresses[i] !== accountsBlockedAddresses[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedAddresses = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedAddresses: string[],\n previousBlockedAddresses: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedAddresses = blockedAddresses\n .filter((x) => !previousBlockedAddresses.includes(x))\n .concat(previousBlockedAddresses.filter((x) => !blockedAddresses.includes(x)));\n\n // if changed blocked addresses arent used in the feeds, do nothing\n for (const address of changedBlockedAddresses) {\n for (const feedName in feedsOptions) {\n const feedOptions = feedsOptions[feedName];\n if (\n getMatchingCommunityRefKeys(getFeedCommunityRefs(feedOptions), address).some(\n (communityKey) => getFeedCommunityKeys(feedOptions).includes(communityKey),\n )\n ) {\n return true;\n }\n }\n }\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedAddressesSet = new Set(changedBlockedAddresses);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.author?.address && changedBlockedAddressesSet.has(post.author.address)) {\n return true;\n }\n }\n }\n\n return false;\n};\n\nexport const getAccountsBlockedCids = (accounts: Accounts) => {\n const blockedCidsSet = new Set<string>();\n for (const { blockedCids } of Object.values(accounts)) {\n for (const address in blockedCids) {\n if (blockedCids[address]) {\n blockedCidsSet.add(address);\n }\n }\n }\n return [...blockedCidsSet].sort();\n};\n\nexport const accountsBlockedCidsChanged = (\n previousAccountsBlockedCids: { [address: string]: boolean }[],\n accountsBlockedCids: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedCids.length !== accountsBlockedCids.length) {\n return true;\n }\n for (const i in previousAccountsBlockedCids) {\n // check if the object is still the same\n if (previousAccountsBlockedCids[i] !== accountsBlockedCids[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedCids = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedCids: string[],\n previousBlockedCids: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedCids = blockedCids\n .filter((x) => !previousBlockedCids.includes(x))\n .concat(previousBlockedCids.filter((x) => !blockedCids.includes(x)));\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedCidsSet = new Set(changedBlockedCids);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.cid && changedBlockedCidsSet.has(post?.cid)) {\n return true;\n }\n }\n }\n\n return false;\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":";;;;;;;;;AAeA,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAEL,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,MAAM,GAAG,GAAG,MAAM,CAAC,oCAAoC,CAAC,CAAC;AAEzD,MAAM,oBAAoB,GAAG,CAAC,WAAiC,EAAwB,EAAE,CACvF,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC;AAEhC,MAAM,oBAAoB,GAAG,CAAC,WAAiC,EAAE,EAAE,CACjE,WAAW,CAAC,aAAa,IAAI,mBAAmB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC;AAEtF,MAAM,mBAAmB,GAAG,CAAC,OAA4B,EAAE,EAAE,eAC3D,OAAA,IAAI,CAAC,GAAG,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,CAAC,EAAE,CAAC,CAAC,CAAA,EAAA,CAAC;AA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C,CAAC,CAAC,CAAC;IAEvE,8DAA8D;IAC9D,+GAA+G;IAC/G,+FAA+F;IAC/F,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC1D,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;YACjD,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,KAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC;gBACtD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import assert from \"assert\";\nimport {\n Comment,\n Feed,\n Feeds,\n FeedOptions,\n FeedsOptions,\n Community,\n Communities,\n Account,\n Accounts,\n CommunityPage,\n CommunitiesPages,\n FeedsCommunitiesPostCounts,\n} from \"../../types\";\nimport { getCommunityPages, getCommunityFirstPageCid } from \"../communities-pages\";\nimport accountsStore from \"../accounts\";\nimport feedSorter from \"./feed-sorter\";\nimport { communityPostsCacheExpired, commentIsValid, removeInvalidComments } from \"../../lib/utils\";\nimport { getCommentCommunityAddress, normalizeCommentCommunityAddress } from \"../../lib/pkc-compat\";\nimport {\n CommunityLookupRef,\n doesAddressMatchCommunityRef,\n getCommunityRefKeys,\n getMatchingCommunityRefKeys,\n} from \"../../lib/community-ref\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport {\n getPostPageSortType,\n getSortTimeframeSeconds,\n isBuiltInPostSortType,\n resolvePostSortType,\n} from \"../../lib/page-sorts\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:stores\");\n\nconst getFeedCommunityRefs = (feedOptions: Partial<FeedOptions>): CommunityLookupRef[] =>\n feedOptions.communities || [];\n\nconst getFeedCommunityKeys = (feedOptions: Partial<FeedOptions>) =>\n feedOptions.communityKeys || getCommunityRefKeys(getFeedCommunityRefs(feedOptions));\n\nconst getCommentFreshness = (comment: Comment | undefined) =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\nconst commentMatchesModQueue = (comment: Comment | undefined, modQueue?: string[]) => {\n const modQueueName = modQueue?.[0];\n if (!modQueueName) {\n return true;\n }\n if (modQueueName === \"pendingApproval\") {\n return comment?.pendingApproval === true;\n }\n return true;\n};\n\nconst getFeedPost = (\n post: Comment,\n communityRef: CommunityLookupRef,\n community: Community,\n modQueue?: string[],\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n const normalizedPost = normalizeCommentCommunityAddress(post) as Comment;\n const freshestComment = post.cid\n ? normalizeCommentCommunityAddress(freshestComments?.[post.cid])\n : undefined;\n const postCommunityAddress = getCommentCommunityAddress(normalizedPost);\n if (!doesAddressMatchCommunityRef(postCommunityAddress, communityRef, community)) {\n return;\n }\n if (!commentMatchesModQueue(normalizedPost, modQueue)) {\n return;\n }\n if (\n !freshestComment ||\n getCommentFreshness(freshestComment) <= getCommentFreshness(normalizedPost)\n ) {\n return normalizedPost;\n }\n if (!commentMatchesModQueue(freshestComment, modQueue)) {\n return;\n }\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(freshestComment),\n communityRef,\n community,\n )\n ) {\n return;\n }\n return freshestComment;\n};\n\nconst reconcileLoadedModQueueFeed = (\n feedOptions: FeedOptions,\n loadedFeed: Feed,\n filteredSortedFeed: Feed,\n) => {\n if (!feedOptions?.modQueue?.[0] || !loadedFeed?.length) {\n return loadedFeed;\n }\n\n const filteredSortedFeedByCid = new Map<string, Comment>();\n for (const post of filteredSortedFeed) {\n if (post.cid) {\n filteredSortedFeedByCid.set(post.cid, post);\n }\n }\n\n let changed = false;\n const nextLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (!post.cid) {\n nextLoadedFeed.push(post);\n continue;\n }\n\n const sourcePost = filteredSortedFeedByCid.get(post.cid);\n if (!sourcePost) {\n changed = true;\n continue;\n }\n\n if (getCommentFreshness(sourcePost) > getCommentFreshness(post)) {\n nextLoadedFeed.push(sourcePost);\n changed = true;\n continue;\n }\n\n nextLoadedFeed.push(post);\n }\n\n return changed ? nextLoadedFeed : loadedFeed;\n};\n\n/**\n * Calculate the feeds from all the loaded community pages, filter and sort them\n */\nexport const getFilteredSortedFeeds = (\n feedsOptions: FeedsOptions,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n freshestComments?: { [commentCid: string]: Comment },\n) => {\n // calculate each feed\n let feeds: Feeds = {};\n for (const feedName in feedsOptions) {\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, filter, newerThan, modQueue } = feedsOptions[feedName];\n const newerThanTimestamp = newerThan ? Math.floor(Date.now() / 1000) - newerThan : undefined;\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n // find all fetched posts\n const bufferedFeedPosts = [];\n\n // add each comment from each page, do not filter at this stage, filter after sorting\n for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const communityRef = communityRefs[communityIndex];\n // community hasn't loaded yet\n const community = communities[communityKey];\n if (!community || !communityRef) {\n continue;\n }\n\n // if cache is expired and has internet access, don't use, wait for next community update\n if (communityPostsCacheExpired(community) && window.navigator.onLine) {\n continue;\n }\n\n // use community preloaded posts if any\n const preloadedPosts = getPreloadedPosts(community, sortType);\n if (preloadedPosts) {\n const clientTimeframeTimestamp = getClientSortTimeframeTimestamp(community, sortType);\n for (const post of preloadedPosts) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(getCommentCommunityAddress(post), communityRef, community)\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (!nextPost) {\n continue;\n }\n // window the reconciled post: pinned is mutable moderation state, and like the pages a\n // community windows itself, pinned posts stay regardless of age\n if (\n clientTimeframeTimestamp !== undefined &&\n !nextPost.pinned &&\n nextPost.timestamp <= clientTimeframeTimestamp\n ) {\n continue;\n }\n bufferedFeedPosts.push(nextPost);\n }\n }\n\n // add all posts from community pages\n const communityPages = getCommunityPages(\n community,\n sortType,\n communitiesPages,\n pageType,\n accountId,\n );\n for (const communityPage of communityPages) {\n if (communityPage?.comments) {\n for (const post of communityPage.comments) {\n // posts are manually validated, could have fake communityAddress\n if (\n !doesAddressMatchCommunityRef(\n getCommentCommunityAddress(post),\n communityRef,\n community,\n )\n ) {\n break;\n }\n const nextPost = getFeedPost(post, communityRef, community, modQueue, freshestComments);\n if (nextPost) {\n bufferedFeedPosts.push(nextPost);\n }\n }\n }\n }\n }\n\n // sort the feed before filtering to get more accurate results\n const resolvedDefaultSortTypes = communityKeys.map((communityKey) =>\n resolvePostSortType(communities[communityKey], feedsOptions[feedName].sortType),\n );\n const uniqueResolvedDefaultSortTypes = new Set(resolvedDefaultSortTypes);\n const originalSortType =\n feedsOptions[feedName].sortType ||\n (uniqueResolvedDefaultSortTypes.size === 1 ? resolvedDefaultSortTypes[0] : undefined);\n // one community's pages of a sort already arrive in its order; re-sorting them with the built-in\n // sorter of the same name would undo a sort the client cannot reproduce. A sort served from\n // another sort's complete page still needs the client sort, and feeds merging several\n // communities need a common order, so both keep using the built-in sorter.\n const singleCommunity = communityKeys.length === 1 ? communities[communityKeys[0]] : undefined;\n const keepCommunityOrder =\n !!singleCommunity &&\n originalSortType !== undefined &&\n getPostPageSortType(singleCommunity, originalSortType) === originalSortType &&\n !isBuiltInPostSortType(singleCommunity, originalSortType);\n const sortedBufferedFeedPosts = keepCommunityOrder\n ? bufferedFeedPosts\n : feedSorter.sort(originalSortType, bufferedFeedPosts);\n\n // filter the feed\n const filteredSortedBufferedFeedPosts = [];\n for (const post of sortedBufferedFeedPosts) {\n // address is blocked\n if (\n accounts[accountId]?.blockedAddresses[getCommentCommunityAddress(post) || \"\"] ||\n (post.author?.address && accounts[accountId]?.blockedAddresses[post.author.address])\n ) {\n continue;\n }\n\n // comment cid is blocked\n if (accounts[accountId]?.blockedCids[post.cid]) {\n continue;\n }\n\n // if a feed has more than 1 sub, don't include pinned posts\n // TODO: add test to check if pinned are filtered\n if (post.pinned && communityKeys.length > 1) {\n continue;\n }\n\n // feedOptions filter function\n if (filter && !filter.filter(post)) {\n continue;\n }\n\n // filter posts older than newerThan option\n if (newerThanTimestamp) {\n if (originalSortType === \"active\") {\n if ((post.lastReplyTimestamp || post.timestamp) <= newerThanTimestamp) {\n continue;\n }\n } else {\n if (post.timestamp <= newerThanTimestamp) {\n continue;\n }\n }\n }\n\n filteredSortedBufferedFeedPosts.push(post);\n }\n\n feeds[feedName] = filteredSortedBufferedFeedPosts;\n }\n return feeds;\n};\n\nconst getPreloadedPosts = (community: Community, sortType?: string) => {\n const pageSortType = getPostPageSortType(community, sortType);\n if (!pageSortType) {\n return;\n }\n return community.posts?.pages?.[pageSortType]?.comments;\n};\n\n// a timeframe sort computed client-side from a complete preloaded page applies its own window,\n// like the pages a community publishes for that sort would\nconst getClientSortTimeframeTimestamp = (community: Community, sortType?: string) => {\n const timeframeSeconds = getSortTimeframeSeconds(sortType);\n if (!timeframeSeconds || getPostPageSortType(community, sortType) === sortType) {\n return;\n }\n return Math.floor(Date.now() / 1000) - timeframeSeconds;\n};\n\nexport const getLoadedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n bufferedFeeds: Feeds,\n accounts: Accounts,\n) => {\n const nextLoadedFeeds: Feeds = { ...loadedFeeds };\n let loadedFeedsChanged = false;\n for (const feedName in feedsOptions) {\n const { pageNumber, postsPerPage, accountId } = feedsOptions[feedName];\n const pkc = accounts[accountId]?.pkc;\n const loadedFeedPostCount = pageNumber * postsPerPage;\n const currentLoadedFeed = reconcileLoadedModQueueFeed(\n feedsOptions[feedName],\n loadedFeeds[feedName] || [],\n filteredSortedFeeds[feedName] || [],\n );\n if (currentLoadedFeed !== loadedFeeds[feedName]) {\n nextLoadedFeeds[feedName] = currentLoadedFeed;\n loadedFeedsChanged = true;\n }\n const missingPostsCount =\n loadedFeedPostCount - currentLoadedFeed.filter((post) => post.index === undefined).length;\n\n // get new posts from buffered feed\n const bufferedFeed = bufferedFeeds[feedName] || [];\n\n let missingPosts: any[] = [];\n for (const post of bufferedFeed) {\n if (missingPosts.length >= missingPostsCount) {\n missingPosts = await removeInvalidComments(missingPosts, { validateReplies: false }, pkc);\n // only stop if there were no invalid comments\n if (missingPosts.length >= missingPostsCount) {\n break;\n }\n }\n missingPosts.push(post);\n }\n\n // the current loaded feed already exist and doesn't need new posts\n if (\n missingPosts.length === 0 &&\n loadedFeeds[feedName] &&\n currentLoadedFeed === loadedFeeds[feedName]\n ) {\n continue;\n }\n nextLoadedFeeds[feedName] = [...currentLoadedFeed, ...missingPosts];\n if (missingPosts.length > 0) {\n loadedFeedsChanged = true;\n }\n }\n\n // add account comments\n const accountCommentsChangedFeeds = addAccountsComments(feedsOptions, nextLoadedFeeds);\n\n // do nothing if there are no missing posts\n if (!loadedFeedsChanged && !accountCommentsChangedFeeds) {\n return loadedFeeds;\n }\n return nextLoadedFeeds;\n};\n\nconst getApprovalPublicationKey = (comment: Comment) =>\n [\n comment.timestamp ?? \"\",\n comment.parentCid ?? \"\",\n comment.postCid ?? \"\",\n getCommentCommunityAddress(comment) ?? \"\",\n comment.author?.address ?? \"\",\n comment.title ?? \"\",\n comment.content ?? \"\",\n comment.link ?? \"\",\n ].join(\"\\0\");\n\nexport const addAccountsComments = (feedsOptions: FeedsOptions, loadedFeeds: Feeds) => {\n let loadedFeedsChanged = false;\n const accountsComments = accountsStore.getState().accountsComments || {};\n for (const feedName in feedsOptions) {\n const { accountId, accountComments: accountCommentsOptions } = feedsOptions[feedName];\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const { newerThan, append } = accountCommentsOptions || {};\n if (!newerThan) {\n continue;\n }\n const newerThanTimestamp =\n newerThan === Infinity ? 0 : Math.floor(Date.now() / 1000) - newerThan;\n const isNewerThan = (post: Comment) => post.timestamp > newerThanTimestamp;\n\n const accountComments = accountsComments[accountId] || [];\n const accountPosts = accountComments.filter((comment) => {\n // is a reply, not a post\n if (comment.parentCid || comment.depth > 0) {\n return false;\n }\n if (!isNewerThan(comment)) {\n return false;\n }\n return (\n getMatchingCommunityRefKeys(communityRefs, getCommentCommunityAddress(comment)).length > 0\n );\n });\n const validAccountIndices = new Set(accountPosts.map((p) => p.index));\n const accountCidToPost = new Map<string, Comment>();\n for (const p of accountPosts) {\n if (p.cid) accountCidToPost.set(p.cid, p);\n }\n\n let loadedFeed = loadedFeeds[feedName] || [];\n const approvedPublicationKeys = new Set(\n loadedFeed\n .filter((post) => post.pendingApproval !== true)\n .map((post) => getApprovalPublicationKey(post)),\n );\n // prune stale local-account entries and replace when cid matches but index changed\n const prunedLoadedFeed: Comment[] = [];\n for (const post of loadedFeed) {\n if (post.index === undefined) {\n prunedLoadedFeed.push(post);\n continue;\n }\n if (\n post.pendingApproval === true &&\n approvedPublicationKeys.has(getApprovalPublicationKey(post))\n ) {\n loadedFeedsChanged = true;\n continue;\n }\n if (!validAccountIndices.has(post.index)) {\n loadedFeedsChanged = true;\n continue;\n }\n if (post.cid) {\n const freshAccountPost = accountCidToPost.get(post.cid);\n if (freshAccountPost && freshAccountPost.index !== post.index) {\n prunedLoadedFeed.push(freshAccountPost);\n loadedFeedsChanged = true;\n continue;\n }\n }\n prunedLoadedFeed.push(post);\n }\n loadedFeed = loadedFeeds[feedName] = prunedLoadedFeed;\n\n if (!accountPosts.length) {\n continue;\n }\n // if a loaded comment doesn't have a cid, then it's pending\n // and pending account comments should always have unique timestamps\n const loadedFeedMap = new Map();\n loadedFeed.forEach((post, loadedFeedIndex) => {\n if (post.cid) loadedFeedMap.set(post.cid, loadedFeedIndex);\n if (typeof post.index === \"number\") loadedFeedMap.set(post.index, loadedFeedIndex);\n if (!post.cid) loadedFeedMap.set(post.timestamp, loadedFeedIndex);\n if (post.pendingApproval !== true) {\n loadedFeedMap.set(getApprovalPublicationKey(post), loadedFeedIndex);\n }\n });\n for (const accountPost of accountPosts) {\n // account post with cid already added\n if (accountPost.cid && loadedFeedMap.has(accountPost.cid)) {\n continue;\n }\n if (\n accountPost.pendingApproval === true &&\n loadedFeedMap.has(getApprovalPublicationKey(accountPost))\n ) {\n continue;\n }\n // account post without cid already added, but now we have the cid\n if (accountPost.cid && loadedFeedMap.has(accountPost.index)) {\n const loadedFeedIndex = loadedFeedMap.get(accountPost.index);\n // update the feed with the accountPost.cid now that we have it\n loadedFeed[loadedFeedIndex] = accountPost;\n loadedFeedsChanged = true;\n continue;\n }\n if (loadedFeedMap.has(accountPost.index)) {\n continue;\n }\n // pending account post without cid already added\n if (!accountPost.cid && loadedFeedMap.has(accountPost.timestamp)) {\n continue;\n }\n if (append) {\n loadedFeed.push(accountPost);\n } else {\n loadedFeed.unshift(accountPost);\n }\n loadedFeedsChanged = true;\n }\n }\n return loadedFeedsChanged;\n};\n\nexport const getBufferedFeedsWithoutLoadedFeeds = (bufferedFeeds: Feeds, loadedFeeds: Feeds) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const loadedFeedsPosts: { [key: string]: Set<string> } = {};\n for (const feedName in loadedFeeds) {\n loadedFeedsPosts[feedName] = new Set();\n for (const post of loadedFeeds[feedName]) {\n loadedFeedsPosts[feedName].add(post.cid);\n }\n }\n\n const newBufferedFeeds: Feeds = {};\n for (const feedName in bufferedFeeds) {\n newBufferedFeeds[feedName] = [];\n let bufferedFeedPostChanged = false;\n for (const [i, post] of bufferedFeeds[feedName].entries()) {\n if (loadedFeedsPosts[feedName]?.has(post.cid)) {\n continue;\n }\n newBufferedFeeds[feedName].push(post);\n if (\n !bufferedFeedPostChanged &&\n (newBufferedFeeds[feedName][i]?.cid !== bufferedFeeds[feedName][i]?.cid ||\n (newBufferedFeeds[feedName][i]?.updatedAt || 0) >\n (bufferedFeeds[feedName][i]?.updatedAt || 0))\n ) {\n bufferedFeedPostChanged = true;\n }\n }\n if (\n !bufferedFeedPostChanged &&\n newBufferedFeeds[feedName].length === bufferedFeeds[feedName].length\n ) {\n newBufferedFeeds[feedName] = bufferedFeeds[feedName];\n }\n }\n return newBufferedFeeds;\n};\n\nexport const getUpdatedFeeds = async (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n updatedFeeds: Feeds,\n loadedFeeds: Feeds,\n accounts: Accounts,\n) => {\n // contruct a list of posts already loaded to remove them from buffered feeds\n const updatedFeedsPosts: { [feedName: string]: { [postCid: string]: any } } = {};\n for (const feedName in updatedFeeds) {\n updatedFeedsPosts[feedName] = {};\n for (const [index, updatedPost] of updatedFeeds[feedName].entries()) {\n updatedFeedsPosts[feedName][updatedPost.cid] = { index, updatedPost };\n }\n }\n\n const newUpdatedFeeds: Feeds = { ...updatedFeeds };\n for (const feedName in filteredSortedFeeds) {\n const pkc = accounts[feedsOptions[feedName]?.accountId]?.pkc;\n const updatedFeed = [...(updatedFeeds[feedName] || [])];\n const onlyHasNewPosts = updatedFeed.length === 0;\n let updatedFeedChanged = false;\n\n // add new posts from loadedFeed posts\n while (updatedFeed.length < loadedFeeds[feedName].length) {\n updatedFeed[updatedFeed.length] = loadedFeeds[feedName][updatedFeed.length];\n updatedFeedChanged = true;\n }\n\n // add updated post from filteredSortedFeed\n if (!onlyHasNewPosts) {\n const promises = [];\n for (const post of filteredSortedFeeds[feedName]) {\n if (updatedFeedsPosts[feedName]?.[post.cid]) {\n const { index, updatedPost } = updatedFeedsPosts[feedName][post.cid];\n // faster to validate comments async\n promises.push(\n (async () => {\n if (\n (post.updatedAt || 0) > (updatedPost.updatedAt || 0) &&\n (await commentIsValid(post, { validateReplies: false }, pkc))\n ) {\n updatedFeed[index] = post;\n updatedFeedChanged = true;\n }\n })(),\n );\n }\n }\n await Promise.all(promises);\n }\n\n if (updatedFeedChanged) {\n newUpdatedFeeds[feedName] = updatedFeed;\n }\n }\n return newUpdatedFeeds;\n};\n\n// find with communities have posts newer (or ranked higher) than the loaded feeds\n// can be used to display \"new posts in x, y, z subs\" alert, like on twitter\nexport const getFeedsCommunityKeysWithNewerPosts = (\n feedsOptions: FeedsOptions,\n filteredSortedFeeds: Feeds,\n loadedFeeds: Feeds,\n previousFeedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] },\n) => {\n const feedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] } = {};\n for (const feedName in loadedFeeds) {\n const loadedFeed = loadedFeeds[feedName];\n const cidsInLoadedFeed = new Set();\n for (const post of loadedFeed) {\n cidsInLoadedFeed.add(post.cid);\n }\n const communityKeysWithNewerPostsSet = new Set<string>();\n for (const [i, post] of filteredSortedFeeds[feedName].entries()) {\n if (i >= loadedFeed.length) {\n break;\n }\n // if any post in filteredSortedFeeds ranks higher than the loaded feed count, it's a newer post\n if (!cidsInLoadedFeed.has(post.cid)) {\n const postCommunityAddress = getCommentCommunityAddress(post);\n if (postCommunityAddress) {\n getMatchingCommunityRefKeys(\n getFeedCommunityRefs(feedsOptions[feedName] || {}),\n postCommunityAddress,\n ).forEach((communityKey) => communityKeysWithNewerPostsSet.add(communityKey));\n }\n }\n }\n const communityKeysWithNewerPosts = [...communityKeysWithNewerPostsSet];\n\n // don't update the array if the data is the same to avoid rerenders\n const previousCommunityKeysWithNewerPosts =\n previousFeedsCommunityKeysWithNewerPosts[feedName] || [];\n if (\n communityKeysWithNewerPosts.length === previousCommunityKeysWithNewerPosts.length &&\n communityKeysWithNewerPosts.toString() === previousCommunityKeysWithNewerPosts.toString()\n ) {\n feedsCommunityKeysWithNewerPosts[feedName] =\n previousFeedsCommunityKeysWithNewerPosts[feedName];\n } else {\n feedsCommunityKeysWithNewerPosts[feedName] = communityKeysWithNewerPosts;\n }\n }\n return feedsCommunityKeysWithNewerPosts;\n};\n\n// find how many posts are left in each communities in a buffereds feeds\nexport const getFeedsCommunitiesPostCounts = (feedsOptions: FeedsOptions, feeds: Feeds) => {\n const feedsCommunitiesPostCounts: FeedsCommunitiesPostCounts = {};\n for (const feedName in feedsOptions) {\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n feedsCommunitiesPostCounts[feedName] = {};\n for (const communityKey of communityKeys) {\n feedsCommunitiesPostCounts[feedName][communityKey] = 0;\n }\n for (const comment of feeds[feedName] || []) {\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress) {\n getMatchingCommunityRefKeys(communityRefs, commentCommunityAddress).forEach(\n (communityKey) => {\n feedsCommunitiesPostCounts[feedName][communityKey] =\n (feedsCommunitiesPostCounts[feedName][communityKey] || 0) + 1;\n },\n );\n }\n }\n }\n return feedsCommunitiesPostCounts;\n};\n\n/**\n * Get which feeds have more posts, i.e. have not reached the final page of all subs\n */\nexport const getFeedsHaveMore = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n communities: Communities,\n communitiesPages: CommunitiesPages,\n accounts: Accounts,\n) => {\n const feedsHaveMore: { [feedName: string]: boolean } = {};\n feedsLoop: for (const feedName in feedsOptions) {\n // if the feed still has buffered posts, then it still has more\n if (bufferedFeeds[feedName]?.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const communityRefs = getFeedCommunityRefs(feedsOptions[feedName]);\n const communityKeys = getFeedCommunityKeys(feedsOptions[feedName]);\n let { sortType, accountId, modQueue } = feedsOptions[feedName];\n\n let pageType = \"posts\";\n if (modQueue?.[0]) {\n // TODO: allow multiple modQueue at once, fow now only use first in array\n sortType = modQueue[0];\n pageType = \"modQueue\";\n }\n\n communityKeysLoop: for (const [communityIndex, communityKey] of communityKeys.entries()) {\n const community = communities[communityKey];\n const communityRef = communityRefs[communityIndex];\n const isBlockedCommunity = Object.keys(accounts[accountId]?.blockedAddresses || {}).some(\n (blockedAddress) =>\n communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community),\n );\n\n // don't consider the sub if the address is blocked\n if (isBlockedCommunity) {\n continue communityKeysLoop;\n }\n\n // if at least 1 community hasn't loaded yet, then the feed still has more\n if (!community?.updatedAt) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n // if at least 1 community has posts cache expired, then the feed still has more\n if (communityPostsCacheExpired(community)) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n\n const firstPageCid = getCommunityFirstPageCid(community, sortType, pageType);\n // TODO: if a loaded community doesn't have a first page, it's unclear what we should do\n // should we try to use another sort type by default, like 'hot', or should we just ignore it?\n // 'continue' to ignore it for now\n if (!firstPageCid) {\n continue communityKeysLoop;\n }\n const pages = getCommunityPages(community, sortType, communitiesPages, pageType, accountId);\n // if first page isn't loaded yet, then the feed still has more\n if (!pages.length) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n const lastPage = pages[pages.length - 1];\n if (lastPage.nextCid) {\n feedsHaveMore[feedName] = true;\n continue feedsLoop;\n }\n }\n\n // if buffered feeds are empty and no last page of any community has a next page, then has more is false\n feedsHaveMore[feedName] = false;\n }\n return feedsHaveMore;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunities = (feedsOptions: FeedsOptions, communities: Communities) => {\n // find all feeds communities\n const feedsCommunityAddresses = new Set<string>();\n Object.keys(feedsOptions).forEach((i) =>\n getFeedCommunityKeys(feedsOptions[i]).forEach((a) => feedsCommunityAddresses.add(a)),\n );\n\n // use map for performance increase when checking size\n const feedsCommunities = new Map<string, Community>();\n for (const communityAddress of feedsCommunityAddresses) {\n feedsCommunities.set(communityAddress, communities[communityAddress]);\n }\n return feedsCommunities;\n};\n\nexport const feedsCommunitiesChanged = (\n previousFeedsCommunities: Map<string, Community>,\n feedsCommunities: Map<string, Community>,\n) => {\n if (previousFeedsCommunities.size !== feedsCommunities.size) {\n return true;\n }\n for (let communityAddress of previousFeedsCommunities.keys()) {\n // check if the object is still the same\n if (previousFeedsCommunities.get(communityAddress) !== feedsCommunities.get(communityAddress)) {\n return true;\n }\n }\n return false;\n};\n\n// get all communities pages cids of all feeds, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesFirstPageCids = (\n feedsCommunities: Map<string, Community>,\n): string[] => {\n // find all the feeds communities first page cids\n const feedsCommunitiesFirstPageCids = new Set<string>();\n for (const community of feedsCommunities.values()) {\n if (!community?.posts && !community?.modQueue) {\n continue;\n }\n\n // check pages\n if (community.posts?.pages) {\n for (const page of Object.values<CommunityPage>(community.posts.pages)) {\n if (page?.nextCid) {\n feedsCommunitiesFirstPageCids.add(page?.nextCid);\n }\n }\n }\n\n // check pageCids\n if (community.posts?.pageCids) {\n for (const pageCid of Object.values<string>(community.posts.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n\n // TODO: would be more performant to only check modQueue if there's a feedOptions with modQueue\n if (community.modQueue?.pageCids) {\n for (const pageCid of Object.values<string>(community.modQueue.pageCids)) {\n if (pageCid) {\n feedsCommunitiesFirstPageCids.add(pageCid);\n }\n }\n }\n }\n\n return [...feedsCommunitiesFirstPageCids].sort();\n};\n\n// get all communities posts pages first post updatedAts, use to check if a communitiesStore change should trigger updateFeeds\nexport const getFeedsCommunitiesPostsPagesFirstUpdatedAts = (\n feedsCommunities: Map<string, Community>,\n): string => {\n let feedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\n for (const community of feedsCommunities.values()) {\n for (const page of Object.values<CommunityPage>(community?.posts?.pages || {})) {\n if (page?.comments?.[0]?.updatedAt) {\n feedsCommunitiesPostsPagesFirstUpdatedAts +=\n page.comments[0].cid + page.comments[0].updatedAt;\n }\n }\n }\n return feedsCommunitiesPostsPagesFirstUpdatedAts;\n};\n\n// get number of feeds community that are loaded\nexport const getFeedsCommunitiesLoadedCount = (\n feedsCommunities: Map<string, Community>,\n): number => {\n let count = 0;\n for (const community of feedsCommunities.values()) {\n if (community?.updatedAt) {\n count++;\n }\n }\n return count;\n};\n\nexport const getAccountsBlockedAddresses = (accounts: Accounts) => {\n const blockedAddressesSet = new Set<string>();\n for (const { blockedAddresses } of Object.values(accounts)) {\n for (const address in blockedAddresses) {\n if (blockedAddresses[address]) {\n blockedAddressesSet.add(address);\n }\n }\n }\n return [...blockedAddressesSet].sort();\n};\n\nexport const accountsBlockedAddressesChanged = (\n previousAccountsBlockedAddresses: { [address: string]: boolean }[],\n accountsBlockedAddresses: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedAddresses.length !== accountsBlockedAddresses.length) {\n return true;\n }\n for (const i in previousAccountsBlockedAddresses) {\n // check if the object is still the same\n if (previousAccountsBlockedAddresses[i] !== accountsBlockedAddresses[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedAddresses = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedAddresses: string[],\n previousBlockedAddresses: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedAddresses = blockedAddresses\n .filter((x) => !previousBlockedAddresses.includes(x))\n .concat(previousBlockedAddresses.filter((x) => !blockedAddresses.includes(x)));\n\n // if changed blocked addresses arent used in the feeds, do nothing\n for (const address of changedBlockedAddresses) {\n for (const feedName in feedsOptions) {\n const feedOptions = feedsOptions[feedName];\n if (\n getMatchingCommunityRefKeys(getFeedCommunityRefs(feedOptions), address).some(\n (communityKey) => getFeedCommunityKeys(feedOptions).includes(communityKey),\n )\n ) {\n return true;\n }\n }\n }\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedAddressesSet = new Set(changedBlockedAddresses);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.author?.address && changedBlockedAddressesSet.has(post.author.address)) {\n return true;\n }\n }\n }\n\n return false;\n};\n\nexport const getAccountsBlockedCids = (accounts: Accounts) => {\n const blockedCidsSet = new Set<string>();\n for (const { blockedCids } of Object.values(accounts)) {\n for (const address in blockedCids) {\n if (blockedCids[address]) {\n blockedCidsSet.add(address);\n }\n }\n }\n return [...blockedCidsSet].sort();\n};\n\nexport const accountsBlockedCidsChanged = (\n previousAccountsBlockedCids: { [address: string]: boolean }[],\n accountsBlockedCids: { [address: string]: boolean }[],\n) => {\n if (previousAccountsBlockedCids.length !== accountsBlockedCids.length) {\n return true;\n }\n for (const i in previousAccountsBlockedCids) {\n // check if the object is still the same\n if (previousAccountsBlockedCids[i] !== accountsBlockedCids[i]) {\n return true;\n }\n }\n return false;\n};\n\nexport const feedsHaveChangedBlockedCids = (\n feedsOptions: FeedsOptions,\n bufferedFeeds: Feeds,\n blockedCids: string[],\n previousBlockedCids: string[],\n) => {\n // find the difference between current and previous blocked addresses\n const changedBlockedCids = blockedCids\n .filter((x) => !previousBlockedCids.includes(x))\n .concat(previousBlockedCids.filter((x) => !blockedCids.includes(x)));\n\n // feeds posts author addresses have a changed blocked address\n // NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update\n // it seems preferable to causing unnecessary rerenders every time an unused block event occurs\n const changedBlockedCidsSet = new Set(changedBlockedCids);\n for (const feedName in bufferedFeeds) {\n for (const post of bufferedFeeds[feedName] || []) {\n if (post?.cid && changedBlockedCidsSet.has(post?.cid)) {\n return true;\n }\n }\n }\n\n return false;\n};\n"]}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
- "version": "0.1.50",
17
+ "version": "0.1.51",
18
18
  "packageManager": "yarn@4.13.0",
19
19
  "files": [
20
20
  "CHANGELOG.md",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@bitsocial/bso-resolver": "0.0.10",
66
- "@pkcprotocol/pkc-js": "0.0.105",
66
+ "@pkcprotocol/pkc-js": "0.0.109",
67
67
  "@pkcprotocol/pkc-logger": "0.1.0",
68
68
  "assert": "2.1.0",
69
69
  "ethers": "5.8.0",