/* Metro module 7866; source: modules/application_commands/CommandPermissionContext.tsx; dependencies: [31, 1937, 1383, 1226, 1379, 1945, 3784, 1878, 661, 7867, 566, 483, 1909, 2] */ 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}); const env0_3 = importAll(31) /* metro dependency 31 */; const impersonateStore = importDefault(1937) /* metro dependency 1937: ImpersonateStore */; const env0_5 = (require(1383) /* metro dependency 1383: ChannelRecord */).ChannelRecordBase; const authenticationStore = importDefault(1226) /* metro dependency 1226: AuthenticationStore */; const channelStore = importDefault(1379) /* metro dependency 1379: ChannelStore */; const guildMemberStore = importDefault(1945) /* metro dependency 1945: GuildMemberStore */; const permissionStore = importDefault(3784) /* metro dependency 3784: PermissionStore */; const userStore = importDefault(1878) /* metro dependency 1878: UserStore */; const constantsModule = require(661) /* metro dependency 661: Constants */; const env0_11 = constantsModule.ChannelTypes; const env0_12 = constantsModule.Permissions; (require(2) /* metro dependency 2 */).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 object2; if (a0 instanceof ChannelRecordBase) { if (a0.isPrivate()) { object2 = {'computedPermissions': null, 'hasBaseAccessPermissions': true, 'hasSendMessagesPermission': true}; object2.computedPermissions = (importAll(483) /* metro dependency 483: BigFlagUtils */).deserialize(0); return object2; } if (a0 == null) { object2 = {'computedPermissions': null, 'hasBaseAccessPermissions': true, 'hasSendMessagesPermission': true}; object2.computedPermissions = (importAll(483) /* metro dependency 483: BigFlagUtils */).deserialize(0); return object2; } permissions = PermissionStore.computePermissions(a0); value2 = (importAll(483) /* metro dependency 483: BigFlagUtils */).has(permissions, Permissions.ADMINISTRATOR); } else { if (a0 == null) { object2 = {'computedPermissions': null, 'hasBaseAccessPermissions': true, 'hasSendMessagesPermission': true}; object2.computedPermissions = (importAll(483) /* metro dependency 483: BigFlagUtils */).deserialize(0); return object2; } 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 = (require(7867) /* metro dependency 7867: AgeRestrictedContentSettingsUtils */).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 object2 = {context: r5, userId: id, roleIds: r8, isImpersonating: isViewingRoles2, commandTypes: a1}; object2.computedPermissions = value.computedPermissions; object2.hasBaseAccessPermissions = value.hasBaseAccessPermissions; object2.hasSendMessagesPermission = value.hasSendMessagesPermission; object2.allowNsfw = computeAllowNsfw(r5, r2, viewNsfwCommandsOrDefault); return object2; } 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 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 = (require(1909) /* metro dependency 1909: Server */).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; } 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 object2 = {}; binding = env0_2; object2.context = binding; object2.userId = id; object2.roleIds = env0_7; object2.commandTypes = require; object2.isImpersonating = env0_8; object2.computedPermissions = computedPermissions; object2.hasBaseAccessPermissions = hasBaseAccessPermissions; object2.hasSendMessagesPermission = hasSendMessagesPermission; object2.allowNsfw = computeAllowNsfw(binding, env0_6, env0_4); return object2; }