@bitsocial/bitsocial-react-hooks 0.1.0
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/LICENSE +674 -0
- package/README.md +1365 -0
- package/dist/hooks/accounts/accounts.d.ts +64 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -0
- package/dist/hooks/accounts/accounts.js +706 -0
- package/dist/hooks/accounts/accounts.js.map +1 -0
- package/dist/hooks/accounts/index.d.ts +2 -0
- package/dist/hooks/accounts/index.d.ts.map +1 -0
- package/dist/hooks/accounts/index.js +2 -0
- package/dist/hooks/accounts/index.js.map +1 -0
- package/dist/hooks/accounts/utils.d.ts +6 -0
- package/dist/hooks/accounts/utils.d.ts.map +1 -0
- package/dist/hooks/accounts/utils.js +226 -0
- package/dist/hooks/accounts/utils.js.map +1 -0
- package/dist/hooks/actions/actions.d.ts +19 -0
- package/dist/hooks/actions/actions.d.ts.map +1 -0
- package/dist/hooks/actions/actions.js +552 -0
- package/dist/hooks/actions/actions.js.map +1 -0
- package/dist/hooks/actions/index.d.ts +2 -0
- package/dist/hooks/actions/index.d.ts.map +1 -0
- package/dist/hooks/actions/index.js +2 -0
- package/dist/hooks/actions/index.js.map +1 -0
- package/dist/hooks/authors/author-avatars.d.ts +28 -0
- package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
- package/dist/hooks/authors/author-avatars.js +191 -0
- package/dist/hooks/authors/author-avatars.js.map +1 -0
- package/dist/hooks/authors/authors.d.ts +37 -0
- package/dist/hooks/authors/authors.d.ts.map +1 -0
- package/dist/hooks/authors/authors.js +509 -0
- package/dist/hooks/authors/authors.js.map +1 -0
- package/dist/hooks/authors/index.d.ts +2 -0
- package/dist/hooks/authors/index.d.ts.map +1 -0
- package/dist/hooks/authors/index.js +2 -0
- package/dist/hooks/authors/index.js.map +1 -0
- package/dist/hooks/authors/utils.d.ts +4 -0
- package/dist/hooks/authors/utils.d.ts.map +1 -0
- package/dist/hooks/authors/utils.js +21 -0
- package/dist/hooks/authors/utils.js.map +1 -0
- package/dist/hooks/comments.d.ts +17 -0
- package/dist/hooks/comments.d.ts.map +1 -0
- package/dist/hooks/comments.js +351 -0
- package/dist/hooks/comments.js.map +1 -0
- package/dist/hooks/communities.d.ts +31 -0
- package/dist/hooks/communities.d.ts.map +1 -0
- package/dist/hooks/communities.js +389 -0
- package/dist/hooks/communities.js.map +1 -0
- package/dist/hooks/feeds/feeds.d.ts +18 -0
- package/dist/hooks/feeds/feeds.d.ts.map +1 -0
- package/dist/hooks/feeds/feeds.js +315 -0
- package/dist/hooks/feeds/feeds.js.map +1 -0
- package/dist/hooks/feeds/index.d.ts +2 -0
- package/dist/hooks/feeds/index.d.ts.map +1 -0
- package/dist/hooks/feeds/index.js +2 -0
- package/dist/hooks/feeds/index.js.map +1 -0
- package/dist/hooks/pkc-rpc.d.ts +7 -0
- package/dist/hooks/pkc-rpc.d.ts.map +1 -0
- package/dist/hooks/pkc-rpc.js +88 -0
- package/dist/hooks/pkc-rpc.js.map +1 -0
- package/dist/hooks/replies.d.ts +5 -0
- package/dist/hooks/replies.d.ts.map +1 -0
- package/dist/hooks/replies.js +155 -0
- package/dist/hooks/replies.js.map +1 -0
- package/dist/hooks/states.d.ts +15 -0
- package/dist/hooks/states.d.ts.map +1 -0
- package/dist/hooks/states.js +213 -0
- package/dist/hooks/states.js.map +1 -0
- package/dist/hooks/utils/use-interval.d.ts +3 -0
- package/dist/hooks/utils/use-interval.d.ts.map +1 -0
- package/dist/hooks/utils/use-interval.js +36 -0
- package/dist/hooks/utils/use-interval.js.map +1 -0
- package/dist/hooks/utils/use-previous.d.ts +1 -0
- package/dist/hooks/utils/use-previous.js +10 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/chain/chain.d.ts +36 -0
- package/dist/lib/chain/chain.d.ts.map +1 -0
- package/dist/lib/chain/chain.js +195 -0
- package/dist/lib/chain/chain.js.map +1 -0
- package/dist/lib/chain/index.d.ts +4 -0
- package/dist/lib/chain/index.d.ts.map +1 -0
- package/dist/lib/chain/index.js +4 -0
- package/dist/lib/chain/index.js.map +1 -0
- package/dist/lib/community-address.d.ts +6 -0
- package/dist/lib/community-address.d.ts.map +1 -0
- package/dist/lib/community-address.js +26 -0
- package/dist/lib/community-address.js.map +1 -0
- package/dist/lib/community-ref.d.ts +23 -0
- package/dist/lib/community-ref.d.ts.map +1 -0
- package/dist/lib/community-ref.js +113 -0
- package/dist/lib/community-ref.js.map +1 -0
- package/dist/lib/debug-utils.d.ts +9 -0
- package/dist/lib/debug-utils.d.ts.map +1 -0
- package/dist/lib/debug-utils.js +21 -0
- package/dist/lib/debug-utils.js.map +1 -0
- package/dist/lib/feed-sort-type.d.ts +2 -0
- package/dist/lib/feed-sort-type.d.ts.map +1 -0
- package/dist/lib/feed-sort-type.js +22 -0
- package/dist/lib/feed-sort-type.js.map +1 -0
- package/dist/lib/localforage-lru/index.d.ts +3 -0
- package/dist/lib/localforage-lru/index.d.ts.map +1 -0
- package/dist/lib/localforage-lru/index.js +46 -0
- package/dist/lib/localforage-lru/index.js.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.js +182 -0
- package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
- package/dist/lib/pkc-compat.d.ts +25 -0
- package/dist/lib/pkc-compat.d.ts.map +1 -0
- package/dist/lib/pkc-compat.js +131 -0
- package/dist/lib/pkc-compat.js.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
- package/dist/lib/pkc-js/index.d.ts +11 -0
- package/dist/lib/pkc-js/index.d.ts.map +1 -0
- package/dist/lib/pkc-js/index.js +85 -0
- package/dist/lib/pkc-js/index.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/lib/polyfill.d.ts +3 -0
- package/dist/lib/polyfill.d.ts.map +1 -0
- package/dist/lib/polyfill.js +14 -0
- package/dist/lib/polyfill.js.map +1 -0
- package/dist/lib/protocol-compat.d.ts +14 -0
- package/dist/lib/protocol-compat.d.ts.map +1 -0
- package/dist/lib/protocol-compat.js +67 -0
- package/dist/lib/protocol-compat.js.map +1 -0
- package/dist/lib/test-utils.d.ts +29 -0
- package/dist/lib/test-utils.d.ts.map +1 -0
- package/dist/lib/test-utils.js +184 -0
- package/dist/lib/test-utils.js.map +1 -0
- package/dist/lib/utils/comment-moderation.d.ts +4 -0
- package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
- package/dist/lib/utils/comment-moderation.js +56 -0
- package/dist/lib/utils/comment-moderation.js.map +1 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/utils.d.ts +23 -0
- package/dist/lib/utils/utils.d.ts.map +1 -0
- package/dist/lib/utils/utils.js +375 -0
- package/dist/lib/utils/utils.js.map +1 -0
- package/dist/lib/validator.d.ts +30 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/dist/lib/validator.js +307 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/stores/accounts/account-generator.d.ts +51 -0
- package/dist/stores/accounts/account-generator.d.ts.map +1 -0
- package/dist/stores/accounts/account-generator.js +160 -0
- package/dist/stores/accounts/account-generator.js.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.js +403 -0
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
- package/dist/stores/accounts/accounts-actions.d.ts +46 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions.js +1341 -0
- package/dist/stores/accounts/accounts-actions.js.map +1 -0
- package/dist/stores/accounts/accounts-database.d.ts +34 -0
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-database.js +685 -0
- package/dist/stores/accounts/accounts-database.js.map +1 -0
- package/dist/stores/accounts/accounts-store.d.ts +32 -0
- package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-store.js +169 -0
- package/dist/stores/accounts/accounts-store.js.map +1 -0
- package/dist/stores/accounts/index.d.ts +4 -0
- package/dist/stores/accounts/index.d.ts.map +1 -0
- package/dist/stores/accounts/index.js +4 -0
- package/dist/stores/accounts/index.js.map +1 -0
- package/dist/stores/accounts/utils.d.ts +49 -0
- package/dist/stores/accounts/utils.d.ts.map +1 -0
- package/dist/stores/accounts/utils.js +419 -0
- package/dist/stores/accounts/utils.js.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.js +338 -0
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
- package/dist/stores/authors-comments/index.d.ts +4 -0
- package/dist/stores/authors-comments/index.d.ts.map +1 -0
- package/dist/stores/authors-comments/index.js +4 -0
- package/dist/stores/authors-comments/index.js.map +1 -0
- package/dist/stores/authors-comments/utils.d.ts +14 -0
- package/dist/stores/authors-comments/utils.d.ts.map +1 -0
- package/dist/stores/authors-comments/utils.js +81 -0
- package/dist/stores/authors-comments/utils.js.map +1 -0
- package/dist/stores/comments/comments-store.d.ts +19 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -0
- package/dist/stores/comments/comments-store.js +385 -0
- package/dist/stores/comments/comments-store.js.map +1 -0
- package/dist/stores/comments/index.d.ts +4 -0
- package/dist/stores/comments/index.d.ts.map +1 -0
- package/dist/stores/comments/index.js +4 -0
- package/dist/stores/comments/index.js.map +1 -0
- package/dist/stores/communities/communities-store.d.ts +17 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -0
- package/dist/stores/communities/communities-store.js +304 -0
- package/dist/stores/communities/communities-store.js.map +1 -0
- package/dist/stores/communities/index.d.ts +4 -0
- package/dist/stores/communities/index.d.ts.map +1 -0
- package/dist/stores/communities/index.js +4 -0
- package/dist/stores/communities/index.js.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.js +316 -0
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
- package/dist/stores/communities-pages/index.d.ts +4 -0
- package/dist/stores/communities-pages/index.d.ts.map +1 -0
- package/dist/stores/communities-pages/index.js +4 -0
- package/dist/stores/communities-pages/index.js.map +1 -0
- package/dist/stores/feeds/feed-sorter.d.ts +5 -0
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
- package/dist/stores/feeds/feed-sorter.js +135 -0
- package/dist/stores/feeds/feed-sorter.js.map +1 -0
- package/dist/stores/feeds/feeds-store.d.ts +25 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
- package/dist/stores/feeds/feeds-store.js +459 -0
- package/dist/stores/feeds/feeds-store.js.map +1 -0
- package/dist/stores/feeds/index.d.ts +4 -0
- package/dist/stores/feeds/index.d.ts.map +1 -0
- package/dist/stores/feeds/index.js +4 -0
- package/dist/stores/feeds/index.js.map +1 -0
- package/dist/stores/feeds/utils.d.ts +43 -0
- package/dist/stores/feeds/utils.d.ts.map +1 -0
- package/dist/stores/feeds/utils.js +736 -0
- package/dist/stores/feeds/utils.js.map +1 -0
- package/dist/stores/replies/index.d.ts +4 -0
- package/dist/stores/replies/index.d.ts.map +1 -0
- package/dist/stores/replies/index.js +4 -0
- package/dist/stores/replies/index.js.map +1 -0
- package/dist/stores/replies/replies-comments-store.d.ts +8 -0
- package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-comments-store.js +23 -0
- package/dist/stores/replies/replies-comments-store.js.map +1 -0
- package/dist/stores/replies/replies-store.d.ts +29 -0
- package/dist/stores/replies/replies-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-store.js +413 -0
- package/dist/stores/replies/replies-store.js.map +1 -0
- package/dist/stores/replies/utils.d.ts +25 -0
- package/dist/stores/replies/utils.d.ts.map +1 -0
- package/dist/stores/replies/utils.js +549 -0
- package/dist/stores/replies/utils.js.map +1 -0
- package/dist/stores/replies-pages/index.d.ts +4 -0
- package/dist/stores/replies-pages/index.d.ts.map +1 -0
- package/dist/stores/replies-pages/index.js +4 -0
- package/dist/stores/replies-pages/index.js.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.js +270 -0
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
- package/dist/stores/replies-pages/utils.d.ts +3 -0
- package/dist/stores/replies-pages/utils.d.ts.map +1 -0
- package/dist/stores/replies-pages/utils.js +43 -0
- package/dist/stores/replies-pages/utils.js.map +1 -0
- package/dist/types.d.ts +638 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +160 -0
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import assert from "assert";
|
|
11
|
+
import Logger from "@pkcprotocol/pkc-logger";
|
|
12
|
+
const log = Logger("bitsocial-react-hooks:feeds:stores");
|
|
13
|
+
import createStore from "zustand";
|
|
14
|
+
import localForageLru from "../../lib/localforage-lru/index.js";
|
|
15
|
+
import { communityPostsCacheExpired } from "../../lib/utils/index.js";
|
|
16
|
+
import { getPkcGetCommunity } from "../../lib/pkc-compat.js";
|
|
17
|
+
import { deriveFeedSortType } from "../../lib/feed-sort-type.js";
|
|
18
|
+
import { getCommunityRefKeys } from "../../lib/community-ref.js";
|
|
19
|
+
import accountsStore from "../accounts/index.js";
|
|
20
|
+
import communitiesStore from "../communities/index.js";
|
|
21
|
+
import communitiesPagesStore from "../communities-pages/index.js";
|
|
22
|
+
import { getFeedsCommunitiesFirstPageCids, getLoadedFeeds, getUpdatedFeeds, getBufferedFeedsWithoutLoadedFeeds, getFeedsCommunitiesPostCounts, getFeedsHaveMore, getAccountsBlockedAddresses, feedsHaveChangedBlockedAddresses, accountsBlockedAddressesChanged, getAccountsBlockedCids, feedsHaveChangedBlockedCids, accountsBlockedCidsChanged, feedsCommunitiesChanged, getFeedsCommunities, getFeedsCommunitiesLoadedCount, getFeedsCommunitiesPostsPagesFirstUpdatedAts, getFilteredSortedFeeds, getFeedsCommunityKeysWithNewerPosts, } from "./utils.js";
|
|
23
|
+
// reddit loads approximately 25 posts per page
|
|
24
|
+
// while infinite scrolling
|
|
25
|
+
export const defaultPostsPerPage = 25;
|
|
26
|
+
// keep large buffer because fetching cids is slow
|
|
27
|
+
const communityPostsLeftBeforeNextPage = 50;
|
|
28
|
+
// don't updateFeeds more than once per updateFeedsMinIntervalTime
|
|
29
|
+
let updateFeedsPending = false;
|
|
30
|
+
const updateFeedsMinIntervalTime = 100;
|
|
31
|
+
const feedsStore = createStore((setState, getState) => ({
|
|
32
|
+
feedsOptions: {},
|
|
33
|
+
bufferedFeeds: {},
|
|
34
|
+
loadedFeeds: {},
|
|
35
|
+
updatedFeeds: {},
|
|
36
|
+
bufferedFeedsCommunitiesPostCounts: {},
|
|
37
|
+
feedsHaveMore: {},
|
|
38
|
+
feedsCommunityKeysWithNewerPosts: {},
|
|
39
|
+
addFeedToStore(feedName, communities, communityKeys, sortType, account, isBufferedFeed, postsPerPage, filter, newerThan, accountComments, modQueue, requestedSortType) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
// init here because must be called after async accounts store finished initializing
|
|
42
|
+
initializeFeedsStore();
|
|
43
|
+
assert(feedName && typeof feedName === "string", `feedsStore.addFeedToStore feedName '${feedName}' invalid`);
|
|
44
|
+
assert(Array.isArray(communities), `addFeedToStore.addFeedToStore communities '${communities}' invalid`);
|
|
45
|
+
assert(Array.isArray(communityKeys), `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' invalid`);
|
|
46
|
+
const derivedCommunityKeys = getCommunityRefKeys(communities);
|
|
47
|
+
assert(communityKeys.length === derivedCommunityKeys.length &&
|
|
48
|
+
communityKeys.every((communityKey, index) => communityKey === derivedCommunityKeys[index]), `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' do not match communities`);
|
|
49
|
+
assert(sortType && typeof sortType === "string", `addFeedToStore.addFeedToStore sortType '${sortType}' invalid`);
|
|
50
|
+
assert(typeof getPkcGetCommunity(account === null || account === void 0 ? void 0 : account.pkc) === "function", `addFeedToStore.addFeedToStore account '${account}' invalid`);
|
|
51
|
+
assert(typeof isBufferedFeed === "boolean" ||
|
|
52
|
+
isBufferedFeed === undefined ||
|
|
53
|
+
isBufferedFeed === null, `addFeedToStore.addFeedToStore isBufferedFeed '${isBufferedFeed}' invalid`);
|
|
54
|
+
assert(!filter || typeof (filter === null || filter === void 0 ? void 0 : filter.filter) === "function", `addFeedToStore.addFeedToStore filter.filter '${filter === null || filter === void 0 ? void 0 : filter.filter}' invalid`);
|
|
55
|
+
assert(!filter || typeof (filter === null || filter === void 0 ? void 0 : filter.key) === "string", `addFeedToStore.addFeedToStore filter.key '${filter === null || filter === void 0 ? void 0 : filter.key}' invalid`);
|
|
56
|
+
assert(!newerThan || typeof newerThan === "number", `addFeedToStore.addFeedToStore newerThan '${newerThan}' invalid`);
|
|
57
|
+
postsPerPage = postsPerPage || defaultPostsPerPage;
|
|
58
|
+
assert(typeof postsPerPage === "number", `addFeedToStore.addFeedToStore postsPerPage '${postsPerPage}' invalid`);
|
|
59
|
+
assert(!accountComments || typeof (accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan) === "number", `addFeedToStore.addFeedToStore accountComments.newerThan '${accountComments === null || accountComments === void 0 ? void 0 : accountComments.newerThan}' invalid`);
|
|
60
|
+
assert(!modQueue || Array.isArray(modQueue), `addFeedToStore.addFeedToStore modQueue '${modQueue}' invalid`);
|
|
61
|
+
const { feedsOptions, updateFeeds } = getState();
|
|
62
|
+
// feed is in store already, do nothing
|
|
63
|
+
// if the feed already exist but is at page 0, reset it to page 1
|
|
64
|
+
if (feedsOptions[feedName] && feedsOptions[feedName].pageNumber !== 0) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// to add a buffered feed, add a feed with pageNumber 0
|
|
68
|
+
const feedOptions = {
|
|
69
|
+
communities,
|
|
70
|
+
communityKeys,
|
|
71
|
+
sortType,
|
|
72
|
+
requestedSortType: requestedSortType || sortType,
|
|
73
|
+
accountId: account.id,
|
|
74
|
+
pageNumber: isBufferedFeed === true ? 0 : 1,
|
|
75
|
+
postsPerPage,
|
|
76
|
+
newerThan,
|
|
77
|
+
filter,
|
|
78
|
+
accountComments,
|
|
79
|
+
// TODO: allow multiple modQueue at once, fow now only use first in array
|
|
80
|
+
modQueue,
|
|
81
|
+
};
|
|
82
|
+
log("feedsActions.addFeedToStore", feedOptions);
|
|
83
|
+
setState(({ feedsOptions }) => ({
|
|
84
|
+
feedsOptions: Object.assign(Object.assign({}, feedsOptions), { [feedName]: feedOptions }),
|
|
85
|
+
}));
|
|
86
|
+
addCommunitiesToCommunitiesStore(communities, account);
|
|
87
|
+
// update feeds right away to use the already loaded communities and pages
|
|
88
|
+
// if no new communities are added by the feed, like for a sort type change,
|
|
89
|
+
// a feed update will never be triggered, so must be triggered it manually
|
|
90
|
+
updateFeeds();
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
incrementFeedPageNumber(feedName) {
|
|
94
|
+
const { feedsOptions, loadedFeeds, updateFeeds } = getState();
|
|
95
|
+
assert(feedsOptions[feedName], `feedsActions.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`);
|
|
96
|
+
log("feedsActions.incrementFeedPageNumber", { feedName });
|
|
97
|
+
assert(feedsOptions[feedName].pageNumber * feedsOptions[feedName].postsPerPage <=
|
|
98
|
+
loadedFeeds[feedName].length, `feedsActions.incrementFeedPageNumber cannot increment feed page number before current page has loaded`);
|
|
99
|
+
setState(({ feedsOptions, loadedFeeds }) => {
|
|
100
|
+
const feedOptions = Object.assign(Object.assign({}, feedsOptions[feedName]), { pageNumber: feedsOptions[feedName].pageNumber + 1 });
|
|
101
|
+
return { feedsOptions: Object.assign(Object.assign({}, feedsOptions), { [feedName]: feedOptions }) };
|
|
102
|
+
});
|
|
103
|
+
// do not update feed at the same time as increment a page number or it might cause
|
|
104
|
+
// a race condition, rather schedule a feed update
|
|
105
|
+
updateFeeds();
|
|
106
|
+
},
|
|
107
|
+
expandFeedTimeWindow(feedName, newerThan) {
|
|
108
|
+
const { feedsOptions, loadedFeeds, updateFeeds } = getState();
|
|
109
|
+
assert(feedsOptions[feedName], `feedsActions.expandFeedTimeWindow feed name '${feedName}' does not exist in feeds store`);
|
|
110
|
+
assert(newerThan === undefined || typeof newerThan === "number", `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' invalid`);
|
|
111
|
+
const currentFeedOptions = feedsOptions[feedName];
|
|
112
|
+
const currentNewerThan = currentFeedOptions.newerThan;
|
|
113
|
+
if (currentNewerThan === newerThan) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const isExpandedTimeWindow = typeof currentNewerThan === "number" &&
|
|
117
|
+
(newerThan === undefined || newerThan > currentNewerThan);
|
|
118
|
+
assert(isExpandedTimeWindow, `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' must broaden the current window '${currentNewerThan}'`);
|
|
119
|
+
const nextSortType = deriveFeedSortType(currentFeedOptions.requestedSortType, newerThan);
|
|
120
|
+
assert(nextSortType === currentFeedOptions.sortType, `feedsActions.expandFeedTimeWindow cannot change sort type from '${currentFeedOptions.sortType}' to '${nextSortType}'`);
|
|
121
|
+
const loadedFeed = loadedFeeds[feedName] || [];
|
|
122
|
+
const shouldPrefetchExpandedPage = currentFeedOptions.pageNumber > 0 &&
|
|
123
|
+
loadedFeed.length >= currentFeedOptions.pageNumber * currentFeedOptions.postsPerPage;
|
|
124
|
+
setState(({ feedsOptions }) => ({
|
|
125
|
+
feedsOptions: Object.assign(Object.assign({}, feedsOptions), { [feedName]: Object.assign(Object.assign({}, currentFeedOptions), { newerThan, pageNumber: shouldPrefetchExpandedPage
|
|
126
|
+
? currentFeedOptions.pageNumber + 1
|
|
127
|
+
: currentFeedOptions.pageNumber }) }),
|
|
128
|
+
}));
|
|
129
|
+
updateFeeds();
|
|
130
|
+
},
|
|
131
|
+
resetFeed(feedName) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
const { feedsOptions, updateFeeds } = getState();
|
|
134
|
+
assert(feedsOptions[feedName], `feedsActions.resetFeed feed name '${feedName}' does not exist in feeds store`);
|
|
135
|
+
assert(feedsOptions[feedName].pageNumber >= 1, `feedsActions.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`);
|
|
136
|
+
log("feedsActions.resetFeed", { feedName });
|
|
137
|
+
const { modQueue, sortType, communities, communityKeys, accountId } = feedsOptions[feedName];
|
|
138
|
+
const account = accountsStore.getState().accounts[accountId];
|
|
139
|
+
assert(account, `feedsActions.resetFeed account id '${accountId}' does not exist in accounts store`);
|
|
140
|
+
setState(({ feedsOptions, loadedFeeds, updatedFeeds }) => {
|
|
141
|
+
const feedOptions = Object.assign(Object.assign({}, feedsOptions[feedName]), { pageNumber: 1 });
|
|
142
|
+
return {
|
|
143
|
+
feedsOptions: Object.assign(Object.assign({}, feedsOptions), { [feedName]: feedOptions }),
|
|
144
|
+
loadedFeeds: Object.assign(Object.assign({}, loadedFeeds), { [feedName]: [] }),
|
|
145
|
+
updatedFeeds: Object.assign(Object.assign({}, updatedFeeds), { [feedName]: [] }),
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
if (modQueue === null || modQueue === void 0 ? void 0 : modQueue[0]) {
|
|
149
|
+
const { communities } = communitiesStore.getState();
|
|
150
|
+
const { invalidateCommunityPages } = communitiesPagesStore.getState();
|
|
151
|
+
const loadedCommunities = communityKeys
|
|
152
|
+
.map((communityKey) => communities[communityKey])
|
|
153
|
+
.filter((community) => Boolean(community));
|
|
154
|
+
yield Promise.all(loadedCommunities.map((community) => invalidateCommunityPages(community, sortType, modQueue, account.id)));
|
|
155
|
+
}
|
|
156
|
+
yield Promise.all(communities.map((communityRef, communityIndex) => communitiesStore
|
|
157
|
+
.getState()
|
|
158
|
+
.refreshCommunity(communityRef, account)
|
|
159
|
+
.catch((error) => log.error("feedsStore.resetFeed refreshCommunity error", {
|
|
160
|
+
feedName,
|
|
161
|
+
community: communityRef,
|
|
162
|
+
communityKey: communityKeys[communityIndex],
|
|
163
|
+
error,
|
|
164
|
+
}))));
|
|
165
|
+
updateFeeds();
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
// recalculate all feeds using new communities.post.pages, communitiesPagesStore and page numbers
|
|
169
|
+
updateFeeds() {
|
|
170
|
+
if (updateFeedsPending) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
updateFeedsPending = true;
|
|
174
|
+
// don't update feeds more than once per updateFeedsMinIntervalTime
|
|
175
|
+
const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;
|
|
176
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
// get state from all stores
|
|
178
|
+
const previousState = getState();
|
|
179
|
+
const { feedsOptions } = previousState;
|
|
180
|
+
const { communities } = communitiesStore.getState();
|
|
181
|
+
const { communitiesPages } = communitiesPagesStore.getState();
|
|
182
|
+
const { accounts } = accountsStore.getState();
|
|
183
|
+
// calculate new feeds
|
|
184
|
+
const filteredSortedFeeds = getFilteredSortedFeeds(feedsOptions, communities, communitiesPages, accounts, communitiesPagesStore.getState().comments);
|
|
185
|
+
const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(filteredSortedFeeds, previousState.loadedFeeds);
|
|
186
|
+
const loadedFeeds = yield getLoadedFeeds(feedsOptions, filteredSortedFeeds, previousState.loadedFeeds, bufferedFeedsWithoutPreviousLoadedFeeds, accounts);
|
|
187
|
+
// after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds
|
|
188
|
+
const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(bufferedFeedsWithoutPreviousLoadedFeeds, loadedFeeds);
|
|
189
|
+
const bufferedFeedsCommunitiesPostCounts = getFeedsCommunitiesPostCounts(feedsOptions, bufferedFeeds);
|
|
190
|
+
const feedsHaveMore = getFeedsHaveMore(feedsOptions, bufferedFeeds, communities, communitiesPages, accounts);
|
|
191
|
+
const feedsCommunityKeysWithNewerPosts = getFeedsCommunityKeysWithNewerPosts(feedsOptions, filteredSortedFeeds, loadedFeeds, previousState.feedsCommunityKeysWithNewerPosts);
|
|
192
|
+
const updatedFeeds = yield getUpdatedFeeds(feedsOptions, filteredSortedFeeds, previousState.updatedFeeds, loadedFeeds, accounts);
|
|
193
|
+
// set new feeds
|
|
194
|
+
setState((state) => ({
|
|
195
|
+
bufferedFeeds,
|
|
196
|
+
loadedFeeds,
|
|
197
|
+
updatedFeeds,
|
|
198
|
+
bufferedFeedsCommunitiesPostCounts,
|
|
199
|
+
feedsHaveMore,
|
|
200
|
+
feedsCommunityKeysWithNewerPosts,
|
|
201
|
+
}));
|
|
202
|
+
log.trace("feedsStore.updateFeeds", {
|
|
203
|
+
feedsOptions,
|
|
204
|
+
bufferedFeeds,
|
|
205
|
+
loadedFeeds,
|
|
206
|
+
updatedFeeds,
|
|
207
|
+
bufferedFeedsCommunitiesPostCounts,
|
|
208
|
+
feedsHaveMore,
|
|
209
|
+
communities,
|
|
210
|
+
communitiesPages,
|
|
211
|
+
feedsCommunityKeysWithNewerPosts,
|
|
212
|
+
});
|
|
213
|
+
// TODO: if updateFeeds was called while updateFeedsPending = true, maybe we should recall updateFeeds here
|
|
214
|
+
updateFeedsPending = false;
|
|
215
|
+
}), timeUntilNextUpdate);
|
|
216
|
+
},
|
|
217
|
+
}));
|
|
218
|
+
let feedsStoreInitialized = false;
|
|
219
|
+
const initializeFeedsStore = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
220
|
+
if (feedsStoreInitialized) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommunitiesChange(communities)
|
|
224
|
+
// subscribe to communities store changes
|
|
225
|
+
communitiesStore.subscribe(updateFeedsOnFeedsCommunitiesChange);
|
|
226
|
+
// subscribe to bufferedFeedsCommunitiesPostCounts change
|
|
227
|
+
feedsStore.subscribe(addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts);
|
|
228
|
+
// subscribe to communities pages store changes
|
|
229
|
+
communitiesPagesStore.subscribe(updateFeedsOnFeedsCommunitiesPagesChange);
|
|
230
|
+
// subscribe to accounts store change (for blocked addresses)
|
|
231
|
+
accountsStore.subscribe(updateFeedsOnAccountsBlockedAddressesChange);
|
|
232
|
+
// subscribe to accounts store change (for blocked cids)
|
|
233
|
+
accountsStore.subscribe(updateFeedsOnAccountsBlockedCidsChange);
|
|
234
|
+
// subscribe to accounts store changes (for account comments)
|
|
235
|
+
accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);
|
|
236
|
+
feedsStoreInitialized = true;
|
|
237
|
+
});
|
|
238
|
+
let previousBlockedAddresses = [];
|
|
239
|
+
let previousAccountsBlockedAddresses = [];
|
|
240
|
+
const updateFeedsOnAccountsBlockedAddressesChange = (accountsStoreState) => {
|
|
241
|
+
const { accounts } = accountsStoreState;
|
|
242
|
+
// blocked addresses haven't changed, do nothing
|
|
243
|
+
const accountsBlockedAddresses = [];
|
|
244
|
+
for (const i in accounts) {
|
|
245
|
+
accountsBlockedAddresses.push(accounts[i].blockedAddresses);
|
|
246
|
+
}
|
|
247
|
+
if (!accountsBlockedAddressesChanged(previousAccountsBlockedAddresses, accountsBlockedAddresses)) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
previousAccountsBlockedAddresses = accountsBlockedAddresses;
|
|
251
|
+
const blockedAddresses = getAccountsBlockedAddresses(accounts);
|
|
252
|
+
// blocked addresses haven't changed, do nothing
|
|
253
|
+
if (blockedAddresses.toString() === previousBlockedAddresses.toString()) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();
|
|
257
|
+
const _feedsHaveChangedBlockedAddresses = feedsHaveChangedBlockedAddresses(feedsOptions, bufferedFeeds, blockedAddresses, previousBlockedAddresses);
|
|
258
|
+
previousBlockedAddresses = blockedAddresses;
|
|
259
|
+
// if changed blocked addresses arent used in the feeds, do nothing
|
|
260
|
+
// NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update
|
|
261
|
+
if (!_feedsHaveChangedBlockedAddresses) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
updateFeeds();
|
|
265
|
+
};
|
|
266
|
+
let previousBlockedCids = [];
|
|
267
|
+
let previousAccountsBlockedCids = [];
|
|
268
|
+
const updateFeedsOnAccountsBlockedCidsChange = (accountsStoreState) => {
|
|
269
|
+
const { accounts } = accountsStoreState;
|
|
270
|
+
// blocked cids haven't changed, do nothing
|
|
271
|
+
const accountsBlockedCids = [];
|
|
272
|
+
for (const i in accounts) {
|
|
273
|
+
accountsBlockedCids.push(accounts[i].blockedCids);
|
|
274
|
+
}
|
|
275
|
+
if (!accountsBlockedCidsChanged(previousAccountsBlockedCids, accountsBlockedCids)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
previousAccountsBlockedCids = accountsBlockedCids;
|
|
279
|
+
const blockedCids = getAccountsBlockedCids(accounts);
|
|
280
|
+
// blocked cids haven't changed, do nothing
|
|
281
|
+
if (blockedCids.toString() === previousBlockedCids.toString()) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();
|
|
285
|
+
const _feedsHaveChangedBlockedCids = feedsHaveChangedBlockedCids(feedsOptions, bufferedFeeds, blockedCids, previousBlockedCids);
|
|
286
|
+
previousBlockedCids = blockedCids;
|
|
287
|
+
// if changed blocked cids arent used in the feeds, do nothing
|
|
288
|
+
// NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update
|
|
289
|
+
if (!_feedsHaveChangedBlockedCids) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
updateFeeds();
|
|
293
|
+
};
|
|
294
|
+
let previousCommunitiesPages = {};
|
|
295
|
+
const updateFeedsOnFeedsCommunitiesPagesChange = (communitiesPagesStoreState) => {
|
|
296
|
+
const { communitiesPages } = communitiesPagesStoreState;
|
|
297
|
+
// no changes, do nothing
|
|
298
|
+
if (communitiesPages === previousCommunitiesPages) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
previousCommunitiesPages = communitiesPages;
|
|
302
|
+
// currently only the feeds use communitiesPagesStore, so any change must
|
|
303
|
+
// trigger a feed update, if in the future another hook uses the communitiesPagesStore
|
|
304
|
+
// we should check if the communities pages changed are actually used by the feeds before
|
|
305
|
+
// triggering an update
|
|
306
|
+
feedsStore.getState().updateFeeds();
|
|
307
|
+
};
|
|
308
|
+
let previousBufferedFeedsCommunitiesPostCountsPageCids = [];
|
|
309
|
+
let previousBufferedFeedsCommunities = new Map();
|
|
310
|
+
let previousBufferedFeedsCommunitiesPostCounts = {};
|
|
311
|
+
const addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts = (feedsStoreState) => {
|
|
312
|
+
const { bufferedFeedsCommunitiesPostCounts, feedsOptions } = feedsStore.getState();
|
|
313
|
+
const { communities } = communitiesStore.getState();
|
|
314
|
+
// if feeds communities have changed, we must try adding them even if buffered posts counts haven't changed
|
|
315
|
+
const bufferedFeedsCommunities = getFeedsCommunities(feedsOptions, communities);
|
|
316
|
+
const _feedsCommunitiesChanged = feedsCommunitiesChanged(previousBufferedFeedsCommunities, bufferedFeedsCommunities);
|
|
317
|
+
const bufferedFeedsCommunitiesPostCountsChanged = previousBufferedFeedsCommunitiesPostCounts !== bufferedFeedsCommunitiesPostCounts;
|
|
318
|
+
// if feeds communities havent changed and buffered posts counts also havent changed, do nothing
|
|
319
|
+
if (!_feedsCommunitiesChanged && !bufferedFeedsCommunitiesPostCountsChanged) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
previousBufferedFeedsCommunities = bufferedFeedsCommunities;
|
|
323
|
+
previousBufferedFeedsCommunitiesPostCounts = bufferedFeedsCommunitiesPostCounts;
|
|
324
|
+
// in case feeds community changed, but the first page cids haven't
|
|
325
|
+
const bufferedFeedsCommunitiesPostCountsPageCids = getFeedsCommunitiesFirstPageCids(bufferedFeedsCommunities);
|
|
326
|
+
const bufferedFeedsCommunitiesPostCountsPageCidsChanged = bufferedFeedsCommunitiesPostCountsPageCids.toString() !==
|
|
327
|
+
previousBufferedFeedsCommunitiesPostCountsPageCids.toString();
|
|
328
|
+
if (!bufferedFeedsCommunitiesPostCountsPageCidsChanged &&
|
|
329
|
+
!bufferedFeedsCommunitiesPostCountsChanged) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
previousBufferedFeedsCommunitiesPostCountsPageCids = bufferedFeedsCommunitiesPostCountsPageCids;
|
|
333
|
+
const { addNextCommunityPageToStore } = communitiesPagesStore.getState();
|
|
334
|
+
const { accounts } = accountsStore.getState();
|
|
335
|
+
// bufferedFeedsCommunitiesPostCounts have changed, check if any of them are low
|
|
336
|
+
for (const feedName in bufferedFeedsCommunitiesPostCounts) {
|
|
337
|
+
const account = accounts[feedsOptions[feedName].accountId];
|
|
338
|
+
const communitiesPostCounts = bufferedFeedsCommunitiesPostCounts[feedName];
|
|
339
|
+
const { sortType, modQueue } = feedsOptions[feedName];
|
|
340
|
+
for (const communityAddress in communitiesPostCounts) {
|
|
341
|
+
// don't fetch more pages if community address is blocked
|
|
342
|
+
if (account === null || account === void 0 ? void 0 : account.blockedAddresses[communityAddress]) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
// community hasn't loaded yet
|
|
346
|
+
if (!communities[communityAddress]) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
// if community posts cache is expired, don't use, wait for next community update
|
|
350
|
+
if (communityPostsCacheExpired(communities[communityAddress])) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
// community post count is low, fetch next community page
|
|
354
|
+
if (communitiesPostCounts[communityAddress] <= communityPostsLeftBeforeNextPage) {
|
|
355
|
+
addNextCommunityPageToStore(communities[communityAddress], sortType, account, modQueue).catch((error) => log.error("feedsStore communitiesActions.addNextCommunityPageToStore error", {
|
|
356
|
+
communityAddress,
|
|
357
|
+
community: communities[communityAddress],
|
|
358
|
+
sortType,
|
|
359
|
+
error,
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
let previousFeedsCommunitiesFirstPageCids = [];
|
|
366
|
+
let previousFeedsCommunities = new Map();
|
|
367
|
+
let previousFeedsCommunitiesLoadedCount = 0;
|
|
368
|
+
let previousFeedsCommunitiesPostsPagesFirstUpdatedAts = "";
|
|
369
|
+
const updateFeedsOnFeedsCommunitiesChange = (communitiesStoreState) => {
|
|
370
|
+
const { communities } = communitiesStoreState;
|
|
371
|
+
const { feedsOptions, updateFeeds } = feedsStore.getState();
|
|
372
|
+
// feeds communities haven't changed, do nothing
|
|
373
|
+
const feedsCommunities = getFeedsCommunities(feedsOptions, communities);
|
|
374
|
+
if (!feedsCommunitiesChanged(previousFeedsCommunities, feedsCommunities)) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
previousFeedsCommunities = feedsCommunities;
|
|
378
|
+
// decide if feeds communities have changed by looking at all feeds communities page cids
|
|
379
|
+
// (in case that a community changed, but its first page cid didn't)
|
|
380
|
+
const feedsCommunitiesFirstPageCids = getFeedsCommunitiesFirstPageCids(feedsCommunities);
|
|
381
|
+
// first page cids haven't changed, do nothing
|
|
382
|
+
if (feedsCommunitiesFirstPageCids.toString() === previousFeedsCommunitiesFirstPageCids.toString()) {
|
|
383
|
+
// if no new feed communities have loaded, do nothing
|
|
384
|
+
// in case a sub loads with no first page cid and first pages cids don't change, need to trigger hasMore update
|
|
385
|
+
const feedsCommunitiesLoadedCount = getFeedsCommunitiesLoadedCount(feedsCommunities);
|
|
386
|
+
if (feedsCommunitiesLoadedCount === previousFeedsCommunitiesLoadedCount) {
|
|
387
|
+
// if community.posts.pages haven't changed, do nothing
|
|
388
|
+
const feedsCommunitiesPostsPagesFirstUpdatedAts = getFeedsCommunitiesPostsPagesFirstUpdatedAts(feedsCommunities);
|
|
389
|
+
if (feedsCommunitiesPostsPagesFirstUpdatedAts ===
|
|
390
|
+
previousFeedsCommunitiesPostsPagesFirstUpdatedAts) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
previousFeedsCommunitiesPostsPagesFirstUpdatedAts = feedsCommunitiesPostsPagesFirstUpdatedAts;
|
|
394
|
+
}
|
|
395
|
+
previousFeedsCommunitiesLoadedCount = feedsCommunitiesLoadedCount;
|
|
396
|
+
}
|
|
397
|
+
// feeds communities have changed, update feeds
|
|
398
|
+
previousFeedsCommunitiesFirstPageCids = feedsCommunitiesFirstPageCids;
|
|
399
|
+
updateFeeds();
|
|
400
|
+
};
|
|
401
|
+
let previousAccountsCommentsCount = 0;
|
|
402
|
+
let previousAccountsCommentsCids = "";
|
|
403
|
+
const updateFeedsOnAccountsCommentsChange = (accountsStoreState) => {
|
|
404
|
+
const { accountsComments } = accountsStoreState;
|
|
405
|
+
const accountsCommentsCount = Object.values(accountsComments).reduce((count, accountComments) => count + accountComments.length, 0);
|
|
406
|
+
// no changes, do nothing
|
|
407
|
+
if (accountsCommentsCount === previousAccountsCommentsCount) {
|
|
408
|
+
// if cids haven't changed (account comments receive cids after pending), do nothing
|
|
409
|
+
const accountsCommentsCids = Object.values(accountsComments).reduce((cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || "")), "");
|
|
410
|
+
if (accountsCommentsCids === previousAccountsCommentsCids) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
previousAccountsCommentsCids = accountsCommentsCids;
|
|
414
|
+
}
|
|
415
|
+
previousAccountsCommentsCount = accountsCommentsCount;
|
|
416
|
+
// TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid
|
|
417
|
+
feedsStore.getState().updateFeeds();
|
|
418
|
+
};
|
|
419
|
+
const addCommunitiesToCommunitiesStore = (communityRefs, account) => {
|
|
420
|
+
const addCommunityToStore = communitiesStore.getState().addCommunityToStore;
|
|
421
|
+
for (const communityRef of communityRefs) {
|
|
422
|
+
addCommunityToStore(communityRef, account).catch((error) => log.error("feedsStore communitiesActions.addCommunityToStore error", {
|
|
423
|
+
communityRef,
|
|
424
|
+
error,
|
|
425
|
+
}));
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
// reset store in between tests
|
|
429
|
+
const originalState = feedsStore.getState();
|
|
430
|
+
// async function because some stores have async init
|
|
431
|
+
export const resetFeedsStore = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
432
|
+
previousBufferedFeedsCommunitiesPostCounts = {};
|
|
433
|
+
previousBufferedFeedsCommunitiesPostCountsPageCids = [];
|
|
434
|
+
previousBufferedFeedsCommunities = new Map();
|
|
435
|
+
previousBlockedAddresses = [];
|
|
436
|
+
previousAccountsBlockedAddresses = [];
|
|
437
|
+
previousBlockedCids = [];
|
|
438
|
+
previousAccountsBlockedCids = [];
|
|
439
|
+
previousFeedsCommunitiesFirstPageCids = [];
|
|
440
|
+
previousFeedsCommunities = new Map();
|
|
441
|
+
previousFeedsCommunitiesLoadedCount = 0;
|
|
442
|
+
previousFeedsCommunitiesPostsPagesFirstUpdatedAts = "";
|
|
443
|
+
previousCommunitiesPages = {};
|
|
444
|
+
previousAccountsCommentsCount = 0;
|
|
445
|
+
previousAccountsCommentsCids = "";
|
|
446
|
+
updateFeedsPending = false;
|
|
447
|
+
// destroy all component subscriptions to the store
|
|
448
|
+
feedsStore.destroy();
|
|
449
|
+
// restore original state
|
|
450
|
+
feedsStore.setState(originalState);
|
|
451
|
+
feedsStoreInitialized = false;
|
|
452
|
+
});
|
|
453
|
+
// reset database and store in between tests
|
|
454
|
+
export const resetFeedsDatabaseAndStore = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
455
|
+
yield localForageLru.createInstance({ name: "bitsocialReactHooks-communitiesPages" }).clear();
|
|
456
|
+
yield resetFeedsStore();
|
|
457
|
+
});
|
|
458
|
+
export default feedsStore;
|
|
459
|
+
//# sourceMappingURL=feeds-store.js.map
|
|
@@ -0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import Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:stores\");\nimport {\n Feed,\n Feeds,\n Community,\n Communities,\n Account,\n FeedsOptions,\n CommunityPage,\n FeedsCommunitiesPostCounts,\n CommentsFilter,\n FeedOptionsAccountComments,\n Comment,\n} from \"../../types\";\nimport createStore from \"zustand\";\nimport localForageLru from \"../../lib/localforage-lru\";\nimport { communityPostsCacheExpired } from \"../../lib/utils\";\nimport { getPkcGetCommunity } from \"../../lib/pkc-compat\";\nimport { deriveFeedSortType } from \"../../lib/feed-sort-type\";\nimport { CommunityLookupRef, getCommunityRefKeys } from \"../../lib/community-ref\";\nimport accountsStore from \"../accounts\";\nimport communitiesStore from \"../communities\";\nimport communitiesPagesStore from \"../communities-pages\";\nimport {\n getFeedsCommunitiesFirstPageCids,\n getLoadedFeeds,\n getUpdatedFeeds,\n getBufferedFeedsWithoutLoadedFeeds,\n getFeedsCommunitiesPostCounts,\n getFeedsHaveMore,\n getAccountsBlockedAddresses,\n feedsHaveChangedBlockedAddresses,\n accountsBlockedAddressesChanged,\n getAccountsBlockedCids,\n feedsHaveChangedBlockedCids,\n accountsBlockedCidsChanged,\n feedsCommunitiesChanged,\n getFeedsCommunities,\n getFeedsCommunitiesLoadedCount,\n getFeedsCommunitiesPostsPagesFirstUpdatedAts,\n getFilteredSortedFeeds,\n getFeedsCommunityKeysWithNewerPosts,\n} from \"./utils\";\n\n// reddit loads approximately 25 posts per page\n// while infinite scrolling\nexport const defaultPostsPerPage = 25;\n\n// keep large buffer because fetching cids is slow\nconst communityPostsLeftBeforeNextPage = 50;\n\ntype FeedsState = {\n feedsOptions: FeedsOptions;\n bufferedFeeds: Feeds;\n loadedFeeds: Feeds;\n updatedFeeds: Feeds;\n bufferedFeedsCommunitiesPostCounts: FeedsCommunitiesPostCounts;\n feedsHaveMore: { [feedName: string]: boolean };\n feedsCommunityKeysWithNewerPosts: { [feedName: string]: string[] };\n addFeedToStore: Function;\n incrementFeedPageNumber: Function;\n expandFeedTimeWindow: Function;\n resetFeed: Function;\n updateFeeds: Function;\n};\n\n// don't updateFeeds more than once per updateFeedsMinIntervalTime\nlet updateFeedsPending = false;\nconst updateFeedsMinIntervalTime = 100;\n\nconst feedsStore = createStore<FeedsState>((setState: Function, getState: Function) => ({\n feedsOptions: {},\n bufferedFeeds: {},\n loadedFeeds: {},\n updatedFeeds: {},\n bufferedFeedsCommunitiesPostCounts: {},\n feedsHaveMore: {},\n feedsCommunityKeysWithNewerPosts: {},\n\n async addFeedToStore(\n feedName: string,\n communities: CommunityLookupRef[],\n communityKeys: string[],\n sortType: string,\n account: Account,\n isBufferedFeed?: boolean,\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: FeedOptionsAccountComments,\n modQueue?: string[],\n requestedSortType?: string,\n ) {\n // init here because must be called after async accounts store finished initializing\n initializeFeedsStore();\n\n assert(\n feedName && typeof feedName === \"string\",\n `feedsStore.addFeedToStore feedName '${feedName}' invalid`,\n );\n assert(\n Array.isArray(communities),\n `addFeedToStore.addFeedToStore communities '${communities}' invalid`,\n );\n assert(\n Array.isArray(communityKeys),\n `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' invalid`,\n );\n const derivedCommunityKeys = getCommunityRefKeys(communities);\n assert(\n communityKeys.length === derivedCommunityKeys.length &&\n communityKeys.every((communityKey, index) => communityKey === derivedCommunityKeys[index]),\n `addFeedToStore.addFeedToStore communityKeys '${communityKeys}' do not match communities`,\n );\n assert(\n sortType && typeof sortType === \"string\",\n `addFeedToStore.addFeedToStore sortType '${sortType}' invalid`,\n );\n assert(\n typeof getPkcGetCommunity(account?.pkc) === \"function\",\n `addFeedToStore.addFeedToStore account '${account}' invalid`,\n );\n assert(\n typeof isBufferedFeed === \"boolean\" ||\n isBufferedFeed === undefined ||\n isBufferedFeed === null,\n `addFeedToStore.addFeedToStore isBufferedFeed '${isBufferedFeed}' invalid`,\n );\n assert(\n !filter || typeof filter?.filter === \"function\",\n `addFeedToStore.addFeedToStore filter.filter '${filter?.filter}' invalid`,\n );\n assert(\n !filter || typeof filter?.key === \"string\",\n `addFeedToStore.addFeedToStore filter.key '${filter?.key}' invalid`,\n );\n assert(\n !newerThan || typeof newerThan === \"number\",\n `addFeedToStore.addFeedToStore newerThan '${newerThan}' invalid`,\n );\n postsPerPage = postsPerPage || defaultPostsPerPage;\n assert(\n typeof postsPerPage === \"number\",\n `addFeedToStore.addFeedToStore postsPerPage '${postsPerPage}' invalid`,\n );\n assert(\n !accountComments || typeof accountComments?.newerThan === \"number\",\n `addFeedToStore.addFeedToStore accountComments.newerThan '${accountComments?.newerThan}' invalid`,\n );\n assert(\n !modQueue || Array.isArray(modQueue),\n `addFeedToStore.addFeedToStore modQueue '${modQueue}' invalid`,\n );\n\n const { feedsOptions, updateFeeds } = getState();\n // feed is in store already, do nothing\n // if the feed already exist but is at page 0, reset it to page 1\n if (feedsOptions[feedName] && feedsOptions[feedName].pageNumber !== 0) {\n return;\n }\n // to add a buffered feed, add a feed with pageNumber 0\n const feedOptions = {\n communities,\n communityKeys,\n sortType,\n requestedSortType: requestedSortType || sortType,\n accountId: account.id,\n pageNumber: isBufferedFeed === true ? 0 : 1,\n postsPerPage,\n newerThan,\n filter,\n accountComments,\n // TODO: allow multiple modQueue at once, fow now only use first in array\n modQueue,\n };\n log(\"feedsActions.addFeedToStore\", feedOptions);\n setState(({ feedsOptions }: any) => ({\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n }));\n\n addCommunitiesToCommunitiesStore(communities, account);\n\n // update feeds right away to use the already loaded communities and pages\n // if no new communities are added by the feed, like for a sort type change,\n // a feed update will never be triggered, so must be triggered it manually\n updateFeeds();\n },\n\n incrementFeedPageNumber(feedName: string) {\n const { feedsOptions, loadedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.incrementFeedPageNumber feed name '${feedName}' does not exist in feeds store`,\n );\n log(\"feedsActions.incrementFeedPageNumber\", { feedName });\n\n assert(\n feedsOptions[feedName].pageNumber * feedsOptions[feedName].postsPerPage <=\n loadedFeeds[feedName].length,\n `feedsActions.incrementFeedPageNumber cannot increment feed page number before current page has loaded`,\n );\n setState(({ feedsOptions, loadedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: feedsOptions[feedName].pageNumber + 1,\n };\n return { feedsOptions: { ...feedsOptions, [feedName]: feedOptions } };\n });\n\n // do not update feed at the same time as increment a page number or it might cause\n // a race condition, rather schedule a feed update\n updateFeeds();\n },\n\n expandFeedTimeWindow(feedName: string, newerThan?: number) {\n const { feedsOptions, loadedFeeds, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.expandFeedTimeWindow feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n newerThan === undefined || typeof newerThan === \"number\",\n `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' invalid`,\n );\n\n const currentFeedOptions = feedsOptions[feedName];\n const currentNewerThan = currentFeedOptions.newerThan;\n\n if (currentNewerThan === newerThan) {\n return;\n }\n\n const isExpandedTimeWindow =\n typeof currentNewerThan === \"number\" &&\n (newerThan === undefined || newerThan > currentNewerThan);\n assert(\n isExpandedTimeWindow,\n `feedsActions.expandFeedTimeWindow newerThan '${newerThan}' must broaden the current window '${currentNewerThan}'`,\n );\n\n const nextSortType = deriveFeedSortType(currentFeedOptions.requestedSortType, newerThan);\n assert(\n nextSortType === currentFeedOptions.sortType,\n `feedsActions.expandFeedTimeWindow cannot change sort type from '${currentFeedOptions.sortType}' to '${nextSortType}'`,\n );\n\n const loadedFeed = loadedFeeds[feedName] || [];\n const shouldPrefetchExpandedPage =\n currentFeedOptions.pageNumber > 0 &&\n loadedFeed.length >= currentFeedOptions.pageNumber * currentFeedOptions.postsPerPage;\n\n setState(({ feedsOptions }: any) => ({\n feedsOptions: {\n ...feedsOptions,\n [feedName]: {\n ...currentFeedOptions,\n newerThan,\n pageNumber: shouldPrefetchExpandedPage\n ? currentFeedOptions.pageNumber + 1\n : currentFeedOptions.pageNumber,\n },\n },\n }));\n\n updateFeeds();\n },\n\n async resetFeed(feedName: string) {\n const { feedsOptions, updateFeeds } = getState();\n assert(\n feedsOptions[feedName],\n `feedsActions.resetFeed feed name '${feedName}' does not exist in feeds store`,\n );\n assert(\n feedsOptions[feedName].pageNumber >= 1,\n `feedsActions.resetFeed cannot reset feed page number '${feedsOptions[feedName].pageNumber}' lower than 1`,\n );\n log(\"feedsActions.resetFeed\", { feedName });\n\n const { modQueue, sortType, communities, communityKeys, accountId } = feedsOptions[feedName];\n const account = accountsStore.getState().accounts[accountId];\n assert(\n account,\n `feedsActions.resetFeed account id '${accountId}' does not exist in accounts store`,\n );\n\n setState(({ feedsOptions, loadedFeeds, updatedFeeds }: any) => {\n const feedOptions = {\n ...feedsOptions[feedName],\n pageNumber: 1,\n };\n return {\n feedsOptions: { ...feedsOptions, [feedName]: feedOptions },\n loadedFeeds: { ...loadedFeeds, [feedName]: [] },\n updatedFeeds: { ...updatedFeeds, [feedName]: [] },\n };\n });\n\n if (modQueue?.[0]) {\n const { communities } = communitiesStore.getState();\n const { invalidateCommunityPages } = communitiesPagesStore.getState();\n const loadedCommunities = communityKeys\n .map((communityKey: string) => communities[communityKey])\n .filter((community: Community | undefined): community is Community => Boolean(community));\n await Promise.all(\n loadedCommunities.map((community: Community) =>\n invalidateCommunityPages(community, sortType, modQueue, account.id),\n ),\n );\n }\n\n await Promise.all(\n communities.map((communityRef: CommunityLookupRef, communityIndex: number) =>\n communitiesStore\n .getState()\n .refreshCommunity(communityRef, account)\n .catch((error: unknown) =>\n log.error(\"feedsStore.resetFeed refreshCommunity error\", {\n feedName,\n community: communityRef,\n communityKey: communityKeys[communityIndex],\n error,\n }),\n ),\n ),\n );\n\n updateFeeds();\n },\n\n // recalculate all feeds using new communities.post.pages, communitiesPagesStore and page numbers\n updateFeeds() {\n if (updateFeedsPending) {\n return;\n }\n updateFeedsPending = true;\n\n // don't update feeds more than once per updateFeedsMinIntervalTime\n const timeUntilNextUpdate = Date.now() % updateFeedsMinIntervalTime;\n\n setTimeout(async () => {\n // get state from all stores\n const previousState = getState();\n const { feedsOptions } = previousState;\n const { communities } = communitiesStore.getState();\n const { communitiesPages } = communitiesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // calculate new feeds\n const filteredSortedFeeds = getFilteredSortedFeeds(\n feedsOptions,\n communities,\n communitiesPages,\n accounts,\n communitiesPagesStore.getState().comments,\n );\n const bufferedFeedsWithoutPreviousLoadedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n filteredSortedFeeds,\n previousState.loadedFeeds,\n );\n const loadedFeeds = await getLoadedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.loadedFeeds,\n bufferedFeedsWithoutPreviousLoadedFeeds,\n accounts,\n );\n // after loaded feeds are caculated, remove new loaded feeds (again) from buffered feeds\n const bufferedFeeds = getBufferedFeedsWithoutLoadedFeeds(\n bufferedFeedsWithoutPreviousLoadedFeeds,\n loadedFeeds,\n );\n const bufferedFeedsCommunitiesPostCounts = getFeedsCommunitiesPostCounts(\n feedsOptions,\n bufferedFeeds,\n );\n const feedsHaveMore = getFeedsHaveMore(\n feedsOptions,\n bufferedFeeds,\n communities,\n communitiesPages,\n accounts,\n );\n const feedsCommunityKeysWithNewerPosts = getFeedsCommunityKeysWithNewerPosts(\n feedsOptions,\n filteredSortedFeeds,\n loadedFeeds,\n previousState.feedsCommunityKeysWithNewerPosts,\n );\n const updatedFeeds = await getUpdatedFeeds(\n feedsOptions,\n filteredSortedFeeds,\n previousState.updatedFeeds,\n loadedFeeds,\n accounts,\n );\n\n // set new feeds\n setState((state: any) => ({\n bufferedFeeds,\n loadedFeeds,\n updatedFeeds,\n bufferedFeedsCommunitiesPostCounts,\n feedsHaveMore,\n feedsCommunityKeysWithNewerPosts,\n }));\n log.trace(\"feedsStore.updateFeeds\", {\n feedsOptions,\n bufferedFeeds,\n loadedFeeds,\n updatedFeeds,\n bufferedFeedsCommunitiesPostCounts,\n feedsHaveMore,\n communities,\n communitiesPages,\n feedsCommunityKeysWithNewerPosts,\n });\n\n // TODO: if updateFeeds was called while updateFeedsPending = true, maybe we should recall updateFeeds here\n updateFeedsPending = false;\n }, timeUntilNextUpdate);\n },\n}));\n\nlet feedsStoreInitialized = false;\nconst initializeFeedsStore = async () => {\n if (feedsStoreInitialized) {\n return;\n }\n // TODO: optimize subscriptions e.g. updateFeedsOnFeedsCommunitiesChange(communities)\n // subscribe to communities store changes\n communitiesStore.subscribe(updateFeedsOnFeedsCommunitiesChange);\n // subscribe to bufferedFeedsCommunitiesPostCounts change\n feedsStore.subscribe(addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts);\n // subscribe to communities pages store changes\n communitiesPagesStore.subscribe(updateFeedsOnFeedsCommunitiesPagesChange);\n // subscribe to accounts store change (for blocked addresses)\n accountsStore.subscribe(updateFeedsOnAccountsBlockedAddressesChange);\n // subscribe to accounts store change (for blocked cids)\n accountsStore.subscribe(updateFeedsOnAccountsBlockedCidsChange);\n // subscribe to accounts store changes (for account comments)\n accountsStore.subscribe(updateFeedsOnAccountsCommentsChange);\n feedsStoreInitialized = true;\n};\n\nlet previousBlockedAddresses: string[] = [];\nlet previousAccountsBlockedAddresses: { [address: string]: boolean }[] = [];\nconst updateFeedsOnAccountsBlockedAddressesChange = (accountsStoreState: any) => {\n const { accounts } = accountsStoreState;\n\n // blocked addresses haven't changed, do nothing\n const accountsBlockedAddresses = [];\n for (const i in accounts) {\n accountsBlockedAddresses.push(accounts[i].blockedAddresses);\n }\n if (\n !accountsBlockedAddressesChanged(previousAccountsBlockedAddresses, accountsBlockedAddresses)\n ) {\n return;\n }\n previousAccountsBlockedAddresses = accountsBlockedAddresses;\n\n const blockedAddresses = getAccountsBlockedAddresses(accounts);\n\n // blocked addresses haven't changed, do nothing\n if (blockedAddresses.toString() === previousBlockedAddresses.toString()) {\n return;\n }\n\n const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();\n const _feedsHaveChangedBlockedAddresses = feedsHaveChangedBlockedAddresses(\n feedsOptions,\n bufferedFeeds,\n blockedAddresses,\n previousBlockedAddresses,\n );\n previousBlockedAddresses = blockedAddresses;\n\n // if changed blocked addresses arent used in the feeds, do nothing\n // NOTE: because of this, if an author address is unblocked, feeds won't update until some other event causes a feed update\n if (!_feedsHaveChangedBlockedAddresses) {\n return;\n }\n\n updateFeeds();\n};\n\nlet previousBlockedCids: string[] = [];\nlet previousAccountsBlockedCids: { [cid: string]: boolean }[] = [];\nconst updateFeedsOnAccountsBlockedCidsChange = (accountsStoreState: any) => {\n const { accounts } = accountsStoreState;\n\n // blocked cids haven't changed, do nothing\n const accountsBlockedCids = [];\n for (const i in accounts) {\n accountsBlockedCids.push(accounts[i].blockedCids);\n }\n if (!accountsBlockedCidsChanged(previousAccountsBlockedCids, accountsBlockedCids)) {\n return;\n }\n previousAccountsBlockedCids = accountsBlockedCids;\n\n const blockedCids = getAccountsBlockedCids(accounts);\n\n // blocked cids haven't changed, do nothing\n if (blockedCids.toString() === previousBlockedCids.toString()) {\n return;\n }\n\n const { feedsOptions, updateFeeds, bufferedFeeds } = feedsStore.getState();\n const _feedsHaveChangedBlockedCids = feedsHaveChangedBlockedCids(\n feedsOptions,\n bufferedFeeds,\n blockedCids,\n previousBlockedCids,\n );\n previousBlockedCids = blockedCids;\n\n // if changed blocked cids arent used in the feeds, do nothing\n // NOTE: because of this, if a cid is unblocked, feeds won't update until some other event causes a feed update\n if (!_feedsHaveChangedBlockedCids) {\n return;\n }\n\n updateFeeds();\n};\n\nlet previousCommunitiesPages: { [pageCid: string]: CommunityPage } = {};\nconst updateFeedsOnFeedsCommunitiesPagesChange = (communitiesPagesStoreState: any) => {\n const { communitiesPages } = communitiesPagesStoreState;\n\n // no changes, do nothing\n if (communitiesPages === previousCommunitiesPages) {\n return;\n }\n previousCommunitiesPages = communitiesPages;\n\n // currently only the feeds use communitiesPagesStore, so any change must\n // trigger a feed update, if in the future another hook uses the communitiesPagesStore\n // we should check if the communities pages changed are actually used by the feeds before\n // triggering an update\n feedsStore.getState().updateFeeds();\n};\n\nlet previousBufferedFeedsCommunitiesPostCountsPageCids: string[] = [];\nlet previousBufferedFeedsCommunities = new Map<string, Community>();\nlet previousBufferedFeedsCommunitiesPostCounts: FeedsCommunitiesPostCounts = {};\nconst addCommunitiesPagesOnLowBufferedFeedsCommunitiesPostCounts = (feedsStoreState: any) => {\n const { bufferedFeedsCommunitiesPostCounts, feedsOptions } = feedsStore.getState();\n const { communities } = communitiesStore.getState();\n\n // if feeds communities have changed, we must try adding them even if buffered posts counts haven't changed\n const bufferedFeedsCommunities = getFeedsCommunities(feedsOptions, communities);\n const _feedsCommunitiesChanged = feedsCommunitiesChanged(\n previousBufferedFeedsCommunities,\n bufferedFeedsCommunities,\n );\n const bufferedFeedsCommunitiesPostCountsChanged =\n previousBufferedFeedsCommunitiesPostCounts !== bufferedFeedsCommunitiesPostCounts;\n\n // if feeds communities havent changed and buffered posts counts also havent changed, do nothing\n if (!_feedsCommunitiesChanged && !bufferedFeedsCommunitiesPostCountsChanged) {\n return;\n }\n previousBufferedFeedsCommunities = bufferedFeedsCommunities;\n previousBufferedFeedsCommunitiesPostCounts = bufferedFeedsCommunitiesPostCounts;\n\n // in case feeds community changed, but the first page cids haven't\n const bufferedFeedsCommunitiesPostCountsPageCids =\n getFeedsCommunitiesFirstPageCids(bufferedFeedsCommunities);\n const bufferedFeedsCommunitiesPostCountsPageCidsChanged =\n bufferedFeedsCommunitiesPostCountsPageCids.toString() !==\n previousBufferedFeedsCommunitiesPostCountsPageCids.toString();\n if (\n !bufferedFeedsCommunitiesPostCountsPageCidsChanged &&\n !bufferedFeedsCommunitiesPostCountsChanged\n ) {\n return;\n }\n previousBufferedFeedsCommunitiesPostCountsPageCids = bufferedFeedsCommunitiesPostCountsPageCids;\n\n const { addNextCommunityPageToStore } = communitiesPagesStore.getState();\n const { accounts } = accountsStore.getState();\n\n // bufferedFeedsCommunitiesPostCounts have changed, check if any of them are low\n for (const feedName in bufferedFeedsCommunitiesPostCounts) {\n const account = accounts[feedsOptions[feedName].accountId];\n const communitiesPostCounts = bufferedFeedsCommunitiesPostCounts[feedName];\n const { sortType, modQueue } = feedsOptions[feedName];\n for (const communityAddress in communitiesPostCounts) {\n // don't fetch more pages if community address is blocked\n if (account?.blockedAddresses[communityAddress]) {\n continue;\n }\n\n // community hasn't loaded yet\n if (!communities[communityAddress]) {\n continue;\n }\n\n // if community posts cache is expired, don't use, wait for next community update\n if (communityPostsCacheExpired(communities[communityAddress])) {\n continue;\n }\n\n // community post count is low, fetch next community page\n if (communitiesPostCounts[communityAddress] <= communityPostsLeftBeforeNextPage) {\n addNextCommunityPageToStore(\n communities[communityAddress],\n sortType,\n account,\n modQueue,\n ).catch((error: unknown) =>\n log.error(\"feedsStore communitiesActions.addNextCommunityPageToStore error\", {\n communityAddress,\n community: communities[communityAddress],\n sortType,\n error,\n }),\n );\n }\n }\n }\n};\n\nlet previousFeedsCommunitiesFirstPageCids: string[] = [];\nlet previousFeedsCommunities: Map<string, Community> = new Map();\nlet previousFeedsCommunitiesLoadedCount = 0;\nlet previousFeedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\nconst updateFeedsOnFeedsCommunitiesChange = (communitiesStoreState: any) => {\n const { communities } = communitiesStoreState;\n const { feedsOptions, updateFeeds } = feedsStore.getState();\n\n // feeds communities haven't changed, do nothing\n const feedsCommunities = getFeedsCommunities(feedsOptions, communities);\n if (!feedsCommunitiesChanged(previousFeedsCommunities, feedsCommunities)) {\n return;\n }\n previousFeedsCommunities = feedsCommunities;\n\n // decide if feeds communities have changed by looking at all feeds communities page cids\n // (in case that a community changed, but its first page cid didn't)\n const feedsCommunitiesFirstPageCids = getFeedsCommunitiesFirstPageCids(feedsCommunities);\n\n // first page cids haven't changed, do nothing\n if (\n feedsCommunitiesFirstPageCids.toString() === previousFeedsCommunitiesFirstPageCids.toString()\n ) {\n // if no new feed communities have loaded, do nothing\n // in case a sub loads with no first page cid and first pages cids don't change, need to trigger hasMore update\n const feedsCommunitiesLoadedCount = getFeedsCommunitiesLoadedCount(feedsCommunities);\n if (feedsCommunitiesLoadedCount === previousFeedsCommunitiesLoadedCount) {\n // if community.posts.pages haven't changed, do nothing\n const feedsCommunitiesPostsPagesFirstUpdatedAts =\n getFeedsCommunitiesPostsPagesFirstUpdatedAts(feedsCommunities);\n if (\n feedsCommunitiesPostsPagesFirstUpdatedAts ===\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts\n ) {\n return;\n }\n\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts = feedsCommunitiesPostsPagesFirstUpdatedAts;\n }\n previousFeedsCommunitiesLoadedCount = feedsCommunitiesLoadedCount;\n }\n\n // feeds communities have changed, update feeds\n previousFeedsCommunitiesFirstPageCids = feedsCommunitiesFirstPageCids;\n updateFeeds();\n};\n\nlet previousAccountsCommentsCount = 0;\nlet previousAccountsCommentsCids = \"\";\nconst updateFeedsOnAccountsCommentsChange = (accountsStoreState: any) => {\n const { accountsComments } = accountsStoreState;\n const accountsCommentsCount = Object.values(accountsComments as Comment[][]).reduce(\n (count, accountComments) => count + accountComments.length,\n 0,\n );\n\n // no changes, do nothing\n if (accountsCommentsCount === previousAccountsCommentsCount) {\n // if cids haven't changed (account comments receive cids after pending), do nothing\n const accountsCommentsCids = Object.values(accountsComments as Comment[][]).reduce(\n (cids, accountComments) => cids + String(accountComments.map((comment) => comment.cid || \"\")),\n \"\",\n );\n if (accountsCommentsCids === previousAccountsCommentsCids) {\n return;\n }\n previousAccountsCommentsCids = accountsCommentsCids;\n }\n previousAccountsCommentsCount = accountsCommentsCount;\n\n // TODO: only update the feeds that are relevant to the new accountComment.parentCid/postCid\n feedsStore.getState().updateFeeds();\n};\n\nconst addCommunitiesToCommunitiesStore = (\n communityRefs: CommunityLookupRef[],\n account: Account,\n) => {\n const addCommunityToStore = communitiesStore.getState().addCommunityToStore;\n for (const communityRef of communityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"feedsStore communitiesActions.addCommunityToStore error\", {\n communityRef,\n error,\n }),\n );\n }\n};\n\n// reset store in between tests\nconst originalState = feedsStore.getState();\n// async function because some stores have async init\nexport const resetFeedsStore = async () => {\n previousBufferedFeedsCommunitiesPostCounts = {};\n previousBufferedFeedsCommunitiesPostCountsPageCids = [];\n previousBufferedFeedsCommunities = new Map();\n previousBlockedAddresses = [];\n previousAccountsBlockedAddresses = [];\n previousBlockedCids = [];\n previousAccountsBlockedCids = [];\n previousFeedsCommunitiesFirstPageCids = [];\n previousFeedsCommunities = new Map();\n previousFeedsCommunitiesLoadedCount = 0;\n previousFeedsCommunitiesPostsPagesFirstUpdatedAts = \"\";\n previousCommunitiesPages = {};\n previousAccountsCommentsCount = 0;\n previousAccountsCommentsCids = \"\";\n updateFeedsPending = false;\n // destroy all component subscriptions to the store\n feedsStore.destroy();\n // restore original state\n feedsStore.setState(originalState);\n feedsStoreInitialized = false;\n};\n\n// reset database and store in between tests\nexport const resetFeedsDatabaseAndStore = async () => {\n await localForageLru.createInstance({ name: \"bitsocialReactHooks-communitiesPages\" }).clear();\n await resetFeedsStore();\n};\n\nexport default feedsStore;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stores/feeds/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,eAAe,UAAU,CAAC","sourcesContent":["import feedsStore from \"./feeds-store\";\nexport * from \"./feeds-store\";\nexport default feedsStore;\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Comment, Feeds, FeedsOptions, Community, Communities, Accounts, CommunitiesPages, FeedsCommunitiesPostCounts } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the feeds from all the loaded community pages, filter and sort them
|
|
4
|
+
*/
|
|
5
|
+
export declare const getFilteredSortedFeeds: (feedsOptions: FeedsOptions, communities: Communities, communitiesPages: CommunitiesPages, accounts: Accounts, freshestComments?: {
|
|
6
|
+
[commentCid: string]: Comment;
|
|
7
|
+
}) => Feeds;
|
|
8
|
+
export declare const getLoadedFeeds: (feedsOptions: FeedsOptions, filteredSortedFeeds: Feeds, loadedFeeds: Feeds, bufferedFeeds: Feeds, accounts: Accounts) => Promise<Feeds>;
|
|
9
|
+
export declare const addAccountsComments: (feedsOptions: FeedsOptions, loadedFeeds: Feeds) => boolean;
|
|
10
|
+
export declare const getBufferedFeedsWithoutLoadedFeeds: (bufferedFeeds: Feeds, loadedFeeds: Feeds) => Feeds;
|
|
11
|
+
export declare const getUpdatedFeeds: (feedsOptions: FeedsOptions, filteredSortedFeeds: Feeds, updatedFeeds: Feeds, loadedFeeds: Feeds, accounts: Accounts) => Promise<Feeds>;
|
|
12
|
+
export declare const getFeedsCommunityKeysWithNewerPosts: (feedsOptions: FeedsOptions, filteredSortedFeeds: Feeds, loadedFeeds: Feeds, previousFeedsCommunityKeysWithNewerPosts: {
|
|
13
|
+
[feedName: string]: string[];
|
|
14
|
+
}) => {
|
|
15
|
+
[feedName: string]: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare const getFeedsCommunitiesPostCounts: (feedsOptions: FeedsOptions, feeds: Feeds) => FeedsCommunitiesPostCounts;
|
|
18
|
+
/**
|
|
19
|
+
* Get which feeds have more posts, i.e. have not reached the final page of all subs
|
|
20
|
+
*/
|
|
21
|
+
export declare const getFeedsHaveMore: (feedsOptions: FeedsOptions, bufferedFeeds: Feeds, communities: Communities, communitiesPages: CommunitiesPages, accounts: Accounts) => {
|
|
22
|
+
[feedName: string]: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare const getFeedsCommunities: (feedsOptions: FeedsOptions, communities: Communities) => Map<string, Community>;
|
|
25
|
+
export declare const feedsCommunitiesChanged: (previousFeedsCommunities: Map<string, Community>, feedsCommunities: Map<string, Community>) => boolean;
|
|
26
|
+
export declare const getFeedsCommunitiesFirstPageCids: (feedsCommunities: Map<string, Community>) => string[];
|
|
27
|
+
export declare const getFeedsCommunitiesPostsPagesFirstUpdatedAts: (feedsCommunities: Map<string, Community>) => string;
|
|
28
|
+
export declare const getFeedsCommunitiesLoadedCount: (feedsCommunities: Map<string, Community>) => number;
|
|
29
|
+
export declare const getAccountsBlockedAddresses: (accounts: Accounts) => string[];
|
|
30
|
+
export declare const accountsBlockedAddressesChanged: (previousAccountsBlockedAddresses: {
|
|
31
|
+
[address: string]: boolean;
|
|
32
|
+
}[], accountsBlockedAddresses: {
|
|
33
|
+
[address: string]: boolean;
|
|
34
|
+
}[]) => boolean;
|
|
35
|
+
export declare const feedsHaveChangedBlockedAddresses: (feedsOptions: FeedsOptions, bufferedFeeds: Feeds, blockedAddresses: string[], previousBlockedAddresses: string[]) => boolean;
|
|
36
|
+
export declare const getAccountsBlockedCids: (accounts: Accounts) => string[];
|
|
37
|
+
export declare const accountsBlockedCidsChanged: (previousAccountsBlockedCids: {
|
|
38
|
+
[address: string]: boolean;
|
|
39
|
+
}[], accountsBlockedCids: {
|
|
40
|
+
[address: string]: boolean;
|
|
41
|
+
}[]) => boolean;
|
|
42
|
+
export declare const feedsHaveChangedBlockedCids: (feedsOptions: FeedsOptions, bufferedFeeds: Feeds, blockedCids: string[], previousBlockedCids: string[]) => boolean;
|
|
43
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/stores/feeds/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EAEP,KAAK,EAEL,YAAY,EACZ,SAAS,EACT,WAAW,EAEX,QAAQ,EAER,gBAAg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