Blur NSFW profile avatars and banners unless the viewer has enabled NSFW

Hop-State: A_06FP9DH64R0TWDEQST5Z460
Hop-Proposal: R_06FP9DF1AKH8Z9GA7AD24G0
Hop-Task: T_06FP9B65YW8Z4VM9386KDB8
Hop-Attempt: AT_06FP9B65YZ94YY9QS6C6Q38
This commit is contained in:
2026-07-15 00:38:06 -07:00
committed by Hop
parent c17b27b240
commit b291c5a453
23 changed files with 206 additions and 34 deletions
+20
View File
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest';
import { shouldBlurProfileMedia } from './profile-media';
describe('shouldBlurProfileMedia', () => {
it('blurs sensitive account media for signed-out viewers', () => {
expect(shouldBlurProfileMedia({ accountIsNsfw: true, viewer: null })).toBe(true);
});
it('blurs every account from an NSFW node when the viewer has NSFW disabled', () => {
expect(shouldBlurProfileMedia({ nodeIsNsfw: true, viewer: { nsfwEnabled: false } })).toBe(true);
});
it('shows sensitive profile media when the viewer has enabled NSFW', () => {
expect(shouldBlurProfileMedia({ accountIsNsfw: true, nodeIsNsfw: true, viewer: { nsfwEnabled: true } })).toBe(false);
});
it('does not blur safe profile media', () => {
expect(shouldBlurProfileMedia({ viewer: null })).toBe(false);
});
});
+15
View File
@@ -0,0 +1,15 @@
export interface ProfileMediaViewer {
nsfwEnabled?: boolean;
}
export function shouldBlurProfileMedia({
accountIsNsfw = false,
nodeIsNsfw = false,
viewer,
}: {
accountIsNsfw?: boolean;
nodeIsNsfw?: boolean;
viewer: ProfileMediaViewer | null;
}): boolean {
return (accountIsNsfw || nodeIsNsfw) && viewer?.nsfwEnabled !== true;
}