@bitsocial/bitsocial-react-hooks 0.1.38 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +13 -1
- package/dist/hooks/feeds/feeds.d.ts +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +25 -38
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/hooks/replies.d.ts.map +1 -1
- package/dist/hooks/replies.js +0 -1
- package/dist/hooks/replies.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/page-sorts.d.ts +8 -0
- package/dist/lib/page-sorts.d.ts.map +1 -0
- package/dist/lib/page-sorts.js +37 -0
- package/dist/lib/page-sorts.js.map +1 -0
- package/dist/lib/serialize-feed-key.d.ts +2 -0
- package/dist/lib/serialize-feed-key.d.ts.map +1 -0
- package/dist/lib/serialize-feed-key.js +5 -0
- package/dist/lib/serialize-feed-key.js.map +1 -0
- package/dist/lib/validator.d.ts.map +1 -1
- package/dist/lib/validator.js +5 -37
- package/dist/lib/validator.js.map +1 -1
- package/dist/lib/wordfilters.d.ts +6 -0
- package/dist/lib/wordfilters.d.ts.map +1 -0
- package/dist/lib/wordfilters.js +131 -0
- package/dist/lib/wordfilters.js.map +1 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +86 -4
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts +1 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +1 -1
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.d.ts +2 -2
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
- package/dist/stores/communities-pages/communities-pages-store.js +11 -6
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
- package/dist/stores/feeds/feed-sorter.d.ts +1 -1
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
- package/dist/stores/feeds/feed-sorter.js +28 -22
- package/dist/stores/feeds/feed-sorter.js.map +1 -1
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
- package/dist/stores/feeds/feeds-store.js +2 -6
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/stores/feeds/utils.d.ts.map +1 -1
- package/dist/stores/feeds/utils.js +10 -22
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/stores/replies/replies-store.d.ts.map +1 -1
- package/dist/stores/replies/replies-store.js +22 -5
- package/dist/stores/replies/replies-store.js.map +1 -1
- package/dist/stores/replies/utils.d.ts +1 -1
- package/dist/stores/replies/utils.d.ts.map +1 -1
- package/dist/stores/replies/utils.js +16 -89
- package/dist/stores/replies/utils.js.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.d.ts +2 -2
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
- package/dist/stores/replies-pages/replies-pages-store.js +15 -5
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
- package/dist/types.d.ts +23 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
|
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
import accountsStore, { listeners } from "./accounts-store.js";
|
|
23
|
-
import communitiesStore from "../communities/index.js";
|
|
23
|
+
import communitiesStore, { isRetriableCommunityLoadError } from "../communities/index.js";
|
|
24
24
|
import accountsDatabase from "./accounts-database.js";
|
|
25
25
|
import accountGenerator from "./account-generator.js";
|
|
26
26
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
@@ -35,6 +35,74 @@ import isEqual from "lodash.isequal";
|
|
|
35
35
|
import { v4 as uuid } from "uuid";
|
|
36
36
|
import utils from "../../lib/utils/index.js";
|
|
37
37
|
import { addOptimisticVoteMetadata } from "../../lib/utils/optimistic-vote-counts.js";
|
|
38
|
+
import { applyCommunityWordfilters } from "../../lib/wordfilters.js";
|
|
39
|
+
const PUBLICATION_COMMUNITY_LOAD_TIMEOUT_MS = 30000;
|
|
40
|
+
const communityHasPublicationConfig = (community) => community &&
|
|
41
|
+
(typeof community.updatedAt === "number" ||
|
|
42
|
+
Object.prototype.hasOwnProperty.call(community, "challenges"));
|
|
43
|
+
const findLoadedPublicationCommunity = (communityAddress) => {
|
|
44
|
+
const communities = communitiesStore.getState().communities;
|
|
45
|
+
return Object.values(communities).find((community) => communityHasPublicationConfig(community) &&
|
|
46
|
+
[community.address, community.name, community.publicKey].includes(communityAddress));
|
|
47
|
+
};
|
|
48
|
+
const loadPublicationCommunity = (communityAddress, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
var _a;
|
|
50
|
+
const loadedCommunity = findLoadedPublicationCommunity(communityAddress);
|
|
51
|
+
if (loadedCommunity)
|
|
52
|
+
return loadedCommunity;
|
|
53
|
+
const community = yield createPkcCommunity(account.pkc, { address: communityAddress });
|
|
54
|
+
try {
|
|
55
|
+
if (communityHasPublicationConfig(community))
|
|
56
|
+
return community;
|
|
57
|
+
return yield new Promise((resolve, reject) => {
|
|
58
|
+
let settled = false;
|
|
59
|
+
let timeout;
|
|
60
|
+
const cleanup = () => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
clearTimeout(timeout);
|
|
63
|
+
(_a = community.removeListener) === null || _a === void 0 ? void 0 : _a.call(community, "update", onUpdate);
|
|
64
|
+
(_b = community.removeListener) === null || _b === void 0 ? void 0 : _b.call(community, "error", onError);
|
|
65
|
+
};
|
|
66
|
+
const onUpdate = (updatedCommunity) => {
|
|
67
|
+
if (settled)
|
|
68
|
+
return;
|
|
69
|
+
settled = true;
|
|
70
|
+
cleanup();
|
|
71
|
+
resolve(updatedCommunity || community);
|
|
72
|
+
};
|
|
73
|
+
const onError = (error) => {
|
|
74
|
+
if (settled)
|
|
75
|
+
return;
|
|
76
|
+
// pkc-js emits an error on every failed fetch attempt while it keeps retrying;
|
|
77
|
+
// keep waiting for a later update and only fail on non-retriable errors or the timeout
|
|
78
|
+
if (isRetriableCommunityLoadError(error))
|
|
79
|
+
return;
|
|
80
|
+
settled = true;
|
|
81
|
+
cleanup();
|
|
82
|
+
reject(error);
|
|
83
|
+
};
|
|
84
|
+
timeout = setTimeout(() => onError(new Error(`timed out loading challenge settings for community '${communityAddress}'`)), PUBLICATION_COMMUNITY_LOAD_TIMEOUT_MS);
|
|
85
|
+
community.once("update", onUpdate);
|
|
86
|
+
community.on("error", onError);
|
|
87
|
+
void Promise.resolve()
|
|
88
|
+
.then(() => community.update())
|
|
89
|
+
.then(() => {
|
|
90
|
+
if (communityHasPublicationConfig(community))
|
|
91
|
+
onUpdate(community);
|
|
92
|
+
}, onError);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
yield ((_a = community.stop) === null || _a === void 0 ? void 0 : _a.call(community));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
const applyPublicationWordfilters = (publicationType, options, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
const communityAddress = options.communityAddress;
|
|
101
|
+
if (typeof communityAddress !== "string" || !communityAddress)
|
|
102
|
+
return options;
|
|
103
|
+
const community = yield loadPublicationCommunity(communityAddress, account);
|
|
104
|
+
return applyCommunityWordfilters(publicationType, options, community === null || community === void 0 ? void 0 : community.challenges);
|
|
105
|
+
});
|
|
38
106
|
// Active publish-session tracking for pending comments (Task 3)
|
|
39
107
|
const activePublishSessions = new Map();
|
|
40
108
|
const abandonedPublishSessionIds = new Set();
|
|
@@ -745,6 +813,7 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
745
813
|
delete createCommentOptions.onPendingComment;
|
|
746
814
|
delete createCommentOptions.onPublishingStateChange;
|
|
747
815
|
delete createCommentOptions._onPendingCommentIndex;
|
|
816
|
+
createCommentOptions = yield applyPublicationWordfilters("comment", createCommentOptions, account);
|
|
748
817
|
const storedCreateCommentOptions = normalizePublicationOptionsForStore(createCommentOptions);
|
|
749
818
|
// make sure the options dont throw
|
|
750
819
|
yield account.pkc.createComment(createCommentOptions);
|
|
@@ -907,7 +976,12 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
907
976
|
var _a, _b;
|
|
908
977
|
applyChallengeVerificationCommentUpdateToPublication(challengeVerification, activeComment);
|
|
909
978
|
publishCommentOptions.onChallengeVerification(challengeVerification, activeComment);
|
|
910
|
-
|
|
979
|
+
// a verification with challengeErrors/reason is a terminal rejection of the publication
|
|
980
|
+
// (e.g. stale wordfilter rules); republishing the same signed content would loop forever,
|
|
981
|
+
// so fall through to the terminal path instead of retrying
|
|
982
|
+
if (!challengeVerification.challengeSuccess &&
|
|
983
|
+
lastChallenge &&
|
|
984
|
+
!hasTerminalChallengeVerificationError(challengeVerification)) {
|
|
911
985
|
// publish again automatically on fail
|
|
912
986
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
913
987
|
createCommentOptions = Object.assign(Object.assign({}, createCommentOptions), { timestamp });
|
|
@@ -1091,6 +1165,7 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1091
1165
|
delete createVoteOptions.onChallengeVerification;
|
|
1092
1166
|
delete createVoteOptions.onError;
|
|
1093
1167
|
delete createVoteOptions.onPublishingStateChange;
|
|
1168
|
+
createVoteOptions = yield applyPublicationWordfilters("vote", createVoteOptions, account);
|
|
1094
1169
|
const accountsState = accountsStore.getState();
|
|
1095
1170
|
const accountCommentInfo = accountsState.commentCidsToAccountsComments[createVoteOptions.commentCid];
|
|
1096
1171
|
const accountComment = accountCommentInfo
|
|
@@ -1107,7 +1182,10 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1107
1182
|
}));
|
|
1108
1183
|
vote.once("challengeverification", (challengeVerification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1109
1184
|
publishVoteOptions.onChallengeVerification(challengeVerification, vote);
|
|
1110
|
-
|
|
1185
|
+
// same terminal short-circuit as publishComment/publishCommentEdit: never retry a rejection
|
|
1186
|
+
if (!challengeVerification.challengeSuccess &&
|
|
1187
|
+
lastChallenge &&
|
|
1188
|
+
!hasTerminalChallengeVerificationError(challengeVerification)) {
|
|
1111
1189
|
// publish again automatically on fail
|
|
1112
1190
|
createVoteOptions = Object.assign(Object.assign({}, createVoteOptions), { timestamp: Math.floor(Date.now() / 1000) });
|
|
1113
1191
|
vote = backfillPublicationCommunityAddress(yield account.pkc.createVote(createVoteOptions), createVoteOptions);
|
|
@@ -1153,6 +1231,7 @@ export const publishCommentEdit = (publishCommentEditOptions, accountName) => __
|
|
|
1153
1231
|
delete createCommentEditOptions.onChallengeVerification;
|
|
1154
1232
|
delete createCommentEditOptions.onError;
|
|
1155
1233
|
delete createCommentEditOptions.onPublishingStateChange;
|
|
1234
|
+
createCommentEditOptions = yield applyPublicationWordfilters("commentEdit", createCommentEditOptions, account);
|
|
1156
1235
|
const storedCreateCommentEditOptions = Object.assign(Object.assign({}, normalizePublicationOptionsForStore(createCommentEditOptions)), { clientId: uuid() });
|
|
1157
1236
|
const storedCommentEdit = sanitizeStoredAccountEdit(storedCreateCommentEditOptions);
|
|
1158
1237
|
let commentEdit = backfillPublicationCommunityAddress(yield account.pkc.createCommentEdit(createCommentEditOptions), createCommentEditOptions);
|
|
@@ -1241,6 +1320,7 @@ export const publishCommentModeration = (publishCommentModerationOptions, accoun
|
|
|
1241
1320
|
delete createCommentModerationOptions.onChallengeVerification;
|
|
1242
1321
|
delete createCommentModerationOptions.onError;
|
|
1243
1322
|
delete createCommentModerationOptions.onPublishingStateChange;
|
|
1323
|
+
createCommentModerationOptions = yield applyPublicationWordfilters("commentModeration", createCommentModerationOptions, account);
|
|
1244
1324
|
const storedCreateCommentModerationOptions = Object.assign(Object.assign({}, normalizePublicationOptionsForStore(createCommentModerationOptions)), { clientId: uuid() });
|
|
1245
1325
|
const storedCommentModeration = sanitizeStoredAccountEdit(storedCreateCommentModerationOptions);
|
|
1246
1326
|
let commentModeration = backfillPublicationCommunityAddress(yield account.pkc.createCommentModeration(createCommentModerationOptions), createCommentModerationOptions);
|
|
@@ -1349,6 +1429,7 @@ export const publishCommunityEdit = (communityAddress, publishCommunityEditOptio
|
|
|
1349
1429
|
communityAddress,
|
|
1350
1430
|
communityEdit: communityEditOptions,
|
|
1351
1431
|
});
|
|
1432
|
+
createCommunityEditOptions = yield applyPublicationWordfilters("communityEdit", createCommunityEditOptions, account);
|
|
1352
1433
|
const storedCreateCommunityEditOptions = Object.assign(Object.assign({}, normalizePublicationOptionsForStore(createCommunityEditOptions)), { clientId: uuid() });
|
|
1353
1434
|
const storedCommunityEdit = sanitizeStoredAccountEdit(storedCreateCommunityEditOptions);
|
|
1354
1435
|
let challengeSucceeded = false;
|
|
@@ -1376,9 +1457,10 @@ export const publishCommunityEdit = (communityAddress, publishCommunityEditOptio
|
|
|
1376
1457
|
});
|
|
1377
1458
|
// account is the owner of the community and can edit it locally, no need to publish
|
|
1378
1459
|
if (accountOwnsCommunityLocally(account, communityAddress)) {
|
|
1460
|
+
// use the wordfiltered edit so the applied community state matches the stored account edit
|
|
1379
1461
|
yield communitiesStore
|
|
1380
1462
|
.getState()
|
|
1381
|
-
.editCommunity(communityAddress,
|
|
1463
|
+
.editCommunity(communityAddress, createCommunityEditOptions.communityEdit, account);
|
|
1382
1464
|
yield storePublishedCommunityEdit();
|
|
1383
1465
|
// create fake success challenge verification for consistent behavior with remote community edit
|
|
1384
1466
|
publishCommunityEditOptions.onChallengeVerification({ challengeSuccess: true });
|