@bitsocial/bitsocial-react-hooks 0.1.65 → 0.2.1
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 +23 -0
- package/README.md +1 -1
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +49 -11
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +34 -1
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +2 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.js +17 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -1
- package/dist/lib/validator.d.ts.map +1 -1
- package/dist/lib/validator.js +2 -0
- package/dist/lib/validator.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts +2 -2
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +127 -43
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts +4 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +241 -33
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/feeds/feeds-store.d.ts +2 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
- package/dist/stores/feeds/feeds-store.js +97 -2
- package/dist/stores/feeds/feeds-store.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -903,8 +903,25 @@ export const saveComment = (commentCid, accountName) => __awaiter(void 0, void 0
|
|
|
903
903
|
export const unsaveComment = (commentCid, accountName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
904
904
|
yield updateSavedComments(commentCid, accountName, false);
|
|
905
905
|
});
|
|
906
|
+
// callbacks passed with the comment publish options, never part of the published comment
|
|
907
|
+
const publishCommentCallbackNames = [
|
|
908
|
+
"onChallenge",
|
|
909
|
+
"onChallengeVerification",
|
|
910
|
+
"onError",
|
|
911
|
+
"onPendingComment",
|
|
912
|
+
"onPublishingStateChange",
|
|
913
|
+
"onBeforeRepublish",
|
|
914
|
+
"_onPendingCommentIndex",
|
|
915
|
+
];
|
|
916
|
+
const omitPublishCommentCallbacks = (options) => {
|
|
917
|
+
const publicationOptions = Object.assign({}, options);
|
|
918
|
+
for (const callbackName of publishCommentCallbackNames) {
|
|
919
|
+
delete publicationOptions[callbackName];
|
|
920
|
+
}
|
|
921
|
+
return publicationOptions;
|
|
922
|
+
};
|
|
906
923
|
export const publishComment = (publishCommentOptions, accountName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
907
|
-
var _a, _b
|
|
924
|
+
var _a, _b;
|
|
908
925
|
const { accounts, accountsComments, accountNamesToAccountIds, activeAccountId } = accountsStore.getState();
|
|
909
926
|
assert(accounts && accountNamesToAccountIds && activeAccountId, `can't use accountsStore.accountActions before initialized`);
|
|
910
927
|
let account = accounts[activeAccountId];
|
|
@@ -930,48 +947,61 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
930
947
|
if (previousComment) {
|
|
931
948
|
author.previousCommentCid = previousComment.cid;
|
|
932
949
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
if (
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
950
|
+
let previousCommentAuthorAddressPromise;
|
|
951
|
+
// builds the options pkc-js publishes from the client's options without callbacks, for the first
|
|
952
|
+
// publish and for each republish whose options onBeforeRepublish returned
|
|
953
|
+
const createPublishCommentOptions = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
954
|
+
var _a, _b, _c, _d, _e;
|
|
955
|
+
const publicationAuthor = Object.assign(Object.assign({}, author), options.author);
|
|
956
|
+
if (publicationAuthor.address !== ((_a = account.author) === null || _a === void 0 ? void 0 : _a.address) &&
|
|
957
|
+
((_b = options.author) === null || _b === void 0 ? void 0 : _b.previousCommentCid) === undefined) {
|
|
958
|
+
delete publicationAuthor.previousCommentCid;
|
|
959
|
+
}
|
|
960
|
+
// a comment without author.address may have been published under an alternate author passed to
|
|
961
|
+
// publishComment, so only link it once its immutable author, loaded from its cid, is the account's
|
|
962
|
+
if (previousComment &&
|
|
963
|
+
!((_c = previousComment.author) === null || _c === void 0 ? void 0 : _c.address) &&
|
|
964
|
+
((_d = options.author) === null || _d === void 0 ? void 0 : _d.previousCommentCid) === undefined &&
|
|
965
|
+
publicationAuthor.previousCommentCid === previousComment.cid) {
|
|
966
|
+
// loaded once, a republish reuses it
|
|
967
|
+
previousCommentAuthorAddressPromise !== null && previousCommentAuthorAddressPromise !== void 0 ? previousCommentAuthorAddressPromise : (previousCommentAuthorAddressPromise = loadCommentAuthorAddress(account, previousComment.cid));
|
|
968
|
+
const previousCommentAuthorAddress = yield previousCommentAuthorAddressPromise;
|
|
969
|
+
if (!previousCommentAuthorAddress ||
|
|
970
|
+
previousCommentAuthorAddress !== ((_e = account.author) === null || _e === void 0 ? void 0 : _e.address)) {
|
|
971
|
+
// fall back to the newest stored comment that kept the account author address
|
|
972
|
+
const previousAccountAuthorComment = accountCommentsWithCids
|
|
973
|
+
.filter((comment) => { var _a; return (_a = comment.author) === null || _a === void 0 ? void 0 : _a.address; })
|
|
974
|
+
.pop();
|
|
975
|
+
if (previousAccountAuthorComment) {
|
|
976
|
+
publicationAuthor.previousCommentCid = previousAccountAuthorComment.cid;
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
delete publicationAuthor.previousCommentCid;
|
|
980
|
+
}
|
|
955
981
|
}
|
|
956
982
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
983
|
+
const createCommentOptions = normalizePublicationOptionsForPkc(account.pkc, Object.assign(Object.assign({ timestamp: Math.floor(Date.now() / 1000), signer: account.signer }, options), { author: publicationAuthor }));
|
|
984
|
+
return applyPublicationWordfilters("comment", createCommentOptions, account);
|
|
985
|
+
});
|
|
986
|
+
const createAccountComment = (createCommentOptions, index) => addShortAddressesToAccountComment(sanitizeAccountCommentForState(Object.assign(Object.assign({}, normalizePublicationOptionsForStore(createCommentOptions)), {
|
|
987
|
+
// try to get comment depth needed for custom depth flat account replies
|
|
988
|
+
depth: getAccountCommentDepth(createCommentOptions), index, accountId: account.id })));
|
|
989
|
+
const commentLinkDimensionsPromises = new Map();
|
|
990
|
+
const getCommentLinkDimensions = (link) => {
|
|
991
|
+
if (!commentLinkDimensionsPromises.has(link)) {
|
|
992
|
+
commentLinkDimensionsPromises.set(link, fetchCommentLinkDimensions(link));
|
|
993
|
+
}
|
|
994
|
+
return commentLinkDimensionsPromises.get(link);
|
|
995
|
+
};
|
|
996
|
+
// the client's options, without callbacks, as last published: onBeforeRepublish receives them
|
|
997
|
+
let publicationOptions = omitPublishCommentCallbacks(publishCommentOptions);
|
|
998
|
+
let createCommentOptions = yield createPublishCommentOptions(publicationOptions);
|
|
967
999
|
// make sure the options dont throw
|
|
968
1000
|
yield account.pkc.createComment(createCommentOptions);
|
|
969
|
-
// try to get comment depth needed for custom depth flat account replies
|
|
970
|
-
const depth = getAccountCommentDepth(createCommentOptions);
|
|
971
1001
|
// set fetching link dimensions state
|
|
972
1002
|
let fetchingLinkDimensionsStates;
|
|
973
1003
|
if (publishCommentOptions.link) {
|
|
974
|
-
(
|
|
1004
|
+
(_a = publishCommentOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, "fetching-link-dimensions");
|
|
975
1005
|
fetchingLinkDimensionsStates = {
|
|
976
1006
|
state: "publishing",
|
|
977
1007
|
publishingState: "fetching-link-dimensions",
|
|
@@ -1015,8 +1045,7 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1015
1045
|
});
|
|
1016
1046
|
return persistedIndex;
|
|
1017
1047
|
});
|
|
1018
|
-
let createdAccountComment =
|
|
1019
|
-
createdAccountComment = addShortAddressesToAccountComment(sanitizeAccountCommentForState(createdAccountComment));
|
|
1048
|
+
let createdAccountComment = createAccountComment(createCommentOptions, accountCommentIndex);
|
|
1020
1049
|
const reportOnPendingCommentError = (error, pendingCommentIndex) => {
|
|
1021
1050
|
log.error("accountsActions.publishComment onPendingComment callback error", {
|
|
1022
1051
|
accountId: account.id,
|
|
@@ -1043,12 +1072,12 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1043
1072
|
if (pendingCommentIndex !== accountCommentIndex) {
|
|
1044
1073
|
notifyPendingComment(pendingCommentIndex, createdAccountComment);
|
|
1045
1074
|
}
|
|
1046
|
-
(
|
|
1075
|
+
(_b = publishCommentOptions._onPendingCommentIndex) === null || _b === void 0 ? void 0 : _b.call(publishCommentOptions, pendingCommentIndex, createdAccountComment);
|
|
1047
1076
|
let comment;
|
|
1048
1077
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1049
1078
|
// fetch comment.link dimensions
|
|
1050
1079
|
if (publishCommentOptions.link) {
|
|
1051
|
-
const commentLinkDimensions = yield
|
|
1080
|
+
const commentLinkDimensions = yield getCommentLinkDimensions(publishCommentOptions.link);
|
|
1052
1081
|
createCommentOptions = Object.assign(Object.assign({}, createCommentOptions), commentLinkDimensions);
|
|
1053
1082
|
// save dimensions to db
|
|
1054
1083
|
createdAccountComment = Object.assign(Object.assign({}, createdAccountComment), commentLinkDimensions);
|
|
@@ -1110,6 +1139,45 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1110
1139
|
queueCleanupFailedPublishSession(activeComment);
|
|
1111
1140
|
(_a = publishCommentOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, error, activeComment);
|
|
1112
1141
|
};
|
|
1142
|
+
// the options onBeforeRepublish returns go through the same pipeline as the first publish; resolves
|
|
1143
|
+
// to false when the publish was abandoned while onBeforeRepublish ran
|
|
1144
|
+
const createRepublishCommentOptions = (timestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1145
|
+
const nextOptions = yield publishCommentOptions.onBeforeRepublish(Object.assign(Object.assign({}, publicationOptions), { timestamp }));
|
|
1146
|
+
if (isPublishSessionAbandoned(publishSessionId)) {
|
|
1147
|
+
return false;
|
|
1148
|
+
}
|
|
1149
|
+
assert(nextOptions && typeof nextOptions === "object", "publishComment publishCommentOptions.onBeforeRepublish did not return an object");
|
|
1150
|
+
const nextPublicationOptions = omitPublishCommentCallbacks(nextOptions);
|
|
1151
|
+
validator.validateAccountsActionsPublishCommentArguments({
|
|
1152
|
+
publishCommentOptions: Object.assign(Object.assign({}, nextPublicationOptions), { onChallenge: publishCommentOptions.onChallenge, onChallengeVerification: publishCommentOptions.onChallengeVerification }),
|
|
1153
|
+
accountName,
|
|
1154
|
+
account,
|
|
1155
|
+
});
|
|
1156
|
+
let nextCreateCommentOptions = yield createPublishCommentOptions(nextPublicationOptions);
|
|
1157
|
+
if (nextPublicationOptions.link) {
|
|
1158
|
+
nextCreateCommentOptions = Object.assign(Object.assign({}, nextCreateCommentOptions), (yield getCommentLinkDimensions(nextPublicationOptions.link)));
|
|
1159
|
+
}
|
|
1160
|
+
// make sure the options dont throw
|
|
1161
|
+
yield account.pkc.createComment(nextCreateCommentOptions);
|
|
1162
|
+
publicationOptions = nextPublicationOptions;
|
|
1163
|
+
createCommentOptions = nextCreateCommentOptions;
|
|
1164
|
+
createdAccountComment = createAccountComment(createCommentOptions, createdAccountComment.index);
|
|
1165
|
+
return true;
|
|
1166
|
+
});
|
|
1167
|
+
// the failed comment was detached for the republish, so its stopped/failed state events were ignored:
|
|
1168
|
+
// reattach it to end the publish with that state and the error, like any other publish error
|
|
1169
|
+
const failRepublish = (error, failedComment) => {
|
|
1170
|
+
var _a;
|
|
1171
|
+
const session = getPublishSession(publishSessionId);
|
|
1172
|
+
if (!session || isPublishSessionAbandoned(publishSessionId))
|
|
1173
|
+
return;
|
|
1174
|
+
updatePublishSessionComment(publishSessionId, failedComment);
|
|
1175
|
+
accountsStore.setState(({ accountsComments }) => maybeUpdateAccountComment(accountsComments, account.id, session.currentIndex, (ac, acc) => {
|
|
1176
|
+
ac[session.currentIndex] = Object.assign(Object.assign({}, acc), { state: "stopped", publishingState: "failed" });
|
|
1177
|
+
}));
|
|
1178
|
+
(_a = publishCommentOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, "failed");
|
|
1179
|
+
reportActivePublishCommentError(error, failedComment);
|
|
1180
|
+
};
|
|
1113
1181
|
function publishAndRetryFailedChallengeVerification() {
|
|
1114
1182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1115
1183
|
if (isPublishSessionAbandoned(publishSessionId)) {
|
|
@@ -1131,11 +1199,27 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1131
1199
|
if (!challengeVerification.challengeSuccess &&
|
|
1132
1200
|
lastChallenge &&
|
|
1133
1201
|
!hasTerminalChallengeVerificationError(challengeVerification)) {
|
|
1134
|
-
// publish again automatically on fail
|
|
1202
|
+
// publish again automatically on fail, unless the publish was abandoned meanwhile
|
|
1203
|
+
if (isPublishSessionAbandoned(publishSessionId)) {
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1135
1206
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
1136
|
-
createCommentOptions = Object.assign(Object.assign({}, createCommentOptions), { timestamp });
|
|
1137
|
-
createdAccountComment = Object.assign(Object.assign({}, createdAccountComment), { timestamp });
|
|
1138
1207
|
updatePublishSessionComment(publishSessionId, undefined);
|
|
1208
|
+
if (publishCommentOptions.onBeforeRepublish) {
|
|
1209
|
+
try {
|
|
1210
|
+
if (!(yield createRepublishCommentOptions(timestamp))) {
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
catch (error) {
|
|
1215
|
+
failRepublish(error, activeComment);
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
else {
|
|
1220
|
+
createCommentOptions = Object.assign(Object.assign({}, createCommentOptions), { timestamp });
|
|
1221
|
+
createdAccountComment = Object.assign(Object.assign({}, createdAccountComment), { timestamp });
|
|
1222
|
+
}
|
|
1139
1223
|
yield saveCreatedAccountComment(createdAccountComment);
|
|
1140
1224
|
if (isPublishSessionAbandoned(publishSessionId)) {
|
|
1141
1225
|
return;
|