mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
feat(app): gate the expression info card behind an experiment (#2773)
This commit is contained in:
@@ -33,6 +33,7 @@ import {VoiceNoiseSuppressionConfigSchema} from '@fluxer/schema/src/domains/admi
|
||||
import {UserIdParam} from '@fluxer/schema/src/domains/common/CommonParamSchemas';
|
||||
import {BlockedMessageGroupsConfigSchema} from '@fluxer/schema/src/domains/experiment/BlockedMessageGroupsSchemas';
|
||||
import {ExperimentDeliveryConfigSchema} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {ExpressionInfoCardConfigSchema} from '@fluxer/schema/src/domains/experiment/ExpressionInfoCardSchemas';
|
||||
import {GuildActivityLogPresentationConfigSchema} from '@fluxer/schema/src/domains/experiment/GuildActivityLogPresentationSchemas';
|
||||
import {MessageHoverTrackingConfigSchema} from '@fluxer/schema/src/domains/experiment/MessageHoverTrackingSchemas';
|
||||
import {MessageKeyboardFocusConfigSchema} from '@fluxer/schema/src/domains/experiment/MessageKeyboardFocusSchemas';
|
||||
@@ -66,6 +67,7 @@ async function buildInstanceConfigResponse(): Promise<InstanceConfigResponse> {
|
||||
messageHoverTracking,
|
||||
messageKeyboardFocus,
|
||||
blockedMessageGroups,
|
||||
expressionInfoCard,
|
||||
registrationConfig,
|
||||
registrationUrls,
|
||||
pendingRegistrations,
|
||||
@@ -78,6 +80,7 @@ async function buildInstanceConfigResponse(): Promise<InstanceConfigResponse> {
|
||||
instanceConfigRepository.getMessageHoverTrackingConfig(),
|
||||
instanceConfigRepository.getMessageKeyboardFocusConfig(),
|
||||
instanceConfigRepository.getBlockedMessageGroupsConfig(),
|
||||
instanceConfigRepository.getExpressionInfoCardConfig(),
|
||||
instanceConfigRepository.getRegistrationConfig(),
|
||||
instanceConfigRepository.getRegistrationUrlsForAdmin(),
|
||||
instanceConfigRepository.getPendingRegistrations(),
|
||||
@@ -113,6 +116,7 @@ async function buildInstanceConfigResponse(): Promise<InstanceConfigResponse> {
|
||||
message_hover_tracking: messageHoverTracking,
|
||||
message_keyboard_focus: messageKeyboardFocus,
|
||||
blocked_message_groups: blockedMessageGroups,
|
||||
expression_info_card: expressionInfoCard,
|
||||
registration: {
|
||||
...registrationConfig,
|
||||
urls: registrationUrls,
|
||||
@@ -305,6 +309,18 @@ export function InstanceConfigAdminController(app: HonoApp) {
|
||||
await instanceConfigRepository.setBlockedMessageGroupsConfig(validated);
|
||||
}
|
||||
}
|
||||
if (data.expression_info_card) {
|
||||
const patch = omitUndefinedFields(data.expression_info_card);
|
||||
if (Object.keys(patch).length > 0) {
|
||||
const currentExpressionInfoCard = await instanceConfigRepository.getExpressionInfoCardConfig();
|
||||
const validated = ExpressionInfoCardConfigSchema.parse({
|
||||
...currentExpressionInfoCard,
|
||||
...patch,
|
||||
config_version: currentExpressionInfoCard.config_version + 1,
|
||||
});
|
||||
await instanceConfigRepository.setExpressionInfoCardConfig(validated);
|
||||
}
|
||||
}
|
||||
if (data.experiment_delivery) {
|
||||
const currentExperimentDelivery = await instanceConfigRepository.getExperimentDeliveryConfig();
|
||||
const validated = ExperimentDeliveryConfigSchema.parse({
|
||||
|
||||
@@ -11,6 +11,7 @@ import {Headers as HttpHeaders} from '@fluxer/constants/src/Headers';
|
||||
import {resolveVoiceNoiseSuppressionAssignment} from '@fluxer/schema/src/domains/admin/VoiceNoiseSuppressionSchemas';
|
||||
import {resolveBlockedMessageGroupsAssignment} from '@fluxer/schema/src/domains/experiment/BlockedMessageGroupsSchemas';
|
||||
import {ExperimentAssignmentsResponse} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {resolveExpressionInfoCardAssignment} from '@fluxer/schema/src/domains/experiment/ExpressionInfoCardSchemas';
|
||||
import {resolveGuildActivityLogPresentationAssignment} from '@fluxer/schema/src/domains/experiment/GuildActivityLogPresentationSchemas';
|
||||
import {resolveMessageHoverTrackingAssignment} from '@fluxer/schema/src/domains/experiment/MessageHoverTrackingSchemas';
|
||||
import {resolveMessageKeyboardFocusAssignment} from '@fluxer/schema/src/domains/experiment/MessageKeyboardFocusSchemas';
|
||||
@@ -39,6 +40,7 @@ export function ExperimentController(app: HonoApp) {
|
||||
messageKeyboardFocusConfig,
|
||||
blockedMessageGroupsConfig,
|
||||
guildActivityLogPresentationConfig,
|
||||
expressionInfoCardConfig,
|
||||
] = await Promise.all([
|
||||
instanceConfigRepository.getExperimentDeliveryConfig(),
|
||||
instanceConfigRepository.getVoiceNoiseSuppressionConfig(),
|
||||
@@ -46,6 +48,7 @@ export function ExperimentController(app: HonoApp) {
|
||||
instanceConfigRepository.getMessageKeyboardFocusConfig(),
|
||||
instanceConfigRepository.getBlockedMessageGroupsConfig(),
|
||||
instanceConfigRepository.getGuildActivityLogPresentationConfig(),
|
||||
instanceConfigRepository.getExpressionInfoCardConfig(),
|
||||
]);
|
||||
const userId = ctx.get('user').id.toString();
|
||||
const body: ExperimentAssignmentsResponse = {
|
||||
@@ -60,6 +63,7 @@ export function ExperimentController(app: HonoApp) {
|
||||
guildActivityLogPresentationConfig,
|
||||
userId,
|
||||
),
|
||||
expression_info_card: resolveExpressionInfoCardAssignment(expressionInfoCardConfig, userId),
|
||||
},
|
||||
};
|
||||
const etag = `"${createHash('sha256').update(JSON.stringify(body)).digest('hex')}"`;
|
||||
|
||||
@@ -20,11 +20,16 @@ import {
|
||||
type ExperimentAssignmentsResponse,
|
||||
type ExperimentDeliveryConfigResponse,
|
||||
readBlockedMessageGroupsAssignment,
|
||||
readExpressionInfoCardAssignment,
|
||||
readGuildActivityLogPresentationAssignment,
|
||||
readMessageHoverTrackingAssignment,
|
||||
readMessageKeyboardFocusAssignment,
|
||||
readVoiceNoiseSuppressionAssignment,
|
||||
} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {
|
||||
DEFAULT_EXPRESSION_INFO_CARD_CONFIG,
|
||||
INERT_EXPRESSION_INFO_CARD_ASSIGNMENT,
|
||||
} from '@fluxer/schema/src/domains/experiment/ExpressionInfoCardSchemas';
|
||||
import {
|
||||
DEFAULT_GUILD_ACTIVITY_LOG_PRESENTATION_CONFIG,
|
||||
INERT_GUILD_ACTIVITY_LOG_PRESENTATION_ASSIGNMENT,
|
||||
@@ -75,6 +80,7 @@ describe('GET /experiments', () => {
|
||||
message_keyboard_focus: INERT_MESSAGE_KEYBOARD_FOCUS_ASSIGNMENT,
|
||||
blocked_message_groups: INERT_BLOCKED_MESSAGE_GROUPS_ASSIGNMENT,
|
||||
guild_activity_log_presentation: INERT_GUILD_ACTIVITY_LOG_PRESENTATION_ASSIGNMENT,
|
||||
expression_info_card: INERT_EXPRESSION_INFO_CARD_ASSIGNMENT,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -312,7 +318,53 @@ describe('GET /experiments', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves all five experiments independently', async () => {
|
||||
it('populates the expression info card key even when the rollout is disabled', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
expect(Object.hasOwn(body.assignments, 'expression_info_card')).toBe(true);
|
||||
expect(readExpressionInfoCardAssignment(body)).toEqual(INERT_EXPRESSION_INFO_CARD_ASSIGNMENT);
|
||||
});
|
||||
|
||||
it('targets an allowlisted account for the expression info card', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
await getInstanceConfigRepository().setExpressionInfoCardConfig({
|
||||
...DEFAULT_EXPRESSION_INFO_CARD_CONFIG,
|
||||
enabled: true,
|
||||
config_version: 4,
|
||||
included_user_ids: [account.userId],
|
||||
});
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
expect(readExpressionInfoCardAssignment(body)).toEqual({
|
||||
enabled: true,
|
||||
config_version: 4,
|
||||
user_targeted: true,
|
||||
source: 'user_rule',
|
||||
});
|
||||
});
|
||||
|
||||
it('leaves an account outside a zero-width expression info card rollout', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
await getInstanceConfigRepository().setExpressionInfoCardConfig({
|
||||
...DEFAULT_EXPRESSION_INFO_CARD_CONFIG,
|
||||
enabled: true,
|
||||
config_version: 2,
|
||||
});
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
expect(readExpressionInfoCardAssignment(body)).toEqual({
|
||||
enabled: true,
|
||||
config_version: 2,
|
||||
user_targeted: false,
|
||||
source: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves all six experiments independently', async () => {
|
||||
const account = await createTestAccount(harness);
|
||||
await getInstanceConfigRepository().setMessageHoverTrackingConfig({
|
||||
...DEFAULT_MESSAGE_HOVER_TRACKING_CONFIG,
|
||||
@@ -334,6 +386,11 @@ describe('GET /experiments', () => {
|
||||
enabled: true,
|
||||
rollout_basis_points: 10000,
|
||||
});
|
||||
await getInstanceConfigRepository().setExpressionInfoCardConfig({
|
||||
...DEFAULT_EXPRESSION_INFO_CARD_CONFIG,
|
||||
enabled: true,
|
||||
rollout_basis_points: 10000,
|
||||
});
|
||||
|
||||
const body = await createBuilder<ExperimentAssignmentsResponse>(harness, account.token).get(ENDPOINT).execute();
|
||||
|
||||
@@ -341,6 +398,7 @@ describe('GET /experiments', () => {
|
||||
expect(readMessageKeyboardFocusAssignment(body).user_targeted).toBe(true);
|
||||
expect(readBlockedMessageGroupsAssignment(body).user_targeted).toBe(true);
|
||||
expect(readGuildActivityLogPresentationAssignment(body).user_targeted).toBe(true);
|
||||
expect(readExpressionInfoCardAssignment(body).user_targeted).toBe(true);
|
||||
expect(readVoiceNoiseSuppressionAssignment(body).enabled).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -15,11 +15,13 @@ import type {GuildMember} from '@app/api/models/GuildMember';
|
||||
import type {GuildRole} from '@app/api/models/GuildRole';
|
||||
import type {GuildSticker} from '@app/api/models/GuildSticker';
|
||||
import {getCachedUserPartialResponse, getCachedUserPartialResponses} from '@app/api/user/UserCacheHelpers';
|
||||
import type {
|
||||
GuildEmojiResponse,
|
||||
GuildEmojiWithUserResponse,
|
||||
GuildStickerResponse,
|
||||
GuildStickerWithUserResponse,
|
||||
import {
|
||||
GUILD_EXPRESSION_SOURCE_BADGE_FEATURES,
|
||||
type GuildEmojiResponse,
|
||||
type GuildEmojiWithUserResponse,
|
||||
type GuildExpressionSourceGuildResponse,
|
||||
type GuildStickerResponse,
|
||||
type GuildStickerWithUserResponse,
|
||||
} from '@fluxer/schema/src/domains/guild/GuildEmojiSchemas';
|
||||
import type {GuildBanResponse, GuildMemberResponse} from '@fluxer/schema/src/domains/guild/GuildMemberSchemas';
|
||||
import type {GuildPartialResponse, GuildResponse} from '@fluxer/schema/src/domains/guild/GuildResponseSchemas';
|
||||
@@ -50,6 +52,15 @@ export function mapGuildToPartialResponse(guild: Guild): GuildPartialResponse {
|
||||
};
|
||||
}
|
||||
|
||||
export function mapGuildToExpressionSourceGuildResponse(guild: Guild): GuildExpressionSourceGuildResponse {
|
||||
return {
|
||||
id: guild.id.toString(),
|
||||
name: guild.name,
|
||||
icon: stripGuildIconForFeatures(guild.iconHash, guild.features),
|
||||
features: GUILD_EXPRESSION_SOURCE_BADGE_FEATURES.filter((feature) => guild.features.has(feature)),
|
||||
};
|
||||
}
|
||||
|
||||
export function mapGuildToGuildResponse(
|
||||
guild: Guild,
|
||||
options?: {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type StoredGuildAuditLogEntryResponse,
|
||||
} from '@app/api/guild/GuildAuditLogEntryMapper';
|
||||
import type {GuildAuditLogService} from '@app/api/guild/GuildAuditLogService';
|
||||
import {mapGuildToExpressionSourceGuildResponse} from '@app/api/guild/GuildModel';
|
||||
import type {IGuildRepositoryAggregate} from '@app/api/guild/repositories/IGuildRepositoryAggregate';
|
||||
import {GuildChannelService} from '@app/api/guild/services/GuildChannelService';
|
||||
import {GuildContentService} from '@app/api/guild/services/GuildContentService';
|
||||
@@ -259,6 +260,7 @@ export class GuildService {
|
||||
name: emoji.name,
|
||||
animated: emoji.isAnimated,
|
||||
allow_cloning: guild.features.has(GuildFeatures.CLONE_EMOJI_ENABLED),
|
||||
guild: mapGuildToExpressionSourceGuildResponse(guild),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -272,6 +274,7 @@ export class GuildService {
|
||||
name: sticker.name,
|
||||
animated: sticker.animated,
|
||||
allow_cloning: guild.features.has(GuildFeatures.CLONE_STICKER_ENABLED),
|
||||
guild: mapGuildToExpressionSourceGuildResponse(guild),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {createTestAccount, type TestAccount} from '@app/api/auth/tests/AuthTestUtils';
|
||||
import {getPngDataUrl} from '@app/api/emoji/tests/EmojiTestUtils';
|
||||
import {createGuild, updateGuild} from '@app/api/guild/tests/GuildTestUtils';
|
||||
import {ensureSessionStarted} from '@app/api/message/tests/MessageTestUtils';
|
||||
import {type ApiTestHarness, createApiTestHarness} from '@app/api/test/ApiTestHarness';
|
||||
import {HTTP_STATUS} from '@app/api/test/TestConstants';
|
||||
import {createBuilder} from '@app/api/test/TestRequestBuilder';
|
||||
import {GuildFeatures} from '@fluxer/constants/src/GuildConstants';
|
||||
import type {
|
||||
GuildEmojiMetadataResponse,
|
||||
GuildEmojiWithUserResponse,
|
||||
GuildStickerMetadataResponse,
|
||||
GuildStickerWithUserResponse,
|
||||
} from '@fluxer/schema/src/domains/guild/GuildEmojiSchemas';
|
||||
import type {GuildResponse} from '@fluxer/schema/src/domains/guild/GuildResponseSchemas';
|
||||
import {afterAll, beforeAll, beforeEach, describe, expect, test} from 'vitest';
|
||||
|
||||
const SOURCE_GUILD_KEYS = ['features', 'icon', 'id', 'name'];
|
||||
|
||||
interface MetadataSource {
|
||||
owner: TestAccount;
|
||||
guild: GuildResponse;
|
||||
emoji: GuildEmojiWithUserResponse;
|
||||
sticker: GuildStickerWithUserResponse;
|
||||
}
|
||||
|
||||
async function createSource(harness: ApiTestHarness, name: string): Promise<MetadataSource> {
|
||||
const owner = await createTestAccount(harness);
|
||||
await ensureSessionStarted(harness, owner.token);
|
||||
const guild = await createGuild(harness, owner.token, name);
|
||||
const emoji = await createBuilder<GuildEmojiWithUserResponse>(harness, owner.token)
|
||||
.post(`/guilds/${guild.id}/emojis`)
|
||||
.body({name: 'source_emoji', image: getPngDataUrl()})
|
||||
.execute();
|
||||
const sticker = await createBuilder<GuildStickerWithUserResponse>(harness, owner.token)
|
||||
.post(`/guilds/${guild.id}/stickers`)
|
||||
.body({name: 'source_sticker', description: 'source sticker', tags: [], image: getPngDataUrl()})
|
||||
.execute();
|
||||
return {owner, guild, emoji, sticker};
|
||||
}
|
||||
|
||||
async function grantGuildFeatures(harness: ApiTestHarness, guildId: string, features: Array<string>): Promise<void> {
|
||||
await createBuilder(harness, '').post(`/test/guilds/${guildId}/features`).body({add_features: features}).execute();
|
||||
}
|
||||
|
||||
async function getEmojiMetadata(
|
||||
harness: ApiTestHarness,
|
||||
token: string,
|
||||
emojiId: string,
|
||||
): Promise<GuildEmojiMetadataResponse> {
|
||||
return createBuilder<GuildEmojiMetadataResponse>(harness, token)
|
||||
.get(`/emojis/${emojiId}/metadata`)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.execute();
|
||||
}
|
||||
|
||||
async function getStickerMetadata(
|
||||
harness: ApiTestHarness,
|
||||
token: string,
|
||||
stickerId: string,
|
||||
): Promise<GuildStickerMetadataResponse> {
|
||||
return createBuilder<GuildStickerMetadataResponse>(harness, token)
|
||||
.get(`/stickers/${stickerId}/metadata`)
|
||||
.expect(HTTP_STATUS.OK)
|
||||
.execute();
|
||||
}
|
||||
|
||||
describe('Guild expression metadata source community', () => {
|
||||
let harness: ApiTestHarness;
|
||||
beforeAll(async () => {
|
||||
harness = await createApiTestHarness();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await harness.reset();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await harness?.shutdown();
|
||||
});
|
||||
|
||||
test('returns the source community presentation for both kinds to a member and a non-member alike', async () => {
|
||||
const source = await createSource(harness, 'Metadata Presentation Source');
|
||||
const withIcon = await updateGuild(harness, source.owner.token, source.guild.id, {icon: getPngDataUrl()});
|
||||
expect(withIcon.icon).toBeTruthy();
|
||||
await grantGuildFeatures(harness, source.guild.id, [GuildFeatures.DISCOVERABLE, GuildFeatures.VERIFIED]);
|
||||
const outsider = await createTestAccount(harness);
|
||||
const responses = [
|
||||
await getEmojiMetadata(harness, source.owner.token, source.emoji.id),
|
||||
await getEmojiMetadata(harness, outsider.token, source.emoji.id),
|
||||
await getStickerMetadata(harness, source.owner.token, source.sticker.id),
|
||||
await getStickerMetadata(harness, outsider.token, source.sticker.id),
|
||||
];
|
||||
for (const response of responses) {
|
||||
expect(response.guild_id).toBe(source.guild.id);
|
||||
expect(response.guild.id).toBe(source.guild.id);
|
||||
expect(response.guild.name).toBe('Metadata Presentation Source');
|
||||
expect(response.guild.icon).toBe(withIcon.icon);
|
||||
expect(response.guild.features).toContain(GuildFeatures.DISCOVERABLE);
|
||||
expect(response.guild.features).toContain(GuildFeatures.VERIFIED);
|
||||
expect(response.allow_cloning).toBe(false);
|
||||
}
|
||||
const [memberEmoji, outsiderEmoji, memberSticker, outsiderSticker] = responses;
|
||||
expect(outsiderEmoji.guild).toEqual(memberEmoji.guild);
|
||||
expect(outsiderSticker.guild).toEqual(memberSticker.guild);
|
||||
expect(memberSticker.guild).toEqual(memberEmoji.guild);
|
||||
});
|
||||
|
||||
test('reports no badge features and no icon for a community that has neither', async () => {
|
||||
const source = await createSource(harness, 'Metadata Plain Source');
|
||||
const outsider = await createTestAccount(harness);
|
||||
const emoji = await getEmojiMetadata(harness, outsider.token, source.emoji.id);
|
||||
const sticker = await getStickerMetadata(harness, outsider.token, source.sticker.id);
|
||||
for (const response of [emoji, sticker]) {
|
||||
expect(response.guild.icon).toBeNull();
|
||||
expect(response.guild.features).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
test('exposes only id, name, icon and badge features to a non-member for both kinds', async () => {
|
||||
const source = await createSource(harness, 'Metadata Envelope Source');
|
||||
await updateGuild(harness, source.owner.token, source.guild.id, {verification_level: 1});
|
||||
await grantGuildFeatures(harness, source.guild.id, [
|
||||
GuildFeatures.DISCOVERABLE,
|
||||
GuildFeatures.VERIFIED,
|
||||
GuildFeatures.INVITES_DISABLED,
|
||||
GuildFeatures.CLONE_EMOJI_ENABLED,
|
||||
GuildFeatures.CLONE_STICKER_ENABLED,
|
||||
GuildFeatures.BANNER,
|
||||
GuildFeatures.INVITE_SPLASH,
|
||||
]);
|
||||
const outsider = await createTestAccount(harness);
|
||||
const emoji = await getEmojiMetadata(harness, outsider.token, source.emoji.id);
|
||||
const sticker = await getStickerMetadata(harness, outsider.token, source.sticker.id);
|
||||
for (const response of [emoji, sticker]) {
|
||||
expect(response.allow_cloning).toBe(true);
|
||||
expect(Object.keys(response.guild).sort()).toEqual(SOURCE_GUILD_KEYS);
|
||||
const leaked = response.guild as Record<string, unknown>;
|
||||
for (const key of [
|
||||
'banner',
|
||||
'banner_width',
|
||||
'banner_height',
|
||||
'splash',
|
||||
'splash_width',
|
||||
'splash_height',
|
||||
'embed_splash',
|
||||
'embed_splash_width',
|
||||
'embed_splash_height',
|
||||
'splash_card_alignment',
|
||||
]) {
|
||||
expect(leaked).not.toHaveProperty(key);
|
||||
}
|
||||
expect([...response.guild.features].sort()).toEqual([GuildFeatures.DISCOVERABLE, GuildFeatures.VERIFIED]);
|
||||
expect(response.guild.features).not.toContain(GuildFeatures.INVITES_DISABLED);
|
||||
expect(response.guild.features).not.toContain(GuildFeatures.CLONE_EMOJI_ENABLED);
|
||||
expect(response.guild.features).not.toContain(GuildFeatures.CLONE_STICKER_ENABLED);
|
||||
expect(response.guild.features).not.toContain(GuildFeatures.BANNER);
|
||||
}
|
||||
expect(sticker.guild).toEqual(emoji.guild);
|
||||
expect(Object.keys(emoji).sort()).toEqual(['allow_cloning', 'animated', 'guild', 'guild_id', 'id', 'name']);
|
||||
expect(Object.keys(sticker).sort()).toEqual(['allow_cloning', 'animated', 'guild', 'guild_id', 'id', 'name']);
|
||||
});
|
||||
});
|
||||
@@ -21,6 +21,10 @@ import {
|
||||
DEFAULT_EXPERIMENT_DELIVERY_CONFIG,
|
||||
type ExperimentDeliveryConfig,
|
||||
} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {
|
||||
DEFAULT_EXPRESSION_INFO_CARD_CONFIG,
|
||||
type ExpressionInfoCardConfig,
|
||||
} from '@fluxer/schema/src/domains/experiment/ExpressionInfoCardSchemas';
|
||||
import {
|
||||
DEFAULT_GUILD_ACTIVITY_LOG_PRESENTATION_CONFIG,
|
||||
type GuildActivityLogPresentationConfig,
|
||||
@@ -40,6 +44,7 @@ const MESSAGE_HOVER_TRACKING_CONFIG_KEY = 'message_hover_tracking_config';
|
||||
const MESSAGE_KEYBOARD_FOCUS_CONFIG_KEY = 'message_keyboard_focus_config';
|
||||
const BLOCKED_MESSAGE_GROUPS_CONFIG_KEY = 'blocked_message_groups_config';
|
||||
const GUILD_ACTIVITY_LOG_PRESENTATION_CONFIG_KEY = 'guild_activity_log_presentation_config';
|
||||
const EXPRESSION_INFO_CARD_CONFIG_KEY = 'expression_info_card_config';
|
||||
const EXPERIMENT_DELIVERY_CONFIG_KEY = 'experiment_delivery_config';
|
||||
const APP_PUBLIC_CONFIG_KEY = 'app_public_config';
|
||||
const INSTANCE_POLICY_CONFIG_KEY = 'instance_policy_config';
|
||||
@@ -516,6 +521,51 @@ describe('InstanceConfigRepository', () => {
|
||||
await expect(repository.getGuildActivityLogPresentationConfig()).resolves.toEqual(config);
|
||||
});
|
||||
|
||||
it('returns the default expression info card config when the key is absent', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
const kvProvider = new MockKVProvider();
|
||||
const repository = createRepository(kvProvider);
|
||||
|
||||
await expect(repository.getExpressionInfoCardConfig()).resolves.toEqual(DEFAULT_EXPRESSION_INFO_CARD_CONFIG);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{name: 'unparseable text', stored: 'not-json'},
|
||||
{name: 'a json array', stored: '[]'},
|
||||
{name: 'out-of-range values', stored: '{"rollout_basis_points":99999}'},
|
||||
{name: 'a target that is not a snowflake', stored: '{"included_user_ids":["nope"]}'},
|
||||
])('falls back to the default expression info card config for $name', async ({stored}) => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
const kvProvider = new MockKVProvider();
|
||||
const repository = createRepository(kvProvider);
|
||||
|
||||
await repository.setConfig(EXPRESSION_INFO_CARD_CONFIG_KEY, stored);
|
||||
|
||||
await expect(repository.getExpressionInfoCardConfig()).resolves.toEqual(DEFAULT_EXPRESSION_INFO_CARD_CONFIG);
|
||||
});
|
||||
|
||||
it('round-trips a stored expression info card config', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
const kvProvider = new MockKVProvider();
|
||||
const repository = createRepository(kvProvider);
|
||||
|
||||
const config: ExpressionInfoCardConfig = {
|
||||
...DEFAULT_EXPRESSION_INFO_CARD_CONFIG,
|
||||
enabled: true,
|
||||
config_version: 5,
|
||||
rollout_basis_points: 2500,
|
||||
rollout_salt: 'expression-info-card-v2',
|
||||
included_user_ids: ['1400000000000000001'],
|
||||
excluded_user_ids: ['1400000000000000002'],
|
||||
};
|
||||
await repository.setExpressionInfoCardConfig(config);
|
||||
|
||||
await expect(repository.getExpressionInfoCardConfig()).resolves.toEqual(config);
|
||||
});
|
||||
|
||||
it('fills newly added voice noise suppression fields from the schema defaults', async () => {
|
||||
const executor = new CountingInMemoryCassandraQueryExecutor();
|
||||
setCassandraQueryExecutorForTesting(executor);
|
||||
|
||||
@@ -40,6 +40,10 @@ import {
|
||||
type ExperimentDeliveryConfig,
|
||||
ExperimentDeliveryConfigSchema,
|
||||
} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {
|
||||
type ExpressionInfoCardConfig,
|
||||
ExpressionInfoCardConfigSchema,
|
||||
} from '@fluxer/schema/src/domains/experiment/ExpressionInfoCardSchemas';
|
||||
import {
|
||||
type GuildActivityLogPresentationConfig,
|
||||
GuildActivityLogPresentationConfigSchema,
|
||||
@@ -75,6 +79,7 @@ const EXPERIMENT_DELIVERY_CONFIG_KEY = 'experiment_delivery_config';
|
||||
const MESSAGE_HOVER_TRACKING_CONFIG_KEY = 'message_hover_tracking_config';
|
||||
const MESSAGE_KEYBOARD_FOCUS_CONFIG_KEY = 'message_keyboard_focus_config';
|
||||
const BLOCKED_MESSAGE_GROUPS_CONFIG_KEY = 'blocked_message_groups_config';
|
||||
const EXPRESSION_INFO_CARD_CONFIG_KEY = 'expression_info_card_config';
|
||||
const REGISTRATION_CONFIG_KEY = 'registration_config';
|
||||
const REGISTRATION_URLS_KEY = 'registration_urls';
|
||||
const REGISTRATION_PENDING_APPROVALS_KEY = 'registration_pending_approvals';
|
||||
@@ -362,6 +367,7 @@ type StoredConfigSection =
|
||||
| 'message hover tracking'
|
||||
| 'message keyboard focus'
|
||||
| 'blocked message groups'
|
||||
| 'expression info card'
|
||||
| 'instance policy'
|
||||
| 'integrations'
|
||||
| 'media'
|
||||
@@ -519,6 +525,10 @@ function parseStoredBlockedMessageGroupsConfig(raw: string | null): BlockedMessa
|
||||
return parseStoredConfigOrDefault(BlockedMessageGroupsConfigSchema, raw, 'blocked message groups');
|
||||
}
|
||||
|
||||
function parseStoredExpressionInfoCardConfig(raw: string | null): ExpressionInfoCardConfig {
|
||||
return parseStoredConfigOrDefault(ExpressionInfoCardConfigSchema, raw, 'expression info card');
|
||||
}
|
||||
|
||||
function validateStoredCollection<T>(schema: z.ZodType<T>, value: unknown, section: StoredConfigSection): Array<T> {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error(`Stored ${section} configuration must be an array`);
|
||||
@@ -1042,6 +1052,7 @@ export class InstanceConfigRepository {
|
||||
parseStoredMessageHoverTrackingConfig(snapshot.get(MESSAGE_HOVER_TRACKING_CONFIG_KEY) ?? null);
|
||||
parseStoredMessageKeyboardFocusConfig(snapshot.get(MESSAGE_KEYBOARD_FOCUS_CONFIG_KEY) ?? null);
|
||||
parseStoredBlockedMessageGroupsConfig(snapshot.get(BLOCKED_MESSAGE_GROUPS_CONFIG_KEY) ?? null);
|
||||
parseStoredExpressionInfoCardConfig(snapshot.get(EXPRESSION_INFO_CARD_CONFIG_KEY) ?? null);
|
||||
const policy = parseStoredInstancePolicyConfig(snapshot.get(INSTANCE_POLICY_CONFIG_KEY) ?? null);
|
||||
checkStoredConfig('registration', () =>
|
||||
parseStoredRegistrationConfig(snapshot.get(REGISTRATION_CONFIG_KEY) ?? null),
|
||||
@@ -1171,6 +1182,16 @@ export class InstanceConfigRepository {
|
||||
await this.setConfig(BLOCKED_MESSAGE_GROUPS_CONFIG_KEY, JSON.stringify(validated));
|
||||
}
|
||||
|
||||
async getExpressionInfoCardConfig(): Promise<ExpressionInfoCardConfig> {
|
||||
const raw = await this.getConfig(EXPRESSION_INFO_CARD_CONFIG_KEY);
|
||||
return parseStoredExpressionInfoCardConfig(raw);
|
||||
}
|
||||
|
||||
async setExpressionInfoCardConfig(config: ExpressionInfoCardConfig): Promise<void> {
|
||||
const validated = validateStoredConfig(ExpressionInfoCardConfigSchema, config, 'expression info card');
|
||||
await this.setConfig(EXPRESSION_INFO_CARD_CONFIG_KEY, JSON.stringify(validated));
|
||||
}
|
||||
|
||||
async setExperimentDeliveryConfig(config: ExperimentDeliveryConfig): Promise<void> {
|
||||
const validated = validateStoredConfig(ExperimentDeliveryConfigSchema, config, 'experiment delivery');
|
||||
await this.setConfig(EXPERIMENT_DELIVERY_CONFIG_KEY, JSON.stringify(validated));
|
||||
|
||||
@@ -24858,9 +24858,10 @@
|
||||
"allow_cloning": {
|
||||
"type": "boolean",
|
||||
"description": "Whether the source guild allows non-members to use the in-app clone shortcut"
|
||||
}
|
||||
},
|
||||
"guild": {"$ref": "#/components/schemas/GuildExpressionSourceGuildResponse"}
|
||||
},
|
||||
"required": ["id", "guild_id", "name", "animated", "allow_cloning"],
|
||||
"required": ["id", "guild_id", "name", "animated", "allow_cloning", "guild"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"GlobalSearchMessagesRequest": {
|
||||
@@ -28264,7 +28265,8 @@
|
||||
"blocked_message_groups": {"$ref": "#/components/schemas/BlockedMessageGroupsAssignmentResponse"},
|
||||
"guild_activity_log_presentation": {
|
||||
"$ref": "#/components/schemas/GuildActivityLogPresentationAssignmentResponse"
|
||||
}
|
||||
},
|
||||
"expression_info_card": {"$ref": "#/components/schemas/ExpressionInfoCardAssignmentResponse"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -28288,9 +28290,10 @@
|
||||
"allow_cloning": {
|
||||
"type": "boolean",
|
||||
"description": "Whether the source guild allows non-members to use the in-app clone shortcut"
|
||||
}
|
||||
},
|
||||
"guild": {"$ref": "#/components/schemas/GuildExpressionSourceGuildResponse"}
|
||||
},
|
||||
"required": ["id", "guild_id", "name", "animated", "allow_cloning"],
|
||||
"required": ["id", "guild_id", "name", "animated", "allow_cloning", "guild"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"DonationRequestLinkRequest": {
|
||||
@@ -32002,6 +32005,33 @@
|
||||
"additionalProperties": false
|
||||
},
|
||||
"DonationCurrency": {"type": "string", "enum": ["usd", "eur", "brl", "inr", "pln", "try"]},
|
||||
"GuildExpressionSourceGuildResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {"description": "The ID of the source guild", "$ref": "#/components/schemas/SnowflakeStringType"},
|
||||
"name": {"type": "string", "description": "The name of the source guild"},
|
||||
"icon": {"anyOf": [{"type": "string"}, {"type": "null"}], "description": "The hash of the source guild icon"},
|
||||
"features": {
|
||||
"type": "array",
|
||||
"items": {"type": "string", "enum": ["VERIFIED", "PARTNERED", "DISCOVERABLE"]},
|
||||
"description": "The badge feature flags of the source guild, limited to VERIFIED, PARTNERED, and DISCOVERABLE"
|
||||
}
|
||||
},
|
||||
"required": ["id", "name", "icon", "features"],
|
||||
"additionalProperties": false,
|
||||
"description": "Public presentation of the source guild of an expression"
|
||||
},
|
||||
"ExpressionInfoCardAssignmentResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"enabled": {"type": "boolean"},
|
||||
"config_version": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991},
|
||||
"user_targeted": {"type": "boolean"},
|
||||
"source": {"anyOf": [{"type": "string", "enum": ["user_rule", "canary"]}, {"type": "null"}]}
|
||||
},
|
||||
"required": ["enabled", "config_version", "user_targeted", "source"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"GuildActivityLogPresentationAssignmentResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Reference in New Issue
Block a user