Files
2026-07-28 01:06:53 +03:00

193 lines
12 KiB
TypeScript

/* Metro module 7866; source: modules/application_commands/CommandPermissionContext.tsx; dependencies: [31, 1937, 1383, 1226, 1379, 1945, 3784, 1878, 661, 7867, 566, 483, 1909, 2] */
import AuthenticationStore from '../../stores/AuthenticationStore.tsx'; /* Metro dependency 1226 */
import ChannelStore from '../../stores/ChannelStore.tsx'; /* Metro dependency 1379 */
import UserStore from '../../stores/UserStore.tsx'; /* Metro dependency 1878 */
import ImpersonateStore from '../impersonate/ImpersonateStore.tsx'; /* Metro dependency 1937 */
import GuildMemberStore from '../../stores/GuildMemberStore.tsx'; /* Metro dependency 1945 */
import PermissionStore from '../../stores/PermissionStore.tsx'; /* Metro dependency 3784 */
import * as FileImportTrackerModule from '../../by-id/module-00002-FileImportTracker.js'; /* Metro dependency 2 */
import * as ReactModule from '../../by-id/module-00031-React.js'; /* Metro dependency 31 */
import * as ConstantsModule from '../../Constants.tsx'; /* Metro dependency 661 */
import * as ChannelRecordModule from '../../records/ChannelRecord.tsx'; /* Metro dependency 1383 */
import * as ServerModule from '../../flow/Server.tsx'; /* Metro dependency 1909 */
import * as AgeRestrictedContentSettingsUtilsModule from '../user_settings/content_and_social/AgeRestrictedContentSettingsUtils.tsx'; /* Metro dependency 7867 */
function _fun62959(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#62959, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:6, offset: 0x01b6d121, size: 324 bytes, params: 8, frame: 21
const env0_0 = require;
const computeAllowNsfw = function(a0, a1, a2) {
return a1 ? a0 instanceof ChannelRecordBase ? a0.guild_id == null ? a2 : a0.nsfw : !(a0 instanceof ChannelRecordBase) : !!a1;
};
const closure = function(a0) {
return a0 instanceof ChannelRecordBase ? a0.guild_id : a0.id;
};
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
(FileImportTrackerModule).fileFinishedImporting('modules/application_commands/CommandPermissionContext.tsx');
exports.buildPermissionContext = buildPermissionContext;
exports.usePermissionContext = usePermissionContext;
exports.computeCommandContextType = computeCommandContextType;
exports.getContextGuildId = closure;
function computePermissions_62961(a0, a1) { // fn#62961, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:330, offset: 0x01b6d2a1, size: 350 bytes, params: 3, frame: 20
var r5;
var r2;
var r3;
var permissions;
var moduleValue;
var has;
var value2;
var value4;
var value5;
var moduleValue3;
var moduleValue4;
var object;
if (a0 instanceof ChannelRecordBase) {
if (a0.isPrivate()) {
object = {'computedPermissions': null, 'hasBaseAccessPermissions': true, 'hasSendMessagesPermission': true};
object.computedPermissions = (importAll(483) /* metro dependency 483: BigFlagUtils */).deserialize(0);
return object;
}
if (a0 == null) {
object = {'computedPermissions': null, 'hasBaseAccessPermissions': true, 'hasSendMessagesPermission': true};
object.computedPermissions = (importAll(483) /* metro dependency 483: BigFlagUtils */).deserialize(0);
return object;
}
permissions = PermissionStore.computePermissions(a0);
value2 = (importAll(483) /* metro dependency 483: BigFlagUtils */).has(permissions, Permissions.ADMINISTRATOR);
} else {
if (a0 == null) {
object = {'computedPermissions': null, 'hasBaseAccessPermissions': true, 'hasSendMessagesPermission': true};
object.computedPermissions = (importAll(483) /* metro dependency 483: BigFlagUtils */).deserialize(0);
return object;
}
permissions = PermissionStore.computePermissions(a0);
moduleValue = importAll(483) /* metro dependency 483: BigFlagUtils */;
value2 = moduleValue.has(permissions, Permissions.ADMINISTRATOR);
}
const value3 = true;
if (value2) {
r2 = value3;
r3 = value3;
} else {
value4 = a0 instanceof ChannelRecordBase;
value5 = (importAll(483) /* metro dependency 483: BigFlagUtils */).has(permissions, Permissions.VIEW_CHANNEL);
if (value4) {
if (value5) {
moduleValue3 = importAll(483) /* metro dependency 483: BigFlagUtils */;
r5 = moduleValue3.has(permissions, Permissions.USE_APPLICATION_COMMANDS);
} else {
r5 = value5;
}
moduleValue4 = importAll(483) /* metro dependency 483: BigFlagUtils */;
has = moduleValue4.has;
r2 = a1 ? Reflect.apply(has, moduleValue4, [permissions,
Permissions.SEND_MESSAGES_IN_THREADS]) : Reflect.apply(has,
moduleValue4, [permissions, Permissions.SEND_MESSAGES]);
r3 = r5;
} else {
r2 = value3;
r3 = value5;
}
}
return {computedPermissions: permissions, hasBaseAccessPermissions: r3, hasSendMessagesPermission: r2};
}
function buildPermissionContext(a0, a1) { // fn#62963, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:1076, offset: 0x01b6d41e, size: 340 bytes, params: 3, frame: 22
var r8;
var r0;
var member;
let value = a0;
const r5 = value instanceof ChannelRecordBase && value.isThread() ? ChannelStore.getChannel(value.parent_id) ?? value : value;
const value4 = undefined;
const r7 = r5 != null ? getContextGuildId(r5) : value4;
const viewNsfwCommandsOrDefault = (AgeRestrictedContentSettingsUtilsModule).getViewNsfwCommandsOrDefault();
const id = AuthenticationStore.getId();
const currentUser = UserStore.getCurrentUser();
const nsfwAllowed = currentUser == null ? value4 : currentUser.nsfwAllowed;
const r2 = nsfwAllowed != null && nsfwAllowed;
if (r7 == null) {
r8 = [];
} else {
member = GuildMemberStore.getMember(r7, id);
r8 = (member == null ? value4 : member.roles) ?? [];
}
const isViewingRoles2 = ImpersonateStore.isViewingRoles(r7);
const computePermissions_62961Binding = computePermissions_62961;
const value11 = value instanceof ChannelRecordBase;
if (value11) {
value = value.isThread();
r0 = value;
} else {
r0 = value11;
}
value = computePermissions_62961Binding(r5, r0);
const object = {context: r5, userId: id, roleIds: r8, isImpersonating: isViewingRoles2, commandTypes: a1};
object.computedPermissions = value.computedPermissions;
object.hasBaseAccessPermissions = value.hasBaseAccessPermissions;
object.hasSendMessagesPermission = value.hasSendMessagesPermission;
object.allowNsfw = computeAllowNsfw(r5, r2, viewNsfwCommandsOrDefault);
return object;
}
function usePermissionContext(a0, a1) { // fn#62964, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:1780, offset: 0x01b6d572, size: 337 bytes, params: 3, frame: 25
const env0_0 = a0;
const env0_1 = a1;
const value2 = env0_3.useMemo(_fun62965, [a0]);
var env0_3 = value2 != null ? getContextGuildId(value2) : undefined;
return env0_3.useMemo(_fun62970, [a1, value2,
(require(566) /* metro dependency 566: flux */).useStateFromStores([ImpersonateStore], _fun62969),
(require(566) /* metro dependency 566: flux */).useStateFromStoresArray([GuildMemberStore], _fun62968),
(require(566) /* metro dependency 566: flux */).useStateFromStores([AuthenticationStore], function() {
return AuthenticationStore.getId();
}), (require(566) /* metro dependency 566: flux */).useStateFromStores([UserStore], _fun62967),
(require(7867) /* metro dependency 7867: AgeRestrictedContentSettingsUtils */).useViewNsfwCommandsOrDefault(),
a0]);
function _fun62965() { // fn#62965, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:1832, offset: 0x01b6d6c3, size: 74 bytes, params: 1, frame: 12
return env0_0 instanceof ChannelRecordBase && env0_0.isThread() ? ChannelStore.getChannel(env0_0.parent_id) ?? env0_0 : env0_0;
}
function _fun62967() { // fn#62967, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:2092, offset: 0x01b6d70d, size: 45 bytes, params: 1, frame: 11
const value = environment.__proto__;
const nsfwAllowed = UserStore.getCurrentUser()?.nsfwAllowed;
return nsfwAllowed != null && nsfwAllowed;
}
function _fun62968() { // fn#62968, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:2218, offset: 0x01b6d73a, size: 65 bytes, params: 1, frame: 14
return env0_3 == null ? [] : GuildMemberStore.getMember(env0_3, id)?.roles ?? [];
}
function _fun62969() { // fn#62969, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:2342, offset: 0x01b6d77b, size: 27 bytes, params: 1, frame: 11
return ImpersonateStore.isViewingRoles(env0_3);
}
function _fun62970() { // fn#62970, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:2386, offset: 0x01b6d796, size: 155 bytes, params: 1, frame: 19
const computePermissions_62961Binding = computePermissions_62961;
let binding = env0_2;
const {computedPermissions, hasBaseAccessPermissions,
hasSendMessagesPermission} = computePermissions_62961Binding(binding,
env0_0 instanceof ChannelRecordBase && env0_0.isThread());
const object = {};
binding = env0_2;
object.context = binding;
object.userId = id;
object.roleIds = env0_7;
object.commandTypes = require;
object.isImpersonating = env0_8;
object.computedPermissions = computedPermissions;
object.hasBaseAccessPermissions = hasBaseAccessPermissions;
object.hasSendMessagesPermission = hasSendMessagesPermission;
object.allowNsfw = computeAllowNsfw(binding, env0_6, env0_4);
return object;
}
}
function computeCommandContextType(a0, a1) { // fn#62971, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8044:2762, offset: 0x01b6d831, size: 203 bytes, params: 3, frame: 15
const InteractionContextType = (ServerModule).InteractionContextType;
return a0 instanceof ChannelRecordBase && a0?.guild_id == null ? a0?.type !== ChannelTypes.DM ? InteractionContextType.PRIVATE_CHANNEL : a0?.getRecipientId() === a1 ? InteractionContextType.BOT_DM : InteractionContextType.PRIVATE_CHANNEL : InteractionContextType.GUILD;
}
}
global.__d(_fun62959, 7866, [31, 1937, 1383, 1226, 1379, 1945, 3784, 1878, 661, 7867, 566, 483, 1909,
2]) /* metro module 7866, dependencies: [31, 1937, 1383, 1226, 1379, 1945, 3784, 1878, 661, 7867, 566, 483, 1909, 2] */;