// Metro module 4085 (f4086). import AppliedGuildBoostRecord from "../records/AppliedGuildBoostRecord"; import GuildBoostSlotRecord from "../records/GuildBoostSlotRecord"; import SubscriptionStore from "../stores/billing/SubscriptionStore"; import { Endpoints } from "../Constants"; import { HTTP, rejectWithMigratedError } from "../_bundle/sendRequest"; import Dispatcher from "../Dispatcher"; import { AppliedGuildBoostError } from "../errors/index"; function $mk114457($env) { return (a0) => AppliedGuildBoostRecord.createFromServer(a0); } function $mk114458($env) { return (a0) => AppliedGuildBoostRecord.createFromServer(a0); } function $mk114459($env) { return (a0) => GuildBoostSlotRecord.createFromServer(a0, SubscriptionStore.getSubscriptionById(a0.subscription_id)); } let env2349 = {}; export async function fetchGuildBoostSlots() { let env29270; const r12 = env2349; let c24933_1 = r12; const r25 = env29270 = { $parent: r12 }; let c24933_0 = r25; env29270[0] = void 0; Dispatcher.dispatch({ type: "GUILD_BOOST_SLOTS_FETCH" }); env29270[0] = (await HTTP.get({ url: Endpoints.USER_GUILD_BOOST_SLOTS, oldFormErrors: true, rejectWithError: rejectWithMigratedError() })).body.map($mk114459(env2349)); Dispatcher.dispatch({ type: "GUILD_BOOST_SLOTS_FETCH_SUCCESS", guildBoostSlots: env29270[0] }); return env29270[0]; } export async function fetchAppliedGuildBoostsForGuild(c24931_0, c24931_1) { let env29268; const r28 = env2349; let c24931_3 = r28; const r10 = env29268 = { $parent: r28 }; let c24931_2 = r10; env29268[1] = void 0; env29268[0] = c24931_0; let r30 = c24931_1; if (r30 === void 0) { r30 = {}; } const includeEnded = r30.includeEnded; if (includeEnded !== void 0) { env29268[1] = includeEnded; env29268[2] = void 0; } else { env29268[1] = false; env29268[2] = void 0; } await void 0; let query = void 0; const r55 = { url: Endpoints.APPLIED_GUILD_BOOSTS_FOR_GUILD(env29268[0]), oldFormErrors: true, query: null, rejectWithError: true }; if (env29268[1]) { query = { include_ended: true }; } r55.query = query; env29268[2] = (await HTTP.get(r55)).body.map($mk114457(env2349)); Dispatcher.dispatch({ type: "GUILD_APPLIED_BOOSTS_FETCH_SUCCESS", guildId: env29268[0], appliedBoosts: env29268[2] }); return env29268[2]; } export async function fetchAppliedGuildBoostsForUser(c24932_0) { let env29269; const r25 = env2349; let c24932_2 = r25; const r10 = env29269 = { $parent: r25 }; let c24932_1 = r10; env29269[0] = void 0; if (c24932_0 !== void 0) { env29269[0] = c24932_0; env29269[1] = void 0; } else { env29269[0] = false; env29269[1] = void 0; } await void 0; env29269[1] = (await HTTP.get({ url: Endpoints.USER_APPLIED_GUILD_BOOSTS, oldFormErrors: true, query: { paused: env29269[0] }, rejectWithError: true })).body.map($mk114458(env2349)); Dispatcher.dispatch({ type: "USER_APPLIED_BOOSTS_FETCH_SUCCESS", appliedGuildBoosts: env29269[1] }); return env29269[1]; } export async function fetchAppliedBoostsCooldown() { let r69; let c24934_2; let c24934_3 = 0; let c29271_0, c29271_1; try { c29271_0 = void 0; c24934_3 = 1; c29271_0 = (await HTTP.get({ url: Endpoints.APPLIED_GUILD_BOOST_COOLDOWN, oldFormErrors: true, rejectWithError: rejectWithMigratedError() })).body.ends_at; Dispatcher.dispatch({ type: "APPLIED_BOOSTS_COOLDOWN_FETCH_SUCCESS", endsAt: c29271_0 }); r69 = c29271_0; c24934_3 = 0; } catch ($e) { const r26 = $e; let r8 = r26; c24934_2 = r26; if (c24934_3 !== 0) { while (true) { try { const r77 = c24934_2; c24934_3 = 0; c29271_1 = r77; if (c29271_1.status !== 404) { throw new AppliedGuildBoostError(c29271_1); } Dispatcher.dispatch({ type: "APPLIED_BOOSTS_COOLDOWN_FETCH_SUCCESS", endsAt: null }); } catch (r74) { r8 = r74; c24934_2 = r74; if (c24934_3 === 0) { break; } continue; } return null; } } throw r8; } return r69; } export async function applyToGuild(c24935_0, c24935_1, c24935_2) { let r127; let c24935_5; let c24935_6 = 0; let c29272_2, c29272_0, c29272_1, c29272_3, c29272_4, c29272_5, c29272_6; try { c29272_2 = void 0; c29272_0 = c24935_0; c29272_1 = c24935_1; if (c24935_2 !== void 0) { c29272_2 = c24935_2; c29272_3 = void 0; c29272_4 = void 0; c29272_5 = void 0; } else { c29272_2 = false; c29272_3 = void 0; c29272_4 = void 0; c29272_5 = void 0; } await void 0; Dispatcher.dispatch({ type: "GUILD_APPLY_BOOST_START" }); c24935_6 = 1; c29272_3 = await HTTP.put({ url: Endpoints.APPLIED_GUILD_BOOSTS_FOR_GUILD(c29272_0), body: { user_premium_guild_subscription_slot_ids: c29272_1, disable_powerup_auto_apply: c29272_2 }, oldFormErrors: true, rejectWithError: rejectWithMigratedError() }); c29272_4 = Array.isArray(c29272_3.body) ? c29272_3.body.map(AppliedGuildBoostRecord.createFromServer) : [AppliedGuildBoostRecord.createFromServer(c29272_3.body)]; Dispatcher.dispatch({ type: "GUILD_APPLY_BOOST_SUCCESS", appliedGuildBoost: c29272_4 }); (0, fetchGuildBoostSlots)(); r127 = c29272_4; c24935_6 = 0; } catch ($e) { const r32 = $e; let r8 = r32; c24935_5 = r32; if (c24935_6 !== 0) { while (true) { try { const r136 = c24935_5; c24935_6 = 0; c29272_6 = r136; c29272_5 = new AppliedGuildBoostError(c29272_6); Dispatcher.dispatch({ type: "GUILD_APPLY_BOOST_FAIL", error: c29272_5 }); throw c29272_5; } catch (r132) { r8 = r132; c24935_5 = r132; if (c24935_6 === 0) { break; } } } } throw r8; } return r127; } export async function unapplyFromGuild(c24936_0, c24936_1) { let c24936_4; let c24936_5 = 0; let c29273_0, c29273_1, c29273_2; try { c29273_0 = c24936_1; c29273_1 = void 0; Dispatcher.dispatch({ type: "GUILD_UNAPPLY_BOOST_START" }); c24936_5 = 1; await HTTP.del({ url: Endpoints.APPLIED_GUILD_BOOST(c24936_0, c24936_1), oldFormErrors: true, rejectWithError: rejectWithMigratedError() }); (0, fetchGuildBoostSlots)(); c24936_5 = 0; Dispatcher.dispatch({ type: "GUILD_UNAPPLY_BOOST_SUCCESS", boostId: c29273_0 }); } catch ($e) { const r28 = $e; let r8 = r28; c24936_4 = r28; if (c24936_5 !== 0) { while (true) { try { const r87 = c24936_4; c24936_5 = 0; c29273_2 = r87; c29273_1 = new AppliedGuildBoostError(c29273_2); Dispatcher.dispatch({ type: "GUILD_UNAPPLY_BOOST_FAIL", error: c29273_1 }); throw c29273_1; } catch (r83) { r8 = r83; c24936_4 = r83; if (c24936_5 === 0) { break; } } } } throw r8; } } export async function cancelGuildBoostSlot(c24937_0) { let c29274_0 = await HTTP.post({ url: Endpoints.USER_GUILD_BOOST_SLOT_CANCEL(c24937_0), oldFormErrors: true, rejectWithError: true }); let c29274_1 = GuildBoostSlotRecord.createFromServer(c29274_0.body, SubscriptionStore.getSubscriptionById(c29274_0.body.subscription_id)); Dispatcher.dispatch({ type: "GUILD_BOOST_SLOT_UPDATE_SUCCESS", guildBoostSlot: c29274_1 }); return c29274_1; } export async function uncancelGuildBoostSlot(c24938_0) { let c29275_0 = await HTTP.post({ url: Endpoints.USER_GUILD_BOOST_SLOT_UNCANCEL(c24938_0), oldFormErrors: true, rejectWithError: true }); let c29275_1 = GuildBoostSlotRecord.createFromServer(c29275_0.body, SubscriptionStore.getSubscriptionById(c29275_0.body.subscription_id)); Dispatcher.dispatch({ type: "GUILD_BOOST_SLOT_UPDATE_SUCCESS", guildBoostSlot: c29275_1 }); return c29275_1; }