fix(flags): move reply flag below link and auto-geo on /bant/

Hide the flag selector on /bant/ while still publishing geographic location, and place the reply modal flag field after the link field.
This commit is contained in:
Tommaso Casaburi
2026-05-24 23:38:15 +07:00
parent 2030b8c5bb
commit 633542a1f7
5 changed files with 105 additions and 19 deletions
@@ -1,5 +1,10 @@
import { describe, expect, it } from 'vitest';
import { getCommentFlagOptionsForDirectory, getCommentFlagPublishOptionsFromSelection, getCommentFlagRequestFromSelection } from '../comment-flag-selection';
import {
getCommentFlagOptionsForDirectory,
getCommentFlagPublishOptionsForDirectory,
getCommentFlagPublishOptionsFromSelection,
getCommentFlagRequestFromSelection,
} from '../comment-flag-selection';
describe('comment-flag-selection', () => {
it('does not expose options for boards without flags', () => {
@@ -16,6 +21,29 @@ describe('comment-flag-selection', () => {
).toEqual([{ label: 'Geographic Location', value: 'country:auto' }]);
});
it('does not expose a flag selector on /bant/ but still publishes geographic location', () => {
expect(
getCommentFlagOptionsForDirectory({
directoryCode: 'bant',
features: { hasFlags: true },
title: '/bant/ - International/Random',
}),
).toEqual([]);
expect(
getCommentFlagPublishOptionsForDirectory({
directoryCode: 'bant',
features: { hasFlags: true },
title: '/bant/ - International/Random',
}),
).toEqual({
challengeRequest: {
challengeAnswers: ['bitsocial-flags:5chan:flag:country:auto'],
},
flairs: [{ type: 'country', code: 'auto', text: 'flag:country:auto' }],
});
});
it('matches the 4chan /pol/ flag order', () => {
const options = getCommentFlagOptionsForDirectory({
directoryCode: 'pol',
+34
View File
@@ -35,6 +35,9 @@ const NO_FLAG_OPTION: CommentFlagSelectOption = {
label: 'None',
};
/** Boards that always publish geographic location without showing a flag selector. */
const AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES = new Set(['bant']);
const getDirectoryCode = (directory: Pick<DirectoryCommunity, 'directoryCode' | 'title'> | undefined): string | undefined => {
const directoryCode = directory?.directoryCode?.trim().toLowerCase();
return directoryCode || directory?.title?.match(/^\/([^/]+)\//)?.[1]?.toLowerCase();
@@ -52,6 +55,10 @@ export const getCommentFlagOptionsForDirectory = (directory: Pick<DirectoryCommu
}
const directoryCode = getDirectoryCode(directory);
if (directoryCode && AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES.has(directoryCode)) {
return [];
}
if (directoryCode === 'mlp') {
return [NO_FLAG_OPTION, ...getBoardFlagOptions('pony')];
}
@@ -63,6 +70,33 @@ export const getCommentFlagOptionsForDirectory = (directory: Pick<DirectoryCommu
return [GEOGRAPHIC_LOCATION_OPTION];
};
export const getCommentFlagPublishOptionsForDirectory = (
directory: Pick<DirectoryCommunity, 'directoryCode' | 'features' | 'title'> | undefined,
selectedValue?: string,
): CommentFlagPublishOptions => {
if (directory?.features?.hasFlags !== true) {
return {
challengeRequest: undefined,
flairs: undefined,
};
}
const directoryCode = getDirectoryCode(directory);
if (directoryCode && AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES.has(directoryCode)) {
return getCommentFlagPublishOptionsFromSelection(GEOGRAPHIC_LOCATION_FLAG_VALUE);
}
const flagOptions = getCommentFlagOptionsForDirectory(directory);
if (flagOptions.length === 0) {
return {
challengeRequest: undefined,
flairs: undefined,
};
}
return getCommentFlagPublishOptionsFromSelection(selectedValue ?? flagOptions[0]?.value);
};
export const getCommentFlagRequestFromSelection = (value: string | undefined): CommentFlagRequest | undefined => {
if (!value || value === NO_FLAG_VALUE) {
return undefined;