mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-10 23:01:10 +00:00
Adjust moderation defaults and store per-profile settings
This commit is contained in:
1 parent
213ba3970f
commit
15b94cfff3
7 files changed
+240
-121
No files matched your search
@@ -244,14 +244,16 @@ test("moderation thresholds emit logger hooks only when crossing", async (t) =>
|
||||
|
||||
const createReporterEntry = (timestamp) => new Map([[reportType, { created_at: timestamp }]]);
|
||||
|
||||
const expectSingleAction = (expectedAction, expectedCount) => {
|
||||
assert.equal(calls.length, 1);
|
||||
const [message, detail] = calls[0];
|
||||
assert.equal(message, "[moderationService] moderation threshold crossed");
|
||||
assert.equal(detail.action, expectedAction);
|
||||
assert.equal(detail.eventId, eventId);
|
||||
assert.equal(detail.reportType, reportType);
|
||||
assert.equal(detail.trustedCount, expectedCount);
|
||||
const expectActions = (...expected) => {
|
||||
assert.equal(calls.length, expected.length);
|
||||
expected.forEach((entry, index) => {
|
||||
const [message, detail] = calls[index];
|
||||
assert.equal(message, "[moderationService] moderation threshold crossed");
|
||||
assert.equal(detail.action, entry.action);
|
||||
assert.equal(detail.eventId, eventId);
|
||||
assert.equal(detail.reportType, reportType);
|
||||
assert.equal(detail.trustedCount, entry.count);
|
||||
});
|
||||
calls.length = 0;
|
||||
};
|
||||
|
||||
@@ -260,34 +262,40 @@ test("moderation thresholds emit logger hooks only when crossing", async (t) =>
|
||||
};
|
||||
|
||||
reports.set(trustedReporters[0], createReporterEntry(100));
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectActions(
|
||||
{ action: "autoplay-block-enabled", count: 1 },
|
||||
{ action: "blur-enabled", count: 1 },
|
||||
);
|
||||
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectNoAction();
|
||||
|
||||
reports.set(trustedReporters[1], createReporterEntry(200));
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectSingleAction("autoplay-block-enabled", 2);
|
||||
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectNoAction();
|
||||
|
||||
reports.set(trustedReporters[2], createReporterEntry(300));
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectSingleAction("blur-enabled", 3);
|
||||
expectNoAction();
|
||||
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectNoAction();
|
||||
|
||||
reports.delete(trustedReporters[2]);
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectSingleAction("blur-cleared", 2);
|
||||
expectNoAction();
|
||||
|
||||
reports.delete(trustedReporters[1]);
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectSingleAction("autoplay-block-cleared", 1);
|
||||
expectNoAction();
|
||||
|
||||
reports.delete(trustedReporters[0]);
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectNoAction();
|
||||
expectActions(
|
||||
{ action: "autoplay-block-cleared", count: 0 },
|
||||
{ action: "blur-cleared", count: 0 },
|
||||
);
|
||||
|
||||
service.recomputeSummaryForEvent(eventId);
|
||||
expectNoAction();
|
||||
|
||||
@@ -55,8 +55,8 @@ test("moderation stage enforces admin lists without whitelist bypass", async ()
|
||||
const stage = createModerationStage({
|
||||
service,
|
||||
reportType: "nudity",
|
||||
autoplayThreshold: 2,
|
||||
blurThreshold: 3,
|
||||
autoplayThreshold: 1,
|
||||
blurThreshold: 1,
|
||||
});
|
||||
|
||||
const items = [
|
||||
@@ -199,8 +199,8 @@ test("moderation stage applies provided thresholds", async () => {
|
||||
|
||||
const relaxedStage = createModerationStage({
|
||||
service,
|
||||
autoplayThreshold: 2,
|
||||
blurThreshold: 3,
|
||||
autoplayThreshold: 1,
|
||||
blurThreshold: 1,
|
||||
});
|
||||
|
||||
const strictResult = await strictStage(items, {});
|
||||
@@ -281,8 +281,8 @@ test("moderation stage propagates whitelist, muters, and threshold updates", asy
|
||||
|
||||
const stage = createModerationStage({
|
||||
service,
|
||||
autoplayThreshold: 2,
|
||||
blurThreshold: 3,
|
||||
autoplayThreshold: 1,
|
||||
blurThreshold: 1,
|
||||
reportType: "nudity",
|
||||
});
|
||||
|
||||
@@ -322,11 +322,11 @@ test("moderation stage propagates whitelist, muters, and threshold updates", asy
|
||||
|
||||
state.summaryById.set("muted-video", {
|
||||
eventId: "muted-video",
|
||||
totalTrusted: 1,
|
||||
types: { nudity: { trusted: 1, total: 1, latest: 1_700_000_500 } },
|
||||
totalTrusted: 0,
|
||||
types: { nudity: { trusted: 0, total: 0, latest: 1_700_000_500 } },
|
||||
updatedAt: 1_700_000_600,
|
||||
});
|
||||
state.trustedCounts.set("muted-video", 1);
|
||||
state.trustedCounts.set("muted-video", 0);
|
||||
state.mutersByAuthor.set(mutedHex, []);
|
||||
state.mutedAuthors.delete(mutedHex);
|
||||
|
||||
|
||||
@@ -67,16 +67,16 @@ beforeEach(async () => {
|
||||
};
|
||||
|
||||
storedSettings = {
|
||||
blurThreshold: 3,
|
||||
autoplayBlockThreshold: 2,
|
||||
blurThreshold: 1,
|
||||
autoplayBlockThreshold: 1,
|
||||
trustedMuteHideThreshold: 1,
|
||||
trustedSpamHideThreshold: 3,
|
||||
};
|
||||
moderationService = {
|
||||
getDefaultModerationSettings() {
|
||||
return {
|
||||
blurThreshold: 3,
|
||||
autoplayBlockThreshold: 2,
|
||||
blurThreshold: 1,
|
||||
autoplayBlockThreshold: 1,
|
||||
trustedMuteHideThreshold: 1,
|
||||
trustedSpamHideThreshold: 3,
|
||||
};
|
||||
@@ -87,7 +87,7 @@ beforeEach(async () => {
|
||||
updateModerationSettings(partial = {}) {
|
||||
if (Object.prototype.hasOwnProperty.call(partial, "blurThreshold")) {
|
||||
const value = partial.blurThreshold;
|
||||
storedSettings.blurThreshold = value === null ? 3 : value;
|
||||
storedSettings.blurThreshold = value === null ? 1 : value;
|
||||
}
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(
|
||||
@@ -96,7 +96,7 @@ beforeEach(async () => {
|
||||
)
|
||||
) {
|
||||
const value = partial.autoplayBlockThreshold;
|
||||
storedSettings.autoplayBlockThreshold = value === null ? 2 : value;
|
||||
storedSettings.autoplayBlockThreshold = value === null ? 1 : value;
|
||||
}
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(
|
||||
@@ -120,8 +120,8 @@ beforeEach(async () => {
|
||||
},
|
||||
resetModerationSettings() {
|
||||
storedSettings = {
|
||||
blurThreshold: 3,
|
||||
autoplayBlockThreshold: 2,
|
||||
blurThreshold: 1,
|
||||
autoplayBlockThreshold: 1,
|
||||
trustedMuteHideThreshold: 1,
|
||||
trustedSpamHideThreshold: 3,
|
||||
};
|
||||
@@ -185,8 +185,8 @@ afterEach(() => {
|
||||
test("moderation settings save updates service and disables control", async () => {
|
||||
await controller.load();
|
||||
|
||||
assert.equal(controller.moderationBlurInput.value, "3");
|
||||
assert.equal(controller.moderationAutoplayInput.value, "2");
|
||||
assert.equal(controller.moderationBlurInput.value, "1");
|
||||
assert.equal(controller.moderationAutoplayInput.value, "1");
|
||||
assert.equal(controller.moderationMuteHideInput.value, "1");
|
||||
assert.equal(controller.moderationSpamHideInput.value, "3");
|
||||
assert.equal(controller.moderationSaveButton.disabled, true);
|
||||
@@ -249,13 +249,13 @@ test("moderation reset restores defaults and clearing inputs uses defaults", asy
|
||||
const resetContext = await controller.handleModerationSettingsReset();
|
||||
assert.equal(resetContext.success, true);
|
||||
assert.deepEqual(storedSettings, {
|
||||
blurThreshold: 3,
|
||||
autoplayBlockThreshold: 2,
|
||||
blurThreshold: 1,
|
||||
autoplayBlockThreshold: 1,
|
||||
trustedMuteHideThreshold: 1,
|
||||
trustedSpamHideThreshold: 3,
|
||||
});
|
||||
assert.equal(controller.moderationBlurInput.value, "3");
|
||||
assert.equal(controller.moderationAutoplayInput.value, "2");
|
||||
assert.equal(controller.moderationBlurInput.value, "1");
|
||||
assert.equal(controller.moderationAutoplayInput.value, "1");
|
||||
assert.equal(controller.moderationMuteHideInput.value, "1");
|
||||
assert.equal(controller.moderationSpamHideInput.value, "3");
|
||||
assert.equal(
|
||||
@@ -276,7 +276,7 @@ test("moderation reset restores defaults and clearing inputs uses defaults", asy
|
||||
assert.equal(saveResult.success, true);
|
||||
assert.deepEqual(storedSettings, {
|
||||
blurThreshold: 7,
|
||||
autoplayBlockThreshold: 2,
|
||||
autoplayBlockThreshold: 1,
|
||||
trustedMuteHideThreshold: 1,
|
||||
trustedSpamHideThreshold: 8,
|
||||
});
|
||||
@@ -302,8 +302,8 @@ test("moderation reset restores defaults and clearing inputs uses defaults", asy
|
||||
const revertContext = await controller.handleModerationSettingsSave();
|
||||
assert.equal(revertContext.success, true);
|
||||
assert.deepEqual(storedSettings, {
|
||||
blurThreshold: 3,
|
||||
autoplayBlockThreshold: 2,
|
||||
blurThreshold: 1,
|
||||
autoplayBlockThreshold: 1,
|
||||
trustedMuteHideThreshold: 1,
|
||||
trustedSpamHideThreshold: 3,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user