Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

refactor: trim dead code in shared packages and tools

Hampus94243cb2ab10
diff --git a/fluxer_api/src/api/admin/services/guild/AdminGuildVanityService.ts b/fluxer_api/src/api/admin/services/guild/AdminGuildVanityService.ts
index 48aaaae87..ad799bc33 100644
--- a/fluxer_api/src/api/admin/services/guild/AdminGuildVanityService.ts
+++ b/fluxer_api/src/api/admin/services/guild/AdminGuildVanityService.ts
@@ -38,16 +38,16 @@ export class AdminGuildVanityService {
const oldVanity = guild.vanityUrlCode;
if (data.vanity_url_code) {
const inviteCode = createInviteCode(data.vanity_url_code);
- const existingInvite = await inviteRepository.findUnique(inviteCode);
- if (existingInvite) {
+ const claimed = await inviteRepository.claimVanityInvite(inviteCode, guildId);
+ if (!claimed) {
throw InputValidationError.fromCode('vanity_url_code', ValidationErrorCodes.THIS_VANITY_URL_IS_ALREADY_TAKEN);
}
if (oldVanity) {
- await inviteRepository.delete(vanityCodeToInviteCode(oldVanity));
+ await inviteRepository.releaseVanityInvite(vanityCodeToInviteCode(oldVanity), guildId);
await enqueueEndGuildVisitsForCode(guildId, vanityCodeToInviteCode(oldVanity));
}
} else if (oldVanity) {
- await inviteRepository.delete(vanityCodeToInviteCode(oldVanity));
+ await inviteRepository.releaseVanityInvite(vanityCodeToInviteCode(oldVanity), guildId);
await enqueueEndGuildVisitsForCode(guildId, vanityCodeToInviteCode(oldVanity));
}
const updatedGuild = await guildRepository.upsertPartial(
diff --git a/fluxer_api/src/api/channel/services/message/MessageRequestService.ts b/fluxer_api/src/api/channel/services/message/MessageRequestService.ts
index b371d32c9..5cc0ec850 100644
--- a/fluxer_api/src/api/channel/services/message/MessageRequestService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessageRequestService.ts
@@ -79,6 +79,7 @@ export class MessageRequestService {
viewer: params.viewer,
userId: params.userId,
authChannel,
+ access,
responses,
requestCache: params.requestCache,
query: params.query,
@@ -141,6 +142,7 @@ export class MessageRequestService {
viewer: params.viewer,
userId: params.userId,
authChannel,
+ access,
messageId: params.messageId,
requestCache: params.requestCache,
});
@@ -162,6 +164,7 @@ export class MessageRequestService {
viewer: params.viewer,
userId: params.userId,
authChannel,
+ access,
responses: [response],
requestCache: params.requestCache,
});
@@ -241,6 +244,7 @@ export class MessageRequestService {
viewer: params.viewer,
userId: params.userId,
authChannel,
+ access,
responses: [response],
requestCache: params.requestCache,
});
diff --git a/fluxer_api/src/api/channel/services/message/MessageResponseDataService.ts b/fluxer_api/src/api/channel/services/message/MessageResponseDataService.ts
index 017a01aab..a2858f471 100644
--- a/fluxer_api/src/api/channel/services/message/MessageResponseDataService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessageResponseDataService.ts
@@ -5,13 +5,14 @@ import type {ChannelID, GuildID, MessageID, UserID} from '@app/api/BrandedTypes'
import {createUserID} from '@app/api/BrandedTypes';
import {Config} from '@app/api/Config';
import type {ChannelRepository} from '@app/api/channel/ChannelRepository';
+import type {AuthenticatedChannel} from '@app/api/channel/services/AuthenticatedChannel';
import {requestSvcJson} from '@app/api/infrastructure/SvcErrorReply';
import {getInstanceProductName} from '@app/api/instance/ProductName';
import {Logger} from '@app/api/Logger';
import type {Channel} from '@app/api/models/Channel';
import type {Message} from '@app/api/models/Message';
import {isJsonRecord} from '@app/api/utils/JsonBoundaryUtils';
-import {MessageTypes} from '@fluxer/constants/src/ChannelConstants';
+import {MessageTypes, Permissions} from '@fluxer/constants/src/ChannelConstants';
import type {MessageResponse} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import type {INatsConnectionManager} from '@pkgs/nats/src/INatsConnectionManager';
import {NatsConnectionManager} from '@pkgs/nats/src/NatsConnectionManager';
@@ -306,6 +307,18 @@ export function messageResponseAccessForGuild(sourceGuildId: GuildID | null): Me
};
}
+export async function messageResponseAccessForAuth(
+ authChannel: AuthenticatedChannel,
+): Promise<MessageResponseAccessContext> {
+ const canReadMessageHistory =
+ !authChannel.guild || (await authChannel.hasPermission(Permissions.READ_MESSAGE_HISTORY));
+ return {
+ sourceGuildId: authChannel.channel.guildId,
+ messageHistoryCutoff: canReadMessageHistory ? null : (authChannel.guild?.message_history_cutoff ?? null),
+ canReadMessageHistory,
+ };
+}
+
function serializeMessageForService(message: Message): Record<string, unknown> {
const row = serializeValue(message.toRow()) as Record<string, unknown>;
row.pinned = message.pinnedTimestamp != null;
diff --git a/fluxer_api/src/api/channel/services/message/MessageRetrievalService.ts b/fluxer_api/src/api/channel/services/message/MessageRetrievalService.ts
index af9fe5e8e..f0e48eeda 100644
--- a/fluxer_api/src/api/channel/services/message/MessageRetrievalService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessageRetrievalService.ts
@@ -12,6 +12,7 @@ import type {MessageProcessingService} from '@app/api/channel/services/message/M
import {
createMessageResponseDataService,
type MessageResponseAccessContext,
+ messageResponseAccessForAuth,
} from '@app/api/channel/services/message/MessageResponseDataService';
import type {MessageSearchService} from '@app/api/channel/services/message/MessageSearchService';
import {maskThreadArtifactsFor, ThreadMessageResponses} from '@app/api/channel/services/message/ThreadMessageResponses';
@@ -106,16 +107,7 @@ export class MessageRetrievalService {
if (params.messageId && !(await this.canAccessMessage(authChannel, params.messageId))) {
throw new UnknownMessageError();
}
- const canReadMessageHistory =
- !authChannel.guild || (await authChannel.hasPermission(Permissions.READ_MESSAGE_HISTORY));
- return {
- authChannel,
- access: {
- sourceGuildId: authChannel.channel.guildId,
- messageHistoryCutoff: canReadMessageHistory ? null : (authChannel.guild?.message_history_cutoff ?? null),
- canReadMessageHistory,
- },
- };
+ return {authChannel, access: await messageResponseAccessForAuth(authChannel)};
}
async getMessage({
diff --git a/fluxer_api/src/api/channel/services/message/ThreadMessageResponses.ts b/fluxer_api/src/api/channel/services/message/ThreadMessageResponses.ts
index e77bf3575..e55d562b1 100644
--- a/fluxer_api/src/api/channel/services/message/ThreadMessageResponses.ts
+++ b/fluxer_api/src/api/channel/services/message/ThreadMessageResponses.ts
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import type {ChannelID, GuildID, MessageID, UserID} from '@app/api/BrandedTypes';
+import type {ChannelID, MessageID, UserID} from '@app/api/BrandedTypes';
import {channelIdToMessageId, createChannelID, createMessageID} from '@app/api/BrandedTypes';
import type {ChannelRepository} from '@app/api/channel/ChannelRepository';
import type {AuthenticatedChannel} from '@app/api/channel/services/AuthenticatedChannel';
-import {
- type MessageResponseDataService,
- messageResponseAccessForGuild,
+import type {
+ MessageResponseAccessContext,
+ MessageResponseDataService,
} from '@app/api/channel/services/message/MessageResponseDataService';
import {mapThreadToResponse} from '@app/api/channel/services/thread/ThreadMappers';
import {type ThreadViewer, viewerActive} from '@app/api/experiment/ChannelThreadsGate';
@@ -113,6 +113,7 @@ export class ThreadMessageResponses {
viewer: ThreadViewer;
userId: UserID;
authChannel: AuthenticatedChannel;
+ access: MessageResponseAccessContext;
responses: Array<MessageResponse>;
requestCache: RequestCache;
query?: ThreadListQuery;
@@ -137,6 +138,7 @@ export class ThreadMessageResponses {
viewer: ThreadViewer;
userId: UserID;
authChannel: AuthenticatedChannel;
+ access: MessageResponseAccessContext;
messageId: MessageID;
requestCache: RequestCache;
}): Promise<MessageResponse | null> {
@@ -147,8 +149,7 @@ export class ThreadMessageResponses {
async getFirstMessages(params: {
userId: UserID;
- guildId: GuildID;
- canReadMessageHistory: boolean;
+ access: MessageResponseAccessContext;
threadIds: Array<ChannelID>;
}): Promise<Map<string, MessageResponse>> {
if (params.threadIds.length === 0) return new Map();
@@ -161,11 +162,7 @@ export class ThreadMessageResponses {
const responses = await this.responseDataService.buildMessages({
userId: params.userId,
messages: found,
- access: {
- sourceGuildId: params.guildId,
- messageHistoryCutoff: null,
- canReadMessageHistory: params.canReadMessageHistory,
- },
+ access: params.access,
});
return new Map(responses.map((response) => [response.channel_id, response]));
}
@@ -199,6 +196,7 @@ export class ThreadMessageResponses {
private async buildStarter(params: {
userId: UserID;
authChannel: AuthenticatedChannel;
+ access: MessageResponseAccessContext;
requestCache: RequestCache;
}): Promise<MessageResponse | null> {
const thread = params.authChannel.thread;
@@ -208,7 +206,7 @@ export class ThreadMessageResponses {
userId: params.userId,
channelId: thread.parent.id,
messageId: createMessageID(BigInt(channel.id)),
- access: messageResponseAccessForGuild(channel.guildId),
+ access: params.access,
});
const author =
source?.author ??
diff --git a/fluxer_api/src/api/channel/services/thread/ThreadCreationService.ts b/fluxer_api/src/api/channel/services/thread/ThreadCreationService.ts
index 110172142..f97c4ffc2 100644
--- a/fluxer_api/src/api/channel/services/thread/ThreadCreationService.ts
+++ b/fluxer_api/src/api/channel/services/thread/ThreadCreationService.ts
@@ -17,6 +17,7 @@ import type {AuthenticatedChannel} from '@app/api/channel/services/Authenticated
import {withChannelFollowLock} from '@app/api/channel/services/ChannelFollowers';
import {dispatchChannelEvent} from '@app/api/channel/services/ChannelGatewayDispatch';
import {buildBroadcastMessageData} from '@app/api/channel/services/message/MessageGatewayDispatch';
+import {messageResponseAccessForGuild} from '@app/api/channel/services/message/MessageResponseDataService';
import {MessageWriteLock} from '@app/api/channel/services/message/MessageWriteLock';
import {resolveAppliedTags} from '@app/api/channel/services/thread/ForumTagRules';
import {assertThreadAllowed} from '@app/api/channel/services/thread/ThreadDenials';
@@ -558,6 +559,7 @@ export class ThreadCreationService {
viewer,
userId,
authChannel: threadAuth,
+ access: messageResponseAccessForGuild(view.channel.guildId),
messageId: createMessageID(BigInt(view.channel.id)),
requestCache,
});
diff --git a/fluxer_api/src/api/channel/services/thread/ThreadForumService.ts b/fluxer_api/src/api/channel/services/thread/ThreadForumService.ts
index ed6415679..4a5d4ca04 100644
--- a/fluxer_api/src/api/channel/services/thread/ThreadForumService.ts
+++ b/fluxer_api/src/api/channel/services/thread/ThreadForumService.ts
@@ -2,6 +2,7 @@
import {type ChannelID, createUserID, type UserID} from '@app/api/BrandedTypes';
import type {AuthenticatedChannel} from '@app/api/channel/services/AuthenticatedChannel';
+import {messageResponseAccessForAuth} from '@app/api/channel/services/message/MessageResponseDataService';
import {assertThreadAllowed} from '@app/api/channel/services/thread/ThreadDenials';
import {mapThreadMemberToResponse, mapThreadToResponse} from '@app/api/channel/services/thread/ThreadMappers';
import type {ThreadServiceContext} from '@app/api/channel/services/thread/ThreadServiceContext';
@@ -59,8 +60,7 @@ export class ThreadForumService {
channelData.listChannels(threadIds),
this.ctx.threadMessageResponses.getFirstMessages({
userId: params.userId,
- guildId,
- canReadMessageHistory: true,
+ access: await messageResponseAccessForAuth(parentAuth),
threadIds,
}),
]);
@@ -187,8 +187,7 @@ export class ThreadForumService {
if (THREAD_ONLY_CHANNEL_TYPES.has(parent.type)) {
const firstMessages = await this.ctx.threadMessageResponses.getFirstMessages({
userId: params.userId,
- guildId,
- canReadMessageHistory: true,
+ access: await messageResponseAccessForAuth(parentAuth),
threadIds,
});
response.first_messages = threadIds.flatMap((threadId) => {
diff --git a/fluxer_api/src/api/channel/tests/ThreadMessagePath.test.ts b/fluxer_api/src/api/channel/tests/ThreadMessagePath.test.ts
index b18e927b6..2938e9876 100644
--- a/fluxer_api/src/api/channel/tests/ThreadMessagePath.test.ts
+++ b/fluxer_api/src/api/channel/tests/ThreadMessagePath.test.ts
@@ -4,7 +4,14 @@ import {createTestAccount, type TestAccount} from '@app/api/auth/tests/AuthTestU
import {createChannelID, createGuildID, createUserID} from '@app/api/BrandedTypes';
import {authorizeBot, createTestBotAccount} from '@app/api/bot/tests/BotTestUtils';
import {ChannelRepository} from '@app/api/channel/ChannelRepository';
-import {acceptInvite, createChannel, createChannelInvite, createGuild} from '@app/api/channel/tests/ChannelTestUtils';
+import {
+ acceptInvite,
+ createChannel,
+ createChannelInvite,
+ createGuild,
+ createPermissionOverwrite,
+ updateGuild,
+} from '@app/api/channel/tests/ChannelTestUtils';
import {threadsRequest} from '@app/api/channel/tests/ThreadTestUtils';
import {upsertOne} from '@app/api/database/CassandraQueryExecution';
import {clearChannelThreadsTaintCacheForTesting} from '@app/api/experiment/ChannelThreadsGate';
@@ -23,6 +30,7 @@ import {ThreadPermissionFlags} from '@fluxer/constants/src/ThreadPermissionUtils
import type {ThreadChannelResponse} from '@fluxer/schema/src/domains/channel/ThreadRequestSchemas';
import type {GuildAuditLogListResponse} from '@fluxer/schema/src/domains/guild/GuildAuditLogSchemas';
import type {MessageResponse} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
+import {extractTimestamp} from '@fluxer/snowflake/src/SnowflakeUtils';
import {afterAll, beforeAll, beforeEach, describe, expect, it} from 'vitest';
interface Setup {
@@ -295,6 +303,29 @@ describe('thread message path', () => {
expect(await threadState(thread.id)).not.toBeNull();
});
+ it('hides the starter source from members who cannot read it in the parent', async () => {
+ const s = await setup();
+ const source = await sendMessage(harness, s.owner.token, s.channelId, 'source');
+ const thread = await threadsRequest<ThreadChannelResponse>(harness, s.owner.token)
+ .post(`/channels/${s.channelId}/messages/${source.id}/threads`)
+ .body({name: 'discussion'})
+ .expect(201)
+ .execute();
+ await updateGuild(harness, s.owner.token, s.guildId, {
+ message_history_cutoff: new Date(extractTimestamp(source.id) + 1).toISOString(),
+ });
+ await createPermissionOverwrite(harness, s.owner.token, s.channelId, s.member.userId, {
+ type: 1,
+ allow: Permissions.VIEW_CHANNEL.toString(),
+ deny: Permissions.READ_MESSAGE_HISTORY.toString(),
+ });
+ const [starter] = await listMessages(s.member.token, thread.id);
+ expect(starter).toMatchObject({id: thread.id, type: MessageTypes.THREAD_STARTER_MESSAGE});
+ expect(starter?.referenced_message).toBeNull();
+ const [ownerStarter] = await listMessages(s.owner.token, thread.id);
+ expect(ownerStarter?.referenced_message?.content).toBe('source');
+ });
+
it('decrements the message count on delete and counts system messages', async () => {
const s = await setup();
const thread = await startThread(s.owner.token, s.channelId);
diff --git a/fluxer_api/src/api/guild/services/data/GuildVanityService.ts b/fluxer_api/src/api/guild/services/data/GuildVanityService.ts
index 59885969e..a33cce9ce 100644
--- a/fluxer_api/src/api/guild/services/data/GuildVanityService.ts
+++ b/fluxer_api/src/api/guild/services/data/GuildVanityService.ts
@@ -14,7 +14,7 @@ import type {InviteRepository} from '@app/api/invite/InviteRepository';
import type {RequestCache} from '@app/api/middleware/RequestCacheMiddleware';
import {serializeGuildForAudit} from '@app/api/utils/AuditSerializationUtils';
import {AuditLogActionType} from '@fluxer/constants/src/AuditLogActionType';
-import {InviteTypes, Permissions} from '@fluxer/constants/src/ChannelConstants';
+import {Permissions} from '@fluxer/constants/src/ChannelConstants';
import {GuildFeatures} from '@fluxer/constants/src/GuildConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
@@ -77,7 +77,7 @@ export class GuildVanityService {
if (guild.vanityUrlCode != null) {
const oldInvite = await this.inviteRepository.findUnique(vanityCodeToInviteCode(guild.vanityUrlCode));
if (oldInvite) {
- await this.inviteRepository.delete(oldInvite.code);
+ await this.inviteRepository.releaseVanityInvite(oldInvite.code, guildId);
await enqueueEndGuildVisitsForCode(guildId, oldInvite.code);
}
const updatedGuild = await this.guildRepository.upsertPartial(guildId, {vanity_url_code: null}, guild.toRow());
@@ -94,14 +94,14 @@ export class GuildVanityService {
}
return {code: null};
}
- const existingInvite = await this.inviteRepository.findUnique(createInviteCode(code));
- if (existingInvite != null) {
+ const claimed = await this.inviteRepository.claimVanityInvite(createInviteCode(code), guildId);
+ if (claimed == null) {
throw InputValidationError.fromCode('code', ValidationErrorCodes.VANITY_URL_CODE_ALREADY_TAKEN);
}
if (guild.vanityUrlCode != null) {
const oldInvite = await this.inviteRepository.findUnique(vanityCodeToInviteCode(guild.vanityUrlCode));
if (oldInvite) {
- await this.inviteRepository.delete(oldInvite.code);
+ await this.inviteRepository.releaseVanityInvite(oldInvite.code, guildId);
await enqueueEndGuildVisitsForCode(guildId, oldInvite.code);
}
}
diff --git a/fluxer_api/src/api/guild/tests/GuildVanityClaim.test.ts b/fluxer_api/src/api/guild/tests/GuildVanityClaim.test.ts
new file mode 100644
index 000000000..15e69fbb3
--- /dev/null
+++ b/fluxer_api/src/api/guild/tests/GuildVanityClaim.test.ts
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {createTestAccount} from '@app/api/auth/tests/AuthTestUtils';
+import {createGuild} from '@app/api/guild/tests/GuildTestUtils';
+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 {beforeAll, beforeEach, describe, expect, it} from 'vitest';
+
+describe('Guild vanity URL claim', () => {
+ let harness: ApiTestHarness;
+ beforeAll(async () => {
+ harness = await createApiTestHarness();
+ });
+ beforeEach(async () => {
+ await harness.reset();
+ });
+ it('gives a vanity code to only one of two communities claiming it at once', async () => {
+ const owners = await Promise.all([createTestAccount(harness), createTestAccount(harness)]);
+ const guilds = await Promise.all(owners.map((owner, i) => createGuild(harness, owner.token, `Vanity ${i}`)));
+ for (const guild of guilds) {
+ await createBuilder(harness, '')
+ .post(`/test/guilds/${guild.id}/features`)
+ .body({add_features: [GuildFeatures.VANITY_URL]})
+ .execute();
+ }
+ const results = await Promise.all(
+ guilds.map((guild, i) =>
+ createBuilder(harness, owners[i]!.token)
+ .patch(`/guilds/${guild.id}/vanity-url`)
+ .body({code: 'samecode'})
+ .executeRaw(),
+ ),
+ );
+ const statuses = results.map((result) => result.response.status).sort();
+ expect(statuses).toEqual([HTTP_STATUS.OK, HTTP_STATUS.BAD_REQUEST].sort());
+ const codes = await Promise.all(
+ guilds.map(async (guild, i) => {
+ const response = await createBuilder<{code: string | null}>(harness, owners[i]!.token)
+ .get(`/guilds/${guild.id}/vanity-url`)
+ .execute();
+ return response.code;
+ }),
+ );
+ const winner = results.findIndex((result) => result.response.status === HTTP_STATUS.OK);
+ expect(codes[winner]).toBe('samecode');
+ expect(codes[1 - winner]).toBeNull();
+ });
+});
diff --git a/fluxer_api/src/api/invite/InviteRepository.ts b/fluxer_api/src/api/invite/InviteRepository.ts
index 366d4fb76..9bbafea4d 100644
--- a/fluxer_api/src/api/invite/InviteRepository.ts
+++ b/fluxer_api/src/api/invite/InviteRepository.ts
@@ -4,6 +4,7 @@ import type {ChannelID, GuildID, InviteCode, UserID} from '@app/api/BrandedTypes
import {createInviteCode} from '@app/api/BrandedTypes';
import {
BatchBuilder,
+ deleteOneOrMany,
executeConditional,
fetchMany,
fetchOne,
@@ -13,6 +14,7 @@ import {Db} from '@app/api/database/CassandraTypes';
import type {InviteRow} from '@app/api/database/types/ChannelTypes';
import {Invite} from '@app/api/models/Invite';
import {Invites, InvitesByChannel, InvitesByGuild} from '@app/api/Tables';
+import {InviteTypes} from '@fluxer/constants/src/ChannelConstants';
const FETCH_INVITE_BY_CODE_CQL = Invites.selectCql({
where: Invites.where.eq('code'),
@@ -171,6 +173,31 @@ export class InviteRepository {
return new Invite(inviteRow);
}
+ async claimVanityInvite(code: InviteCode, guildId: GuildID): Promise<Invite | null> {
+ const inviteRow: InviteRow = {
+ code,
+ type: InviteTypes.GUILD,
+ guild_id: guildId,
+ channel_id: null,
+ inviter_id: null,
+ created_at: new Date(),
+ uses: 0,
+ max_uses: 0,
+ max_age: 0,
+ temporary: false,
+ version: 1,
+ };
+ const applied = await executeConditional(Invites.insertIfNotExists(inviteRow));
+ if (!applied) return null;
+ await upsertOne(InvitesByGuild.upsertAll({guild_id: guildId, code}));
+ return new Invite(inviteRow);
+ }
+
+ async releaseVanityInvite(code: InviteCode, guildId: GuildID): Promise<void> {
+ await executeConditional(Invites.conditionalDeleteByPk({code}, {guild_id: guildId}));
+ await deleteOneOrMany(InvitesByGuild.deleteByPk({guild_id: guildId, code}));
+ }
+
async updateInviteUses(code: InviteCode, uses: number, invite: Invite): Promise<void> {
if (invite.maxAge > 0) {
await upsertOne(
diff --git a/fluxer_api/src/api/oauth/tests/OAuth2ScopeEnforcement.test.ts b/fluxer_api/src/api/oauth/tests/OAuth2ScopeEnforcement.test.ts
index 0dace2bfe..4f426d8eb 100644
--- a/fluxer_api/src/api/oauth/tests/OAuth2ScopeEnforcement.test.ts
+++ b/fluxer_api/src/api/oauth/tests/OAuth2ScopeEnforcement.test.ts
@@ -27,6 +27,9 @@ interface UserMeResponse {
id: string;
username: string;
email?: string | null;
+ verified?: boolean;
+ premium_type?: number | null;
+ terms_agreed_at?: string | null;
}
interface UserGuildResponse {
@@ -211,6 +214,11 @@ describe('OAuth2 Scope Enforcement', () => {
.expect(HTTP_STATUS.OK)
.execute();
expect(json.email).toBeNull();
+ expect(json.verified).toBe(false);
+ expect(json.premium_type).toBeNull();
+ expect(json.terms_agreed_at).toBeNull();
+ expect(json).not.toHaveProperty('timezone');
+ expect(json).not.toHaveProperty('account_tier');
});
test('Token with identify and email can access both user info and email', async () => {
const account = await createTestAccount(harness);
diff --git a/fluxer_api/src/api/test/NoopGatewayService.ts b/fluxer_api/src/api/test/NoopGatewayService.ts
index 423505088..bd9c26c60 100644
--- a/fluxer_api/src/api/test/NoopGatewayService.ts
+++ b/fluxer_api/src/api/test/NoopGatewayService.ts
@@ -285,7 +285,7 @@ export class NoopGatewayService implements IGatewayService {
if (!userHighest || !this.roleOutranks(userHighest, targetRole)) {
return false;
}
- return this.checkTargetMember({guildId, userId, targetUserId});
+ return userId === targetUserId || this.checkTargetMember({guildId, userId, targetUserId});
}
async canManageRole(params: {guildId: GuildID; userId: UserID; roleId: RoleID}): Promise<boolean> {
diff --git a/fluxer_api/src/api/user/controllers/UserAccountController.ts b/fluxer_api/src/api/user/controllers/UserAccountController.ts
index ef1495ff2..18be310cb 100644
--- a/fluxer_api/src/api/user/controllers/UserAccountController.ts
+++ b/fluxer_api/src/api/user/controllers/UserAccountController.ts
@@ -116,7 +116,7 @@ export function UserAccountController(app: HonoApp) {
security: ['botToken', 'bearerToken', 'sessionToken'],
tags: ['Users'],
description:
- "Retrieves the current authenticated user's profile information, including account details and settings. OAuth2 bearer tokens require identify scope, and email is returned only when the email scope is also present. Bearer tokens receive a reduced response: sensitive fields such as MFA status, authenticator types, ACLs, traits, premium billing details, and password metadata are omitted. Session and bot tokens return the full user object with all private fields.",
+ "Retrieves the current authenticated user's profile information, including account details and settings. OAuth2 bearer tokens require identify scope, and email is returned only when the email scope is also present. Bearer tokens receive a reduced response with only identity and profile fields. Session and bot tokens return the full user object with all private fields.",
}),
async (ctx) => {
const userAccountRequestService = ctx.get('userAccountRequestService');
diff --git a/fluxer_api/src/api/user/services/UserAccountRequestService.ts b/fluxer_api/src/api/user/services/UserAccountRequestService.ts
index 4193c70a0..eb383d7e2 100644
--- a/fluxer_api/src/api/user/services/UserAccountRequestService.ts
+++ b/fluxer_api/src/api/user/services/UserAccountRequestService.ts
@@ -147,6 +147,7 @@ export class UserAccountRequestService {
const response = mapUserToPrivateResponse(bearerUser);
if (!includeEmail) {
response.email = null;
+ response.verified = false;
}
this.stripBearerSensitiveFields(response);
return response;
@@ -475,9 +476,26 @@ export class UserAccountRequestService {
}
private stripBearerSensitiveFields(response: UserPrivateResponse): void {
+ response.is_staff = false;
response.acls = [];
response.traits = [];
response.email_bounced = undefined;
+ response.timezone = undefined;
+ response.timezone_privacy_flags = undefined;
+ response.account_limited = undefined;
+ response.premium_type = null;
+ response.premium_grace_ends_at = null;
+ response.premium_discriminator = false;
+ response.last_voice_activity_sharing_change_at = null;
+ response.age_verified_adult = undefined;
+ response.terms_agreed_at = null;
+ response.privacy_agreed_at = null;
+ response.claimed = undefined;
+ response.account_tier = undefined;
+ response.verification_need = undefined;
+ response.has_password = undefined;
+ response.date_of_birth_required = undefined;
+ response.profile_restricted = undefined;
response.mfa_enabled = false;
response.authenticator_types = undefined;
response.password_last_changed_at = null;
diff --git a/fluxer_app/src/features/messaging/components/markdown/renderers/common/CodeElements.tsx b/fluxer_app/src/features/messaging/components/markdown/renderers/common/CodeElements.tsx
index 059c6858f..7407dab3f 100644
--- a/fluxer_app/src/features/messaging/components/markdown/renderers/common/CodeElements.tsx
+++ b/fluxer_app/src/features/messaging/components/markdown/renderers/common/CodeElements.tsx
@@ -41,6 +41,9 @@ const logger = new Logger('CodeElementsRenderer');
const KATEX_CODE_BLOCK_LANGUAGES = new Set(['katex', 'latex', 'tex']);
const ANSI_CODE_BLOCK_LANGUAGES = new Set(['ansi']);
const KATEX_CONTROL_SEQUENCE_REGEX = /\\(?:[a-zA-Z@]+|.)/gu;
+const KATEX_MACRO_DEFINITION_REGEX =
+ /\\(?:def|gdef|edef|xdef|global|let|futurelet|newcommand|renewcommand|providecommand)(?![a-zA-Z@])/u;
+const KATEX_MAX_EXPAND = 512;
type KatexModule = typeof katexDefault;
@@ -95,6 +98,9 @@ function shouldRenderKatexSource(content: string): boolean {
if (content.length > MAX_KATEX_RENDER_SOURCE_LENGTH) {
return false;
}
+ if (KATEX_MACRO_DEFINITION_REGEX.test(content)) {
+ return false;
+ }
return countKatexControlSequences(content) <= MAX_KATEX_RENDER_CONTROL_SEQUENCE_COUNT;
}
@@ -183,6 +189,7 @@ function RichCodeBlockRenderer({
throwOnError: false,
errorColor: 'var(--accent-danger)',
trust: false,
+ maxExpand: KATEX_MAX_EXPAND,
strict: false,
output: 'html',
});
diff --git a/fluxer_app/src/features/messaging/components/markdown/renderers/index.tsx b/fluxer_app/src/features/messaging/components/markdown/renderers/index.tsx
index d671190a8..93ce7998d 100644
--- a/fluxer_app/src/features/messaging/components/markdown/renderers/index.tsx
+++ b/fluxer_app/src/features/messaging/components/markdown/renderers/index.tsx
@@ -43,6 +43,7 @@ import React from 'react';
const logger = new Logger('MarkdownRenderers');
export const parse = parseMarkdownContent;
+const MAX_INTERACTIVE_EMOJI_COUNT = 100;
const renderers = {
[NodeType.Sequence]: SequenceRenderer,
@@ -87,10 +88,40 @@ function renderNode(node: Node, id: string, options: MarkdownRenderOptions): Rea
});
}
+function childNodesOf(node: Node): ReadonlyArray<Node> {
+ switch (node.type) {
+ case NodeType.List:
+ return node.items.flatMap((item) => item.children);
+ case NodeType.Table:
+ return [node.header, ...node.rows].flatMap((row) => row.cells.flatMap((cell) => cell.children));
+ case NodeType.Link:
+ return node.text ? [node.text] : [];
+ default:
+ return 'children' in node ? node.children : [];
+ }
+}
+
+function exceedsEmojiCount(nodes: ReadonlyArray<Node>, limit: number): boolean {
+ let count = 0;
+ const stack: Array<Node> = [...nodes];
+ while (stack.length > 0) {
+ const node = stack.pop()!;
+ if (node.type === NodeType.Emoji) {
+ count++;
+ if (count > limit) return true;
+ continue;
+ }
+ stack.push(...childNodesOf(node));
+ }
+ return false;
+}
+
export function render(nodes: Array<Node>, options: MarkdownParseOptions): React.ReactNode {
const shouldJumboEmojis = options.context === MarkdownContext.STANDARD_WITH_JUMBO && shouldRenderAsJumboEmojis(nodes);
const renderOptions: MarkdownRenderOptions = {
...options,
+ disableEmojiInteractions:
+ options.disableEmojiInteractions === true || exceedsEmojiCount(nodes, MAX_INTERACTIVE_EMOJI_COUNT),
shouldJumboEmojis,
i18n,
};
diff --git a/fluxer_app/src/features/ui/action_menu/items/GuildMemberMenuItems.tsx b/fluxer_app/src/features/ui/action_menu/items/GuildMemberMenuItems.tsx
index 874ba49d5..4f46b80a9 100644
--- a/fluxer_app/src/features/ui/action_menu/items/GuildMemberMenuItems.tsx
+++ b/fluxer_app/src/features/ui/action_menu/items/GuildMemberMenuItems.tsx
@@ -38,8 +38,10 @@ export const ManageRolesMenuItem: React.FC<ManageRolesMenuItemProps> = observer(
const {i18n} = useLingui();
const guild = Guilds.getGuild(guildId);
const currentMember = GuildMembers.getMember(guildId, member.user.id);
- const {canManageRole} = useRoleHierarchy(guild);
- const canManageRoles = Permission.can(Permissions.MANAGE_ROLES, {guildId});
+ const {canManageRole, canManageTarget} = useRoleHierarchy(guild);
+ const canManageRoles =
+ Permission.can(Permissions.MANAGE_ROLES, {guildId}) &&
+ (member.user.id === Authentication.currentUserId || canManageTarget(member.user.id));
const allRoles = useMemo(() => {
if (!guild) return [];
return Object.values(guild.roles)
diff --git a/fluxer_docs/src/content/docs/http-api/users.mdx b/fluxer_docs/src/content/docs/http-api/users.mdx
index 7a835b929..ce0686796 100644
--- a/fluxer_docs/src/content/docs/http-api/users.mdx
+++ b/fluxer_docs/src/content/docs/http-api/users.mdx
@@ -12,7 +12,7 @@ The routes on this page accept a user session token or a bot token, and an OAuth
## Partial user object
-The public account shape inside messages, relationships, guild members and applications.
+The public account object inside messages, relationships, guild members and applications.
### Structure
@@ -81,7 +81,7 @@ The current account as its owner sees it, returned by [Get current user](/http-a
| Field | Type | Description |
| --- | --- | --- |
-| is_staff | boolean | Whether the account has the staff flag, even when it is hidden from `flags` |
+| is_staff<sup>1</sup> | boolean | Whether the account has the staff flag, even when it is hidden from `flags` |
| acls<sup>1</sup> | array[string] | The [Admin API](/admin-api/users/#set-user-acls) access entries, empty for most accounts |
| traits<sup>1</sup> | array[string] | The account traits, sorted |
| email<sup>2</sup> | ?string | The email address, or null |
@@ -90,22 +90,22 @@ The current account as its owner sees it, returned by [Get current user](/http-a
| bio | ?string | The profile biography, or null |
| pronouns | ?string | The profile pronouns, or null |
| accent_color | ?integer | The profile accent color as 24-bit RGB, or null |
-| timezone? | ?string | The IANA timezone, or null |
-| timezone_privacy_flags? | integer | [Profile field privacy flags](#profile-field-privacy-flags) for the timezone |
+| timezone?<sup>1</sup> | ?string | The IANA timezone, or null |
+| timezone_privacy_flags?<sup>1</sup> | integer | [Profile field privacy flags](#profile-field-privacy-flags) for the timezone |
| banner | ?string | The profile banner hash, or null |
| banner_color | ?integer | The 24-bit RGB color taken from the banner, or null |
| mfa_enabled<sup>1</sup> | boolean | Whether any authenticator is set up |
| authenticator_types?<sup>1</sup> | array[integer] | [Authenticator types](#authenticator-types) set up for the account |
| verified<sup>2</sup> | boolean | Whether the email address is confirmed |
-| account_limited? | boolean | Whether the account is [limited](#account-limitation) |
-| premium_type | ?integer | [Premium type](#premium-types), `0` while premium is not active |
+| account_limited?<sup>1</sup> | boolean | Whether the account is [limited](#account-limitation) |
+| premium_type<sup>1</sup> | ?integer | [Premium type](#premium-types), `0` while premium is not active |
| premium_since<sup>1</sup> | ?ISO8601 timestamp | When premium started, or null while premium is not active |
| premium_until<sup>1</sup> | ?ISO8601 timestamp | When the current premium period ends, or null |
| premium_will_cancel<sup>1</sup> | boolean | Whether the premium subscription cancels at the end of the period |
| premium_billing_cycle<sup>1</sup> | ?string | The premium billing cycle, or null |
| premium_lifetime_sequence<sup>1</sup> | ?integer | The lifetime premium sequence number, or null |
-| premium_grace_ends_at | ?ISO8601 timestamp | When premium access ends after `premium_until` passes, or null |
-| premium_discriminator<sup>4</sup> | boolean | Whether the discriminator was picked with premium |
+| premium_grace_ends_at<sup>1</sup> | ?ISO8601 timestamp | When premium access ends after `premium_until` passes, or null |
+| premium_discriminator<sup>1</sup> <sup>4</sup> | boolean | Whether the discriminator was picked with premium |
| premium_badge_hidden<sup>1</sup> | boolean | Whether the premium badge is hidden from the profile |
| premium_badge_masked<sup>1</sup> | boolean | Whether a lifetime badge shows as a subscription badge |
| premium_badge_timestamp_hidden<sup>1</sup> | boolean | Whether the premium start date is hidden from the profile |
@@ -114,7 +114,7 @@ The current account as its owner sees it, returned by [Get current user](/http-a
| premium_enabled_override<sup>1</sup> | boolean | Whether an admin override grants premium |
| premium_perks_disabled<sup>1</sup> | boolean | Whether premium is suspended for the account |
| password_last_changed_at<sup>1</sup> | ?ISO8601 timestamp | When the password last changed, or null |
-| last_voice_activity_sharing_change_at | ?ISO8601 timestamp | When voice activity sharing last changed for all friends (24-hour cooldown), or null |
+| last_voice_activity_sharing_change_at<sup>1</sup> | ?ISO8601 timestamp | When voice activity sharing last changed for all friends (24-hour cooldown), or null |
| required_actions<sup>1</sup> | array[string] | Deprecated. Always empty |
| nsfw_allowed<sup>1</sup> | boolean | Whether the account can see age-restricted content |
| has_dismissed_premium_onboarding<sup>1</sup> | boolean | Whether premium onboarding was dismissed, false while premium is not active |
@@ -122,19 +122,19 @@ The current account as its owner sees it, returned by [Get current user](/http-a
| has_unread_gift_inventory<sup>1</sup> | boolean | Whether the gift inventory has unread items |
| unread_gift_inventory_count<sup>1</sup> | integer | The number of unread gift inventory items |
| pending_bulk_message_deletion<sup>1</sup> | ?[pending bulk message deletion](#pending-bulk-message-deletion-object) object | The scheduled deletion of all the account's messages, or null |
-| age_verified_adult? | boolean | Whether adult age verification is done, omitted when false |
-| terms_agreed_at | ?ISO8601 timestamp | When the account last accepted the terms, or null |
-| privacy_agreed_at | ?ISO8601 timestamp | When the account was last shown the current privacy policy, or null |
-| claimed? | boolean | Whether the account can sign in on another device with an email, a password or a passkey |
-| account_tier? | string | The [account tier](#account-tiers), `unclaimed`, `unverified` or `verified` |
-| verification_need? | ?string | `add_email`, `confirm_email` or `password` until the account is verified, then null |
-| has_password? | boolean | Whether the account has a password |
-| date_of_birth_required?<sup>3</sup> | boolean | Whether the account has to [set its date of birth](/http-api/users/current-user/#set-date-of-birth) first |
-| profile_restricted? | boolean | Whether other accounts see only the username and discriminator |
-
-<sup>1</sup> With an OAuth2 bearer token on [Get current user](/http-api/users/current-user/#get-current-user), arrays are empty, `email_bounced` and `authenticator_types` are left out, booleans are false, nullable fields are null and `unread_gift_inventory_count` is `0`
-
-<sup>2</sup> With an OAuth2 bearer token that lacks the `email` [scope](/http-api/oauth2/#oauth2-scopes), `email` is null
+| age_verified_adult?<sup>1</sup> | boolean | Whether adult age verification is done, omitted when false |
+| terms_agreed_at<sup>1</sup> | ?ISO8601 timestamp | When the account last accepted the terms, or null |
+| privacy_agreed_at<sup>1</sup> | ?ISO8601 timestamp | When the account was last shown the current privacy policy, or null |
+| claimed?<sup>1</sup> | boolean | Whether the account can sign in on another device with an email, a password or a passkey |
+| account_tier?<sup>1</sup> | string | The [account tier](#account-tiers), `unclaimed`, `unverified` or `verified` |
+| verification_need?<sup>1</sup> | ?string | `add_email`, `confirm_email` or `password` until the account is verified, then null |
+| has_password?<sup>1</sup> | boolean | Whether the account has a password |
+| date_of_birth_required?<sup>1</sup> <sup>3</sup> | boolean | Whether the account has to [set its date of birth](/http-api/users/current-user/#set-date-of-birth) first |
+| profile_restricted?<sup>1</sup> | boolean | Whether other accounts see only the username and discriminator |
+
+<sup>1</sup> With an OAuth2 bearer token on [Get current user](/http-api/users/current-user/#get-current-user), arrays are empty, optional fields are left out, booleans are false, nullable fields are null and `unread_gift_inventory_count` is `0`
+
+<sup>2</sup> With an OAuth2 bearer token that lacks the `email` [scope](/http-api/oauth2/#oauth2-scopes), `email` is null and `verified` is false
<sup>3</sup> When the [accounts configuration](/admin-api/instance/#accounts-configuration-object) enforces it, most routes return 403 `DATE_OF_BIRTH_REQUIRED` until the date is set
diff --git a/fluxer_gateway/src/guild/guild_members_roles.erl b/fluxer_gateway/src/guild/guild_members_roles.erl
index 80ffe4969..fb5be6429 100644
--- a/fluxer_gateway/src/guild/guild_members_roles.erl
+++ b/fluxer_gateway/src/guild/guild_members_roles.erl
@@ -45,13 +45,14 @@ add_user_map_ids(UserMap, AccSet) ->
lists:foldl(fun gb_sets:add/2, AccSet, maps:keys(UserMap)).
-spec can_manage_roles(map(), guild_state()) -> guild_reply(map()).
-can_manage_roles(#{user_id := UserId, target_user_id := _TU, role_id := RoleId}, State) ->
+can_manage_roles(
+ #{user_id := UserId, target_user_id := TargetUserId, role_id := RoleId}, State
+) ->
OwnerId = guild_members_common:owner_id(State),
- Reply = check_can_manage(UserId, RoleId, OwnerId, State),
- {reply, #{can_manage => Reply}, State};
-can_manage_roles(#{user_id := UserId, role_id := RoleId}, State) ->
- OwnerId = guild_members_common:owner_id(State),
- Reply = check_can_manage(UserId, RoleId, OwnerId, State),
+ Reply =
+ check_can_manage(UserId, RoleId, OwnerId, State) andalso
+ (UserId =:= TargetUserId orelse
+ check_can_manage_target(UserId, TargetUserId, OwnerId, State)),
{reply, #{can_manage => Reply}, State}.
-spec can_manage_role(map(), guild_state()) -> guild_reply(map()).
diff --git a/packages/constants/src/HttpConstants.ts b/packages/constants/src/HttpConstants.ts
index 29a8de914..dd5ff7a2e 100644
--- a/packages/constants/src/HttpConstants.ts
+++ b/packages/constants/src/HttpConstants.ts
@@ -5,7 +5,6 @@ export const HttpStatus = {
CREATED: 201,
ACCEPTED: 202,
NO_CONTENT: 204,
- PARTIAL_CONTENT: 206,
MOVED_PERMANENTLY: 301,
FOUND: 302,
SEE_OTHER: 303,
@@ -17,16 +16,9 @@ export const HttpStatus = {
FORBIDDEN: 403,
NOT_FOUND: 404,
METHOD_NOT_ALLOWED: 405,
- NOT_ACCEPTABLE: 406,
- REQUEST_TIMEOUT: 408,
CONFLICT: 409,
GONE: 410,
- LENGTH_REQUIRED: 411,
- PRECONDITION_FAILED: 412,
PAYLOAD_TOO_LARGE: 413,
- URI_TOO_LONG: 414,
- UNSUPPORTED_MEDIA_TYPE: 415,
- RANGE_NOT_SATISFIABLE: 416,
TOO_MANY_REQUESTS: 429,
INTERNAL_SERVER_ERROR: 500,
NOT_IMPLEMENTED: 501,
@@ -37,14 +29,10 @@ export const HttpStatus = {
export const MimeType = {
JSON: 'application/json',
- XML: 'application/xml',
- OCTET_STREAM: 'application/octet-stream',
PDF: 'application/pdf',
PLAIN: 'text/plain',
HTML: 'text/html',
CSS: 'text/css',
- JAVASCRIPT: 'text/javascript',
- CSV: 'text/csv',
PNG: 'image/png',
JPEG: 'image/jpeg',
GIF: 'image/gif',
diff --git a/packages/markdown_parser/rust/src/plaintext.rs b/packages/markdown_parser/rust/src/plaintext.rs
index cb1c0d1ef..65796ddd4 100644
--- a/packages/markdown_parser/rust/src/plaintext.rs
+++ b/packages/markdown_parser/rust/src/plaintext.rs
@@ -167,7 +167,7 @@ fn render_node_to_plaintext(node: &Node, options: &PlaintextOptions) -> String {
if options.preserve_markdown {
return format!(
"> [!{}]\n{}",
- alert_type_name(*alert_type).to_ascii_uppercase(),
+ label.to_ascii_uppercase(),
content
.split('\n')
.map(|line| format!("> {line}"))
@@ -442,7 +442,7 @@ fn render_nodes_to_plaintext(nodes: &[Node], options: &PlaintextOptions) -> Stri
result
}
-fn render_to_plaintext(nodes: &[Node], options: &PlaintextOptions) -> String {
+pub fn render_ast_to_plaintext(nodes: &[Node], options: &PlaintextOptions) -> String {
let rendered = render_nodes_to_plaintext(nodes, options);
let whitespace_normalized = if options.preserve_markdown {
trim_horizontal_whitespace_before_newlines_preserving_empty_blockquotes(&rendered)
diff --git a/packages/schema/src/domains/admin/AdminSchemas.ts b/packages/schema/src/domains/admin/AdminSchemas.ts
index 9495aae8a..b8da01130 100644
--- a/packages/schema/src/domains/admin/AdminSchemas.ts
+++ b/packages/schema/src/domains/admin/AdminSchemas.ts
@@ -385,20 +385,22 @@ export const BanPhraseRequest = z.object({
export type BanPhraseRequest = z.infer<typeof BanPhraseRequest>;
+const BanSeverityType = z
+ .number()
+ .int()
+ .min(0)
+ .max(3)
+ .optional()
+ .describe(
+ 'Stored severity label: 0 allow, 1 warn, 2 block, 3 block and report (default 2). The label is informational and every row blocks whatever its severity.',
+ );
+
export const BanUrlRequest = z.object({
url: createStringType(1, 2048)
.refine((v) => /^https?:\/\//i.test(v), 'Must be an absolute http(s) URL')
.describe('Absolute URL to ban. Canonicalized before storage.'),
category: createStringType(1, 64).optional().describe('Category / source slug (defaults to "manual")'),
- severity: z
- .number()
- .int()
- .min(0)
- .max(3)
- .optional()
- .describe(
- 'Stored severity label: 0 allow, 1 warn, 2 block, 3 block and report (default 2). The label is informational and every row blocks whatever its severity.',
- ),
+ severity: BanSeverityType,
source_url: createStringType(1, 2048).optional().describe('Upstream source URL if imported from a feed'),
notes: createStringType(1, 1024).optional().describe('Internal notes for audit trail'),
});
@@ -414,15 +416,7 @@ export const BanUrlDomainRequest = z.object({
.default(true)
.describe('If true, any subdomain rooted at this domain, or at a host the pattern matches, is also banned'),
category: createStringType(1, 64).optional().describe('Category / source slug (defaults to "manual")'),
- severity: z
- .number()
- .int()
- .min(0)
- .max(3)
- .optional()
- .describe(
- 'Stored severity label: 0 allow, 1 warn, 2 block, 3 block and report (default 2). The label is informational and every row blocks whatever its severity.',
- ),
+ severity: BanSeverityType,
source_url: createStringType(1, 2048).optional().describe('Upstream source URL if imported from a feed'),
notes: createStringType(1, 1024).optional().describe('Internal notes for audit trail'),
});
@@ -434,15 +428,7 @@ export const BanFileShaRequest = z.object({
.refine((v) => /^[0-9a-fA-F]{64}$/.test(v), 'Must be a 64-character hex SHA-256')
.describe('SHA-256 in hex'),
category: createStringType(1, 64).optional(),
- severity: z
- .number()
- .int()
- .min(0)
- .max(3)
- .optional()
- .describe(
- 'Stored severity label: 0 allow, 1 warn, 2 block, 3 block and report (default 2). The label is informational and every row blocks whatever its severity.',
- ),
+ severity: BanSeverityType,
content_type: createStringType(1, 128).optional().describe('Optional MIME type hint for observability'),
source_url: createStringType(1, 2048).optional(),
notes: createStringType(1, 1024).optional(),
@@ -457,15 +443,7 @@ const AvatarHashShortType = createStringType(8, 10).refine(
export const BanAvatarHashRequest = z.object({
hashes: z.array(AvatarHashShortType).min(1).max(1000),
category: createStringType(1, 64).optional(),
- severity: z
- .number()
- .int()
- .min(0)
- .max(3)
- .optional()
- .describe(
- 'Stored severity label: 0 allow, 1 warn, 2 block, 3 block and report (default 2). The label is informational and every row blocks whatever its severity.',
- ),
+ severity: BanSeverityType,
source_url: createStringType(1, 2048).optional(),
reason: createStringType(1, 1024).optional(),
notes: createStringType(1, 1024).optional(),
diff --git a/packages/voice_engine_v2/benches/baseline.json b/packages/voice_engine_v2/benches/baseline.json
deleted file mode 100644
index d7cac68da..000000000
--- a/packages/voice_engine_v2/benches/baseline.json
+++ /dev/null
@@ -1,73 +0,0 @@
-{
- "measured_at": "85e057a273fd",
- "host": "darwin-arm64-apple-silicon",
- "regression_budget_percent": 5.0,
- "note": "Vitest bench medians captured as `mean_ms` (mean over samples). check-regression.sh treats `mean_ms` like `median_ns` after scaling. p75 captured as a secondary stability hint.",
- "benches": {
- "src/runtime/VoiceEngineV2Runtime.bench.ts > dispatch inboundVideo.frameReceived": {
- "mean_ms": 0.3517,
- "p75_ms": 0.4266,
- "hz": 2843.2
- },
- "src/runtime/VoiceEngineV2Runtime.bench.ts > dispatch microphone.publishRequested": {
- "mean_ms": 0.4786,
- "p75_ms": 0.534,
- "hz": 2089.33
- },
- "src/runtime/VoiceEngineV2Runtime.bench.ts > dispatch screen.publishRequested": {
- "mean_ms": 0.474,
- "p75_ms": 0.5327,
- "hz": 2109.75
- },
- "src/runtime/VoiceEngineV2Runtime.bench.ts > dispatch room.participantJoined": {
- "mean_ms": 0.344,
- "p75_ms": 0.4121,
- "hz": 2906.83
- },
- "src/runtime/VoiceEngineV2Runtime.bench.ts > dispatch stats.collected": {
- "mean_ms": 0.3451,
- "p75_ms": 0.4295,
- "hz": 2897.74
- },
- "src/core/reducer.bench.ts > inboundVideo.frameReceived": {
- "mean_ms": 0.0001,
- "p75_ms": 0.0001,
- "hz": 7877275.4
- },
- "src/core/reducer.bench.ts > microphone.publishRequested": {
- "mean_ms": 0.0002,
- "p75_ms": 0.0002,
- "hz": 5768974.56
- },
- "src/core/reducer.bench.ts > screen.publishRequested": {
- "mean_ms": 0.0002,
- "p75_ms": 0.0002,
- "hz": 6149233.82
- },
- "src/core/reducer.bench.ts > room.participantJoined": {
- "mean_ms": 0.0001,
- "p75_ms": 0.0001,
- "hz": 11101158.62
- },
- "src/core/reducer.bench.ts > stats.collected": {
- "mean_ms": 0.0,
- "p75_ms": 0.0,
- "hz": 28019021.94
- },
- "src/runtime/snapshot.bench.ts > JSON.stringify snapshot (8 participants × 4 tracks)": {
- "mean_ms": 0.0174,
- "p75_ms": 0.018,
- "hz": 57366.32
- },
- "src/runtime/snapshot.bench.ts > JSON.parse snapshot (8 participants × 4 tracks)": {
- "mean_ms": 0.0168,
- "p75_ms": 0.0167,
- "hz": 59607.57
- },
- "src/runtime/snapshot.bench.ts > JSON.stringify + JSON.parse round-trip": {
- "mean_ms": 0.0358,
- "p75_ms": 0.0356,
- "hz": 27897.14
- }
- }
-}
diff --git a/tools/ci/src/ci_workflow.rs b/tools/ci/src/ci_workflow.rs
index fe0c0ab2d..5d12e38b0 100644
--- a/tools/ci/src/ci_workflow.rs
+++ b/tools/ci/src/ci_workflow.rs
@@ -69,14 +69,12 @@ pub async fn run_ci(args: CiArgs) -> Result<()> {
.current_dir(root),
)
}
- CiStep::GatewayFmt => {
- run_gateway_step(&root.join("fluxer_gateway"), GatewayStep::FmtCheck, "test")
- }
+ CiStep::GatewayFmt => run_gateway_step(&root.join("fluxer_gateway"), GatewayStep::FmtCheck),
CiStep::GatewayCompile => {
- run_gateway_step(&root.join("fluxer_gateway"), GatewayStep::Compile, "test")
+ run_gateway_step(&root.join("fluxer_gateway"), GatewayStep::Compile)
}
CiStep::GatewayDialyzer => {
- run_gateway_step(&root.join("fluxer_gateway"), GatewayStep::Dialyzer, "test")
+ run_gateway_step(&root.join("fluxer_gateway"), GatewayStep::Dialyzer)
}
}
}
diff --git a/tools/ci/src/common.rs b/tools/ci/src/common.rs
index 68f2c912b..6ce8731e0 100644
--- a/tools/ci/src/common.rs
+++ b/tools/ci/src/common.rs
@@ -476,7 +476,7 @@ pub(crate) async fn upload_s3_plan_append_only(
let bucket = bucket.clone();
tasks.spawn(async move {
let _permit = permit;
- let disposition = put_file_to_s3_if_absent(&client, &bucket, &item)
+ let disposition = put_file_to_s3(&client, &bucket, &item, true)
.await
.with_context(|| {
format!("Failed append-only upload for s3://{}/{}", bucket, item.key)
@@ -495,12 +495,11 @@ pub(crate) async fn upload_s3_plan_append_only(
let bucket = bucket.clone();
tasks.spawn(async move {
let _permit = permit;
- repair_existing_s3_object_metadata(&client, &bucket, &item)
+ put_file_to_s3(&client, &bucket, &item, false)
.await
.with_context(|| {
format!("Failed to repair metadata for s3://{}/{}", bucket, item.key)
- })?;
- Ok::<_, anyhow::Error>(S3UploadDisposition::MetadataRepaired)
+ })
});
} else {
println!("Skipping existing s3://{bucket}/{}", item.key);
@@ -689,13 +688,29 @@ fn ensure_unique_s3_keys(plan: &[S3UploadPlanItem]) -> Result<()> {
Ok(())
}
-async fn put_file_to_s3_if_absent(
+async fn put_file_to_s3(
client: &S3Client,
bucket: &str,
item: &S3UploadPlanItem,
+ if_absent: bool,
) -> Result<S3UploadDisposition> {
+ let (action, operation, failure, done) = if if_absent {
+ (
+ "Uploading",
+ "upload",
+ "upload",
+ S3UploadDisposition::Uploaded,
+ )
+ } else {
+ (
+ "Repairing metadata for",
+ "metadata repair",
+ "repair metadata for",
+ S3UploadDisposition::MetadataRepaired,
+ )
+ };
println!(
- "Uploading {} -> s3://{bucket}/{}",
+ "{action} {} -> s3://{bucket}/{}",
item.path.display(),
item.key
);
@@ -709,7 +724,7 @@ async fn put_file_to_s3_if_absent(
.put_object()
.bucket(bucket)
.key(&item.key)
- .if_none_match("*")
+ .set_if_none_match(if_absent.then(|| "*".to_string()))
.content_md5(identity.md5_base64.clone())
.body(body);
if let Some(content_type) = &item.content_type {
@@ -719,7 +734,7 @@ async fn put_file_to_s3_if_absent(
request = request.cache_control(cache_control);
}
match request.send().await {
- Ok(_) => return Ok(S3UploadDisposition::Uploaded),
+ Ok(_) => return Ok(done),
Err(error) => {
let code = error
.as_service_error()
@@ -728,73 +743,13 @@ async fn put_file_to_s3_if_absent(
let status = error
.raw_response()
.map(|response| response.status().as_u16());
- if is_existing_object_error(code.as_deref(), status) {
+ if if_absent && is_existing_object_error(code.as_deref(), status) {
println!("Skipping existing s3://{bucket}/{}", item.key);
return Ok(S3UploadDisposition::SkippedExisting);
}
if is_retryable_s3_error(code.as_deref(), status) && attempt < attempts {
sleep_before_s3_retry(
- "upload",
- &format!("s3://{bucket}/{}", item.key),
- attempt,
- attempts,
- code.as_deref(),
- status,
- )
- .await;
- continue;
- }
- let summary = s3_error_summary(code.as_deref(), status);
- return Err(error).with_context(|| {
- format!("Failed to upload s3://{bucket}/{}{summary}", item.key)
- });
- }
- }
- }
- unreachable!("S3 retry attempts are always greater than zero")
-}
-
-async fn repair_existing_s3_object_metadata(
- client: &S3Client,
- bucket: &str,
- item: &S3UploadPlanItem,
-) -> Result<()> {
- println!(
- "Repairing metadata for {} -> s3://{bucket}/{}",
- item.path.display(),
- item.key
- );
- let identity = s3_file_identity(&item.path)?;
- let attempts = s3_retry_attempts();
- for attempt in 1..=attempts {
- let body = ByteStream::from_path(&item.path)
- .await
- .with_context(|| format!("Failed to read {}", item.path.display()))?;
- let mut request = client
- .put_object()
- .bucket(bucket)
- .key(&item.key)
- .content_md5(identity.md5_base64.clone())
- .body(body);
- if let Some(content_type) = &item.content_type {
- request = request.content_type(content_type);
- }
- if let Some(cache_control) = &item.cache_control {
- request = request.cache_control(cache_control);
- }
- match request.send().await {
- Ok(_) => return Ok(()),
- Err(error) => {
- let code = error
- .as_service_error()
- .and_then(|error| error.code())
- .map(ToOwned::to_owned);
- let status = error
- .raw_response()
- .map(|response| response.status().as_u16());
- if is_retryable_s3_error(code.as_deref(), status) && attempt < attempts {
- sleep_before_s3_retry(
- "metadata repair",
+ operation,
&format!("s3://{bucket}/{}", item.key),
attempt,
attempts,
@@ -806,10 +761,7 @@ async fn repair_existing_s3_object_metadata(
}
let summary = s3_error_summary(code.as_deref(), status);
return Err(error).with_context(|| {
- format!(
- "Failed to repair metadata for s3://{bucket}/{}{summary}",
- item.key
- )
+ format!("Failed to {failure} s3://{bucket}/{}{summary}", item.key)
});
}
}
diff --git a/tools/ci/src/gateway.rs b/tools/ci/src/gateway.rs
index eb7df56a5..5b1662f3f 100644
--- a/tools/ci/src/gateway.rs
+++ b/tools/ci/src/gateway.rs
@@ -55,33 +55,29 @@ pub fn run_build_gateway_nifs(args: BuildGatewayNifsArgs) -> Result<()> {
pub fn run_gateway(args: GatewayArgs) -> Result<()> {
let gateway_dir = resolve_gateway_dir()?;
- run_gateway_step(&gateway_dir, args.step, &args.eqwalizer_profile)
+ run_gateway_step(&gateway_dir, args.step)
}
-pub(crate) fn run_gateway_step(
- gateway_dir: &Path,
- step: GatewayStep,
- eqwalizer_profile: &str,
-) -> Result<()> {
+pub(crate) fn run_gateway_step(gateway_dir: &Path, step: GatewayStep) -> Result<()> {
match step {
GatewayStep::Fmt => run_rebar(gateway_dir, ["fmt"]),
GatewayStep::FmtCheck => run_gateway_fmt_check(gateway_dir),
GatewayStep::Lint => run_rebar(gateway_dir, ["lint"]),
GatewayStep::Compile => run_rebar(gateway_dir, ["compile"]),
GatewayStep::Dialyzer => run_rebar(gateway_dir, ["dialyzer"]),
- GatewayStep::Typecheck => run_eqwalizer(gateway_dir, eqwalizer_profile),
+ GatewayStep::Typecheck => run_eqwalizer(gateway_dir),
GatewayStep::AllChecks => {
run_gateway_check_step("Step 1/4: Format check (erlfmt)", || {
- run_gateway_step(gateway_dir, GatewayStep::FmtCheck, eqwalizer_profile)
+ run_gateway_step(gateway_dir, GatewayStep::FmtCheck)
})?;
run_gateway_check_step("Step 2/4: Lint (elvis)", || {
- run_gateway_step(gateway_dir, GatewayStep::Lint, eqwalizer_profile)
+ run_gateway_step(gateway_dir, GatewayStep::Lint)
})?;
run_gateway_check_step("Step 3/4: Compile", || {
- run_gateway_step(gateway_dir, GatewayStep::Compile, eqwalizer_profile)
+ run_gateway_step(gateway_dir, GatewayStep::Compile)
})?;
run_gateway_check_step("Step 4/4: Type check", || {
- run_gateway_step(gateway_dir, GatewayStep::Typecheck, eqwalizer_profile)
+ run_gateway_step(gateway_dir, GatewayStep::Typecheck)
})?;
println!("All gateway checks passed.");
Ok(())
@@ -193,11 +189,7 @@ fn run_gateway_fmt_check(gateway_dir: &Path) -> Result<()> {
Ok(())
}
-fn run_eqwalizer(gateway_dir: &Path, profile: &str) -> Result<()> {
- ensure!(
- !profile.is_empty(),
- "--eqwalizer-profile requires a non-empty profile name"
- );
+fn run_eqwalizer(gateway_dir: &Path) -> Result<()> {
ensure!(
command_succeeds(with_asdf_shims(CommandSpec::new("elp").arg("version"))),
"elp not found in PATH. Install ELP from https://github.com/WhatsApp/erlang-language-platform/releases"
@@ -210,7 +202,7 @@ fn run_eqwalizer(gateway_dir: &Path, profile: &str) -> Result<()> {
let elp_version = output_text(with_asdf_shims(CommandSpec::new("elp").arg("version")))?;
println!("==> Running eqWAlizer with {elp_version}");
println!("==> Using Erlang source: {erlang_source}");
- println!("==> Rebar profile: {profile}");
+ println!("==> Rebar profile: default");
run_command(
with_asdf_shims(
CommandSpec::new("elp")
@@ -218,7 +210,7 @@ fn run_eqwalizer(gateway_dir: &Path, profile: &str) -> Result<()> {
"eqwalize-all",
"--rebar",
"--as",
- profile,
+ "default",
"--stats",
"--bail-on-error",
])