152 lines
4.9 KiB
TypeScript
152 lines
4.9 KiB
TypeScript
// Metro module 5682 (f5683).
|
|
import ApplicationStore from "../../applications/ApplicationStore";
|
|
import GuildStore from "../../../stores/GuildStore";
|
|
import PermissionStore from "../../../stores/PermissionStore";
|
|
import VibegrationsProjectStore from "../stores/VibegrationsProjectStore";
|
|
import { ChannelTypes, GuildFeatures, Permissions } from "../../../Constants";
|
|
import * as _VibegrationsGuildExperiment from "../experiments/VibegrationsGuildExperiment";
|
|
import { useIsVibegrationsGuildEnabled } from "../experiments/VibegrationsGuildExperiment";
|
|
import { useStateFromStores } from "../../../_bundle/Module589";
|
|
import { publishPreviewProject } from "../actions/VibegrationsActionCreators";
|
|
import VibegrationsPlatformUtils_native from "./VibegrationsPlatformUtils.native";
|
|
let c3518_11 = "vibegrations_application_id=";
|
|
let c3518_12 = /^\d{17,20}$/;
|
|
export function vibegrationsAppIdFromTopic(a0) {
|
|
if (a0 != null && a0.startsWith(c3518_11)) {
|
|
const r8 = a0.slice(28);
|
|
return c3518_12.test(r8) ? r8 : null;
|
|
}
|
|
return null;
|
|
}
|
|
export function vibegrationsTopicForApp(a0) {
|
|
return `${c3518_11}${a0}`;
|
|
}
|
|
export function canManageVibegrations(a0, a1) {
|
|
return _VibegrationsGuildExperiment.isVibegrationsGuildEnabled({
|
|
guildId: a0.id,
|
|
location: a1
|
|
}) && PermissionStore.can(Permissions.MANAGE_CHANNELS, a0) && PermissionStore.can(Permissions.MANAGE_GUILD, a0) && !a0.features.has(GuildFeatures.INTERNAL_EMPLOYEE_ONLY);
|
|
}
|
|
export function useCanManageVibegrations(a0, a1) {
|
|
const stateFromStores = useStateFromStores([PermissionStore], () => {
|
|
const MANAGE_CHANNELS = Permissions.MANAGE_CHANNELS;
|
|
return PermissionStore.can(MANAGE_CHANNELS, a0) && PermissionStore.can(Permissions.MANAGE_GUILD, a0);
|
|
}, [a0]);
|
|
let r20 = useIsVibegrationsGuildEnabled({
|
|
guildId: a0.id,
|
|
location: a1
|
|
});
|
|
const r25 = a0.features.has(GuildFeatures.INTERNAL_EMPLOYEE_ONLY);
|
|
if (r20) {
|
|
r20 = stateFromStores;
|
|
}
|
|
if (r20) {
|
|
r20 = !r25;
|
|
}
|
|
return r20;
|
|
}
|
|
export async function publishPreviewAndReauthorizeIfPermissionsChanged(c25536_0) {
|
|
let c25536_2;
|
|
let c29551_0, c29551_1, c29551_2, c29551_3, c29551_4, c29551_5, c29551_6, c29551_7;
|
|
L20: {
|
|
L19: {
|
|
c25536_2 = void 0;
|
|
c29551_0 = void 0;
|
|
c29551_1 = void 0;
|
|
c29551_2 = void 0;
|
|
c29551_3 = void 0;
|
|
c29551_4 = void 0;
|
|
c29551_5 = void 0;
|
|
c29551_6 = void 0;
|
|
c29551_7 = void 0;
|
|
c29551_0 = VibegrationsProjectStore.getProject(c25536_0)?.preview_guild_id;
|
|
c29551_1 = await publishPreviewProject(c25536_0);
|
|
if (!c29551_1.ok) {
|
|
break L20;
|
|
}
|
|
c29551_2 = c29551_1.body;
|
|
c29551_3 = c29551_2.application;
|
|
c29551_4 = c29551_2.bot_permissions_changed;
|
|
c29551_5 = c29551_2.integration_installed;
|
|
c29551_6 = c29551_2.project.preview_application_id;
|
|
if (c29551_0 == null) {
|
|
break L20;
|
|
}
|
|
if (c29551_6 == null) {
|
|
break L20;
|
|
}
|
|
if (c29551_5 && !c29551_4) {
|
|
break L20;
|
|
}
|
|
c29551_7 = ApplicationStore.getApplication(c29551_6);
|
|
if (c29551_7 != null) {
|
|
await VibegrationsPlatformUtils_native.openVibegrationsAppInstallModal({
|
|
applicationId: c29551_3.id,
|
|
application: c29551_7,
|
|
guildId: c29551_0
|
|
});
|
|
break L19;
|
|
}
|
|
break L20;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|
|
export function isVibegrationsChannelCandidate(a0, a1) {
|
|
const guild = GuildStore.getGuild(a0?.guild_id);
|
|
let r13 = a0 != null && a0.type === ChannelTypes.GUILD_TEXT;
|
|
if (r13) {
|
|
const topic = a0.topic;
|
|
const r16 = topic == null;
|
|
let r17 = null;
|
|
if (!r16) {
|
|
const r19 = topic.startsWith(c3518_11);
|
|
r17 = null;
|
|
if (r19) {
|
|
const r21 = topic.slice(28);
|
|
r17 = c3518_12.test(r21) ? r21 : null;
|
|
}
|
|
}
|
|
r13 = r17 != null;
|
|
}
|
|
if (r13) {
|
|
r13 = !(guild == null ? void 0 : guild.features.has(GuildFeatures.INTERNAL_EMPLOYEE_ONLY));
|
|
}
|
|
if (r13) {
|
|
r13 = _VibegrationsGuildExperiment.isVibegrationsGuildEnabled({
|
|
guildId: a0?.guild_id,
|
|
location: a1
|
|
});
|
|
}
|
|
return r13;
|
|
}
|
|
export function useIsVibegrationsChannelCandidate(a0, a1) {
|
|
const stateFromStores = useStateFromStores([GuildStore], () => GuildStore.getGuild(a0?.guild_id));
|
|
const isVibegrationsGuildEnabled = useIsVibegrationsGuildEnabled({
|
|
guildId: a0?.guild_id,
|
|
location: a1
|
|
});
|
|
let r23 = a0 != null && a0.type === ChannelTypes.GUILD_TEXT;
|
|
if (r23) {
|
|
const topic = a0.topic;
|
|
const r28 = topic == null;
|
|
let r29 = null;
|
|
if (!r28) {
|
|
const r32 = topic.startsWith(c3518_11);
|
|
r29 = null;
|
|
if (r32) {
|
|
const r34 = topic.slice(28);
|
|
r29 = c3518_12.test(r34) ? r34 : null;
|
|
}
|
|
}
|
|
r23 = r29 != null;
|
|
}
|
|
if (r23) {
|
|
r23 = !(stateFromStores == null ? void 0 : stateFromStores.features.has(GuildFeatures.INTERNAL_EMPLOYEE_ONLY));
|
|
}
|
|
if (r23) {
|
|
r23 = isVibegrationsGuildEnabled;
|
|
}
|
|
return r23;
|
|
}
|