Files
discord-decomp/modules/parent_tools/ParentalConsentWarningActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

195 lines
5.8 KiB
TypeScript

// Metro module 16297 (f16298).
import ParentalConsentWarningStore from "./ParentalConsentWarningStore";
import { Logger } from "../../_bundle/log";
import Backoff from "../../_bundle/Backoff";
import Durations from "../../utils/Durations";
import { isParentalConsentWarningFetchEnabled } from "./ParentalConsentWarningFetchExperiment";
import { HTTP } from "../../_bundle/sendRequest";
import Dispatcher from "../../Dispatcher";
import SentryUtils_native from "../../utils/SentryUtils.native";
function $mk117263($env) {
return function scheduleRetry() {
const r2 = $env;
if (r2[8] == null) {
const r4 = setTimeout;
const r7 = c11716_6.fail();
r2[8] = r4($mk118544(r2), r7);
}
};
}
function $mk118544($env) {
return () => {
$env[8] = null;
(0, maybeFetchWarning)();
};
}
let fetchWarning, maybeFetchWarning, c11716_5, c11716_6;
let env11716 = {};
const clearPendingRetry = function clearPendingRetry() {
if (env11716[8] != null) {
clearTimeout(env11716[8]);
env11716[8] = null;
}
};
fetchWarning = function fetchWarning() {
if (isParentalConsentWarningFetchEnabled("parental_consent_warning_manager")) {
if (env11716[7] != null) {
return env11716[7];
}
let c22954_0 = env11716[9];
const r20 = (async () => {
let c28331_0, c28331_1, c28331_2;
let c28331_3 = 0;
const r13 = void 0;
const r12 = env11716;
L17: {
L14: {
try {
let env31026;
c28331_1 = r13;
const r32 = env31026 = {
$parent: r12
};
c28331_0 = r32;
env31026[0] = void 0;
env31026[1] = void 0;
c28331_3 = 2;
env31026[0] = await HTTP.get({
url: "/users/@me/parental-consent/warning",
rejectWithError: true
});
if (c22954_0 !== env11716[9]) {
c28331_3 = 0;
if (c22954_0 !== env11716[9]) {
break L17;
}
env11716[7] = null;
break L17;
}
env31026[1] = (function normalizeWarning(a0) {
return {
inGrace: a0.in_grace === true,
daysRemaining: typeof a0.days_remaining === "number" ? a0.days_remaining : null,
surfaces: Array.isArray(a0.surfaces) ? a0.surfaces : []
};
})(env31026[0].body);
c11716_6.succeed();
(0, clearPendingRetry)();
Dispatcher.dispatch({
type: "PARENTAL_CONSENT_WARNING_FETCH_SUCCESS",
warning: env31026[1]
});
c28331_3 = 1;
c28331_3 = 0;
if (c22954_0 === env11716[9]) {
env11716[7] = null;
}
} catch ($e) {
const r30 = $e;
let r7 = r30;
c28331_2 = r30;
let r31 = c28331_3;
if (r31 !== 0) {
while (true) {
if (r31 !== 1) {
try {
const r90 = c28331_2;
c28331_3 = 1;
env31026[2] = r90;
if (c22954_0 === env11716[9]) {
c11716_5.error("Failed to fetch parental-consent warning", env31026[2]);
SentryUtils_native.captureException(env31026[2], {
tags: {
source: "parental_consent_warning",
step: "fetch_warning"
}
});
$mk117263(env11716)();
c28331_3 = 0;
if (c22954_0 !== env11716[9]) {
break L14;
}
env11716[7] = null;
break L14;
}
c28331_3 = 0;
if (c22954_0 === env11716[9]) {
env11716[7] = null;
}
} catch (r87) {
r7 = r87;
c28331_2 = r87;
r31 = c28331_3;
if (r31 === 0) {
break;
}
continue;
}
return void 0;
}
try {
const r121 = c28331_2;
c28331_3 = 0;
if (c22954_0 === env11716[9]) {
env11716[7] = null;
}
throw r121;
} catch (r119) {
r7 = r119;
c28331_2 = r119;
r31 = c28331_3;
if (r31 === 0) {
break;
}
}
}
}
throw r7;
}
}
return void 0;
}
})();
env11716[7] = r20;
return r20;
}
return Promise.resolve();
};
maybeFetchWarning = async function maybeFetchWarning() {
L15: {
if (env11716[7] == null && env11716[8] == null && ParentalConsentWarningStore.shouldFetchToday()) {
await fetchWarning();
break L15;
}
return void 0;
}
};
c11716_5 = new Logger("ParentalConsentWarning");
c11716_6 = new Backoff(5 * Durations.Millis.SECOND, 5 * Durations.Millis.MINUTE, true);
env11716[7] = null;
env11716[8] = null;
env11716[9] = 0;
export { maybeFetchWarning };
export async function forceFetchWarning() {
clearPendingRetry();
if (env11716[7] != null) {
env11716[9] = env11716[9] + 1;
env11716[7] = null;
}
await fetchWarning();
}
export function resetFetchState() {
env11716[9] = env11716[9] + 1;
if (env11716[8] != null) {
clearTimeout(env11716[8]);
env11716[8] = null;
}
env11716[7] = null;
c11716_6.succeed();
}
export function clearWarning() {
Dispatcher.dispatch({
type: "PARENTAL_CONSENT_WARNING_CLEARED"
});
}