Skip to content

Commit

Permalink
fix: avoid voting to delete if the flag changes the state of the post
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Jul 5, 2024
1 parent 3caf45c commit faaca22
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/UserscriptTools/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class Post {

public readonly type: PostType;
public readonly id: number;
public readonly deleted: boolean;
public deleted: boolean;

public readonly date: Date;

Expand Down Expand Up @@ -171,6 +171,8 @@ export default class Post {
// flag changes the state of the post
// => reload the page
if (response.ResultChangedState) {
// the post should now be considered deleted
this.deleted = true;
// wait 1 second before reloading
setTimeout(() => location.reload(), 1000);
}
Expand Down Expand Up @@ -408,7 +410,9 @@ export default class Post {
const userRep = StackExchange.options.user.rep;

// >20k rep users can vote to delete answers with score < 0
return Boolean(deleteButton) || (userRep > 20_000 && this.score < 0);
return (Boolean(deleteButton) || (userRep > 20_000 && this.score < 0))
// can delete if post isn't already deleted
&& !this.deleted;
}

public qualifiesForVlq(): boolean {
Expand Down

0 comments on commit faaca22

Please sign in to comment.