Skip to content

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

TypeScript fluxerfluxerapp

fix(api): allow 18+ community emojis and stickers anywhere (#3862)

Hampus799062296093
diff --git a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
index d87a41837..f95bb66af 100644
--- a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
+++ b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts
@@ -17,7 +17,7 @@ import type {User} from '@app/api/models/User';
import {assertAccountNotLimited} from '@app/api/user/AccountLimit';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import {mapUserToPartialResponse} from '@app/api/user/UserMappers';
-import {checkUserGlobalExpressions, isExpressionSourceAgeRestricted} from '@app/api/utils/EmojiUtils';
+import {checkUserGlobalExpressions} from '@app/api/utils/EmojiUtils';
import {assertGuildMemberCanCommunicate} from '@app/api/utils/GuildCommunicationUtils';
import {Permissions} from '@fluxer/constants/src/ChannelConstants';
import {GuildOperations} from '@fluxer/constants/src/GuildConstants';
@@ -404,9 +404,6 @@ export class MessageReactionService {
throw InputValidationError.fromCode('emoji', ValidationErrorCodes.CUSTOM_EMOJI_NOT_FOUND);
}
const isExternalEmoji = emoji.guildId.toString() !== guildId;
- if (isExternalEmoji && (await isExpressionSourceAgeRestricted(this.guildRepository, emoji.guildId))) {
- throw new MissingPermissionsError();
- }
if (hasGlobalExpressions === 0 && isExternalEmoji) {
throw InputValidationError.fromCode('emoji', ValidationErrorCodes.CUSTOM_EMOJIS_REQUIRE_PREMIUM_OUTSIDE_SOURCE);
}
diff --git a/fluxer_api/src/api/channel/services/message/MessageStickerService.ts b/fluxer_api/src/api/channel/services/message/MessageStickerService.ts
index dfb0bf04c..a246a9253 100644
--- a/fluxer_api/src/api/channel/services/message/MessageStickerService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessageStickerService.ts
@@ -5,7 +5,7 @@ import type {MessageStickerItem} from '@app/api/database/types/MessageTypes';
import type {GuildRepository} from '@app/api/guild/repositories/GuildRepository';
import type {LimitConfigService} from '@app/api/limits/LimitConfigService';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
-import {checkUserGlobalExpressions, isExpressionSourceAgeRestricted} from '@app/api/utils/EmojiUtils';
+import {checkUserGlobalExpressions} from '@app/api/utils/EmojiUtils';
import {Permissions} from '@fluxer/constants/src/ChannelConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
@@ -38,9 +38,6 @@ export class MessageStickerService {
if (!stickerFromAnyGuild) {
throw InputValidationError.fromCode('sticker', ValidationErrorCodes.CUSTOM_STICKER_NOT_FOUND);
}
- if (await isExpressionSourceAgeRestricted(this.guildRepository, stickerFromAnyGuild.guildId)) {
- throw new MissingPermissionsError();
- }
return {
sticker_id: stickerFromAnyGuild.id,
name: stickerFromAnyGuild.name,
@@ -59,9 +56,6 @@ export class MessageStickerService {
if (!stickerFromOtherGuild) {
throw InputValidationError.fromCode('sticker', ValidationErrorCodes.CUSTOM_STICKER_NOT_FOUND);
}
- if (await isExpressionSourceAgeRestricted(this.guildRepository, stickerFromOtherGuild.guildId)) {
- throw new MissingPermissionsError();
- }
if (hasGlobalExpressions === 0) {
throw InputValidationError.fromCode(
'sticker',
diff --git a/fluxer_api/src/api/channel/tests/ReactionExternalEmojiPermissions.test.ts b/fluxer_api/src/api/channel/tests/ReactionExternalEmojiPermissions.test.ts
index 35e0818fd..e45e1dcb3 100644
--- a/fluxer_api/src/api/channel/tests/ReactionExternalEmojiPermissions.test.ts
+++ b/fluxer_api/src/api/channel/tests/ReactionExternalEmojiPermissions.test.ts
@@ -61,7 +61,7 @@ describe('Reactions without USE_EXTERNAL_EMOJIS', () => {
}
});
- it('refuses emojis from an 18+ community outside it', async () => {
+ it('allows emojis from an 18+ community outside it', async () => {
const {owner, members, systemChannel} = await setupTestGuildWithMembers(harness, 1);
const [reactor] = members;
const message = await sendChannelMessage(harness, owner.token, systemChannel.id, 'react to me');
@@ -76,7 +76,7 @@ describe('Reactions without USE_EXTERNAL_EMOJIS', () => {
await createBuilder(harness, reactor.token)
.put(`/channels/${systemChannel.id}/messages/${message.id}/reactions/${matureEmoji.name}:${matureEmoji.id}/@me`)
.body(null)
- .expect(HTTP_STATUS.FORBIDDEN, APIErrorCodes.MISSING_PERMISSIONS)
+ .expect(HTTP_STATUS.NO_CONTENT)
.execute();
} finally {
await restore();
diff --git a/fluxer_api/src/api/utils/EmojiUtils.ts b/fluxer_api/src/api/utils/EmojiUtils.ts
index 070ac8c1f..8ecb8ea22 100644
--- a/fluxer_api/src/api/utils/EmojiUtils.ts
+++ b/fluxer_api/src/api/utils/EmojiUtils.ts
@@ -6,11 +6,9 @@ import type {GuildRepository} from '@app/api/guild/repositories/GuildRepository'
import type {LimitConfigService} from '@app/api/limits/LimitConfigService';
import {resolveLimitSafe} from '@app/api/limits/LimitConfigUtils';
import {createLimitMatchContext} from '@app/api/limits/LimitMatchContextBuilder';
-import type {Guild} from '@app/api/models/Guild';
import type {GuildEmoji} from '@app/api/models/GuildEmoji';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import {Permissions} from '@fluxer/constants/src/ChannelConstants';
-import {GuildNSFWLevel} from '@fluxer/constants/src/GuildConstants';
type EmojiGuildRepository = Pick<GuildRepository, 'getEmoji' | 'getEmojiById' | 'findUnique'>;
type EmojiUserRepository = Pick<UserRepository, 'findUnique'>;
@@ -110,17 +108,6 @@ function collectEmojiMatches(content: string, isInEscapedContext: (index: number
return matches;
}
-function isAgeRestrictedGuild(guild: Guild | null): boolean {
- return guild != null && (guild.nsfw || guild.nsfwLevel === GuildNSFWLevel.AGE_RESTRICTED);
-}
-
-export async function isExpressionSourceAgeRestricted(
- guildRepository: Pick<GuildRepository, 'findUnique'>,
- sourceGuildId: GuildID,
-): Promise<boolean> {
- return isAgeRestrictedGuild(await guildRepository.findUnique(sourceGuildId));
-}
-
export async function checkUserGlobalExpressions(
userId: UserID,
userRepository: EmojiUserRepository,
@@ -135,7 +122,6 @@ interface EmojiLookupResult {
emojiId: EmojiID;
guildEmoji: GuildEmoji | null;
globalEmoji: GuildEmoji | null;
- sourceAgeRestricted: boolean;
}
async function batchFetchEmojis(
@@ -150,11 +136,7 @@ async function batchFetchEmojis(
guildId ? guildRepository.getEmoji(emojiId, guildId) : Promise.resolve(null),
guildRepository.getEmojiById(emojiId),
]);
- const sourceAgeRestricted =
- guildEmoji === null && globalEmoji !== null
- ? await isExpressionSourceAgeRestricted(guildRepository, globalEmoji.guildId)
- : false;
- return {emojiId, guildEmoji, globalEmoji, sourceAgeRestricted};
+ return {emojiId, guildEmoji, globalEmoji};
}),
);
const lookupMap = new Map<EmojiID, EmojiLookupResult>();
@@ -209,7 +191,6 @@ async function shouldReplaceEmoji(params: {
canUseExternalEmojis: boolean | null;
}): Promise<boolean> {
const {lookup, guildId, isWebhook, hasGlobalExpressions, canUseExternalEmojis} = params;
- if (lookup.sourceAgeRestricted) return true;
if (!guildId) {
if (!lookup.globalEmoji) return true;
if (!isWebhook && hasGlobalExpressions === 0) return true;