@bitsocial/bitsocial-react-hooks 0.1.39 → 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 +12 -0
- package/README.md +1 -1
- package/dist/lib/wordfilters.d.ts +1 -1
- package/dist/lib/wordfilters.d.ts.map +1 -1
- package/dist/lib/wordfilters.js +23 -5
- package/dist/lib/wordfilters.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +25 -9
- 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/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [0.1.40](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.39...v0.1.40) (2026-08-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** upgrade pkc-js to 0.1.0 ([cbd8c9e](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/cbd8c9e69047f7182208b2f9a42f341ef3222ed5))
|
|
7
|
+
* **stores:** ignore retriable community errors while loading wordfilter challenge config ([#99](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/99)) ([515e0db](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/515e0db72793569b71f7af868fafd5e640980340)), closes [#92](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/92)
|
|
8
|
+
* **stores:** stop publishComment/publishVote auto-retry on terminal challenge verification errors ([#100](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/100)) ([a17240a](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/a17240ae2a858c314ec6168a19bc6c69f776c250)), closes [#93](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/93)
|
|
9
|
+
* **stores:** support prefixed wordfilter/v1 field paths across all publication types ([#101](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/101)) ([fcfebed](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/fcfebed025a135a30992023461263fb9f34ee0e4)), closes [#98](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/98)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
1
13
|
## [0.1.39](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.1.38...v0.1.39) (2026-08-21)
|
|
2
14
|
|
|
3
15
|
|
package/README.md
CHANGED
|
@@ -190,7 +190,7 @@ useExportCommunity(options?: UseExportCommunityOptions): {
|
|
|
190
190
|
}
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
Before `publishComment` or `
|
|
193
|
+
Before `publishComment`, `publishCommentEdit`, `publishVote`, `publishCommentModeration`, or `publishCommunityEdit` signs a publication, hooks load the community challenge configuration and apply compatible wordfilters. The current `@bitsocial/wordfilter-challenge` contract uses a JSON array of `{src, dst}` objects in `wordfilter/v1/rules` and an optional JSON array of dot-notation paths in `wordfilter/v1/fieldNames`, both published through `publicOptions`. Every path starts with the publication type and is resolved against the publication being signed, so a path for another type is simply skipped. Without configured paths the defaults apply: `comment.content`, `comment.title`, `comment.author.displayName`, `commentEdit.content`, `commentEdit.reason`, `commentEdit.author.displayName`, and `vote.author.displayName`. Moderator and owner text is opt-in through configured paths (`commentModeration.commentModeration.reason`, `communityEdit.communityEdit.title`, `communityEdit.communityEdit.description`); structural and signing fields are never rewritten by community configuration. Matching is literal and case-insensitive, not regular-expression or Unicode-evasion matching. The transformed values are the values signed, published, and stored as the pending account publication. If composed rule sets do not stabilize within eight passes, publication stops before signing.
|
|
194
194
|
|
|
195
195
|
#### States Hooks
|
|
196
196
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type Challenge = {
|
|
2
2
|
publicOptions?: Record<string, unknown>;
|
|
3
3
|
};
|
|
4
|
-
export declare const applyCommunityWordfilters: <T extends Record<string, any>>(publication: T, challenges?: Challenge[]) => T;
|
|
4
|
+
export declare const applyCommunityWordfilters: <T extends Record<string, any>>(publicationType: string, publication: T, challenges?: Challenge[]) => T;
|
|
5
5
|
export {};
|
|
6
6
|
//# sourceMappingURL=wordfilters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wordfilters.d.ts","sourceRoot":"","sources":["../../src/lib/wordfilters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wordfilters.d.ts","sourceRoot":"","sources":["../../src/lib/wordfilters.ts"],"names":[],"mappings":"AAyBA,KAAK,SAAS,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAoF7D,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrE,iBAAiB,MAAM,EACvB,aAAa,CAAC,EACd,aAAa,SAAS,EAAE,KACvB,CA0BF,CAAC"}
|
package/dist/lib/wordfilters.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
const RULES_KEY = "wordfilter/v1/rules";
|
|
2
2
|
const FIELD_NAMES_KEY = "wordfilter/v1/fieldNames";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// every wordfilter/v1 path starts with the publication type and is resolved against
|
|
4
|
+
// {[publicationType]: publication}, so a path for another type is simply absent and skipped
|
|
5
|
+
const DEFAULT_FIELD_NAMES = [
|
|
6
|
+
"comment.content",
|
|
7
|
+
"comment.title",
|
|
8
|
+
"comment.author.displayName",
|
|
9
|
+
"commentEdit.content",
|
|
10
|
+
"commentEdit.reason",
|
|
11
|
+
"commentEdit.author.displayName",
|
|
12
|
+
"vote.author.displayName",
|
|
13
|
+
];
|
|
14
|
+
// user-authored text only: never let community configuration rewrite structural or
|
|
15
|
+
// signing fields (addresses, CIDs, signer material), whatever paths it publishes
|
|
16
|
+
const SUPPORTED_FIELD_NAMES = new Set([
|
|
17
|
+
...DEFAULT_FIELD_NAMES,
|
|
18
|
+
"commentModeration.commentModeration.reason",
|
|
19
|
+
"communityEdit.communityEdit.title",
|
|
20
|
+
"communityEdit.communityEdit.description",
|
|
21
|
+
]);
|
|
5
22
|
const MAX_PASSES = 8;
|
|
6
23
|
const unsafePathParts = new Set(["__proto__", "constructor", "prototype"]);
|
|
7
24
|
const parseStringArray = (value) => {
|
|
@@ -80,7 +97,7 @@ const setOwnPath = (value, path, replacement) => {
|
|
|
80
97
|
target[parts[parts.length - 1]] = replacement;
|
|
81
98
|
return output;
|
|
82
99
|
};
|
|
83
|
-
export const applyCommunityWordfilters = (publication, challenges) => {
|
|
100
|
+
export const applyCommunityWordfilters = (publicationType, publication, challenges) => {
|
|
84
101
|
var _a, _b;
|
|
85
102
|
const rulesByField = new Map();
|
|
86
103
|
for (const challenge of challenges || []) {
|
|
@@ -96,10 +113,11 @@ export const applyCommunityWordfilters = (publication, challenges) => {
|
|
|
96
113
|
for (const fieldName of fieldNames) {
|
|
97
114
|
if (!SUPPORTED_FIELD_NAMES.has(fieldName))
|
|
98
115
|
continue;
|
|
116
|
+
// merge every challenge's rules per field so one apply call sees their interactions
|
|
99
117
|
rulesByField.set(fieldName, [...(rulesByField.get(fieldName) || []), ...rules]);
|
|
100
118
|
}
|
|
101
119
|
}
|
|
102
|
-
let output = publication;
|
|
120
|
+
let output = { [publicationType]: publication };
|
|
103
121
|
for (const [fieldName, rules] of rulesByField) {
|
|
104
122
|
const value = getOwnStringAtPath(output, fieldName);
|
|
105
123
|
if (value === undefined)
|
|
@@ -108,6 +126,6 @@ export const applyCommunityWordfilters = (publication, challenges) => {
|
|
|
108
126
|
if (replacement !== value)
|
|
109
127
|
output = setOwnPath(output, fieldName, replacement);
|
|
110
128
|
}
|
|
111
|
-
return output;
|
|
129
|
+
return output[publicationType];
|
|
112
130
|
};
|
|
113
131
|
//# sourceMappingURL=wordfilters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wordfilters.js","sourceRoot":"","sources":["../../src/lib/wordfilters.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,qBAAqB,CAAC;AACxC,MAAM,eAAe,GAAG,0BAA0B,CAAC;AACnD,MAAM,mBAAmB,GAAG,
|
|
1
|
+
{"version":3,"file":"wordfilters.js","sourceRoot":"","sources":["../../src/lib/wordfilters.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,qBAAqB,CAAC;AACxC,MAAM,eAAe,GAAG,0BAA0B,CAAC;AACnD,oFAAoF;AACpF,4FAA4F;AAC5F,MAAM,mBAAmB,GAAG;IAC1B,iBAAiB;IACjB,eAAe;IACf,4BAA4B;IAC5B,qBAAqB;IACrB,oBAAoB;IACpB,gCAAgC;IAChC,yBAAyB;CAC1B,CAAC;AACF,mFAAmF;AACnF,iFAAiF;AACjF,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,GAAG,mBAAmB;IACtB,4CAA4C;IAC5C,mCAAmC;IACnC,yCAAyC;CAC1C,CAAC,CAAC;AACH,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAK3E,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAwB,EAAE;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO;IACtC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO;QAC/F,OAAO,MAAM,CAAC;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;YACpF,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;IAED,IAAI,MAAM,GAAwB,EAAE,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE,CAAC;IACrE,KAAK,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,YAAY,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QACpD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC7C,IAAI,WAAW,KAAK,KAAK;YAAE,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,MAAM,CAAC,eAAe,CAAM,CAAC;AACtC,CAAC,CAAC","sourcesContent":["const RULES_KEY = \"wordfilter/v1/rules\";\nconst FIELD_NAMES_KEY = \"wordfilter/v1/fieldNames\";\n// every wordfilter/v1 path starts with the publication type and is resolved against\n// {[publicationType]: publication}, so a path for another type is simply absent and skipped\nconst DEFAULT_FIELD_NAMES = [\n \"comment.content\",\n \"comment.title\",\n \"comment.author.displayName\",\n \"commentEdit.content\",\n \"commentEdit.reason\",\n \"commentEdit.author.displayName\",\n \"vote.author.displayName\",\n];\n// user-authored text only: never let community configuration rewrite structural or\n// signing fields (addresses, CIDs, signer material), whatever paths it publishes\nconst SUPPORTED_FIELD_NAMES = new Set([\n ...DEFAULT_FIELD_NAMES,\n \"commentModeration.commentModeration.reason\",\n \"communityEdit.communityEdit.title\",\n \"communityEdit.communityEdit.description\",\n]);\nconst MAX_PASSES = 8;\nconst unsafePathParts = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\ntype WordfilterRule = { src: string; dst: string };\ntype Challenge = { publicOptions?: Record<string, unknown> };\n\nconst parseStringArray = (value: unknown): string[] | undefined => {\n if (typeof value !== \"string\") return;\n try {\n const parsed = JSON.parse(value);\n if (!Array.isArray(parsed) || parsed.some((item) => typeof item !== \"string\" || !item)) return;\n return parsed;\n } catch {\n return;\n }\n};\n\nconst parseRules = (value: unknown): WordfilterRule[] | undefined => {\n if (typeof value !== \"string\") return;\n try {\n const parsed = JSON.parse(value);\n if (\n !Array.isArray(parsed) ||\n parsed.some(\n (rule) =>\n !rule ||\n typeof rule !== \"object\" ||\n Array.isArray(rule) ||\n typeof rule.src !== \"string\" ||\n !rule.src ||\n typeof rule.dst !== \"string\",\n )\n ) {\n return;\n }\n return parsed;\n } catch {\n return;\n }\n};\n\nconst escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\nconst applyRules = (value: string, rules: WordfilterRule[]) => {\n let current = value;\n for (let pass = 0; pass < MAX_PASSES; pass++) {\n let next = current;\n for (const { src, dst } of rules) {\n next = next.replace(new RegExp(escapeRegExp(src), \"gi\"), () => dst);\n }\n if (next === current) return current;\n current = next;\n }\n throw new Error(\"wordfilter rules did not stabilise\");\n};\n\nconst getOwnStringAtPath = (value: Record<string, any>, path: string) => {\n const parts = path.split(\".\");\n if (!parts.length || parts.some((part) => !part || unsafePathParts.has(part))) return;\n let current: any = value;\n for (const part of parts) {\n if (\n !current ||\n typeof current !== \"object\" ||\n !Object.prototype.hasOwnProperty.call(current, part)\n ) {\n return;\n }\n current = current[part];\n }\n return typeof current === \"string\" ? current : undefined;\n};\n\nconst setOwnPath = (value: Record<string, any>, path: string, replacement: string) => {\n const parts = path.split(\".\");\n const output = { ...value };\n let source: any = value;\n let target: any = output;\n for (let index = 0; index < parts.length - 1; index++) {\n const part = parts[index];\n source = source[part];\n target[part] = Array.isArray(source) ? [...source] : { ...source };\n target = target[part];\n }\n target[parts[parts.length - 1]] = replacement;\n return output;\n};\n\nexport const applyCommunityWordfilters = <T extends Record<string, any>>(\n publicationType: string,\n publication: T,\n challenges?: Challenge[],\n): T => {\n const rulesByField = new Map<string, WordfilterRule[]>();\n for (const challenge of challenges || []) {\n const rules = parseRules(challenge?.publicOptions?.[RULES_KEY]);\n if (!rules) continue;\n const configuredFieldNames = challenge.publicOptions?.[FIELD_NAMES_KEY];\n const fieldNames =\n configuredFieldNames === undefined\n ? DEFAULT_FIELD_NAMES\n : parseStringArray(configuredFieldNames);\n if (!fieldNames) continue;\n for (const fieldName of fieldNames) {\n if (!SUPPORTED_FIELD_NAMES.has(fieldName)) continue;\n // merge every challenge's rules per field so one apply call sees their interactions\n rulesByField.set(fieldName, [...(rulesByField.get(fieldName) || []), ...rules]);\n }\n }\n\n let output: Record<string, any> = { [publicationType]: publication };\n for (const [fieldName, rules] of rulesByField) {\n const value = getOwnStringAtPath(output, fieldName);\n if (value === undefined) continue;\n const replacement = applyRules(value, rules);\n if (replacement !== value) output = setOwnPath(output, fieldName, replacement);\n }\n return output[publicationType] as T;\n};\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,EAClB,yBAAyB,EACzB,+BAA+B,EAC/B,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAGhB,MAAM,aAAa,CAAC;
|
|
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,EAClB,yBAAyB,EACzB,+BAA+B,EAC/B,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAGhB,MAAM,aAAa,CAAC;AAmPrB,sGAAsG;AACtG,eAAO,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2BAA2B,yBAAyB,EACpD,cAAc,MAAM,kBA4IrB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,iCAAiC,+BAA+B,EAChE,cAAc,MAAM,kBAyJrB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,kBAAkB,MAAM,EACxB,6BAA6B,2BAA2B,EACxD,cAAc,MAAM,kBAmKrB,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"}
|
|
@@ -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";
|
|
@@ -73,13 +73,17 @@ const loadPublicationCommunity = (communityAddress, account) => __awaiter(void 0
|
|
|
73
73
|
const onError = (error) => {
|
|
74
74
|
if (settled)
|
|
75
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;
|
|
76
80
|
settled = true;
|
|
77
81
|
cleanup();
|
|
78
82
|
reject(error);
|
|
79
83
|
};
|
|
80
84
|
timeout = setTimeout(() => onError(new Error(`timed out loading challenge settings for community '${communityAddress}'`)), PUBLICATION_COMMUNITY_LOAD_TIMEOUT_MS);
|
|
81
85
|
community.once("update", onUpdate);
|
|
82
|
-
community.
|
|
86
|
+
community.on("error", onError);
|
|
83
87
|
void Promise.resolve()
|
|
84
88
|
.then(() => community.update())
|
|
85
89
|
.then(() => {
|
|
@@ -92,12 +96,12 @@ const loadPublicationCommunity = (communityAddress, account) => __awaiter(void 0
|
|
|
92
96
|
yield ((_a = community.stop) === null || _a === void 0 ? void 0 : _a.call(community));
|
|
93
97
|
}
|
|
94
98
|
});
|
|
95
|
-
const applyPublicationWordfilters = (options, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
const applyPublicationWordfilters = (publicationType, options, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
100
|
const communityAddress = options.communityAddress;
|
|
97
101
|
if (typeof communityAddress !== "string" || !communityAddress)
|
|
98
102
|
return options;
|
|
99
103
|
const community = yield loadPublicationCommunity(communityAddress, account);
|
|
100
|
-
return applyCommunityWordfilters(options, community === null || community === void 0 ? void 0 : community.challenges);
|
|
104
|
+
return applyCommunityWordfilters(publicationType, options, community === null || community === void 0 ? void 0 : community.challenges);
|
|
101
105
|
});
|
|
102
106
|
// Active publish-session tracking for pending comments (Task 3)
|
|
103
107
|
const activePublishSessions = new Map();
|
|
@@ -809,7 +813,7 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
809
813
|
delete createCommentOptions.onPendingComment;
|
|
810
814
|
delete createCommentOptions.onPublishingStateChange;
|
|
811
815
|
delete createCommentOptions._onPendingCommentIndex;
|
|
812
|
-
createCommentOptions = yield applyPublicationWordfilters(createCommentOptions, account);
|
|
816
|
+
createCommentOptions = yield applyPublicationWordfilters("comment", createCommentOptions, account);
|
|
813
817
|
const storedCreateCommentOptions = normalizePublicationOptionsForStore(createCommentOptions);
|
|
814
818
|
// make sure the options dont throw
|
|
815
819
|
yield account.pkc.createComment(createCommentOptions);
|
|
@@ -972,7 +976,12 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
972
976
|
var _a, _b;
|
|
973
977
|
applyChallengeVerificationCommentUpdateToPublication(challengeVerification, activeComment);
|
|
974
978
|
publishCommentOptions.onChallengeVerification(challengeVerification, activeComment);
|
|
975
|
-
|
|
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)) {
|
|
976
985
|
// publish again automatically on fail
|
|
977
986
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
978
987
|
createCommentOptions = Object.assign(Object.assign({}, createCommentOptions), { timestamp });
|
|
@@ -1156,6 +1165,7 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1156
1165
|
delete createVoteOptions.onChallengeVerification;
|
|
1157
1166
|
delete createVoteOptions.onError;
|
|
1158
1167
|
delete createVoteOptions.onPublishingStateChange;
|
|
1168
|
+
createVoteOptions = yield applyPublicationWordfilters("vote", createVoteOptions, account);
|
|
1159
1169
|
const accountsState = accountsStore.getState();
|
|
1160
1170
|
const accountCommentInfo = accountsState.commentCidsToAccountsComments[createVoteOptions.commentCid];
|
|
1161
1171
|
const accountComment = accountCommentInfo
|
|
@@ -1172,7 +1182,10 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1172
1182
|
}));
|
|
1173
1183
|
vote.once("challengeverification", (challengeVerification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1174
1184
|
publishVoteOptions.onChallengeVerification(challengeVerification, vote);
|
|
1175
|
-
|
|
1185
|
+
// same terminal short-circuit as publishComment/publishCommentEdit: never retry a rejection
|
|
1186
|
+
if (!challengeVerification.challengeSuccess &&
|
|
1187
|
+
lastChallenge &&
|
|
1188
|
+
!hasTerminalChallengeVerificationError(challengeVerification)) {
|
|
1176
1189
|
// publish again automatically on fail
|
|
1177
1190
|
createVoteOptions = Object.assign(Object.assign({}, createVoteOptions), { timestamp: Math.floor(Date.now() / 1000) });
|
|
1178
1191
|
vote = backfillPublicationCommunityAddress(yield account.pkc.createVote(createVoteOptions), createVoteOptions);
|
|
@@ -1218,7 +1231,7 @@ export const publishCommentEdit = (publishCommentEditOptions, accountName) => __
|
|
|
1218
1231
|
delete createCommentEditOptions.onChallengeVerification;
|
|
1219
1232
|
delete createCommentEditOptions.onError;
|
|
1220
1233
|
delete createCommentEditOptions.onPublishingStateChange;
|
|
1221
|
-
createCommentEditOptions = yield applyPublicationWordfilters(createCommentEditOptions, account);
|
|
1234
|
+
createCommentEditOptions = yield applyPublicationWordfilters("commentEdit", createCommentEditOptions, account);
|
|
1222
1235
|
const storedCreateCommentEditOptions = Object.assign(Object.assign({}, normalizePublicationOptionsForStore(createCommentEditOptions)), { clientId: uuid() });
|
|
1223
1236
|
const storedCommentEdit = sanitizeStoredAccountEdit(storedCreateCommentEditOptions);
|
|
1224
1237
|
let commentEdit = backfillPublicationCommunityAddress(yield account.pkc.createCommentEdit(createCommentEditOptions), createCommentEditOptions);
|
|
@@ -1307,6 +1320,7 @@ export const publishCommentModeration = (publishCommentModerationOptions, accoun
|
|
|
1307
1320
|
delete createCommentModerationOptions.onChallengeVerification;
|
|
1308
1321
|
delete createCommentModerationOptions.onError;
|
|
1309
1322
|
delete createCommentModerationOptions.onPublishingStateChange;
|
|
1323
|
+
createCommentModerationOptions = yield applyPublicationWordfilters("commentModeration", createCommentModerationOptions, account);
|
|
1310
1324
|
const storedCreateCommentModerationOptions = Object.assign(Object.assign({}, normalizePublicationOptionsForStore(createCommentModerationOptions)), { clientId: uuid() });
|
|
1311
1325
|
const storedCommentModeration = sanitizeStoredAccountEdit(storedCreateCommentModerationOptions);
|
|
1312
1326
|
let commentModeration = backfillPublicationCommunityAddress(yield account.pkc.createCommentModeration(createCommentModerationOptions), createCommentModerationOptions);
|
|
@@ -1415,6 +1429,7 @@ export const publishCommunityEdit = (communityAddress, publishCommunityEditOptio
|
|
|
1415
1429
|
communityAddress,
|
|
1416
1430
|
communityEdit: communityEditOptions,
|
|
1417
1431
|
});
|
|
1432
|
+
createCommunityEditOptions = yield applyPublicationWordfilters("communityEdit", createCommunityEditOptions, account);
|
|
1418
1433
|
const storedCreateCommunityEditOptions = Object.assign(Object.assign({}, normalizePublicationOptionsForStore(createCommunityEditOptions)), { clientId: uuid() });
|
|
1419
1434
|
const storedCommunityEdit = sanitizeStoredAccountEdit(storedCreateCommunityEditOptions);
|
|
1420
1435
|
let challengeSucceeded = false;
|
|
@@ -1442,9 +1457,10 @@ export const publishCommunityEdit = (communityAddress, publishCommunityEditOptio
|
|
|
1442
1457
|
});
|
|
1443
1458
|
// account is the owner of the community and can edit it locally, no need to publish
|
|
1444
1459
|
if (accountOwnsCommunityLocally(account, communityAddress)) {
|
|
1460
|
+
// use the wordfiltered edit so the applied community state matches the stored account edit
|
|
1445
1461
|
yield communitiesStore
|
|
1446
1462
|
.getState()
|
|
1447
|
-
.editCommunity(communityAddress,
|
|
1463
|
+
.editCommunity(communityAddress, createCommunityEditOptions.communityEdit, account);
|
|
1448
1464
|
yield storePublishedCommunityEdit();
|
|
1449
1465
|
// create fake success challenge verification for consistent behavior with remote community edit
|
|
1450
1466
|
publishCommunityEditOptions.onChallengeVerification({ challengeSuccess: true });
|