Skip to content

Commit

Permalink
Avoid flagging duplicate answers as plagiarism
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Aug 22, 2023
1 parent cce8b26 commit 6c8aca0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 32 deletions.
30 changes: 17 additions & 13 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import {
import { buildConfigurationOverlay } from './modals/config';
import { setupCommentsAndFlagsModal } from './modals/comments/main';

export function isPlagiarismOrNoFlag(flagName: Flags): boolean {
const result =
[
FlagNames.NoFlag,
FlagNames.Plagiarism
]
.some(reportType => reportType === flagName);

return result;
export function isSpecialFlag(flagName: Flags, checkNoFlag = true): boolean {
const arrayOfFlags: Flags[] = [
FlagNames.ModFlag,
FlagNames.Plagiarism
];

if (checkNoFlag) {
arrayOfFlags.push(FlagNames.NoFlag);
}

return arrayOfFlags.includes(flagName);
}

export function wrapInFlexItem(element: HTMLElement): HTMLElement {
Expand All @@ -40,7 +42,7 @@ export function cacheFlags(): void {
return category.FlagTypes.map(flagType => {
return Object.assign(flagType, {
belongsTo: category.name,
downvote: !isPlagiarismOrNoFlag(flagType.reportType),
downvote: !isSpecialFlag(flagType.reportType),
enabled: true // all flags should be enabled by default
});
});
Expand Down Expand Up @@ -83,10 +85,12 @@ function setupDefaults(): void {
cacheCategories();
}

// PostOther is no more!
// Replace with PlagiarizedContent.
// PostOther can be replaced with PlagiarizedContent
// for "Plagiarism" flag type.
cachedFlagTypes.forEach(cachedFlag => {
if (cachedFlag.reportType as Flags | 'PostOther' !== 'PostOther') return;
// Plagiarism and Bad Attribution flag types,
// filter by id because names can be edited by the user
if (cachedFlag.id !== 3 && cachedFlag.id !== 5) return;

cachedFlag.reportType = FlagNames.Plagiarism;
});
Expand Down
4 changes: 2 additions & 2 deletions src/FlagTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type Flags = 'AnswerNotAnAnswer'
| 'PostOffensive'
| 'PostSpam'
| 'NoFlag'
//| 'PostOther'
| 'PostOther'
| 'PostLowQuality'
| 'PlagiarizedContent';

Expand Down Expand Up @@ -75,7 +75,7 @@ export const flagCategories: FlagCategory[] = [
{
id: 4,
displayName: 'Duplicate answer',
reportType: FlagNames.Plagiarism,
reportType: FlagNames.ModFlag,
flagText: 'The post is a repost of their other answer, but as there are slight differences '
+ '(see $COPYPASTOR$), an auto flag would not be raised.',
comments: {
Expand Down
2 changes: 1 addition & 1 deletion src/modals/comments/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import {
]
Notes:
- The ReportType can't be changed to/from PlagiarizedContent for default flags.
- The ReportType can't be changed to/from PostOther/PlagiarizedContent for default flags.
- The Human field is retrieved on runtime when the flag is raised based on ReportType.
- Each s-card div has a data-flag-id attribute based on which we can store the
information on cache again.
Expand Down
11 changes: 6 additions & 5 deletions src/modals/comments/rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {
BotNames,
AllFeedbacks,
possibleFeedbacks,
FlagNames,
} from '../../shared';
import { flagCategories } from '../../FlagTypes';
import { wrapInFlexItem, isPlagiarismOrNoFlag } from '../../Configuration';
import { wrapInFlexItem, isSpecialFlag } from '../../Configuration';
import { toggleHideIfNeeded } from './main';

import {
Expand Down Expand Up @@ -247,6 +246,8 @@ function getFlagSelect(
id: CachedFlag['id'],
reportType: CachedFlag['reportType']
): HTMLElement[] {
const shouldDisable = isSpecialFlag(reportType, false);

const options = flagNames.map(flagName => {
return {
value: flagName,
Expand All @@ -258,7 +259,7 @@ function getFlagSelect(
const select = Select.makeStacksSelect(
`advanced-flagging-select-flag-${id}`,
options,
{ disabled: reportType === FlagNames.Plagiarism }
{ disabled: shouldDisable }
);
select.className = 'd-flex ai-center';

Expand All @@ -271,7 +272,7 @@ function getFlagSelect(
flagLabel.classList.add('fw-bold', 'ps-relative', 'z-selected', 'l12', 'fs-body1', 'flex--item');
flagLabel.innerText = 'Flag:';

if (reportType === FlagNames.Plagiarism) {
if (shouldDisable) {
flagLabel.classList.add('o50');
}

Expand Down Expand Up @@ -319,7 +320,7 @@ export function getSelectRow({
wrapInFlexItem(downvoteBox)
);

if (!isPlagiarismOrNoFlag(reportType)) {
if (!isSpecialFlag(reportType)) {
container.append(wrapInFlexItem(feedback));
}

Expand Down
13 changes: 8 additions & 5 deletions src/modals/comments/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
FlagTypeFeedbacks,
getFlagTypeFromFlagId,
updateFlagTypes,
FlagNames,
} from '../../shared';
import { Flags } from '../../FlagTypes';
import { isSpecialFlag } from '../../Configuration';

function saveName(
card: HTMLElement,
Expand Down Expand Up @@ -48,11 +48,14 @@ function saveReportType(
const select = expandable.querySelector('select');
const newReportType = select?.value as Flags;

// can't select to flag for plagiarism
// unless it's disabled, meaning it's a Guttenberg flag type
if (newReportType === FlagNames.Plagiarism && !select?.disabled) {
// can't select to flag for plagiarism/mod attention
// (if disabled, it's a Guttenberg flag type)
if (
isSpecialFlag(newReportType, false)
&& !select?.disabled
) {
displayStacksToast(
'This type of flag cannot be raised with this option',
'You cannot use this type of flag!',
'danger',
true
);
Expand Down
6 changes: 3 additions & 3 deletions src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
cachedCategories,
cachedFlagTypes,

FlagNames,
isStackOverflow,
getFullFlag,
getCachedConfigBotKey,
Expand All @@ -33,6 +32,7 @@ import { GenericBotAPI } from './UserscriptTools/GenericBotAPI';
import { CopyPastorAPI } from './UserscriptTools/CopyPastorAPI';

import { Menu } from '@userscripters/stacks-helpers';
import { isSpecialFlag } from './Configuration';

const noneSpan = document.createElement('span');
noneSpan.classList.add('o50');
Expand Down Expand Up @@ -382,8 +382,8 @@ function getReportLinks(
cachedFlagTypes
// exclude disabled and non-SO flag types
.filter(({ reportType, id, belongsTo, enabled }) => {
// only Guttenberg reports (can) have ReportType === 'PlagiarizedContent'
const isGuttenbergItem = reportType === FlagNames.Plagiarism;
// only Guttenberg reports (can) have ReportType === 'PlagiarizedContent/PostOther'
const isGuttenbergItem = isSpecialFlag(reportType, false);

const showGutReport = Boolean(copypastorId) // a CopyPastor id must exist
// https://github.com/SOBotics/AdvancedFlagging/issues/16
Expand Down
14 changes: 11 additions & 3 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export enum FlagNames {
NAA = 'AnswerNotAnAnswer',
VLQ = 'PostLowQuality',
NoFlag = 'NoFlag',
Plagiarism = 'PlagiarizedContent'
Plagiarism = 'PlagiarizedContent',
ModFlag = 'PostOther'
}

// Constants
Expand Down Expand Up @@ -236,7 +237,13 @@ export function getFlagTypeFromFlagId(flagId: number): CachedFlag | null {
return cachedFlagTypes.find(({ id }) => id === flagId) || null;
}

export type HumanFlags = 'as NAA' | 'as R/A' | 'as spam' | 'for plagiarism' | 'as VLQ' | '';
export type HumanFlags = 'as NAA'
| 'as R/A'
| 'as spam'
| 'for plagiarism'
| 'as VLQ'
| 'for moderator attention'
| '';

export function getHumanFromDisplayName(displayName: Flags): HumanFlags {
const flags = {
Expand All @@ -245,7 +252,8 @@ export function getHumanFromDisplayName(displayName: Flags): HumanFlags {
[FlagNames.NAA]: 'as NAA',
[FlagNames.VLQ]: 'as VLQ',
[FlagNames.NoFlag]: '',
[FlagNames.Plagiarism]: 'for plagiarism'
[FlagNames.Plagiarism]: 'for plagiarism',
[FlagNames.ModFlag]: 'for moderator attention',
} as const;

return flags[displayName] || '';
Expand Down

0 comments on commit 6c8aca0

Please sign in to comment.