305 lines
11 KiB
TypeScript
305 lines
11 KiB
TypeScript
// Metro module 4372 (f4373).
|
|
import { isGuildSelectableChannelType, THREAD_CHANNEL_TYPES, TEXT_CHANNEL_TYPES } from "../records/ChannelRecord";
|
|
import ChannelStore from "../stores/ChannelStore";
|
|
import GuildChannelStore from "../stores/GuildChannelStore";
|
|
import PermissionStore from "../stores/PermissionStore";
|
|
import SelectedChannelStore from "../stores/SelectedChannelStore";
|
|
import SortedVoiceStateStore from "../stores/views/SortedVoiceStateStore";
|
|
import { Permissions, ChannelTypes, BITRATE_DEFAULT, BITRATE_MAX, GuildFeatures, BoostedGuildTiers, Routes, AnalyticsPages } from "../Constants";
|
|
import { BoostedGuildFeatures } from "../modules/premium/PremiumConstants";
|
|
import { NONE } from "./PermissionUtils";
|
|
import { add } from "../_bundle/HighLow";
|
|
import { PermissionOverwriteType } from "../flow/Server";
|
|
import { hasStream } from "../modules/guild_sidebar/ChannelListUtils";
|
|
import { getAudienceRequestToSpeakState, RequestToSpeakStates } from "../modules/stage_channels/useAudienceRequestToSpeakState";
|
|
import { intl, t } from "../intl/index.native";
|
|
import UserUtils from "./UserUtils";
|
|
import * as _MediaPostEmbedUtils from "../modules/media_channel/MediaPostEmbedUtils";
|
|
import SnowflakeUtils from "./SnowflakeUtils";
|
|
import sanitizeGuildTextChannelName from "../modules/channel/sanitizeGuildTextChannelName";
|
|
function $mk74367($env) {
|
|
return (a0) => {
|
|
const r1 = $env;
|
|
if (a0.id !== r1[1] && a0.id !== r1[0]) {
|
|
const r9 = r1[2][a0.id];
|
|
if (r9 != null) {
|
|
if (a0.isGuildStageVoice()) {
|
|
r9.forEach($mk103750(r1));
|
|
} else {
|
|
r9.forEach($mk103751(r1));
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
function $mk103750($env) {
|
|
return (a0) => {
|
|
const r1 = $env.$parent;
|
|
const r4 = r1[0];
|
|
const r7 = r1[3];
|
|
if (r4(r7[12]).getAudienceRequestToSpeakState(a0.voiceState) === r4(r7[12]).RequestToSpeakStates.ON_STAGE) {
|
|
$env[3].push(a0);
|
|
}
|
|
};
|
|
}
|
|
function $mk103751($env) {
|
|
return (a0) => $env[3].push(a0);
|
|
}
|
|
let GUILD_VOICE, GUILD_CATEGORY, GUILD_STAGE_VOICE;
|
|
let env2590 = {};
|
|
export function allowChannelAccess(a0, a1, a2) {
|
|
const r11 = (0, isGuildSelectableChannelType)(a1) || a1 === GUILD_CATEGORY ? add(NONE, Permissions.VIEW_CHANNEL) : NONE;
|
|
return {
|
|
id: a0,
|
|
type: a2,
|
|
deny: NONE,
|
|
allow: a1 === GUILD_VOICE || a1 === GUILD_CATEGORY || (a1 === GUILD_STAGE_VOICE || a1 === GUILD_CATEGORY) ? add(add(r11, Permissions.VIEW_CHANNEL), Permissions.CONNECT) : r11
|
|
};
|
|
}
|
|
const ChannelTypes2 = ChannelTypes;
|
|
GUILD_VOICE = ChannelTypes2.GUILD_VOICE;
|
|
GUILD_CATEGORY = ChannelTypes2.GUILD_CATEGORY;
|
|
GUILD_STAGE_VOICE = ChannelTypes2.GUILD_STAGE_VOICE;
|
|
export function denyChannelAccessForNonPaidUsers(a0, a1) {
|
|
if (a1 === ChannelTypes.GUILD_STAGE_VOICE) {
|
|
return {
|
|
id: a0,
|
|
type: PermissionOverwriteType.ROLE,
|
|
allow: NONE,
|
|
deny: add(NONE, Permissions.CONNECT)
|
|
};
|
|
}
|
|
throw new Error(`Premium channel feature not supported for channel type ${a1}`);
|
|
}
|
|
export function permissionOverwritesForRoles(a0, a1, a2) {
|
|
let r8 = arguments[3];
|
|
if (r8 === void 0) {
|
|
r8 = false;
|
|
}
|
|
const r4 = [];
|
|
let c14146_1 = r4;
|
|
if (a2.length > 0 || r8) {
|
|
const ROLE = PermissionOverwriteType.ROLE;
|
|
const r16 = (0, isGuildSelectableChannelType)(a1) || a1 === GUILD_CATEGORY ? add(NONE, Permissions.VIEW_CHANNEL) : NONE;
|
|
r4.push({
|
|
id: a0,
|
|
type: ROLE,
|
|
allow: NONE,
|
|
deny: a1 === GUILD_VOICE || a1 === GUILD_CATEGORY ? add(add(r16, Permissions.VIEW_CHANNEL), Permissions.CONNECT) : r16
|
|
});
|
|
}
|
|
a2.forEach((item) => {
|
|
c14146_1.push(allowChannelAccess(item, a1, PermissionOverwriteType.ROLE));
|
|
});
|
|
return r4;
|
|
}
|
|
export function permissionOverwriteForUser(a0, a1) {
|
|
return allowChannelAccess(a0, a1, PermissionOverwriteType.MEMBER);
|
|
}
|
|
export function permissionOverwriteForRole(a0, a1) {
|
|
return allowChannelAccess(a0, a1, PermissionOverwriteType.ROLE);
|
|
}
|
|
export function permissionOverwritesForAnnouncement(a0) {
|
|
return [{
|
|
id: a0,
|
|
type: PermissionOverwriteType.ROLE,
|
|
deny: Permissions.SEND_MESSAGES,
|
|
allow: NONE
|
|
}];
|
|
}
|
|
export function isChannelFull(a0, a1, a2) {
|
|
const guildId = a0.getGuildId();
|
|
const guild = a2.getGuild(guildId);
|
|
let r11 = guild?.maxVideoChannelUsers;
|
|
if (r11 == null) {
|
|
r11 = -1;
|
|
}
|
|
let r10 = guild?.maxStageVideoChannelUsers;
|
|
if (r10 == null) {
|
|
r10 = -1;
|
|
}
|
|
const r22 = SortedVoiceStateStore.countVoiceStatesForChannel(a0.id);
|
|
const voiceStatesForChannel = SortedVoiceStateStore.getVoiceStatesForChannel(a0);
|
|
const r26 = PermissionStore.can(Permissions.MOVE_MEMBERS, a0) && PermissionStore.can(Permissions.CONNECT, a0);
|
|
let r32 = a0.type === GUILD_STAGE_VOICE ? guildId != null && (a1.hasVideo(a0.id) || hasStream(voiceStatesForChannel)) && r10 > 0 && r22 >= r10 : guildId != null && a1.hasVideo(a0.id) && r11 > 0 && r22 >= r11 + (r26 ? 1 : 0);
|
|
let r48 = a0.userLimit > 0 && r22 >= a0.userLimit;
|
|
if (!r32) {
|
|
if (r48) {
|
|
r48 = !r26;
|
|
}
|
|
r32 = r48;
|
|
}
|
|
return r32;
|
|
}
|
|
exports.sanitizeGuildTextChannelName = sanitizeGuildTextChannelName;
|
|
export function getBitrateLimit(a0, a1) {
|
|
return a1.isGuildStageVoice() ? BITRATE_DEFAULT : a0 == null ? BITRATE_MAX : Math.max(a0.features.has(GuildFeatures.VIP_REGIONS) ? BoostedGuildFeatures[BoostedGuildTiers.TIER_3].limits.bitrate : BITRATE_MAX, BoostedGuildFeatures[a0.premiumTier].limits.bitrate);
|
|
}
|
|
export function computeSummarizedVoiceStates(a0) {
|
|
let env14145;
|
|
const r1 = env14145 = {
|
|
$parent: env2590
|
|
};
|
|
const channels = a0.channels;
|
|
env14145[0] = a0.selectedChannelId;
|
|
env14145[1] = a0.selectedVoiceChannelId;
|
|
env14145[2] = a0.voiceStates;
|
|
const r6 = [];
|
|
env14145[3] = r6;
|
|
channels.forEach($mk74367(r1));
|
|
return r6;
|
|
}
|
|
export function computeSummarizedVoiceUsers({ channels, selectedChannelId, selectedVoiceChannelId, voiceStates }) {
|
|
let env14147;
|
|
const r6 = env14147 = {
|
|
$parent: env2590
|
|
};
|
|
env14147[0] = selectedChannelId;
|
|
env14147[1] = selectedVoiceChannelId;
|
|
env14147[2] = voiceStates;
|
|
const r7 = [];
|
|
env14147[3] = r7;
|
|
channels.forEach($mk74367(r6));
|
|
return r7.map((item) => item.user);
|
|
}
|
|
export function isAnyVoiceStateStage(a0, a1, a2) {
|
|
for (const item2 of a0) {
|
|
L10: {
|
|
if (item2.id === a1) {
|
|
continue;
|
|
}
|
|
const r34 = a2[item2.id];
|
|
if (r34 == null) {
|
|
continue;
|
|
}
|
|
if (!item2.isGuildStageVoice()) {
|
|
continue;
|
|
}
|
|
for (const item of r34) {
|
|
if (getAudienceRequestToSpeakState(item.voiceState) !== RequestToSpeakStates.ON_STAGE) {
|
|
continue;
|
|
}
|
|
break L10;
|
|
}
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
export function channelTypeString({ type }) {
|
|
if (ChannelTypes.DM === type) {
|
|
return intl.string(t.jN2DfZ);
|
|
}
|
|
if (ChannelTypes.GROUP_DM === type) {
|
|
return intl.string(t["e5y+gm"]);
|
|
}
|
|
if (ChannelTypes.GUILD_TEXT === type) {
|
|
return intl.string(t.Pnajj0);
|
|
}
|
|
if (ChannelTypes.GUILD_FORUM === type) {
|
|
return intl.string(t.GbryDd);
|
|
}
|
|
if (ChannelTypes.GUILD_MEDIA === type) {
|
|
return intl.string(t.seKITE);
|
|
}
|
|
if (ChannelTypes.GUILD_VOICE === type) {
|
|
return intl.string(t.BVZqJl);
|
|
}
|
|
if (ChannelTypes.GUILD_STAGE_VOICE === type) {
|
|
return intl.string(t.EErMzA);
|
|
}
|
|
if (ChannelTypes.GUILD_ANNOUNCEMENT === type) {
|
|
return intl.string(t.l1dkSD);
|
|
}
|
|
if (ChannelTypes.GUILD_STORE === type) {
|
|
return intl.string(t["P1/Erq"]);
|
|
}
|
|
if (ChannelTypes.GUILD_CATEGORY === type) {
|
|
return intl.string(t.vHCZwr);
|
|
}
|
|
return null;
|
|
}
|
|
export function getPrivateChannelUserTagsString(a0, a1) {
|
|
if (a0 == null) {
|
|
return null;
|
|
}
|
|
const id = a1.getCurrentUser()?.id;
|
|
if (id == null) {
|
|
return null;
|
|
}
|
|
const r6 = [];
|
|
for (const item of a0) {
|
|
if (id !== item) {
|
|
const user = a1.getUser(item);
|
|
if (user != null) {
|
|
r6.push(user);
|
|
}
|
|
}
|
|
}
|
|
if (r6.length === 0) {
|
|
return null;
|
|
}
|
|
const r46 = r6.slice(0, 2).map((item) => item.isProvisional ? UserUtils.getName(item) : UserUtils.getUserTag(item));
|
|
return intl.formatToPlainString(t.BXG0Eh, {
|
|
users: r6.length,
|
|
user1: r46[0],
|
|
user2: r46[1],
|
|
extras: r6.length - r46.length
|
|
});
|
|
}
|
|
export function getMentionIconType(a0) {
|
|
if (a0 == null) {
|
|
return "text";
|
|
}
|
|
const isNSFW = a0.isNSFW();
|
|
const isSpoilerChannel = a0.isSpoilerChannel();
|
|
const isMediaChannel = a0.isMediaChannel();
|
|
return a0.type === ChannelTypes.GUILD_VOICE ? PermissionStore.can(Permissions.CONNECT, a0) ? isNSFW ? "voice-nsfw" : isSpoilerChannel ? "voice-spoiler" : "voice" : "voice-locked" : a0.type === ChannelTypes.GUILD_STAGE_VOICE ? PermissionStore.can(Permissions.CONNECT, a0) ? "stage" : "stage-locked" : THREAD_CHANNEL_TYPES.has(a0.type) ? a0.isForumPost() ? "post" : "thread" : a0.type === ChannelTypes.GUILD_FORUM ? isMediaChannel ? isNSFW ? "media-nsfw" : "media" : isNSFW ? "forum-nsfw" : isSpoilerChannel ? "forum-spoiler" : "forum" : a0.type === ChannelTypes.GUILD_MEDIA ? isNSFW ? "media-nsfw" : "media" : a0.type === ChannelTypes.GUILD_ANNOUNCEMENT ? isNSFW ? "announcement-nsfw" : isSpoilerChannel ? "announcement-spoiler" : "announcement" : TEXT_CHANNEL_TYPES.has(a0.type) ? isNSFW ? "text-nsfw" : isSpoilerChannel ? "text-spoiler" : "text" : void 0;
|
|
}
|
|
export function previousTextChannelRouteForGuild(a0) {
|
|
let id;
|
|
const channel = ChannelStore.getChannel(SelectedChannelStore.getLastSelectedChannelId());
|
|
if (channel != null && (channel.getGuildId() === a0 && channel.type === ChannelTypes.GUILD_TEXT)) {
|
|
id = channel.id;
|
|
} else {
|
|
const defaultChannel = GuildChannelStore.getDefaultChannel(a0);
|
|
id = defaultChannel != null ? defaultChannel.id : null;
|
|
}
|
|
return Routes.CHANNEL(a0, id);
|
|
}
|
|
export function getChannelPermalink(a0, a1, a2, a3) {
|
|
const r6 = a3 == null ? "" : `?summaryId=${a3}`;
|
|
return `${location.protocol}//${location.host}${Routes.CHANNEL(a0, a1, a2)}${r6}`;
|
|
}
|
|
export function getChannelThreadPermalink(a0, a1, a2, a3) {
|
|
return a0 != null && (a1 != null && a2 != null) ? `${location.protocol}//${location.host}${Routes.CHANNEL_THREAD_VIEW(a0, a1, a2, a3)}` : `${location.protocol}//${location.host}${Routes.CHANNEL(a0, a1, a3)}`;
|
|
}
|
|
export function getChannelLinkToCopy(a0, a1, a2, a3) {
|
|
let r25;
|
|
const guildId = a0.getGuildId();
|
|
const canUseMediaPostEmbed = _MediaPostEmbedUtils.canUseMediaPostEmbed(guildId, a1);
|
|
if (a1 != null && canUseMediaPostEmbed) {
|
|
const id = a1.id;
|
|
const id2 = a0.id;
|
|
const r39 = SnowflakeUtils.castChannelIdAsMessageId(a0.id);
|
|
r25 = guildId != null && (id != null && id2 != null) ? `${location.protocol}//${location.host}${Routes.CHANNEL_THREAD_VIEW(guildId, id, id2, r39)}` : `${location.protocol}//${location.host}${Routes.CHANNEL(guildId, id, r39)}`;
|
|
} else {
|
|
r25 = a3 == null ? `${location.protocol}//${location.host}${Routes.CHANNEL(guildId, a0.id, a2)}` : a3;
|
|
}
|
|
return r25;
|
|
}
|
|
export function getChannelAnalyticsPage(a0) {
|
|
if (a0 == null) {
|
|
return null;
|
|
}
|
|
const type = a0.type;
|
|
if (ChannelTypes.GUILD_ANNOUNCEMENT !== type && ChannelTypes.GUILD_TEXT !== type && ChannelTypes.GUILD_FORUM !== type && ChannelTypes.GUILD_MEDIA !== type) {
|
|
if (ChannelTypes.GROUP_DM !== type && ChannelTypes.DM !== type) {
|
|
return null;
|
|
}
|
|
return AnalyticsPages.DM_CHANNEL;
|
|
}
|
|
return AnalyticsPages.GUILD_CHANNEL;
|
|
}
|