Skip to content

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

TypeScript fluxerfluxerapp

feat(api): gate on verification level, hide restricted profiles

Hampus5a198f92a07a
diff --git a/fluxer_api/src/api/auth/EmailVerificationUtils.ts b/fluxer_api/src/api/auth/EmailVerificationUtils.ts
deleted file mode 100644
index f3534d340..000000000
--- a/fluxer_api/src/api/auth/EmailVerificationUtils.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-import {usesUsernameSignIn} from '@app/api/instance/AccountIdentityModeCache';
-import {
- DirectMessageEmailVerificationRequiredError,
- EmailVerificationRequiredError,
- FriendRequestEmailVerificationRequiredError,
- GuildCreationEmailVerificationRequiredError,
- GuildEmailVerificationRequiredError,
- MfaEmailVerificationRequiredError,
- ProfileEmailVerificationRequiredError,
- ReactionEmailVerificationRequiredError,
- ReportEmailVerificationRequiredError,
-} from '@fluxer/errors/src/domains/auth/EmailVerificationRequiredError';
-
-export type EmailVerificationRequiredReason =
- | 'direct_message'
- | 'friend_request'
- | 'guild'
- | 'guild_creation'
- | 'mfa'
- | 'profile'
- | 'reaction'
- | 'report';
-
-const ErrorByReason = {
- direct_message: DirectMessageEmailVerificationRequiredError,
- friend_request: FriendRequestEmailVerificationRequiredError,
- guild: GuildEmailVerificationRequiredError,
- guild_creation: GuildCreationEmailVerificationRequiredError,
- mfa: MfaEmailVerificationRequiredError,
- profile: ProfileEmailVerificationRequiredError,
- reaction: ReactionEmailVerificationRequiredError,
- report: ReportEmailVerificationRequiredError,
-} satisfies Record<EmailVerificationRequiredReason, new () => EmailVerificationRequiredError>;
-
-export function requireEmailVerified(
- user: {emailVerified: boolean; isBot?: boolean},
- reason?: EmailVerificationRequiredReason,
-): void {
- if (user.isBot || usesUsernameSignIn()) {
- return;
- }
- if (!user.emailVerified) {
- const ErrorClass = reason ? ErrorByReason[reason] : EmailVerificationRequiredError;
- throw new ErrorClass();
- }
-}
diff --git a/fluxer_api/src/api/auth/tests/UnclaimedAccountRestrictions.test.ts b/fluxer_api/src/api/auth/tests/UnclaimedAccountRestrictions.test.ts
index a5140e209..0d6d965ee 100644
--- a/fluxer_api/src/api/auth/tests/UnclaimedAccountRestrictions.test.ts
+++ b/fluxer_api/src/api/auth/tests/UnclaimedAccountRestrictions.test.ts
@@ -40,7 +40,7 @@ describe('Unclaimed Account Restrictions', () => {
code: string;
}>(harness, unclaimed.token)
.put(`/channels/${channelId}/messages/${message.id}/reactions/%F0%9F%91%8D/@me`)
- .expect(HTTP_STATUS.BAD_REQUEST)
+ .expect(HTTP_STATUS.FORBIDDEN)
.executeWithResponse();
expect(error.code).toBe('UNCLAIMED_ACCOUNT_CANNOT_ADD_REACTIONS');
});
@@ -52,7 +52,7 @@ describe('Unclaimed Account Restrictions', () => {
await createBuilder(harness, unclaimed.token)
.post('/users/@me/channels')
.body({recipients: [user1.userId, user2.userId]})
- .expect(HTTP_STATUS.BAD_REQUEST)
+ .expect(HTTP_STATUS.FORBIDDEN)
.execute();
});
test('unclaimed account cannot join group DM via invite', async () => {
@@ -79,7 +79,7 @@ describe('Unclaimed Account Restrictions', () => {
}>(harness, friend2.token)
.post(`/invites/${invite.code}`)
.body({})
- .expect(HTTP_STATUS.BAD_REQUEST)
+ .expect(HTTP_STATUS.FORBIDDEN)
.executeWithResponse();
expect(error.code).toBe('UNCLAIMED_ACCOUNT_CANNOT_JOIN_GROUP_DMS');
});
@@ -92,7 +92,7 @@ describe('Unclaimed Account Restrictions', () => {
await createBuilder(harness, sender.token)
.post(`/channels/${dmChannel.id}/messages`)
.body({content: 'Hello from unclaimed'})
- .expect(HTTP_STATUS.BAD_REQUEST)
+ .expect(HTTP_STATUS.FORBIDDEN)
.execute();
});
test('unclaimed account cannot send guild messages', async () => {
@@ -108,7 +108,7 @@ describe('Unclaimed Account Restrictions', () => {
}>(harness, unclaimed.token)
.post(`/channels/${channelId}/messages`)
.body({content: 'Hello world'})
- .expect(HTTP_STATUS.BAD_REQUEST)
+ .expect(HTTP_STATUS.FORBIDDEN)
.executeWithResponse();
expect(error.code).toBe('UNCLAIMED_ACCOUNT_CANNOT_SEND_MESSAGES');
});
@@ -127,7 +127,7 @@ describe('Unclaimed Account Restrictions', () => {
await createBuilder(harness, unclaimed.token)
.post('/guilds')
.body({name: 'Guild'})
- .expect(HTTP_STATUS.BAD_REQUEST, APIErrorCodes.UNCLAIMED_ACCOUNT_CANNOT_CREATE_GUILDS)
+ .expect(HTTP_STATUS.FORBIDDEN, APIErrorCodes.UNCLAIMED_ACCOUNT_CANNOT_CREATE_GUILDS)
.execute();
});
test('bot account cannot create guild', async () => {
diff --git a/fluxer_api/src/api/channel/controllers/ChannelFollowController.ts b/fluxer_api/src/api/channel/controllers/ChannelFollowController.ts
index d8c2b638d..df92a011e 100644
--- a/fluxer_api/src/api/channel/controllers/ChannelFollowController.ts
+++ b/fluxer_api/src/api/channel/controllers/ChannelFollowController.ts
@@ -8,7 +8,9 @@ import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
import type {HonoApp} from '@app/api/types/HonoEnv';
import {assertAccountNotLimited} from '@app/api/user/AccountLimit';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {Validator} from '@app/api/Validator';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {
ChannelFollowerStatsResponse,
ChannelFollowRequest,
@@ -36,12 +38,12 @@ export function ChannelFollowController(app: HonoApp) {
}),
async (ctx) => {
assertAccountNotLimited(ctx.get('user'));
+ assertTierAllows(ctx.get('user'), TierGatedActions.CHANNEL_FOLLOW, NO_TIER_CONTEXT);
const followed = await ctx.get('channelFollowService').followChannel({
userId: ctx.get('user').id,
viewer: viewerFromCtx(ctx),
channelId: createChannelID(ctx.req.valid('param').channel_id),
webhookChannelId: createChannelID(ctx.req.valid('json').webhook_channel_id),
- requestCache: ctx.get('requestCache'),
auditLogReason: ctx.get('auditLogReason') ?? null,
});
return ctx.json({
diff --git a/fluxer_api/src/api/channel/controllers/MessageController.ts b/fluxer_api/src/api/channel/controllers/MessageController.ts
index cc2b25a9b..999b6ea18 100644
--- a/fluxer_api/src/api/channel/controllers/MessageController.ts
+++ b/fluxer_api/src/api/channel/controllers/MessageController.ts
@@ -4,6 +4,7 @@ import {requireSudoMode} from '@app/api/auth/services/SudoVerificationService';
import {createAttachmentID, createChannelID, createMessageID} from '@app/api/BrandedTypes';
import type {MessageRequest, MessageUpdateRequest} from '@app/api/channel/MessageTypes';
import {parseMessageRequestBody} from '@app/api/channel/services/message/MessageRequestParser';
+import {isPersonalNotesChannelId} from '@app/api/channel/services/PersonalNotesChannelRepair';
import {viewerFromCtx} from '@app/api/experiment/ChannelThreadsGate';
import {DefaultUserOnly, LoginRequired} from '@app/api/middleware/AuthMiddleware';
import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
@@ -13,8 +14,10 @@ import {RateLimitConfigs} from '@app/api/RateLimitConfig';
import {readStateCapable} from '@app/api/read_state/ReadStateChannelMeta';
import type {HonoApp} from '@app/api/types/HonoEnv';
import {assertAccountNotLimited} from '@app/api/user/AccountLimit';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {requireRequestClientIp} from '@app/api/utils/RequestClientIp';
import {Validator} from '@app/api/Validator';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {SudoVerificationSchema} from '@fluxer/schema/src/domains/auth/AuthSchemas';
import {
ChannelIdMessageIdAttachmentIdParam,
@@ -276,6 +279,9 @@ export function MessageController(app: HonoApp) {
const messageId = createMessageID(message_id);
const requestCache = ctx.get('requestCache');
const messageRequestService = ctx.get('messageRequestService');
+ if (!isPersonalNotesChannelId({userId, channelId})) {
+ assertTierAllows(user, TierGatedActions.MESSAGE, NO_TIER_CONTEXT);
+ }
const validatedData = await parseMessageRequestBody(ctx, user, channelId, MessageUpdateRequestSchema);
return ctx.json(
await messageRequestService.editMessage({
@@ -480,6 +486,9 @@ export function MessageController(app: HonoApp) {
const user = ctx.get('user');
const viewer = viewerFromCtx(ctx);
const channelId = createChannelID(ctx.req.valid('param').channel_id);
+ if (!isPersonalNotesChannelId({userId: user.id, channelId})) {
+ assertTierAllows(user, TierGatedActions.TYPING, NO_TIER_CONTEXT);
+ }
const channelService = ctx.get('channelService');
const auth = await channelService.interactions.startTyping({viewer, userId: user.id, channelId});
const cooldown = await channelService.getTypingCooldown({user, viewer, auth});
@@ -504,6 +513,7 @@ export function MessageController(app: HonoApp) {
async (ctx) => {
const {channel_id, message_id} = ctx.req.valid('param');
assertAccountNotLimited(ctx.get('user'));
+ assertTierAllows(ctx.get('user'), TierGatedActions.MESSAGE, NO_TIER_CONTEXT);
return ctx.json(
await ctx.get('messageRequestService').crosspostMessage({
userId: ctx.get('user').id,
diff --git a/fluxer_api/src/api/channel/controllers/MessageInteractionController.ts b/fluxer_api/src/api/channel/controllers/MessageInteractionController.ts
index 8fd76de22..dbd5cc624 100644
--- a/fluxer_api/src/api/channel/controllers/MessageInteractionController.ts
+++ b/fluxer_api/src/api/channel/controllers/MessageInteractionController.ts
@@ -10,11 +10,12 @@ import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
import {readStateCapable} from '@app/api/read_state/ReadStateChannelMeta';
import type {HonoApp} from '@app/api/types/HonoEnv';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {Validator} from '@app/api/Validator';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {UserFlags} from '@fluxer/constants/src/UserConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {InvalidChannelTypeError} from '@fluxer/errors/src/domains/channel/InvalidChannelTypeError';
-import {UnclaimedAccountCannotAddReactionsError} from '@fluxer/errors/src/domains/channel/UnclaimedAccountCannotAddReactionsError';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
import {
ChannelIdMessageIdEmojiParam,
@@ -53,14 +54,12 @@ export function MessageInteractionController(app: HonoApp) {
async (ctx) => {
const userId = ctx.get('user').id;
const channelId = createChannelID(ctx.req.valid('param').channel_id);
- const requestCache = ctx.get('requestCache');
const {limit, before} = ctx.req.valid('query');
return ctx.json(
await ctx.get('channelService').interactions.getChannelPins({
viewer: viewerFromCtx(ctx),
userId,
channelId,
- requestCache,
limit,
beforeTimestamp: before,
}),
@@ -168,14 +167,12 @@ export function MessageInteractionController(app: HonoApp) {
const userId = ctx.get('user').id;
const channelId = createChannelID(channel_id);
const messageId = createMessageID(message_id);
- const requestCache = ctx.get('requestCache');
const auditLogReason = ctx.get('auditLogReason') ?? null;
await ctx.get('channelService').interactions.unpinMessage({
viewer: viewerFromCtx(ctx),
userId,
channelId,
messageId,
- requestCache,
auditLogReason,
});
return ctx.body(null, 204);
@@ -272,7 +269,7 @@ export function MessageInteractionController(app: HonoApp) {
operationId: 'add_reaction',
summary: 'Add reaction to message',
description:
- 'Adds an emoji reaction to a message. Each user can react once with each emoji. Cannot be used from unclaimed accounts outside personal notes. Returns 204 No Content on success.',
+ 'Adds an emoji reaction to a message. Each user can react once with each emoji. Outside personal notes, needs an account with a confirmed email address. Returns 204 No Content on success.',
responseSchema: null,
statusCode: 204,
security: ['botToken', 'bearerToken', 'sessionToken'],
@@ -285,8 +282,8 @@ export function MessageInteractionController(app: HonoApp) {
const messageId = createMessageID(message_id);
const sessionId = ctx.req.valid('query').session_id;
const requestCache = ctx.get('requestCache');
- if (user.isUnclaimedAccount() && !isPersonalNotesChannelId({userId: user.id, channelId})) {
- throw new UnclaimedAccountCannotAddReactionsError();
+ if (!isPersonalNotesChannelId({userId: user.id, channelId})) {
+ assertTierAllows(user, TierGatedActions.REACTION, NO_TIER_CONTEXT);
}
if (!user.isBot && user.id !== SYSTEM_USER_ID && !(user.flags & UserFlags.HAS_SESSION_STARTED)) {
throw InputValidationError.fromCode('emoji', ValidationErrorCodes.MUST_START_SESSION_BEFORE_SENDING);
@@ -325,7 +322,6 @@ export function MessageInteractionController(app: HonoApp) {
const channelId = createChannelID(channel_id);
const messageId = createMessageID(message_id);
const sessionId = ctx.req.valid('query').session_id;
- const requestCache = ctx.get('requestCache');
await ctx.get('channelService').interactions.removeOwnReaction({
viewer: viewerFromCtx(ctx),
userId,
@@ -333,7 +329,6 @@ export function MessageInteractionController(app: HonoApp) {
channelId,
messageId,
emoji,
- requestCache,
});
return ctx.body(null, 204);
},
@@ -361,7 +356,6 @@ export function MessageInteractionController(app: HonoApp) {
const channelId = createChannelID(channel_id);
const messageId = createMessageID(message_id);
const sessionId = ctx.req.valid('query').session_id;
- const requestCache = ctx.get('requestCache');
await ctx.get('channelService').interactions.removeReaction({
viewer: viewerFromCtx(ctx),
userId,
@@ -370,7 +364,6 @@ export function MessageInteractionController(app: HonoApp) {
messageId,
emoji,
targetId,
- requestCache,
});
return ctx.body(null, 204);
},
diff --git a/fluxer_api/src/api/channel/controllers/ThreadController.ts b/fluxer_api/src/api/channel/controllers/ThreadController.ts
index e73a225d4..d2ad1aa71 100644
--- a/fluxer_api/src/api/channel/controllers/ThreadController.ts
+++ b/fluxer_api/src/api/channel/controllers/ThreadController.ts
@@ -12,8 +12,10 @@ import {RateLimitMiddleware} from '@app/api/middleware/RateLimitMiddleware';
import {OpenAPI} from '@app/api/middleware/ResponseTypeMiddleware';
import {RateLimitConfigs} from '@app/api/RateLimitConfig';
import type {HonoApp, HonoEnv} from '@app/api/types/HonoEnv';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {parseJsonPreservingLargeIntegers} from '@app/api/utils/LosslessJsonParser';
import {inputValidationErrorFromZodIssues, Validator} from '@app/api/Validator';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {TEXT_THREAD_PARENT_CHANNEL_TYPES} from '@fluxer/constants/src/ThreadConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {InvalidChannelTypeError} from '@fluxer/errors/src/domains/channel/InvalidChannelTypeError';
@@ -150,6 +152,7 @@ export function ThreadController(app: HonoApp) {
async (ctx) => {
const {channel_id, message_id} = ctx.req.valid('param');
const body = ctx.req.valid('json');
+ assertTierAllows(ctx.get('user'), TierGatedActions.MESSAGE, NO_TIER_CONTEXT);
const thread = await ctx.get('threadService').creation.createFromMessage({
viewer: viewerFromCtx(ctx),
user: ctx.get('user'),
@@ -188,6 +191,7 @@ export function ThreadController(app: HonoApp) {
async (ctx) => {
const viewer = viewerFromCtx(ctx);
const user = ctx.get('user');
+ assertTierAllows(user, TierGatedActions.MESSAGE, NO_TIER_CONTEXT);
const channelId = createChannelID(ctx.req.valid('param').channel_id);
const creation = ctx.get('threadService').creation;
const parentAuth = await creation.authenticateParent(viewer, user.id, channelId);
@@ -394,6 +398,7 @@ export function ThreadController(app: HonoApp) {
experiment: EXPERIMENT,
}),
async (ctx) => {
+ assertTierAllows(ctx.get('user'), TierGatedActions.THREAD_JOIN, NO_TIER_CONTEXT);
await ctx.get('threadService').members.join({
viewer: viewerFromCtx(ctx),
user: ctx.get('user'),
diff --git a/fluxer_api/src/api/channel/services/CallService.ts b/fluxer_api/src/api/channel/services/CallService.ts
index b65104e4d..404c63e3e 100644
--- a/fluxer_api/src/api/channel/services/CallService.ts
+++ b/fluxer_api/src/api/channel/services/CallService.ts
@@ -14,9 +14,11 @@ import type {UserCacheService} from '@app/api/infrastructure/UserCacheService';
import type {RequestCache} from '@app/api/middleware/RequestCacheMiddleware';
import type {Channel} from '@app/api/models/Channel';
import type {ReadStateService} from '@app/api/read_state/ReadStateService';
+import {canTierPerform, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {assertMayStartConversation} from '@app/api/user/NewConversationLimit';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import type {VoiceAccessContext, VoiceAvailabilityService} from '@app/api/voice/VoiceAvailabilityService';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {AUTOMATIC_VOICE_REGION_ID, ChannelTypes, MessageTypes} from '@fluxer/constants/src/ChannelConstants';
import {IncomingCallFlags, RelationshipTypes} from '@fluxer/constants/src/UserConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
@@ -66,8 +68,8 @@ export class CallService {
}> {
const channel = await this.requireCallChannel(channelId, userId);
const caller = await this.userRepository.findUnique(userId);
- const isUnclaimedCaller = caller?.isUnclaimedAccount() ?? false;
- if (isUnclaimedCaller && channel.type === ChannelTypes.DM) {
+ const callAction = channel.type === ChannelTypes.DM ? TierGatedActions.CALL : TierGatedActions.GROUP_CALL;
+ if (caller && !canTierPerform(caller, callAction, NO_TIER_CONTEXT)) {
return {ringable: false};
}
const call = await this.gatewayService.getCall(channelId);
diff --git a/fluxer_api/src/api/channel/services/DMPermissionValidator.ts b/fluxer_api/src/api/channel/services/DMPermissionValidator.ts
index 29cd1deaf..3c18ade1c 100644
--- a/fluxer_api/src/api/channel/services/DMPermissionValidator.ts
+++ b/fluxer_api/src/api/channel/services/DMPermissionValidator.ts
@@ -6,13 +6,14 @@ import type {GuildRepository} from '@app/api/guild/repositories/GuildRepository'
import type {Guild} from '@app/api/models/Guild';
import type {User} from '@app/api/models/User';
import type {UserSettings} from '@app/api/models/UserSettings';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import {isBugHunterBotUser} from '@app/api/user/UserHelpers';
import {checkGuildVerificationWithGuildModel} from '@app/api/utils/GuildVerificationUtils';
import {getMutualGuildsForDmAccess} from '@app/api/utils/MutualGuildDmAccess';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {RelationshipTypes, UserFlags} from '@fluxer/constants/src/UserConstants';
import {CannotSendMessagesToUserError} from '@fluxer/errors/src/domains/channel/CannotSendMessagesToUserError';
-import {UnclaimedAccountCannotSendDirectMessagesError} from '@fluxer/errors/src/domains/channel/UnclaimedAccountCannotSendDirectMessagesError';
interface DMPermissionValidatorDeps {
userRepository: UserRepository;
@@ -30,9 +31,7 @@ export class DMPermissionValidator {
if (!senderUser) {
throw new CannotSendMessagesToUserError();
}
- if (senderUser.isUnclaimedAccount()) {
- throw new UnclaimedAccountCannotSendDirectMessagesError();
- }
+ assertTierAllows(senderUser, TierGatedActions.DIRECT_MESSAGE, NO_TIER_CONTEXT);
const targetUser = await this.deps.userRepository.findUnique(recipientId);
if (!targetUser) {
throw new CannotSendMessagesToUserError();
diff --git a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
index a3d23c6c1..c93530c87 100644
--- a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
+++ b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {requireEmailVerified} from '@app/api/auth/EmailVerificationUtils';
import {createEmojiID, type MessageID, type UserID} from '@app/api/BrandedTypes';
import type {ChannelRepository} from '@app/api/channel/ChannelRepository';
import type {AuthenticatedChannel} from '@app/api/channel/services/AuthenticatedChannel';
@@ -186,7 +185,6 @@ export class MessageReactionService {
if (!message) throw new UnknownMessageError();
const requestingUser = await this.userRepository.findUnique(userId);
if (requestingUser) {
- requireEmailVerified(requestingUser, 'reaction');
assertAccountNotLimited(requestingUser);
}
const guildFeatures = guild?.features ?? null;
diff --git a/fluxer_api/src/api/channel/services/message/MessageRequestService.ts b/fluxer_api/src/api/channel/services/message/MessageRequestService.ts
index 9f24f2bdc..b371d32c9 100644
--- a/fluxer_api/src/api/channel/services/message/MessageRequestService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessageRequestService.ts
@@ -11,10 +11,11 @@ import {isPersonalNotesChannelId} from '@app/api/channel/services/PersonalNotesC
import {isTainted, type ThreadViewer, viewerActive} from '@app/api/experiment/ChannelThreadsGate';
import type {RequestCache} from '@app/api/middleware/RequestCacheMiddleware';
import type {User} from '@app/api/models/User';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {mapWithConcurrency} from '@app/api/utils/ConcurrencyUtils';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {THREAD_FEATURE_CHANNEL_TYPES} from '@fluxer/constants/src/ThreadConstants';
import {InvalidChannelTypeError} from '@fluxer/errors/src/domains/channel/InvalidChannelTypeError';
-import {UnclaimedAccountCannotSendMessagesError} from '@fluxer/errors/src/domains/channel/UnclaimedAccountCannotSendMessagesError';
import {UnknownMessageError} from '@fluxer/errors/src/domains/channel/UnknownMessageError';
import type {CrosspostSourceResponse} from '@fluxer/schema/src/domains/message/CrosspostSourceSchemas';
import type {
@@ -58,6 +59,7 @@ export class MessageRequestService {
viewer: params.viewer,
userId: params.userId,
channelId: params.channelId,
+ access: 'visitor_read',
});
if (authChannel.channel.isThreadOnly()) throw new InvalidChannelTypeError();
const request = {
@@ -133,6 +135,7 @@ export class MessageRequestService {
userId: params.userId,
channelId: params.channelId,
messageId: params.messageId,
+ access: 'visitor_read',
});
const starter = await retrieval.threadResponses.getStarter({
viewer: params.viewer,
@@ -186,11 +189,8 @@ export class MessageRequestService {
data: MessageRequest;
requestCache: RequestCache;
}): Promise<MessageResponse> {
- if (
- params.user.isUnclaimedAccount() &&
- !isPersonalNotesChannelId({userId: params.user.id, channelId: params.channelId})
- ) {
- throw new UnclaimedAccountCannotSendMessagesError();
+ if (!isPersonalNotesChannelId({userId: params.user.id, channelId: params.channelId})) {
+ assertTierAllows(params.user, TierGatedActions.MESSAGE, NO_TIER_CONTEXT);
}
const {message, authChannel} = await this.channelService.messages.send.sendMessage({
viewer: params.viewer,
@@ -252,7 +252,7 @@ export class MessageRequestService {
parentAuth: AuthenticatedChannel;
data: MessageRequest;
}): Promise<void> {
- if (params.user.isUnclaimedAccount()) throw new UnclaimedAccountCannotSendMessagesError();
+ assertTierAllows(params.user, TierGatedActions.MESSAGE, NO_TIER_CONTEXT);
await this.channelService.messages.send.validateForumStarter(params);
}
@@ -264,7 +264,7 @@ export class MessageRequestService {
data: MessageRequest;
requestCache: RequestCache;
}): Promise<MessageResponse> {
- if (params.user.isUnclaimedAccount()) throw new UnclaimedAccountCannotSendMessagesError();
+ assertTierAllows(params.user, TierGatedActions.MESSAGE, NO_TIER_CONTEXT);
const {message, authChannel} = await this.channelService.messages.send.sendMessage({
viewer: params.viewer,
user: params.user,
diff --git a/fluxer_api/src/api/guild/services/data/GuildOwnershipService.ts b/fluxer_api/src/api/guild/services/data/GuildOwnershipService.ts
index 83f200de3..487ca721d 100644
--- a/fluxer_api/src/api/guild/services/data/GuildOwnershipService.ts
+++ b/fluxer_api/src/api/guild/services/data/GuildOwnershipService.ts
@@ -4,8 +4,10 @@ import type {GuildID, UserID} from '@app/api/BrandedTypes';
import {mapGuildToGuildResponse} from '@app/api/guild/GuildModel';
import type {GuildRepository} from '@app/api/guild/repositories/GuildRepository';
import type {GuildDataHelpers} from '@app/api/guild/services/data/GuildDataHelpers';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import {serializeGuildForAudit} from '@app/api/utils/AuditSerializationUtils';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {AuditLogActionType} from '@fluxer/constants/src/AuditLogActionType';
import {MissingAccessError} from '@fluxer/errors/src/domains/core/MissingAccessError';
import {MissingPermissionsError} from '@fluxer/errors/src/domains/core/MissingPermissionsError';
@@ -46,6 +48,7 @@ export class GuildOwnershipService {
if (newOwnerUser?.isBot) {
throw new CannotTransferOwnershipToBotError();
}
+ if (newOwnerUser) assertTierAllows(newOwnerUser, TierGatedActions.OWNERSHIP_TRANSFER, NO_TIER_CONTEXT);
const guild = await this.guildRepository.findUnique(guildId);
if (!guild) throw new UnknownGuildError();
const previousSnapshot = serializeGuildForAudit(guild);
diff --git a/fluxer_api/src/api/oauth/ApplicationService.ts b/fluxer_api/src/api/oauth/ApplicationService.ts
index 3d16449b2..43eea02e5 100644
--- a/fluxer_api/src/api/oauth/ApplicationService.ts
+++ b/fluxer_api/src/api/oauth/ApplicationService.ts
@@ -15,6 +15,7 @@ import type {Application} from '@app/api/models/Application';
import type {User} from '@app/api/models/User';
import type {BotAuthService} from '@app/api/oauth/BotAuthService';
import type {ApplicationRepository} from '@app/api/oauth/repositories/ApplicationRepository';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {enforceFluxerTagChangeRateLimit} from '@app/api/user/FluxerTagChangeRateLimit';
import {dispatchUserUpdate, hasPartialUserFieldsChanged} from '@app/api/user/UserMappers';
import {runAllInOrder} from '@app/api/utils/ConcurrencyUtils';
@@ -22,6 +23,7 @@ import {hashPassword} from '@app/api/utils/PasswordUtils';
import {randomBase64Url} from '@app/api/utils/SecretHash';
import {generateRandomUsername} from '@app/api/utils/UsernameGenerator';
import {deriveUsernameFromDisplayName} from '@app/api/utils/UsernameSuggestionUtils';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {
DELETED_USER_GLOBAL_NAME,
@@ -35,7 +37,6 @@ import {AccessDeniedError} from '@fluxer/errors/src/domains/core/AccessDeniedErr
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
import {InternalServerError} from '@fluxer/errors/src/domains/core/InternalServerError';
import {BotUserNotFoundError} from '@fluxer/errors/src/domains/oauth/BotUserNotFoundError';
-import {UnclaimedAccountCannotCreateApplicationsError} from '@fluxer/errors/src/domains/oauth/UnclaimedAccountCannotCreateApplicationsError';
import {UnknownApplicationError} from '@fluxer/errors/src/domains/oauth/UnknownApplicationError';
import type {BotProfileUpdateRequest} from '@fluxer/schema/src/domains/oauth/OAuthSchemas';
@@ -127,9 +128,7 @@ export class ApplicationService {
const owner = await this.apiContext.services.users.findUniqueAssert(args.ownerUserId);
const botIsPublic = args.botPublic ?? true;
const botRequireCodeGrant = args.botRequireCodeGrant ?? false;
- if (owner.isUnclaimedAccount()) {
- throw new UnclaimedAccountCannotCreateApplicationsError();
- }
+ assertTierAllows(owner, TierGatedActions.APPLICATION_CREATE, NO_TIER_CONTEXT);
const applicationId: ApplicationID = (await this.apiContext.services.snowflake.generate()) as ApplicationID;
const botUserId = applicationIdToUserId(applicationId);
const {username, discriminator} = await this.generateBotUsername(args.name);
diff --git a/fluxer_api/src/api/user/UserMappers.ts b/fluxer_api/src/api/user/UserMappers.ts
index d405fa694..bf1a4e7ae 100644
--- a/fluxer_api/src/api/user/UserMappers.ts
+++ b/fluxer_api/src/api/user/UserMappers.ts
@@ -3,6 +3,7 @@
import {createGuildID, type UserID} from '@app/api/BrandedTypes';
import {stripAvatarForUser, stripBannerForUser} from '@app/api/infrastructure/AssetEntitlementUtils';
import type {IGatewayService} from '@app/api/infrastructure/IGatewayService';
+import {resolveEffectiveUserTraits} from '@app/api/limits/EffectiveUserTraits';
import type {GuildChannelOverride} from '@app/api/models/GuildChannelOverride';
import type {GuildMember} from '@app/api/models/GuildMember';
import type {MuteConfiguration} from '@app/api/models/MuteConfiguration';
@@ -12,8 +13,16 @@ import type {UserGuildSettings} from '@app/api/models/UserGuildSettings';
import type {UserSettings} from '@app/api/models/UserSettings';
import type {WebAuthnCredential} from '@app/api/models/WebAuthnCredential';
import {isAccountLimited} from '@app/api/user/AccountLimit';
+import {
+ canReachOthers,
+ getAccountTier,
+ getVerificationNeed,
+ isInteractionTierEnforced,
+} from '@app/api/user/AccountTier';
+import {isDateOfBirthMissing} from '@app/api/user/DateOfBirth';
import {hiddenUserPartial, isProfileHidden} from '@app/api/user/ProfileVisibility';
import {canUserAccessNsfwContent} from '@app/api/utils/AgeUtils';
+import {AccountTiers} from '@fluxer/constants/src/AccountTierConstants';
import type {ChannelMessageNotifications} from '@fluxer/constants/src/NotificationConstants';
import {
DEFAULT_GUILD_FOLDER_ICON,
@@ -73,7 +82,12 @@ function sortUserIds(userIds: Iterable<UserID>): Array<string> {
export function mapUserToPartialResponse(user: User): UserPartialResponse {
const partial = mapUserToOwnPartialResponse(user);
- return isProfileHidden(user) && !isDeletedForDisplay(user) ? hiddenUserPartial(partial) : partial;
+ if (isProfileHidden(user) && !isDeletedForDisplay(user)) return hiddenUserPartial(partial);
+ return isProfileRestricted(user) ? {...partial, global_name: null, avatar: null} : partial;
+}
+
+function isProfileRestricted(user: User): boolean {
+ return isInteractionTierEnforced() && !canReachOthers(user);
}
function isDeletedForDisplay(user: User): boolean {
@@ -131,17 +145,9 @@ export function mapUserToPrivateResponse(user: User): UserPrivateResponse {
const isStaff = (user.flags & UserFlags.STAFF) !== 0n;
const partialResponse = mapUserToOwnPartialResponse(user);
const isActuallyPremium = user.isPremium();
- const traitSet = new Set<string>();
- for (const trait of user.traits ?? []) {
- if (trait && trait !== 'premium') {
- traitSet.add(trait);
- }
- }
- if (isActuallyPremium) {
- traitSet.add('premium');
- }
- const traits = Array.from(traitSet).sort();
+ const traits = Array.from(resolveEffectiveUserTraits(user.traits, isActuallyPremium)).sort();
const authenticatorTypes = getActiveAuthenticatorTypes(user);
+ const accountTier = getAccountTier(user);
return {
...partialResponse,
flags: mapUserFlagsToPublicBitfield(user),
@@ -191,6 +197,12 @@ export function mapUserToPrivateResponse(user: User): UserPrivateResponse {
age_verified_adult: !!(user.flags & UserFlags.AGE_VERIFIED_ADULT) || undefined,
terms_agreed_at: user.termsAgreedAt?.toISOString() ?? null,
privacy_agreed_at: user.privacyAgreedAt?.toISOString() ?? null,
+ claimed: accountTier !== AccountTiers.UNCLAIMED,
+ account_tier: accountTier,
+ verification_need: getVerificationNeed(user),
+ has_password: user.passwordHash !== null,
+ date_of_birth_required: isDateOfBirthMissing(user),
+ profile_restricted: isProfileRestricted(user),
pending_bulk_message_deletion:
user.pendingBulkMessageDeletionAt != null
? {
@@ -202,8 +214,11 @@ export function mapUserToPrivateResponse(user: User): UserPrivateResponse {
};
}
-export function mapUserToProfileResponse(user: User, options?: {restrictProfile?: boolean}): UserProfileResponse {
- if (isProfileHidden(user)) {
+export function mapUserToProfileResponse(
+ user: User,
+ options?: {restrictProfile?: boolean; viewerIsSelf?: boolean},
+): UserProfileResponse {
+ if (isProfileHidden(user) || (isProfileRestricted(user) && !options?.viewerIsSelf)) {
return {bio: null, pronouns: null, banner: null, banner_color: null, accent_color: null};
}
if (options?.restrictProfile) {
diff --git a/fluxer_api/src/api/user/services/UserChannelService.ts b/fluxer_api/src/api/user/services/UserChannelService.ts
index 7e9778acf..a26f64872 100644
--- a/fluxer_api/src/api/user/services/UserChannelService.ts
+++ b/fluxer_api/src/api/user/services/UserChannelService.ts
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import type {ApiContext} from '@app/api/ApiContext';
-import {requireEmailVerified} from '@app/api/auth/EmailVerificationUtils';
import type {ChannelID, UserID} from '@app/api/BrandedTypes';
import {createChannelID, createMessageID, createUserID} from '@app/api/BrandedTypes';
import {mapChannelToResponse} from '@app/api/channel/ChannelMappers';
@@ -26,10 +25,12 @@ import type {Channel} from '@app/api/models/Channel';
import type {Message} from '@app/api/models/Message';
import type {User} from '@app/api/models/User';
import {assertAccountNotLimited} from '@app/api/user/AccountLimit';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import {assertMayStartConversation} from '@app/api/user/NewConversationLimit';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import {isDirectDeliverySuppressed} from '@app/api/user/UserHelpers';
import type {UserPermissionUtils} from '@app/api/utils/UserPermissionUtils';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {ChannelTypes, MessageTypes} from '@fluxer/constants/src/ChannelConstants';
import type {LimitKey} from '@fluxer/constants/src/LimitConfigMetadata';
import {MAX_GROUP_DM_RECIPIENTS, MAX_GROUP_DMS_PER_USER} from '@fluxer/constants/src/LimitConstants';
@@ -39,11 +40,8 @@ import type {GroupDmUnaddableRecipient} from '@fluxer/errors/src/domains/channel
import {GroupDmRecipientsNotAddableError} from '@fluxer/errors/src/domains/channel/GroupDmRecipientsNotAddableError';
import {MaxGroupDmRecipientsError} from '@fluxer/errors/src/domains/channel/MaxGroupDmRecipientsError';
import {MaxGroupDmsError} from '@fluxer/errors/src/domains/channel/MaxGroupDmsError';
-import {UnclaimedAccountCannotJoinGroupDmsError} from '@fluxer/errors/src/domains/channel/UnclaimedAccountCannotJoinGroupDmsError';
-import {UnclaimedAccountCannotSendDirectMessagesError} from '@fluxer/errors/src/domains/channel/UnclaimedAccountCannotSendDirectMessagesError';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
import {MissingAccessError} from '@fluxer/errors/src/domains/core/MissingAccessError';
-import {UnknownUserError} from '@fluxer/errors/src/domains/user/UnknownUserError';
import type {MessageResponse} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import type {CreatePrivateChannelRequest} from '@fluxer/schema/src/domains/user/UserRequestSchemas';
import * as BucketUtils from '@fluxer/snowflake/src/SnowflakeBuckets';
@@ -141,13 +139,12 @@ export class UserChannelService {
}): Promise<Channel> {
const callingUser = await this.userRepository.findUnique(userId);
if (!callingUser) throw new UnknownUserError();
- if (callingUser.isUnclaimedAccount()) {
- if (data.recipients !== undefined) {
- throw new UnclaimedAccountCannotJoinGroupDmsError();
- }
- throw new UnclaimedAccountCannotSendDirectMessagesError();
- }
- requireEmailVerified(callingUser, 'direct_message');
+ assertTierAllows(
+ callingUser,
+ data.recipients !== undefined ? TierGatedActions.GROUP_DM : TierGatedActions.DIRECT_MESSAGE,
+ NO_TIER_CONTEXT,
+ );
+ assertTierAllows(callingUser, TierGatedActions.DIRECT_MESSAGE_OPEN, NO_TIER_CONTEXT);
if (data.recipients !== undefined) {
assertAccountNotLimited(callingUser);
return await this.createGroupDMChannel({
@@ -347,7 +344,7 @@ export class UserChannelService {
return await this.createNewDmForBothUsers({userId, recipientId, userCacheService, requestCache});
}
- async createNewDmForBothUsers({
+ private async createNewDmForBothUsers({
userId,
recipientId,
userCacheService,
diff --git a/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts b/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts
index d0c56e27c..04395386b 100644
--- a/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts
+++ b/fluxer_api/src/api/user/tests/UserRelationshipStateTransitions.test.ts
@@ -174,7 +174,7 @@ describe('UserRelationshipStateTransitions', () => {
await unclaimAccount(harness, alice.userId);
await createBuilder(harness, alice.token)
.post(`/users/@me/relationships/${bob.userId}`)
- .expect(HTTP_STATUS.BAD_REQUEST, 'UNCLAIMED_ACCOUNT_CANNOT_SEND_FRIEND_REQUESTS')
+ .expect(HTTP_STATUS.FORBIDDEN, 'UNCLAIMED_ACCOUNT_CANNOT_SEND_FRIEND_REQUESTS')
.execute();
});
test('unclaimed account cannot accept friend request', async () => {
@@ -185,7 +185,7 @@ describe('UserRelationshipStateTransitions', () => {
await createBuilder(harness, bob.token)
.put(`/users/@me/relationships/${alice.userId}`)
.body({})
- .expect(HTTP_STATUS.BAD_REQUEST, 'UNCLAIMED_ACCOUNT_CANNOT_ACCEPT_FRIEND_REQUESTS')
+ .expect(HTTP_STATUS.FORBIDDEN, 'UNCLAIMED_ACCOUNT_CANNOT_ACCEPT_FRIEND_REQUESTS')
.execute();
});
test('cannot accept non-existent incoming request', async () => {
diff --git a/fluxer_api/src/api/utils/GuildVerificationUtils.ts b/fluxer_api/src/api/utils/GuildVerificationUtils.ts
index f5d72374d..93cb87f27 100644
--- a/fluxer_api/src/api/utils/GuildVerificationUtils.ts
+++ b/fluxer_api/src/api/utils/GuildVerificationUtils.ts
@@ -1,18 +1,21 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {createRoleIDSet, createUserID, type RoleID, type UserID} from '@app/api/BrandedTypes';
-import {usesUsernameSignIn} from '@app/api/instance/AccountIdentityModeCache';
import type {Guild} from '@app/api/models/Guild';
import type {GuildMember} from '@app/api/models/GuildMember';
import type {User} from '@app/api/models/User';
+import {assertTierAllows, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {
GuildFeatures,
GuildVerificationLevel,
getEffectiveGuildVerificationLevel,
} from '@fluxer/constants/src/GuildConstants';
-import {GuildEmailVerificationRequiredError} from '@fluxer/errors/src/domains/auth/EmailVerificationRequiredError';
import {AccountTooNewForGuildError} from '@fluxer/errors/src/domains/guild/AccountTooNewForGuildError';
-import {GuildVerificationRequiredError} from '@fluxer/errors/src/domains/guild/GuildVerificationRequiredError';
+import {
+ GuildVerificationRequiredError,
+ GuildVerificationRequiredReasons,
+} from '@fluxer/errors/src/domains/guild/GuildVerificationRequiredError';
import type {GuildMemberResponse} from '@fluxer/schema/src/domains/guild/GuildMemberSchemas';
import type {GuildResponse} from '@fluxer/schema/src/domains/guild/GuildResponseSchemas';
import {snowflakeToDate} from '@fluxer/snowflake/src/Snowflake';
@@ -40,20 +43,7 @@ function checkGuildVerification(params: VerificationParams): void {
if (memberRoles && memberRoles.size > 0) {
return;
}
- if (usesUsernameSignIn()) {
- if (user.isUnclaimedAccount()) {
- throw new GuildVerificationRequiredError('You need to claim your account to send messages in this guild.');
- }
- } else {
- if (!user.email) {
- throw new GuildVerificationRequiredError('You need to claim your account to send messages in this guild.');
- }
- if (verificationLevel >= GuildVerificationLevel.LOW) {
- if (!user.emailVerified) {
- throw new GuildEmailVerificationRequiredError();
- }
- }
- }
+ assertTierAllows(user, TierGatedActions.GUILD_VERIFICATION, NO_TIER_CONTEXT);
if (verificationLevel >= GuildVerificationLevel.MEDIUM) {
const createdAt = snowflakeToDate(BigInt(user.id)).getTime();
const accountAge = Date.now() - createdAt;
@@ -67,9 +57,7 @@ function checkGuildVerification(params: VerificationParams): void {
typeof memberJoinedAt === 'string' ? new Date(memberJoinedAt).getTime() : memberJoinedAt.getTime();
const membershipDuration = Date.now() - joinedAtTime;
if (membershipDuration < ms('10 minutes')) {
- throw new GuildVerificationRequiredError(
- "You haven't been a member of this guild long enough to send messages.",
- );
+ throw new GuildVerificationRequiredError(GuildVerificationRequiredReasons.MEMBERSHIP_AGE);
}
}
}
diff --git a/fluxer_api/src/api/voice/VoiceService.ts b/fluxer_api/src/api/voice/VoiceService.ts
index 795f94778..787b281fd 100644
--- a/fluxer_api/src/api/voice/VoiceService.ts
+++ b/fluxer_api/src/api/voice/VoiceService.ts
@@ -10,6 +10,7 @@ import type {PinnedRoomServer, VoiceRoomStore} from '@app/api/infrastructure/Voi
import type {InstanceConfigRepository} from '@app/api/instance/InstanceConfigRepository';
import {Logger} from '@app/api/Logger';
import type {User} from '@app/api/models/User';
+import {assertTierAllows, canReachOthers, NO_TIER_CONTEXT} from '@app/api/user/AccountTier';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import type {VoiceAccessContext, VoiceAvailabilityService} from '@app/api/voice/VoiceAvailabilityService';
import type {VoiceRegionAvailability, VoiceServerRecord} from '@app/api/voice/VoiceModel';
@@ -19,9 +20,8 @@ import {
selectVoiceRegionId,
} from '@app/api/voice/VoiceRegionSelection';
import {generateConnectionId} from '@app/api/words/Words';
+import {TierGatedActions} from '@fluxer/constants/src/AccountTierConstants';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
-import {UnclaimedAccountCannotJoinOneOnOneVoiceCallsError} from '@fluxer/errors/src/domains/channel/UnclaimedAccountCannotJoinOneOnOneVoiceCallsError';
-import {UnclaimedAccountCannotJoinVoiceChannelsError} from '@fluxer/errors/src/domains/channel/UnclaimedAccountCannotJoinVoiceChannelsError';
import {UnknownChannelError} from '@fluxer/errors/src/domains/channel/UnknownChannelError';
import {FeatureTemporarilyDisabledError} from '@fluxer/errors/src/domains/core/FeatureTemporarilyDisabledError';
import {UnknownGuildMemberError} from '@fluxer/errors/src/domains/guild/UnknownGuildMemberError';
@@ -100,18 +100,8 @@ export class VoiceService {
if (!channel) {
throw new UnknownChannelError();
}
- const isUnclaimed = user.isUnclaimedAccount();
- if (isUnclaimed) {
- if (channel.type === ChannelTypes.DM) {
- throw new UnclaimedAccountCannotJoinOneOnOneVoiceCallsError();
- }
- if (channel.type === ChannelTypes.GUILD_VOICE) {
- const guild = guildId ? await this.guildRepository.findUnique(guildId) : null;
- const isOwner = guild?.ownerId === userId;
- if (!isOwner) {
- throw new UnclaimedAccountCannotJoinVoiceChannelsError();
- }
- }
+ if (!canReachOthers(user)) {
+ await this.assertVoiceReach(user, channel.type, guildId);
}
let mute = false;
let deaf = false;
@@ -501,4 +491,17 @@ export class VoiceService {
deaf,
});
}
+
+ private async assertVoiceReach(user: User, channelType: number, guildId: GuildID | null | undefined): Promise<void> {
+ if (channelType === ChannelTypes.GUILD_VOICE) {
+ const guild = guildId ? await this.guildRepository.findUnique(guildId) : null;
+ assertTierAllows(user, TierGatedActions.VOICE, {...NO_TIER_CONTEXT, isGuildOwner: guild?.ownerId === user.id});
+ return;
+ }
+ if (channelType === ChannelTypes.DM) {
+ assertTierAllows(user, TierGatedActions.CALL, NO_TIER_CONTEXT);
+ } else if (channelType === ChannelTypes.GROUP_DM) {
+ assertTierAllows(user, TierGatedActions.GROUP_CALL, NO_TIER_CONTEXT);
+ }
+ }
}