181 lines
6.5 KiB
TypeScript
181 lines
6.5 KiB
TypeScript
// Metro module 5705 (f5706).
|
|
import { useMemo } from "react";
|
|
import ImpersonateStore from "../impersonate/ImpersonateStore";
|
|
import { ChannelRecordBase } from "../../records/ChannelRecord";
|
|
import { isGuildNSFW } from "../../records/GuildRecord";
|
|
import AuthenticationStore from "../../stores/AuthenticationStore";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildMemberStore from "../../stores/GuildMemberStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { ChannelTypes, Permissions } from "../../Constants";
|
|
import { getViewNsfwCommandsOrDefault, useViewNsfwCommandsOrDefault } from "../user_settings/content_and_social/AgeRestrictedContentSettingsUtils";
|
|
import { useStateFromStores, useStateFromStoresArray } from "../../_bundle/Module589";
|
|
import { has, deserialize } from "../../_bundle/HighLow";
|
|
import { InteractionContextType } from "../../flow/Server";
|
|
const computePermissions = function computePermissions(a0, a1) {
|
|
if (!(a0 instanceof ChannelRecordBase && a0.isPrivate()) && a0 != null) {
|
|
const computedPermissions = PermissionStore.computePermissions(a0);
|
|
const r22 = has(computedPermissions, Permissions.ADMINISTRATOR);
|
|
let hasSendMessagesPermission = true;
|
|
let hasBaseAccessPermissions = true;
|
|
if (!r22) {
|
|
const r3 = a0 instanceof ChannelRecordBase;
|
|
const r29 = has(computedPermissions, Permissions.VIEW_CHANNEL);
|
|
if (r3) {
|
|
const r30 = r29 ? has(computedPermissions, Permissions.USE_APPLICATION_COMMANDS) : r29;
|
|
hasSendMessagesPermission = a1 ? has(computedPermissions, Permissions.SEND_MESSAGES_IN_THREADS) : has(computedPermissions, Permissions.SEND_MESSAGES);
|
|
hasBaseAccessPermissions = r30;
|
|
} else {
|
|
hasSendMessagesPermission = true;
|
|
hasBaseAccessPermissions = r29;
|
|
}
|
|
}
|
|
return {
|
|
computedPermissions,
|
|
hasBaseAccessPermissions,
|
|
hasSendMessagesPermission
|
|
};
|
|
}
|
|
return {
|
|
computedPermissions: deserialize(0),
|
|
hasBaseAccessPermissions: true,
|
|
hasSendMessagesPermission: true
|
|
};
|
|
};
|
|
export function buildPermissionContext(a0, a1) {
|
|
let roleIds;
|
|
const r2 = a0 instanceof ChannelRecordBase;
|
|
let context = a0;
|
|
if (r2) {
|
|
const isThread = a0.isThread();
|
|
context = a0;
|
|
if (isThread) {
|
|
let r19 = ChannelStore.getChannel(a0.parent_id);
|
|
if (r19 == null) {
|
|
r19 = a0;
|
|
}
|
|
context = r19;
|
|
}
|
|
}
|
|
const r12 = context != null ? context instanceof ChannelRecordBase ? context.guild_id : context.id : void 0;
|
|
let r29 = getViewNsfwCommandsOrDefault();
|
|
const id = AuthenticationStore.getId();
|
|
let r36 = UserStore.getCurrentUser()?.nsfwAllowed;
|
|
if (r36 == null) {
|
|
r36 = false;
|
|
}
|
|
if (r12 != null) {
|
|
let r40 = GuildMemberStore.getMember(r12, id)?.roles;
|
|
if (r40 == null) {
|
|
r40 = [];
|
|
}
|
|
roleIds = r40;
|
|
} else {
|
|
roleIds = [];
|
|
}
|
|
const isViewingRoles = ImpersonateStore.isViewingRoles(r12);
|
|
const r46 = computePermissions(context, a0 instanceof ChannelRecordBase && a0.isThread());
|
|
const isGuildNSFW2 = isGuildNSFW(GuildStore.getGuild(r12));
|
|
let allowNsfw = !!r36;
|
|
if (allowNsfw) {
|
|
let r59 = !(context instanceof ChannelRecordBase);
|
|
if (!r59) {
|
|
if (context.guild_id != null) {
|
|
r29 = context.isNSFW() || isGuildNSFW2;
|
|
}
|
|
r59 = r29;
|
|
}
|
|
allowNsfw = r59;
|
|
}
|
|
return {
|
|
context,
|
|
userId: id,
|
|
roleIds,
|
|
isImpersonating: isViewingRoles,
|
|
commandTypes: a1,
|
|
computedPermissions: r46.computedPermissions,
|
|
hasBaseAccessPermissions: r46.hasBaseAccessPermissions,
|
|
hasSendMessagesPermission: r46.hasSendMessagesPermission,
|
|
allowNsfw
|
|
};
|
|
}
|
|
export function usePermissionContext(a0, a1) {
|
|
let guild_id, stateFromStores, stateFromStoresArray, stateFromStores2, stateFromStores3;
|
|
const commandTypes = a1;
|
|
const memo = useMemo(() => {
|
|
const r0 = a0 instanceof ChannelRecordBase;
|
|
let r7 = a0;
|
|
if (r0) {
|
|
const isThread = a0.isThread();
|
|
r7 = a0;
|
|
if (isThread) {
|
|
let r11 = ChannelStore.getChannel(a0.parent_id);
|
|
if (r11 == null) {
|
|
r11 = a0;
|
|
}
|
|
r7 = r11;
|
|
}
|
|
}
|
|
return r7;
|
|
}, [a0]);
|
|
guild_id = memo != null ? memo instanceof ChannelRecordBase ? memo.guild_id : memo.id : void 0;
|
|
let r26 = useViewNsfwCommandsOrDefault();
|
|
stateFromStores = useStateFromStores([AuthenticationStore], () => AuthenticationStore.getId());
|
|
const stateFromStores4 = useStateFromStores([UserStore], () => {
|
|
let r6 = UserStore.getCurrentUser()?.nsfwAllowed;
|
|
if (r6 == null) {
|
|
r6 = false;
|
|
}
|
|
return r6;
|
|
});
|
|
stateFromStoresArray = useStateFromStoresArray([GuildMemberStore], () => {
|
|
let r2;
|
|
if (guild_id != null) {
|
|
let r10 = GuildMemberStore.getMember(guild_id, stateFromStores)?.roles;
|
|
if (r10 == null) {
|
|
r10 = [];
|
|
}
|
|
r2 = r10;
|
|
} else {
|
|
r2 = [];
|
|
}
|
|
return r2;
|
|
});
|
|
stateFromStores2 = useStateFromStores([ImpersonateStore], () => ImpersonateStore.isViewingRoles(guild_id));
|
|
const stateFromStores5 = useStateFromStores([GuildStore], () => isGuildNSFW(GuildStore.getGuild(guild_id)), [guild_id]);
|
|
let r59 = !!stateFromStores4;
|
|
if (r59) {
|
|
let r62 = !(memo instanceof ChannelRecordBase);
|
|
if (!r62) {
|
|
if (memo.guild_id != null) {
|
|
r26 = memo.isNSFW() || stateFromStores5;
|
|
}
|
|
r62 = r26;
|
|
}
|
|
r59 = r62;
|
|
}
|
|
stateFromStores3 = r59;
|
|
return useMemo(() => {
|
|
const r9 = computePermissions(memo, a0 instanceof ChannelRecordBase && a0.isThread());
|
|
return {
|
|
context: memo,
|
|
userId: stateFromStores,
|
|
roleIds: stateFromStoresArray,
|
|
commandTypes,
|
|
isImpersonating: stateFromStores2,
|
|
computedPermissions: r9.computedPermissions,
|
|
hasBaseAccessPermissions: r9.hasBaseAccessPermissions,
|
|
hasSendMessagesPermission: r9.hasSendMessagesPermission,
|
|
allowNsfw: stateFromStores3
|
|
};
|
|
}, [a1, memo, stateFromStores2, stateFromStoresArray, stateFromStores, stateFromStores3, a0]);
|
|
}
|
|
export function computeCommandContextType(a0, a1) {
|
|
return a0 instanceof ChannelRecordBase ? a0?.guild_id == null ? a0?.type === ChannelTypes.DM ? (a0 == null ? void 0 : a0.getRecipientId()) === a1 ? InteractionContextType.BOT_DM : InteractionContextType.PRIVATE_CHANNEL : InteractionContextType.PRIVATE_CHANNEL : InteractionContextType.GUILD : InteractionContextType.GUILD;
|
|
}
|
|
export function getContextGuildId(a0) {
|
|
return a0 instanceof ChannelRecordBase ? a0.guild_id : a0.id;
|
|
}
|