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

416 lines
11 KiB
TypeScript

// Metro module 6213 (f6214).
import UserRecord from "../../records/UserRecord";
import SelectedChannelStore from "../../stores/SelectedChannelStore";
import { Endpoints, AbortCodes } from "../../Constants";
import { HTTP } from "../../_bundle/sendRequest";
import Dispatcher from "../../Dispatcher";
import SentryUtils_native from "../../utils/SentryUtils.native";
import MessageActionCreators from "../../actions/MessageActionCreators";
function $mk114905($env) {
return (a0) => new UserRecord(a0);
}
let c3941_9;
let env3941 = {};
const r34 = {
REDEEMED: 1,
1: "REDEEMED",
PENDING: 2,
2: "PENDING",
CONVERTED: 3,
3: "CONVERTED"
};
const c3941_8 = {
SUCCESS: 1,
1: "SUCCESS",
FAIL: 2,
2: "FAIL"
};
class EligibleUserCache {
cache = new Map();
expiration = Date.now() + 600000;
set(a0, a1) {
this.cache.set(a0, a1);
}
get(a0) {
this._checkExpiration();
return this.cache.get(a0);
}
has(a0) {
this._checkExpiration();
return this.cache.has(a0);
}
_checkExpiration() {
if (this.expiration < Date.now()) {
this.cache.clear();
}
}
}
const r52 = {
__proto__: EligibleUserCache.prototype
};
r52.cache = new Map();
r52.expiration = Date.now() + 600000;
c3941_9 = r52;
export { r34 as ReferralOfferStatus };
export { c3941_8 as CreateReferralStatus };
export async function fetchReferralEligibleUsers(index, searchQuery, c25745_2) {
let r36;
let limit, c25745_4, c25745_5;
L14: {
let env29687;
const r28 = env3941;
c25745_5 = r28;
const r11 = env29687 = {
$parent: r28
};
c25745_4 = r11;
env29687[0] = void 0;
env29687[1] = void 0;
env29687[2] = void 0;
env29687[3] = void 0;
env29687[4] = void 0;
const r30 = JSON.stringify({
index,
searchQuery
});
env29687[0] = r30;
if (c3941_9.has(r30)) {
r36 = c3941_9.get(r30);
break L14;
}
limit = c25745_2;
if (c25745_2 == null) {
limit = 10;
}
env29687[1] = (await HTTP.post({
url: Endpoints.GET_REFERRAL_ELIGIBLE_USERS,
body: {
index,
limit,
search_query: searchQuery
},
oldFormErrors: true,
rejectWithError: false
})).body;
env29687[2] = env29687[1].users;
env29687[3] = env29687[1].next_index;
env29687[4] = {
users: env29687[2].map($mk114905(env3941)),
nextIndex: env29687[3]
};
c3941_9.set(env29687[0], env29687[4]);
return env29687[4];
}
return r36;
}
export function fetchReferralsRemaining() {
Dispatcher.dispatch({
type: "BILLING_REFERRALS_REMAINING_FETCH_START"
});
return HTTP.get({
url: Endpoints.GET_REFERRALS_REMAINING,
oldFormErrors: true,
rejectWithError: false
}).then((result) => {
const map = new Map();
if (result.body != null && result.body.recipient_status != null) {
const recipient_status = result.body.recipient_status;
for (const key in recipient_status) {
map.set(key, result.body.recipient_status[key]);
}
}
const referrals_remaining = result.body != null ? result.body.referrals_remaining != null ? result.body.referrals_remaining : 0 : 0;
const sent_user_ids = result.body != null && result.body.sent_user_ids != null ? result.body.sent_user_ids : [];
let refresh_at = result.body?.refresh_at;
if (refresh_at == null) {
refresh_at = null;
}
let has_eligible_friends = result.body?.has_eligible_friends;
if (has_eligible_friends == null) {
has_eligible_friends = false;
}
let reminder_state_id = result.body?.reminder_state_id;
if (reminder_state_id == null) {
reminder_state_id = null;
}
Dispatcher.dispatch({
type: "BILLING_REFERRALS_REMAINING_FETCH_SUCCESS",
referrals_remaining,
sent_user_ids,
refresh_at,
recipient_status: map,
has_eligible_friends,
reminder_state_id
});
}, (a0) => {
if (a0?.status !== 404) {
Dispatcher.dispatch({
type: "BILLING_REFERRALS_REMAINING_FETCH_FAIL"
});
}
});
}
export async function createReferralTrials(c25746_0) {
let r32, r63, r125;
let c25746_1, c25746_2, body, c25746_6;
let c25746_7 = 0;
let c29688_1, c29688_2, c29688_3, c29688_0, c29688_4;
L22: {
L21: {
try {
c29688_1 = void 0;
c29688_2 = void 0;
c29688_3 = void 0;
c29688_0 = [];
c29688_1 = new Map();
c25746_2 = c25746_0;
const r49 = c25746_0[Symbol.iterator]();
c25746_2 = r49.next;
c25746_1 = r49;
const r51 = c25746_2;
let r52 = c25746_1;
const r53 = r52 === void 0 ? void 0 : (r32 = r51.call(r52)).done ? r52 = void 0 : r32.value;
c25746_1 = r52;
if (r52 === void 0) {
Dispatcher.dispatch({
type: "CREATE_REFERRALS_SUCCESS",
userTrialOffers: c29688_0
});
r63 = c29688_1;
break L22;
}
c29688_2 = r53;
c25746_7 = 2;
let r83 = await HTTP.post({
url: Endpoints.CREATE_REFERRAL(c29688_2),
oldFormErrors: true,
rejectWithError: true
});
while (true) {
const body4 = r83.body;
body = body4;
if (body4 == null) {
body = null;
}
c29688_3 = body;
if (c29688_3 != null) {
c29688_0.push(c29688_3);
}
c29688_1.set(c29688_2, c3941_8.SUCCESS);
c25746_7 = 1;
c25746_7 = 0;
const r112 = c25746_2;
let r113 = c25746_1;
const r114 = r113 === void 0 ? void 0 : (r32 = r112.call(r113)).done ? r113 = void 0 : r32.value;
c25746_1 = r113;
if (r113 === void 0) {
Dispatcher.dispatch({
type: "CREATE_REFERRALS_SUCCESS",
userTrialOffers: c29688_0
});
r125 = c29688_1;
break;
}
c29688_2 = r114;
c25746_7 = 2;
r83 = await HTTP.post({
url: Endpoints.CREATE_REFERRAL(c29688_2),
oldFormErrors: true,
rejectWithError: true
});
}
} catch ($e) {
const r42 = $e;
let r8 = r42;
c25746_6 = r42;
let r43 = c25746_7;
if (r43 !== 0) {
while (true) {
if (r43 === 1) {
try {
const r243 = c25746_6;
c25746_7 = 0;
const r245 = c25746_1;
if (r245 !== void 0 && typeof r245.return === "function") {
try {
r245.return();
} catch {}
}
throw r243;
} catch (r242) {
r8 = r242;
c25746_6 = r242;
r43 = c25746_7;
if (r43 === 0) {
break;
}
}
} else {
try {
const r163 = c25746_6;
c25746_7 = 1;
c29688_4 = r163;
SentryUtils_native.captureException(c29688_4);
c29688_1.set(c29688_2, c3941_8.FAIL);
while (true) {
c25746_7 = 0;
const r178 = c25746_2;
let r179 = c25746_1;
const r180 = r179 === void 0 ? void 0 : (r32 = r178.call(r179)).done ? r179 = void 0 : r32.value;
c25746_1 = r179;
if (r179 === void 0) {
Dispatcher.dispatch({
type: "CREATE_REFERRALS_SUCCESS",
userTrialOffers: c29688_0
});
r125 = c29688_1;
break L21;
}
c29688_2 = r180;
c25746_7 = 2;
body = (await HTTP.post({
url: Endpoints.CREATE_REFERRAL(c29688_2),
oldFormErrors: true,
rejectWithError: true
})).body;
if (body == null) {
body = null;
}
c29688_3 = body;
if (c29688_3 != null) {
c29688_0.push(c29688_3);
}
c29688_1.set(c29688_2, c3941_8.SUCCESS);
c25746_7 = 1;
}
} catch (r160) {
r8 = r160;
c25746_6 = r160;
r43 = c25746_7;
if (r43 === 0) {
break;
}
}
}
}
}
throw r8;
}
}
return r125;
}
return r63;
}
export async function createReferralTrial(c25747_0) {
let r66;
let body2, c25747_4;
let c25747_5 = 0;
let c29689_0, c29689_1, c29689_2;
try {
c29689_0 = void 0;
c29689_1 = void 0;
c25747_5 = 1;
const body4 = (await HTTP.post({
url: Endpoints.CREATE_REFERRAL(c25747_0),
oldFormErrors: true,
rejectWithError: false
})).body;
body2 = body4;
if (body4 == null) {
body2 = null;
}
c29689_0 = body2;
Dispatcher.dispatch({
type: "BILLING_CREATE_REFERRAL_SUCCESS",
userTrialOffer: c29689_0
});
r66 = {
userTrialOffer: c29689_0
};
c25747_5 = 0;
} catch ($e) {
const r27 = $e;
let r8 = r27;
c25747_4 = r27;
if (c25747_5 !== 0) {
while (true) {
try {
const r75 = c25747_4;
c25747_5 = 0;
c29689_2 = r75;
Dispatcher.dispatch({
type: "BILLING_CREATE_REFERRAL_FAIL"
});
if (c29689_2.body.code === AbortCodes.INVALID_MESSAGE_SEND_USER) {
c29689_1 = SelectedChannelStore.getCurrentlySelectedChannelId();
if (c29689_1 != null) {
MessageActionCreators.sendClydeError(c29689_1, c29689_2.body.code);
}
}
} catch (r71) {
r8 = r71;
c25747_4 = r71;
if (c25747_5 === 0) {
break;
}
continue;
}
return void 0;
}
}
throw r8;
}
return r66;
}
export async function resolveReferralTrialOffer(c25748_0) {
let r65;
let body3;
let c25748_5 = 0;
let c29690_0, c29690_1;
try {
c29690_0 = c25748_0;
c29690_1 = void 0;
c25748_5 = 1;
const body4 = (await HTTP.get({
url: Endpoints.REFERRAL_OFFER_ID_RESOLVE(c25748_0),
oldFormErrors: true,
rejectWithError: false
})).body;
body3 = body4;
if (body4 == null) {
body3 = null;
}
c29690_1 = body3;
Dispatcher.dispatch({
type: "BILLING_REFERRAL_RESOLVE_SUCCESS",
userTrialOffer: c29690_1
});
r65 = {
userTrialOffer: c29690_1
};
c25748_5 = 0;
} catch ($e) {
let r8 = $e;
if (c25748_5 !== 0) {
while (true) {
try {
c25748_5 = 0;
Dispatcher.dispatch({
type: "BILLING_REFERRAL_RESOLVE_FAIL",
userTrialOfferId: c29690_0
});
} catch ($e) {
r8 = $e;
if (c25748_5 === 0) {
break;
}
continue;
}
return void 0;
}
}
throw r8;
}
return r65;
}