235 lines
8.6 KiB
TypeScript
235 lines
8.6 KiB
TypeScript
// Metro module 3834 (f3835).
|
|
import { isGuildTextChannelType, isGuildVocalChannelType } from "../records/ChannelRecord";
|
|
import PermissionStore from "../stores/PermissionStore";
|
|
import UserStore from "../stores/UserStore";
|
|
import { Permissions } from "../Constants";
|
|
import { EMOJI_MAX_FILESIZE, EMOJI_MAX_LENGTH, EMOJI_RE, EmojiDisabledReasons, EmojiIntention, isExternalEmojiAllowedForIntention } from "../modules/emojis/EmojiConstants";
|
|
import { EmojiTypes } from "../modules/emojis/EmojiTypes";
|
|
import PremiumUtils from "./PremiumUtils";
|
|
import { isUnusableRoleSubscriptionEmoji, isPurchasableRoleSubscriptionEmoji } from "../modules/guild_role_subscriptions/RoleSubscriptionEmojiUtils";
|
|
import { shouldHideGuildPurchaseEntryPoints } from "../modules/creator_monetization_review/CreatorMonetizationRestrictionsUtils";
|
|
import EmojiUtilsPlatformed_native from "./EmojiUtilsPlatformed.native";
|
|
import { dataUriFileSize } from "./ImageUtils";
|
|
import AvatarUtils from "./AvatarUtils";
|
|
let c2168_15, c2168_16, c2168_17;
|
|
const getEmojiUnavailableReason = function getEmojiUnavailableReason(a0) {
|
|
const { emoji, channel } = a0;
|
|
let guildId = a0.guildId;
|
|
if (guildId === void 0) {
|
|
guildId = channel == null ? void 0 : channel.getGuildId();
|
|
}
|
|
const { intention, forceIncludeExternalGuilds } = a0;
|
|
if (emoji.type === EmojiTypes.GUILD || emoji.guildId != null) {
|
|
if (intention !== EmojiIntention.GUILD_PROFILE && intention !== EmojiIntention.NO_CUSTOM_EMOJI) {
|
|
const r15 = channel != null && isGuildTextChannelType(channel.type);
|
|
const r34 = channel != null && isGuildVocalChannelType(channel.type);
|
|
let r36 = emoji != null && guildId != null;
|
|
if (r36) {
|
|
const r2 = emoji.type === EmojiTypes.GUILD || emoji.guildId != null;
|
|
r36 = r2 ? guildId === emoji.guildId : !r2;
|
|
}
|
|
const r48 = PermissionStore.can(Permissions.USE_EXTERNAL_EMOJIS, channel);
|
|
if (intention === EmojiIntention.COMMUNITY_CONTENT) {
|
|
return r36 && emoji.guildId != null ? emoji.available ? null : EmojiDisabledReasons.DISALLOW_EXTERNAL : EmojiDisabledReasons.DISALLOW_EXTERNAL;
|
|
}
|
|
if (!isExternalEmojiAllowedForIntention(intention)) {
|
|
let r52 = emoji != null && guildId != null;
|
|
if (r52) {
|
|
const r4 = emoji.type === EmojiTypes.GUILD || emoji.guildId != null;
|
|
r52 = r4 ? guildId === emoji.guildId : !r4;
|
|
}
|
|
if (!r52 && !forceIncludeExternalGuilds) {
|
|
return EmojiDisabledReasons.DISALLOW_EXTERNAL;
|
|
}
|
|
}
|
|
if (!(!r15 && !r34) && !r36 && !r48) {
|
|
return EmojiDisabledReasons.DISALLOW_EXTERNAL;
|
|
}
|
|
if (emoji.id != null && !emoji.available) {
|
|
return EmojiDisabledReasons.GUILD_SUBSCRIPTION_UNAVAILABLE;
|
|
}
|
|
const currentUser = UserStore.getCurrentUser();
|
|
if (!PremiumUtils.canUseEmojisEverywhere(currentUser) && !r36) {
|
|
if (intention === EmojiIntention.STATUS) {
|
|
return EmojiDisabledReasons.PREMIUM_LOCKED;
|
|
}
|
|
if (!emoji.managed) {
|
|
return EmojiDisabledReasons.PREMIUM_LOCKED;
|
|
}
|
|
}
|
|
if (guildId == null) {
|
|
guildId = void 0;
|
|
}
|
|
return isUnusableRoleSubscriptionEmoji(emoji, guildId) ? shouldHideGuildPurchaseEntryPoints(emoji.guildId) ? EmojiDisabledReasons.ROLE_SUBSCRIPTION_UNAVAILABLE : EmojiDisabledReasons.ROLE_SUBSCRIPTION_LOCKED : emoji.animated ? PremiumUtils.canUseAnimatedEmojis(currentUser) ? null : isPurchasableRoleSubscriptionEmoji(emoji) ? null : EmojiDisabledReasons.PREMIUM_LOCKED : null;
|
|
}
|
|
return EmojiDisabledReasons.DISALLOW_CUSTOM;
|
|
}
|
|
return null;
|
|
};
|
|
c2168_15 = new Set([EmojiDisabledReasons.PREMIUM_LOCKED, EmojiDisabledReasons.ROLE_SUBSCRIPTION_LOCKED]);
|
|
c2168_16 = new Set([...c2168_15, EmojiDisabledReasons.GUILD_SUBSCRIPTION_UNAVAILABLE, EmojiDisabledReasons.ROLE_SUBSCRIPTION_UNAVAILABLE]);
|
|
c2168_17 = new Set([EmojiDisabledReasons.DISALLOW_CUSTOM, EmojiDisabledReasons.DISALLOW_EXTERNAL, EmojiDisabledReasons.GUILD_SUBSCRIPTION_UNAVAILABLE, EmojiDisabledReasons.ONLY_GUILD_EMOJIS_ALLOWED]);
|
|
const r71 = {
|
|
sanitizeEmojiName: (a0) => {
|
|
let length2;
|
|
const r9 = a0.replace(EMOJI_RE, "").slice(0, EMOJI_MAX_LENGTH);
|
|
const length = r9.length;
|
|
let r13 = r9;
|
|
let r14 = r13;
|
|
if (length < 2) {
|
|
do {
|
|
const r15 = r13 + "_";
|
|
length2 = r15.length;
|
|
r13 = r15;
|
|
r14 = r13;
|
|
} while (length2 < 2);
|
|
}
|
|
return r14;
|
|
},
|
|
filterUnsupportedEmojis: EmojiUtilsPlatformed_native.filterUnsupportedEmojis,
|
|
getURL: EmojiUtilsPlatformed_native.getURL,
|
|
isInternalEmojiForGuildId: function isInternalEmojiForGuildId(a0, a1) {
|
|
let r0 = a0 != null && a1 != null;
|
|
if (r0) {
|
|
const r13 = a0.type === EmojiTypes.GUILD || a0.guildId != null;
|
|
r0 = r13 ? a1 === a0.guildId : !r13;
|
|
}
|
|
return r0;
|
|
},
|
|
getEmojiUnavailableReason,
|
|
isCustomEmoji: function isCustomEmoji(a0) {
|
|
return a0.type === EmojiTypes.GUILD || a0.guildId != null;
|
|
},
|
|
getEmojiUnavailableReasons: ({ categoryEmojis, channel, guildId, intention }) => {
|
|
const set = new Set();
|
|
const emojisUnfiltered = [];
|
|
let emojisPremiumLockedCount = 0;
|
|
let emojiNitroLocked = false;
|
|
for (const item of categoryEmojis) {
|
|
const emojiUnavailableReason = getEmojiUnavailableReason({
|
|
emoji: item,
|
|
channel,
|
|
guildId,
|
|
intention
|
|
});
|
|
if (emojiUnavailableReason != null) {
|
|
if (!c2168_17.has(emojiUnavailableReason)) {
|
|
emojisUnfiltered.push(item);
|
|
}
|
|
if (c2168_16.has(emojiUnavailableReason)) {
|
|
if (item.id != null) {
|
|
set.add(item.id);
|
|
}
|
|
if (c2168_15.has(emojiUnavailableReason)) {
|
|
if (!(emojiNitroLocked || emojiUnavailableReason !== EmojiDisabledReasons.PREMIUM_LOCKED)) {
|
|
emojiNitroLocked = true;
|
|
}
|
|
emojisPremiumLockedCount = emojisPremiumLockedCount + 1;
|
|
}
|
|
}
|
|
} else {
|
|
emojisUnfiltered.push(item);
|
|
}
|
|
}
|
|
return {
|
|
emojisDisabled: set,
|
|
emojisUnfiltered,
|
|
emojisPremiumLockedCount,
|
|
emojiNitroLocked
|
|
};
|
|
},
|
|
isEmojiFiltered: (a0) => c2168_17.has(getEmojiUnavailableReason(a0)),
|
|
isEmojiPremiumLocked: (a0) => c2168_15.has(getEmojiUnavailableReason(a0)),
|
|
isEmojiCategoryNitroLocked: ({ categoryEmojis, channel, guildId, intention }) => {
|
|
let r0 = false;
|
|
let r2 = 0;
|
|
for (const item of categoryEmojis) {
|
|
const emojiUnavailableReason = getEmojiUnavailableReason({
|
|
emoji: item,
|
|
channel,
|
|
intention,
|
|
guildId
|
|
});
|
|
if (emojiUnavailableReason === EmojiDisabledReasons.PREMIUM_LOCKED) {
|
|
r0 = true;
|
|
r2 = r2 + 1;
|
|
} else if (emojiUnavailableReason === EmojiDisabledReasons.GUILD_SUBSCRIPTION_UNAVAILABLE) {
|
|
r2 = r2 + 1;
|
|
}
|
|
}
|
|
if (r0) {
|
|
r0 = r2 === categoryEmojis.length;
|
|
}
|
|
return r0;
|
|
},
|
|
isEmojiFilteredOrLocked: function isEmojiFilteredOrLocked(a0) {
|
|
return this.isEmojiFiltered(a0) || this.isEmojiPremiumLocked(a0);
|
|
},
|
|
isEmojiDisabled: (a0) => c2168_16.has(getEmojiUnavailableReason(a0)),
|
|
isFileTooBig: (a0) => a0.size > 2097152,
|
|
isDataTooBig: (a0) => dataUriFileSize(a0) > EMOJI_MAX_FILESIZE
|
|
};
|
|
export default r71;
|
|
export function countEmoji(a0, c13647_0) {
|
|
let unicode = 0;
|
|
const custom = 0;
|
|
let customExternal = 0;
|
|
let managed = 0;
|
|
let managedExternal = 0;
|
|
const animated = 0;
|
|
a0.forEach((item) => {
|
|
if (item.id != null) {
|
|
if (item.type === EmojiTypes.GUILD) {
|
|
if (item.guildId === c13647_0) {
|
|
if (item.managed) {
|
|
managed = managed + 1;
|
|
} else {
|
|
custom = custom + 1;
|
|
}
|
|
} else if (item.managed) {
|
|
managedExternal = managedExternal + 1;
|
|
} else {
|
|
customExternal = customExternal + 1;
|
|
}
|
|
}
|
|
if (item.animated) {
|
|
animated = animated + 1;
|
|
}
|
|
} else {
|
|
unicode = unicode + 1;
|
|
}
|
|
});
|
|
return {
|
|
unicode,
|
|
custom,
|
|
customExternal,
|
|
managed,
|
|
managedExternal,
|
|
animated
|
|
};
|
|
}
|
|
export async function getEmojiColors(c24736_0) {
|
|
return await EmojiUtilsPlatformed_native.getEmojiColors(c24736_0);
|
|
}
|
|
export function getEmojiUrl(a0, size = 32) {
|
|
let r14;
|
|
const { id, name } = a0;
|
|
let animated2 = a0.animated;
|
|
if (id != null) {
|
|
if (animated2 == null) {
|
|
animated2 = false;
|
|
}
|
|
r14 = AvatarUtils.getEmojiURL({
|
|
id,
|
|
size,
|
|
animated: animated2
|
|
});
|
|
} else {
|
|
r14 = EmojiUtilsPlatformed_native.getURL(name);
|
|
}
|
|
return r14;
|
|
}
|
|
export function getAllEmojiNamesString(a0) {
|
|
return "allNamesString" in a0 ? a0.allNamesString : `:${a0.name}:`;
|
|
}
|