Skip to content

Commit

Permalink
fix: do not cast a delete vote if a red flag is raised
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Nov 30, 2024
1 parent bdf4fad commit a4c848c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Store, Cached, Configuration, CachedFlag } from './UserscriptTools/Stor
import Reporter from './UserscriptTools/Reporter';
import Page from './UserscriptTools/Page';
import { Progress } from './UserscriptTools/Progress';
import { Flags } from './FlagTypes';

const noneSpan = document.createElement('span');
noneSpan.classList.add('o50');
Expand All @@ -30,6 +31,15 @@ export class Popover {
this.popover = this.makeMenu();
}

// do not vote to delete if reportType is one of these:
private readonly excludedTypes: Flags[] = [
FlagNames.Plagiarism,
FlagNames.ModFlag,
FlagNames.NoFlag,
FlagNames.Spam,
FlagNames.Rude
];

private makeMenu(): HTMLUListElement {
const menu = Menu.makeMenu(
{
Expand Down Expand Up @@ -262,10 +272,9 @@ export class Popover {
popoverParent.append(downvoteWrapper);

// Votes to delete the post
if (this.post.canDelete() && !this.post.deleted
&& reportType !== FlagNames.Plagiarism
&& reportType !== FlagNames.ModFlag
&& reportType !== FlagNames.NoFlag
if (this.post.canDelete()
&& !this.post.deleted
&& !this.excludedTypes.includes(reportType)
) {
const wrapper = document.createElement('li');
wrapper.innerHTML = '<b>Votes to delete</b> the post';
Expand Down Expand Up @@ -467,12 +476,8 @@ export class Popover {
this.post.progress.updateLocation(); // just in case

// delete vote if the user has chosen to flag the post
// as spam/rude/NAA/VLQ
if (del && this.post.canDelete()
&& reportType !== FlagNames.Plagiarism
&& reportType !== FlagNames.ModFlag
&& reportType !== FlagNames.NoFlag
) {
// as NAA/VQL (exclude spam and r/a)
if (del && this.post.canDelete() && !this.excludedTypes.includes(reportType)) {
const dProgress = this.post.progress.addItem('Voting to delete...');

try {
Expand Down
1 change: 1 addition & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface FlagTypeFeedbacks {
export type BotNames = keyof FlagTypeFeedbacks;
export type AllFeedbacks = FlagTypeFeedbacks[BotNames] | '(none)';

// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
export const possibleFeedbacks: { [key in BotNames]: AllFeedbacks[] } = {
Smokey: ['tpu-', 'tp-', 'fp-', 'naa-', ''],
Natty: ['tp', 'fp', 'ne', ''],
Expand Down

0 comments on commit a4c848c

Please sign in to comment.