fix(post): show specific role in moderation posting warning

Replace the generic "posting as moderator" label with the effective role
(5chan dev, owner, admin, or moderator) in post and reply forms.
This commit is contained in:
Tommaso Casaburi
2026-06-01 12:48:42 +07:00
parent d48cf10ee8
commit 812b6bc79c
6 changed files with 47 additions and 6 deletions
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { KNOWN_5CHAN_DEVELOPER_ENTRIES, get5chanDeveloperBadge, getAuthorBadge, isKnown5chanDeveloper } from '../author-display-utils';
import { KNOWN_5CHAN_DEVELOPER_ENTRIES, get5chanDeveloperBadge, getAuthorBadge, getModerationPostingRoleLabel, isKnown5chanDeveloper } from '../author-display-utils';
describe('author display utils', () => {
it('recognizes the hardcoded 5chan developer addresses', () => {
@@ -61,4 +61,12 @@ describe('author display utils', () => {
title: 'administrator_of_this_board',
});
});
it('returns the posting warning label for the effective moderator role', () => {
expect(getModerationPostingRoleLabel({ address: 'plebeius.bso', role: 'owner' })).toBe('5chan dev');
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'owner' })).toBe('owner');
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'admin' })).toBe('admin');
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'moderator' })).toBe('moderator');
expect(getModerationPostingRoleLabel({ address: 'other.bso', role: 'viewer' })).toBeUndefined();
});
});
+9
View File
@@ -51,3 +51,12 @@ export const getAuthorBadge = ({ address, role }: { address?: string; role?: str
title: isMod ? 'moderator_of_this_board' : 'administrator_of_this_board',
};
};
export const getModerationPostingRoleLabel = ({ address, role }: { address?: string; role?: string }): string | undefined => {
if (isKnown5chanDeveloper(address)) return '5chan dev';
const normalizedRole = role?.trim().toLowerCase();
if (normalizedRole === 'owner' || normalizedRole === 'admin' || normalizedRole === 'moderator') return normalizedRole;
return undefined;
};