@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,385 @@
|
|
|
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 localForageLru from "../../lib/localforage-lru/index.js";
|
|
11
|
+
const commentsDatabase = localForageLru.createInstance({
|
|
12
|
+
name: "bitsocialReactHooks-comments",
|
|
13
|
+
size: 5000,
|
|
14
|
+
});
|
|
15
|
+
import Logger from "@pkcprotocol/pkc-logger";
|
|
16
|
+
export const log = Logger("bitsocial-react-hooks:comments:stores");
|
|
17
|
+
import utils from "../../lib/utils/index.js";
|
|
18
|
+
import createStore from "zustand";
|
|
19
|
+
import accountsStore from "../accounts/index.js";
|
|
20
|
+
import repliesPagesStore from "../replies-pages/index.js";
|
|
21
|
+
import { normalizeCommentCommunityAddress } from "../../lib/pkc-compat.js";
|
|
22
|
+
let pkcGetCommentPending = {};
|
|
23
|
+
const liveComments = {};
|
|
24
|
+
const liveCommentPromises = {};
|
|
25
|
+
const commentAutoUpdateSubscribers = {};
|
|
26
|
+
const stopCommentAfterNextUpdate = {};
|
|
27
|
+
const initializedComments = new WeakSet();
|
|
28
|
+
const trackedListeners = new WeakSet();
|
|
29
|
+
// reset all event listeners in between tests
|
|
30
|
+
export const listeners = [];
|
|
31
|
+
const removeCommentListener = (comment, event, listener) => {
|
|
32
|
+
if (typeof (comment === null || comment === void 0 ? void 0 : comment.off) === "function") {
|
|
33
|
+
comment.off(event, listener);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (typeof (comment === null || comment === void 0 ? void 0 : comment.removeListener) === "function") {
|
|
37
|
+
comment.removeListener(event, listener);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const getCommentAutoUpdateSubscribersCount = (commentCid) => Object.keys(commentAutoUpdateSubscribers[commentCid] || {}).length;
|
|
41
|
+
const hasCommentAutoUpdateSubscribers = (commentCid) => getCommentAutoUpdateSubscribersCount(commentCid) > 0;
|
|
42
|
+
const releaseLiveComment = (commentCid, comment) => {
|
|
43
|
+
const liveComment = comment || liveComments[commentCid];
|
|
44
|
+
if (liveComment) {
|
|
45
|
+
const listenerIndex = listeners.indexOf(liveComment);
|
|
46
|
+
if (listenerIndex !== -1) {
|
|
47
|
+
listeners.splice(listenerIndex, 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!comment || liveComments[commentCid] === liveComment) {
|
|
51
|
+
delete liveComments[commentCid];
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const maybeReleaseStoppedLiveComment = (commentCid, comment) => {
|
|
55
|
+
if (!comment || hasCommentAutoUpdateSubscribers(commentCid)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (liveComments[commentCid] !== comment) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
releaseLiveComment(commentCid, comment);
|
|
62
|
+
};
|
|
63
|
+
const commentsStore = createStore((setState, getState) => {
|
|
64
|
+
const addCommentError = (commentCid, error) => {
|
|
65
|
+
setState((state) => {
|
|
66
|
+
let commentErrors = state.errors[commentCid] || [];
|
|
67
|
+
commentErrors = [...commentErrors, error];
|
|
68
|
+
return Object.assign(Object.assign({}, state), { errors: Object.assign(Object.assign({}, state.errors), { [commentCid]: commentErrors }) });
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const persistComment = (commentCid, nextComment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const normalizedComment = normalizeCommentCommunityAddress(utils.clone(nextComment));
|
|
73
|
+
yield commentsDatabase.setItem(commentCid, normalizedComment);
|
|
74
|
+
log("commentsStore comment update", { commentCid, updatedComment: normalizedComment });
|
|
75
|
+
setState((state) => ({
|
|
76
|
+
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: normalizedComment }),
|
|
77
|
+
}));
|
|
78
|
+
// add comment replies pages to repliesPagesStore so they can be used in useComment
|
|
79
|
+
repliesPagesStore.getState().addRepliesPageCommentsToStore(nextComment);
|
|
80
|
+
return normalizedComment;
|
|
81
|
+
});
|
|
82
|
+
const stopLiveComment = (commentCid, comment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const liveComment = comment || liveComments[commentCid];
|
|
84
|
+
if (typeof (liveComment === null || liveComment === void 0 ? void 0 : liveComment.stop) !== "function") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
yield liveComment.stop();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
log.trace("comment.stop error", { commentCid, comment: liveComment, error });
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const maybeStopCommentAfterOneShotUpdate = (commentCid, comment) => {
|
|
95
|
+
if (!stopCommentAfterNextUpdate[commentCid]) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
delete stopCommentAfterNextUpdate[commentCid];
|
|
99
|
+
if (hasCommentAutoUpdateSubscribers(commentCid)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
void stopLiveComment(commentCid, comment).finally(() => {
|
|
103
|
+
maybeReleaseStoppedLiveComment(commentCid, comment);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const initializeComment = (commentCid, comment, account) => {
|
|
107
|
+
var _a, _b, _c, _d;
|
|
108
|
+
if (initializedComments.has(comment)) {
|
|
109
|
+
liveComments[commentCid] = comment;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
initializedComments.add(comment);
|
|
113
|
+
liveComments[commentCid] = comment;
|
|
114
|
+
(_a = comment === null || comment === void 0 ? void 0 : comment.on) === null || _a === void 0 ? void 0 : _a.call(comment, "update", (updatedComment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
updatedComment = normalizeCommentCommunityAddress(utils.clone(updatedComment));
|
|
116
|
+
yield persistComment(commentCid, updatedComment);
|
|
117
|
+
}));
|
|
118
|
+
(_b = comment === null || comment === void 0 ? void 0 : comment.on) === null || _b === void 0 ? void 0 : _b.call(comment, "updatingstatechange", (updatingState) => {
|
|
119
|
+
setState((state) => ({
|
|
120
|
+
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: Object.assign(Object.assign({}, state.comments[commentCid]), { updatingState }) }),
|
|
121
|
+
}));
|
|
122
|
+
if (updatingState === "succeeded" || updatingState === "failed") {
|
|
123
|
+
maybeStopCommentAfterOneShotUpdate(commentCid, comment);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
(_c = comment === null || comment === void 0 ? void 0 : comment.on) === null || _c === void 0 ? void 0 : _c.call(comment, "error", (error) => {
|
|
127
|
+
addCommentError(commentCid, error);
|
|
128
|
+
});
|
|
129
|
+
// set clients on comment so the frontend can display it, dont persist in db because a reload cancels updating
|
|
130
|
+
utils.clientsOnStateChange(comment === null || comment === void 0 ? void 0 : comment.clients, (clientState, clientType, clientUrl, chainTicker) => {
|
|
131
|
+
setState((state) => {
|
|
132
|
+
var _a;
|
|
133
|
+
// make sure not undefined, sometimes happens in e2e tests
|
|
134
|
+
if (!state.comments[commentCid]) {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
const clients = Object.assign({}, (_a = state.comments[commentCid]) === null || _a === void 0 ? void 0 : _a.clients);
|
|
138
|
+
const client = { state: clientState };
|
|
139
|
+
if (chainTicker) {
|
|
140
|
+
const chainProviders = Object.assign(Object.assign({}, clients[clientType][chainTicker]), { [clientUrl]: client });
|
|
141
|
+
clients[clientType] = Object.assign(Object.assign({}, clients[clientType]), { [chainTicker]: chainProviders });
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
clients[clientType] = Object.assign(Object.assign({}, clients[clientType]), { [clientUrl]: client });
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: Object.assign(Object.assign({}, state.comments[commentCid]), { clients }) }),
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
// when publishing a comment, you don't yet know its CID
|
|
152
|
+
// so when a new comment is fetched, check to see if it's your own
|
|
153
|
+
// comment, and if yes, add the CID to your account comments database
|
|
154
|
+
// if comment.timestamp isn't defined, it means the next update will contain the timestamp and author
|
|
155
|
+
// which is used in addCidToAccountComment
|
|
156
|
+
if (!(comment === null || comment === void 0 ? void 0 : comment.timestamp)) {
|
|
157
|
+
(_d = comment === null || comment === void 0 ? void 0 : comment.once) === null || _d === void 0 ? void 0 : _d.call(comment, "update", () => accountsStore
|
|
158
|
+
.getState()
|
|
159
|
+
.accountsActionsInternal.addCidToAccountComment(comment)
|
|
160
|
+
.catch((error) => log.error("accountsActionsInternal.addCidToAccountComment error", { comment, error })));
|
|
161
|
+
}
|
|
162
|
+
if (!trackedListeners.has(comment)) {
|
|
163
|
+
trackedListeners.add(comment);
|
|
164
|
+
listeners.push(comment);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const ensureLiveComment = (commentCid, account, commentData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
+
if (liveComments[commentCid]) {
|
|
169
|
+
return liveComments[commentCid];
|
|
170
|
+
}
|
|
171
|
+
if (liveCommentPromises[commentCid]) {
|
|
172
|
+
return liveCommentPromises[commentCid];
|
|
173
|
+
}
|
|
174
|
+
const liveCommentPromise = (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
const initialComment = normalizeCommentCommunityAddress(utils.clone(commentData || { cid: commentCid })) ||
|
|
176
|
+
{ cid: commentCid };
|
|
177
|
+
const liveComment = normalizeCommentCommunityAddress(yield account.pkc.createComment(initialComment));
|
|
178
|
+
initializeComment(commentCid, liveComment, account);
|
|
179
|
+
return liveComment;
|
|
180
|
+
}))();
|
|
181
|
+
liveCommentPromises[commentCid] = liveCommentPromise;
|
|
182
|
+
try {
|
|
183
|
+
return yield liveCommentPromise;
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
if (liveCommentPromises[commentCid] === liveCommentPromise) {
|
|
187
|
+
delete liveCommentPromises[commentCid];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
const requestCommentUpdate = (commentCid, comment, options) => {
|
|
192
|
+
var _a;
|
|
193
|
+
if (options === null || options === void 0 ? void 0 : options.stopAfterNextUpdate) {
|
|
194
|
+
stopCommentAfterNextUpdate[commentCid] = true;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
delete stopCommentAfterNextUpdate[commentCid];
|
|
198
|
+
}
|
|
199
|
+
(_a = comment === null || comment === void 0 ? void 0 : comment.update) === null || _a === void 0 ? void 0 : _a.call(comment).catch((error) => log.trace("comment.update error", { commentCid, comment, error }));
|
|
200
|
+
};
|
|
201
|
+
const waitForCommentUpdateCycle = (commentCid, comment) => new Promise((resolve, reject) => {
|
|
202
|
+
var _a, _b;
|
|
203
|
+
const onUpdatingStateChange = (updatingState) => {
|
|
204
|
+
var _a;
|
|
205
|
+
if (updatingState === "succeeded") {
|
|
206
|
+
cleanup();
|
|
207
|
+
resolve(normalizeCommentCommunityAddress(utils.clone(comment)));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (updatingState === "failed") {
|
|
211
|
+
cleanup();
|
|
212
|
+
reject(((_a = getState().errors[commentCid]) === null || _a === void 0 ? void 0 : _a.slice(-1)[0]) || Error("comment update failed"));
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const onError = (error) => {
|
|
216
|
+
cleanup();
|
|
217
|
+
reject(error);
|
|
218
|
+
};
|
|
219
|
+
const cleanup = () => {
|
|
220
|
+
removeCommentListener(comment, "updatingstatechange", onUpdatingStateChange);
|
|
221
|
+
removeCommentListener(comment, "error", onError);
|
|
222
|
+
};
|
|
223
|
+
(_a = comment === null || comment === void 0 ? void 0 : comment.on) === null || _a === void 0 ? void 0 : _a.call(comment, "updatingstatechange", onUpdatingStateChange);
|
|
224
|
+
(_b = comment === null || comment === void 0 ? void 0 : comment.on) === null || _b === void 0 ? void 0 : _b.call(comment, "error", onError);
|
|
225
|
+
});
|
|
226
|
+
return {
|
|
227
|
+
comments: {},
|
|
228
|
+
errors: {},
|
|
229
|
+
addCommentToStore(commentCid, account) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const { comments } = getState();
|
|
232
|
+
const pendingKey = commentCid + account.id;
|
|
233
|
+
// comment is in store already, do nothing
|
|
234
|
+
let comment = comments[commentCid];
|
|
235
|
+
if (comment || pkcGetCommentPending[pendingKey]) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
pkcGetCommentPending[pendingKey] = true;
|
|
239
|
+
try {
|
|
240
|
+
// try to find comment in database
|
|
241
|
+
comment = yield getCommentFromDatabase(commentCid, account);
|
|
242
|
+
if (!comment) {
|
|
243
|
+
comment = yield ensureLiveComment(commentCid, account, { cid: commentCid });
|
|
244
|
+
comment = normalizeCommentCommunityAddress(comment);
|
|
245
|
+
log("commentsStore.addCommentToStore", { commentCid, comment, account });
|
|
246
|
+
setState((state) => ({
|
|
247
|
+
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: utils.clone(comment) }),
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
comment = normalizeCommentCommunityAddress(comment);
|
|
252
|
+
setState((state) => ({
|
|
253
|
+
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: utils.clone(comment) }),
|
|
254
|
+
}));
|
|
255
|
+
// add comment replies pages to repliesPagesStore so they can be used in useComment
|
|
256
|
+
repliesPagesStore.getState().addRepliesPageCommentsToStore(comment);
|
|
257
|
+
comment = yield ensureLiveComment(commentCid, account, comment);
|
|
258
|
+
}
|
|
259
|
+
if (comment) {
|
|
260
|
+
requestCommentUpdate(commentCid, comment, { stopAfterNextUpdate: true });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
addCommentError(commentCid, e);
|
|
265
|
+
throw e;
|
|
266
|
+
}
|
|
267
|
+
finally {
|
|
268
|
+
pkcGetCommentPending[pendingKey] = false;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
startCommentAutoUpdate(commentCid, subscriberId, account) {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
+
const hadAutoUpdateSubscribers = hasCommentAutoUpdateSubscribers(commentCid);
|
|
275
|
+
commentAutoUpdateSubscribers[commentCid] = Object.assign(Object.assign({}, (commentAutoUpdateSubscribers[commentCid] || {})), { [subscriberId]: true });
|
|
276
|
+
if (hadAutoUpdateSubscribers && liveComments[commentCid]) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const storedComment = getState().comments[commentCid];
|
|
280
|
+
const liveComment = yield ensureLiveComment(commentCid, account, storedComment || { cid: commentCid });
|
|
281
|
+
if (!storedComment) {
|
|
282
|
+
setState((state) => ({
|
|
283
|
+
comments: Object.assign(Object.assign({}, state.comments), { [commentCid]: utils.clone(liveComment) }),
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
if (!hasCommentAutoUpdateSubscribers(commentCid)) {
|
|
287
|
+
yield stopLiveComment(commentCid, liveComment);
|
|
288
|
+
maybeReleaseStoppedLiveComment(commentCid, liveComment);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
requestCommentUpdate(commentCid, liveComment);
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
stopCommentAutoUpdate(commentCid, subscriberId) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
if (commentAutoUpdateSubscribers[commentCid]) {
|
|
297
|
+
delete commentAutoUpdateSubscribers[commentCid][subscriberId];
|
|
298
|
+
if (Object.keys(commentAutoUpdateSubscribers[commentCid]).length === 0) {
|
|
299
|
+
delete commentAutoUpdateSubscribers[commentCid];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (hasCommentAutoUpdateSubscribers(commentCid)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
delete stopCommentAfterNextUpdate[commentCid];
|
|
306
|
+
const liveComment = liveComments[commentCid];
|
|
307
|
+
yield stopLiveComment(commentCid, liveComment);
|
|
308
|
+
maybeReleaseStoppedLiveComment(commentCid, liveComment);
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
refreshComment(commentCid, account) {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
const storedComment = getState().comments[commentCid];
|
|
314
|
+
const liveComment = yield ensureLiveComment(commentCid, account, storedComment || { cid: commentCid });
|
|
315
|
+
if (!hasCommentAutoUpdateSubscribers(commentCid) &&
|
|
316
|
+
(liveComment === null || liveComment === void 0 ? void 0 : liveComment.updatingState) !== "stopped") {
|
|
317
|
+
yield stopLiveComment(commentCid, liveComment);
|
|
318
|
+
}
|
|
319
|
+
const waitForUpdate = waitForCommentUpdateCycle(commentCid, liveComment);
|
|
320
|
+
requestCommentUpdate(commentCid, liveComment, {
|
|
321
|
+
stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),
|
|
322
|
+
});
|
|
323
|
+
return waitForUpdate;
|
|
324
|
+
});
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
});
|
|
328
|
+
const getCommentFromDatabase = (commentCid, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
329
|
+
const commentData = yield commentsDatabase.getItem(commentCid);
|
|
330
|
+
if (!commentData) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
const comment = normalizeCommentCommunityAddress(yield account.pkc.createComment(commentData));
|
|
335
|
+
return comment;
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
// need to log this always or it could silently fail in production and cache never be used
|
|
339
|
+
console.error("failed pkc.createComment(cachedComment)", {
|
|
340
|
+
cachedComment: commentData,
|
|
341
|
+
error: e,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
// reset store in between tests
|
|
346
|
+
const originalState = commentsStore.getState();
|
|
347
|
+
// async function because some stores have async init
|
|
348
|
+
export const resetCommentsStore = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
349
|
+
pkcGetCommentPending = {};
|
|
350
|
+
for (const commentCid in commentAutoUpdateSubscribers) {
|
|
351
|
+
delete commentAutoUpdateSubscribers[commentCid];
|
|
352
|
+
}
|
|
353
|
+
for (const commentCid in stopCommentAfterNextUpdate) {
|
|
354
|
+
delete stopCommentAfterNextUpdate[commentCid];
|
|
355
|
+
}
|
|
356
|
+
for (const commentCid in liveCommentPromises) {
|
|
357
|
+
delete liveCommentPromises[commentCid];
|
|
358
|
+
}
|
|
359
|
+
for (const commentCid in liveComments) {
|
|
360
|
+
delete liveComments[commentCid];
|
|
361
|
+
}
|
|
362
|
+
// remove all event listeners
|
|
363
|
+
yield Promise.all(listeners.map((listener) => __awaiter(void 0, void 0, void 0, function* () {
|
|
364
|
+
var _a;
|
|
365
|
+
try {
|
|
366
|
+
if (typeof (listener === null || listener === void 0 ? void 0 : listener.stop) === "function") {
|
|
367
|
+
yield listener.stop();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
catch (_b) { }
|
|
371
|
+
(_a = listener === null || listener === void 0 ? void 0 : listener.removeAllListeners) === null || _a === void 0 ? void 0 : _a.call(listener);
|
|
372
|
+
})));
|
|
373
|
+
listeners.length = 0;
|
|
374
|
+
// destroy all component subscriptions to the store
|
|
375
|
+
commentsStore.destroy();
|
|
376
|
+
// restore original state
|
|
377
|
+
commentsStore.setState(originalState);
|
|
378
|
+
});
|
|
379
|
+
// reset database and store in between tests
|
|
380
|
+
export const resetCommentsDatabaseAndStore = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
381
|
+
yield localForageLru.createInstance({ name: "bitsocialReactHooks-comments" }).clear();
|
|
382
|
+
yield resetCommentsStore();
|
|
383
|
+
});
|
|
384
|
+
export default commentsStore;
|
|
385
|
+
//# sourceMappingURL=comments-store.js.map
|
|
@@ -0,0 +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,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAU,CAAC;AAClD,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAU,CAAC;AAE/C,6CAA6C;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAQ,EAAE,CAAC;AAWjC,MAAM,qBAAqB,GAAG,CAAC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AAC;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 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 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 await commentsDatabase.setItem(commentCid, normalizedComment);\n log(\"commentsStore comment update\", { commentCid, updatedComment: normalizedComment });\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 return normalizedComment;\n };\n\n const stopLiveComment = async (commentCid: string, comment?: Comment) => {\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 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 (updatingState === \"succeeded\" || updatingState === \"failed\") {\n maybeStopCommentAfterOneShotUpdate(commentCid, comment);\n }\n });\n\n comment?.on?.(\"error\", (error: Error) => {\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 =\n normalizeCommentCommunityAddress(utils.clone(commentData || { cid: commentCid })) ||\n ({ cid: commentCid } as Comment);\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 comment\n ?.update?.()\n .catch((error: unknown) => log.trace(\"comment.update error\", { commentCid, comment, error }));\n };\n\n const waitForCommentUpdateCycle = (commentCid: string, comment: Comment) =>\n new Promise<Comment>((resolve, reject) => {\n const onUpdatingStateChange = (updatingState: string) => {\n if (updatingState === \"succeeded\") {\n cleanup();\n resolve(normalizeCommentCommunityAddress(utils.clone(comment)) as Comment);\n return;\n }\n if (updatingState === \"failed\") {\n cleanup();\n reject(getState().errors[commentCid]?.slice(-1)[0] || Error(\"comment update failed\"));\n }\n };\n\n const onError = (error: Error) => {\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\n return {\n comments: {},\n errors: {},\n\n async addCommentToStore(commentCid: string, account: Account) {\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);\n\n if (!comment) {\n comment = await ensureLiveComment(commentCid, account, { cid: commentCid });\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(commentCid, account, comment);\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(commentCid: string, subscriberId: string, account: Account) {\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 storedComment || ({ cid: commentCid } as Comment),\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) {\n const storedComment = getState().comments[commentCid];\n const liveComment = await ensureLiveComment(\n commentCid,\n account,\n storedComment || ({ cid: commentCid } as Comment),\n );\n\n if (\n !hasCommentAutoUpdateSubscribers(commentCid) &&\n liveComment?.updatingState !== \"stopped\"\n ) {\n await stopLiveComment(commentCid, liveComment);\n }\n\n const waitForUpdate = waitForCommentUpdateCycle(commentCid, liveComment);\n requestCommentUpdate(commentCid, liveComment, {\n stopAfterNextUpdate: !hasCommentAutoUpdateSubscribers(commentCid),\n });\n return waitForUpdate;\n },\n };\n});\n\nconst getCommentFromDatabase = async (commentCid: string, account: Account) => {\n const commentData: any = await commentsDatabase.getItem(commentCid);\n if (!commentData) {\n return;\n }\n try {\n const comment = normalizeCommentCommunityAddress(await account.pkc.createComment(commentData));\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 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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stores/comments/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stores/comments/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,eAAe,aAAa,CAAC","sourcesContent":["import commentsStore from \"./comments-store\";\nexport * from \"./comments-store\";\nexport default commentsStore;\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Communities } from "../../types.js";
|
|
2
|
+
export type CommunitiesState = {
|
|
3
|
+
communities: Communities;
|
|
4
|
+
errors: {
|
|
5
|
+
[communityAddress: string]: Error[];
|
|
6
|
+
};
|
|
7
|
+
addCommunityToStore: Function;
|
|
8
|
+
refreshCommunity: Function;
|
|
9
|
+
editCommunity: Function;
|
|
10
|
+
createCommunity: Function;
|
|
11
|
+
deleteCommunity: Function;
|
|
12
|
+
};
|
|
13
|
+
declare const communitiesStore: import("zustand").UseBoundStore<import("zustand").StoreApi<CommunitiesState>>;
|
|
14
|
+
export declare const resetCommunitiesStore: () => Promise<void>;
|
|
15
|
+
export declare const resetCommunitiesDatabaseAndStore: () => Promise<void>;
|
|
16
|
+
export default communitiesStore;
|
|
17
|
+
//# sourceMappingURL=communities-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"communities-store.d.ts","sourceRoot":"","sources":["../../../src/stores/communities/communities-store.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,WAAW,EAIZ,MAAM,aAAa,CAAC;AAgCrB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE;QAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;KAAE,CAAC;IAChD,mBAAmB,EAAE,QAAQ,CAAC;IAC9B,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,aAAa,EAAE,QAAQ,CAAC;IACxB,eAAe,EAAE,QAAQ,CAAC;IAC1B,eAAe,EAAE,QAAQ,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,gBAAgB,+EAkVrB,CAAC;AAKF,eAAO,MAAM,qBAAqB,qBAQjC,CAAC;AAGF,eAAO,MAAM,gCAAgC,qBAG5C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|