@bitsocial/bitsocial-react-hooks 0.1.29 → 0.1.31
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 +14 -0
- package/README.md +18 -1
- package/dist/hooks/comments.d.ts.map +1 -1
- package/dist/hooks/comments.js +5 -1
- package/dist/hooks/comments.js.map +1 -1
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +2 -1
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/replies.d.ts.map +1 -1
- package/dist/hooks/replies.js +6 -3
- package/dist/hooks/replies.js.map +1 -1
- package/dist/lib/utils/optimistic-vote-counts.d.ts +11 -0
- package/dist/lib/utils/optimistic-vote-counts.d.ts.map +1 -0
- package/dist/lib/utils/optimistic-vote-counts.js +70 -0
- package/dist/lib/utils/optimistic-vote-counts.js.map +1 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +9 -2
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/utils.d.ts +2 -0
- package/dist/stores/accounts/utils.d.ts.map +1 -1
- package/dist/stores/accounts/utils.js +15 -0
- package/dist/stores/accounts/utils.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts +9 -1
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +36 -3
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +23 -12
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export const optimisticVoteBaseKey = "_optimisticVoteBase";
|
|
2
|
+
export const optimisticVoteObservedAtKey = "_optimisticVoteObservedAt";
|
|
3
|
+
export const optimisticVoteTransitionsKey = "_optimisticVoteTransitions";
|
|
4
|
+
const normalizeVote = (vote) => (vote === 1 || vote === -1 ? vote : 0);
|
|
5
|
+
export const getCommentVoteCountsVersion = (comment) => { var _a, _b; return Math.max((_a = comment === null || comment === void 0 ? void 0 : comment.updatedAt) !== null && _a !== void 0 ? _a : 0, (_b = comment === null || comment === void 0 ? void 0 : comment.timestamp) !== null && _b !== void 0 ? _b : 0, 0); };
|
|
6
|
+
export const addOptimisticVoteMetadata = (accountVote, previousAccountVote, comment) => {
|
|
7
|
+
const currentVersion = getCommentVoteCountsVersion(comment);
|
|
8
|
+
// Keep the full local transition chain so cached comment copies at different
|
|
9
|
+
// versions can each determine which account vote their counts already include.
|
|
10
|
+
const previousTransitions = Array.isArray(previousAccountVote === null || previousAccountVote === void 0 ? void 0 : previousAccountVote[optimisticVoteTransitionsKey])
|
|
11
|
+
? previousAccountVote[optimisticVoteTransitionsKey]
|
|
12
|
+
: [];
|
|
13
|
+
const hasPreviousTransitionHistory = previousTransitions.length > 0 &&
|
|
14
|
+
typeof (previousAccountVote === null || previousAccountVote === void 0 ? void 0 : previousAccountVote[optimisticVoteObservedAtKey]) === "number";
|
|
15
|
+
const recoveredPreviousTransitions = !hasPreviousTransitionHistory &&
|
|
16
|
+
previousAccountVote &&
|
|
17
|
+
typeof previousAccountVote.timestamp === "number"
|
|
18
|
+
? [
|
|
19
|
+
{
|
|
20
|
+
vote: normalizeVote(previousAccountVote.vote),
|
|
21
|
+
timestamp: previousAccountVote.timestamp,
|
|
22
|
+
},
|
|
23
|
+
]
|
|
24
|
+
: [];
|
|
25
|
+
const transitions = hasPreviousTransitionHistory
|
|
26
|
+
? previousTransitions
|
|
27
|
+
: recoveredPreviousTransitions;
|
|
28
|
+
const observedAt = hasPreviousTransitionHistory
|
|
29
|
+
? previousAccountVote[optimisticVoteObservedAtKey]
|
|
30
|
+
: currentVersion || Math.max((accountVote.timestamp || 1) - 1, 0);
|
|
31
|
+
const baseVote = hasPreviousTransitionHistory
|
|
32
|
+
? normalizeVote(previousAccountVote === null || previousAccountVote === void 0 ? void 0 : previousAccountVote[optimisticVoteBaseKey])
|
|
33
|
+
: recoveredPreviousTransitions.length > 0
|
|
34
|
+
? 0
|
|
35
|
+
: normalizeVote(previousAccountVote === null || previousAccountVote === void 0 ? void 0 : previousAccountVote.vote);
|
|
36
|
+
const lastTransition = transitions[transitions.length - 1];
|
|
37
|
+
const transition = {
|
|
38
|
+
vote: normalizeVote(accountVote.vote),
|
|
39
|
+
// A displayed comment can only include this vote after both the vote was
|
|
40
|
+
// published and every comment copy used to establish the initial baseline.
|
|
41
|
+
timestamp: Math.max(accountVote.timestamp || 0, observedAt + 1, lastTransition ? lastTransition.timestamp + 1 : 0),
|
|
42
|
+
};
|
|
43
|
+
return Object.assign(Object.assign({}, accountVote), { [optimisticVoteBaseKey]: baseVote, [optimisticVoteObservedAtKey]: observedAt, [optimisticVoteTransitionsKey]: [...transitions, transition] });
|
|
44
|
+
};
|
|
45
|
+
export const addOptimisticVoteCounts = (comment, accountVote) => {
|
|
46
|
+
if (!comment ||
|
|
47
|
+
!accountVote ||
|
|
48
|
+
typeof accountVote[optimisticVoteObservedAtKey] !== "number" ||
|
|
49
|
+
!Array.isArray(accountVote[optimisticVoteTransitionsKey]) ||
|
|
50
|
+
typeof comment.upvoteCount !== "number" ||
|
|
51
|
+
typeof comment.downvoteCount !== "number") {
|
|
52
|
+
return comment;
|
|
53
|
+
}
|
|
54
|
+
const commentVersion = getCommentVoteCountsVersion(comment);
|
|
55
|
+
let baseVote = normalizeVote(accountVote[optimisticVoteBaseKey]);
|
|
56
|
+
// Each transition timestamp already includes the initial baseline, so every
|
|
57
|
+
// displayed copy can reconcile directly against its own canonical version.
|
|
58
|
+
for (const transition of accountVote[optimisticVoteTransitionsKey]) {
|
|
59
|
+
if (typeof (transition === null || transition === void 0 ? void 0 : transition.timestamp) === "number" && transition.timestamp <= commentVersion) {
|
|
60
|
+
baseVote = normalizeVote(transition.vote);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const vote = normalizeVote(accountVote.vote);
|
|
64
|
+
if (baseVote === vote) {
|
|
65
|
+
return comment;
|
|
66
|
+
}
|
|
67
|
+
return Object.assign(Object.assign({}, comment), { upvoteCount: Math.max(0, comment.upvoteCount + Number(vote === 1) - Number(baseVote === 1)), downvoteCount: Math.max(0, comment.downvoteCount + Number(vote === -1) - Number(baseVote === -1)) });
|
|
68
|
+
};
|
|
69
|
+
export const addOptimisticVoteCountsToComments = (comments, accountVotes) => (comments || []).map((comment) => addOptimisticVoteCounts(comment, (comment === null || comment === void 0 ? void 0 : comment.cid) ? accountVotes === null || accountVotes === void 0 ? void 0 : accountVotes[comment.cid] : undefined));
|
|
70
|
+
//# sourceMappingURL=optimistic-vote-counts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimistic-vote-counts.js","sourceRoot":"","sources":["../../../src/lib/utils/optimistic-vote-counts.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAC3D,MAAM,CAAC,MAAM,2BAA2B,GAAG,2BAA2B,CAAC;AACvE,MAAM,CAAC,MAAM,4BAA4B,GAAG,4BAA4B,CAAC;AAEzE,MAAM,aAAa,GAAG,CAAC,IAAa,EAAc,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAO5F,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,OAA4B,EAAU,EAAE,eAClF,OAAA,IAAI,CAAC,GAAG,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,CAAC,EAAE,CAAC,CAAC,CAAA,EAAA,CAAC;AAEhE,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,WAAwB,EACxB,mBAA4C,EAC5C,OAA4B,EACf,EAAE;IACf,MAAM,cAAc,GAAG,2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AE,CAAC;QACnE,IAAI,OAAO,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,CAAA,KAAK,QAAQ,IAAI,UAAU,CAAC,SAAS,IAAI,cAAc,EAAE,CAAC;YACxF,QAAQ,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,uCACK,OAAO,KACV,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,EAC3F,aAAa,EAAE,IAAI,CAAC,GAAG,CACrB,CAAC,EACD,OAAO,CAAC,aAAa,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CACtE,IACD;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,QAAyB,EACzB,YAA+D,EAC1D,EAAE,CACP,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAC/B,uBAAuB,CAAC,OAAO,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,EAAC,CAAC,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAClF,CAAC","sourcesContent":["import { AccountVote, Comment } from \"../../types\";\n\nexport const optimisticVoteBaseKey = \"_optimisticVoteBase\";\nexport const optimisticVoteObservedAtKey = \"_optimisticVoteObservedAt\";\nexport const optimisticVoteTransitionsKey = \"_optimisticVoteTransitions\";\n\nconst normalizeVote = (vote: unknown): -1 | 0 | 1 => (vote === 1 || vote === -1 ? vote : 0);\n\ntype OptimisticVoteTransition = {\n vote: -1 | 0 | 1;\n timestamp: number;\n};\n\nexport const getCommentVoteCountsVersion = (comment: Comment | undefined): number =>\n Math.max(comment?.updatedAt ?? 0, comment?.timestamp ?? 0, 0);\n\nexport const addOptimisticVoteMetadata = (\n accountVote: AccountVote,\n previousAccountVote: AccountVote | undefined,\n comment: Comment | undefined,\n): AccountVote => {\n const currentVersion = getCommentVoteCountsVersion(comment);\n // Keep the full local transition chain so cached comment copies at different\n // versions can each determine which account vote their counts already include.\n const previousTransitions: OptimisticVoteTransition[] = Array.isArray(\n previousAccountVote?.[optimisticVoteTransitionsKey],\n )\n ? previousAccountVote[optimisticVoteTransitionsKey]\n : [];\n const hasPreviousTransitionHistory =\n previousTransitions.length > 0 &&\n typeof previousAccountVote?.[optimisticVoteObservedAtKey] === \"number\";\n const recoveredPreviousTransitions: OptimisticVoteTransition[] =\n !hasPreviousTransitionHistory &&\n previousAccountVote &&\n typeof previousAccountVote.timestamp === \"number\"\n ? [\n {\n vote: normalizeVote(previousAccountVote.vote),\n timestamp: previousAccountVote.timestamp,\n },\n ]\n : [];\n const transitions = hasPreviousTransitionHistory\n ? previousTransitions\n : recoveredPreviousTransitions;\n const observedAt = hasPreviousTransitionHistory\n ? previousAccountVote[optimisticVoteObservedAtKey]\n : currentVersion || Math.max((accountVote.timestamp || 1) - 1, 0);\n const baseVote = hasPreviousTransitionHistory\n ? normalizeVote(previousAccountVote?.[optimisticVoteBaseKey])\n : recoveredPreviousTransitions.length > 0\n ? 0\n : normalizeVote(previousAccountVote?.vote);\n const lastTransition = transitions[transitions.length - 1];\n const transition: OptimisticVoteTransition = {\n vote: normalizeVote(accountVote.vote),\n // A displayed comment can only include this vote after both the vote was\n // published and every comment copy used to establish the initial baseline.\n timestamp: Math.max(\n accountVote.timestamp || 0,\n observedAt + 1,\n lastTransition ? lastTransition.timestamp + 1 : 0,\n ),\n };\n\n return {\n ...accountVote,\n [optimisticVoteBaseKey]: baseVote,\n [optimisticVoteObservedAtKey]: observedAt,\n [optimisticVoteTransitionsKey]: [...transitions, transition],\n };\n};\n\nexport const addOptimisticVoteCounts = (\n comment: Comment | undefined,\n accountVote: AccountVote | undefined,\n): Comment | undefined => {\n if (\n !comment ||\n !accountVote ||\n typeof accountVote[optimisticVoteObservedAtKey] !== \"number\" ||\n !Array.isArray(accountVote[optimisticVoteTransitionsKey]) ||\n typeof comment.upvoteCount !== \"number\" ||\n typeof comment.downvoteCount !== \"number\"\n ) {\n return comment;\n }\n\n const commentVersion = getCommentVoteCountsVersion(comment);\n let baseVote = normalizeVote(accountVote[optimisticVoteBaseKey]);\n // Each transition timestamp already includes the initial baseline, so every\n // displayed copy can reconcile directly against its own canonical version.\n for (const transition of accountVote[optimisticVoteTransitionsKey]) {\n if (typeof transition?.timestamp === \"number\" && transition.timestamp <= commentVersion) {\n baseVote = normalizeVote(transition.vote);\n }\n }\n const vote = normalizeVote(accountVote.vote);\n if (baseVote === vote) {\n return comment;\n }\n\n return {\n ...comment,\n upvoteCount: Math.max(0, comment.upvoteCount + Number(vote === 1) - Number(baseVote === 1)),\n downvoteCount: Math.max(\n 0,\n comment.downvoteCount + Number(vote === -1) - Number(baseVote === -1),\n ),\n };\n};\n\nexport const addOptimisticVoteCountsToComments = <T extends Comment | undefined>(\n comments: T[] | undefined,\n accountVotes: { [commentCid: string]: AccountVote } | undefined,\n): T[] =>\n (comments || []).map((comment) =>\n addOptimisticVoteCounts(comment, comment?.cid ? accountVotes?.[comment.cid] : undefined),\n ) as T[];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts-actions.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/accounts-actions.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,OAAO,EAEP,qBAAqB,EAGrB,kBAAkB,EA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AAM,EAAE,cAAc,MAAM,kBA6B/D,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,KAAK,MAAM,EAAE,cAAc,MAAM,kBA6BjE,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,uBAAuB,qBAAqB,EAC5C,cAAc,MAAM,iBA0XrB,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,iCAAiC,MAAM,GAAG,MAAM,EAChD,cAAc,MAAM,kBA2DrB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,oBAAoB,kBAAkB,EAAE,cAAc,MAAM,kBA6F7F,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,2BAA2B,yBAAyB,EACpD,cAAc,MAAM,kBAuIrB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,iCAAiC,+BAA+B,EAChE,cAAc,MAAM,kBAoJrB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,kBAAkB,MAAM,EACxB,6BAA6B,2BAA2B,EACxD,cAAc,MAAM,kBA6JrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,wBAAwB,sBAAsB,EAC9C,cAAc,MAAM,iBAkBrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,kBAAkB,MAAM,EAAE,cAAc,MAAM,kBAcnF,CAAC"}
|
|
@@ -30,10 +30,11 @@ import assert from "assert";
|
|
|
30
30
|
const log = Logger("bitsocial-react-hooks:accounts:stores");
|
|
31
31
|
import * as accountsActionsInternal from "./accounts-actions-internal.js";
|
|
32
32
|
import { backfillPublicationCommunityAddress, createPkcCommunity, createPkcCommunityEdit, getPkcCommunityAddresses, normalizeCommunityEditOptionsForPkc, normalizePublicationOptionsForStore, normalizePublicationOptionsForPkc, withPublishChallengeAnswersCompat, } from "../../lib/pkc-compat.js";
|
|
33
|
-
import { getAccountCommentsIndex, getAccountCommunities, getCommentCidsToAccountsComments, COMMENT_MODERATION_AUTHOR_SUMMARY_KEY, getAccountEditPropertySummary, fetchCommentLinkDimensions, getAccountCommentDepth, addShortAddressesToAccountComment, sanitizeAccountCommentForState, sanitizeStoredAccountComment, } from "./utils.js";
|
|
33
|
+
import { getAccountCommentsIndex, getAccountCommunities, getCommentCidsToAccountsComments, COMMENT_MODERATION_AUTHOR_SUMMARY_KEY, getAccountEditPropertySummary, fetchCommentLinkDimensions, getAccountCommentDepth, addShortAddressesToAccountComment, sanitizeAccountCommentForState, sanitizeStoredAccountComment, getFreshestLoadedComment, } from "./utils.js";
|
|
34
34
|
import isEqual from "lodash.isequal";
|
|
35
35
|
import { v4 as uuid } from "uuid";
|
|
36
36
|
import utils from "../../lib/utils/index.js";
|
|
37
|
+
import { addOptimisticVoteMetadata } from "../../lib/utils/optimistic-vote-counts.js";
|
|
37
38
|
// Active publish-session tracking for pending comments (Task 3)
|
|
38
39
|
const activePublishSessions = new Map();
|
|
39
40
|
const abandonedPublishSessionIds = new Set();
|
|
@@ -1032,6 +1033,7 @@ export const deleteComment = (commentCidOrAccountCommentIndex, accountName) => _
|
|
|
1032
1033
|
log("accountsActions.deleteComment", { accountId: account.id, accountCommentIndex });
|
|
1033
1034
|
});
|
|
1034
1035
|
export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1036
|
+
var _a, _b;
|
|
1035
1037
|
const { accounts, accountNamesToAccountIds, activeAccountId } = accountsStore.getState();
|
|
1036
1038
|
assert(accounts && accountNamesToAccountIds && activeAccountId, `can't use accountsStore.accountActions before initialized`);
|
|
1037
1039
|
let account = accounts[activeAccountId];
|
|
@@ -1049,7 +1051,12 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1049
1051
|
delete createVoteOptions.onChallengeVerification;
|
|
1050
1052
|
delete createVoteOptions.onError;
|
|
1051
1053
|
delete createVoteOptions.onPublishingStateChange;
|
|
1052
|
-
const
|
|
1054
|
+
const accountsState = accountsStore.getState();
|
|
1055
|
+
const accountCommentInfo = accountsState.commentCidsToAccountsComments[createVoteOptions.commentCid];
|
|
1056
|
+
const accountComment = accountCommentInfo
|
|
1057
|
+
? (_a = accountsState.accountsComments[accountCommentInfo.accountId]) === null || _a === void 0 ? void 0 : _a[accountCommentInfo.accountCommentIndex]
|
|
1058
|
+
: undefined;
|
|
1059
|
+
const storedCreateVoteOptions = addOptimisticVoteMetadata(normalizePublicationOptionsForStore(createVoteOptions), (_b = accountsState.accountsVotes[account.id]) === null || _b === void 0 ? void 0 : _b[createVoteOptions.commentCid], getFreshestLoadedComment(createVoteOptions.commentCid, accountComment));
|
|
1053
1060
|
let vote = backfillPublicationCommunityAddress(yield account.pkc.createVote(createVoteOptions), createVoteOptions);
|
|
1054
1061
|
let lastChallenge;
|
|
1055
1062
|
const publishAndRetryFailedChallengeVerification = () => __awaiter(void 0, void 0, void 0, function* () {
|