352 lines
10 KiB
TypeScript
352 lines
10 KiB
TypeScript
// Metro module 3841 (f3842).
|
|
import { isNoneSubscription } from "../../records/SubscriptionPlanRecord";
|
|
import { SubscriptionRecord } from "../../records/SubscriptionRecord";
|
|
import AuthenticationStore from "../AuthenticationStore";
|
|
import { SubscriptionStatusTypes, SubscriptionTypes } from "../../Constants";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { HermesBuiltin, $forInKeys } from "../../_hermes/prelude";
|
|
function $mk72858($env) {
|
|
return (a0) => a0.id === $env[0].id;
|
|
}
|
|
let c2175_5, c2175_6, fromServer, c2175_8, c2175_9, c2175_10, fromServer2, c2175_12, c2175_13, eligible, c2175_15, lastLazyPerkSync;
|
|
const reset = function reset() {
|
|
c2175_5 = null;
|
|
c2175_6 = null;
|
|
fromServer = null;
|
|
c2175_8 = null;
|
|
c2175_9 = null;
|
|
c2175_10 = false;
|
|
fromServer2 = null;
|
|
c2175_12 = false;
|
|
c2175_13 = false;
|
|
c2175_15 = false;
|
|
lastLazyPerkSync = null;
|
|
};
|
|
c2175_5 = null;
|
|
c2175_6 = null;
|
|
fromServer = null;
|
|
c2175_8 = null;
|
|
c2175_9 = null;
|
|
c2175_10 = false;
|
|
fromServer2 = null;
|
|
c2175_12 = false;
|
|
c2175_13 = false;
|
|
eligible = null;
|
|
c2175_15 = false;
|
|
lastLazyPerkSync = null;
|
|
class SubscriptionStore extends Module589.Store {
|
|
static displayName = "SubscriptionStore";
|
|
initialize() {
|
|
this.waitFor(AuthenticationStore);
|
|
}
|
|
hasFetchedSubscriptions() {
|
|
return c2175_5 != null;
|
|
}
|
|
hasFetchedMostRecentPremiumTypeSubscription() {
|
|
return c2175_10;
|
|
}
|
|
hasFetchedPreviousPremiumTypeSubscription() {
|
|
return c2175_12;
|
|
}
|
|
getPremiumSubscription(r5 = true) {
|
|
const PREMIUM = SubscriptionTypes.PREMIUM;
|
|
if (r5 === void 0) {
|
|
r5 = true;
|
|
}
|
|
const r10 = r5 ? c2175_6 : c2175_5;
|
|
const r3 = r10 == null;
|
|
let r16 = null;
|
|
if (!r3) {
|
|
r16 = null;
|
|
for (const key in r10) {
|
|
r16 = null;
|
|
const r13 = r10[key];
|
|
const userId = r13.userId;
|
|
const id2 = AuthenticationStore.getId();
|
|
r16 = null;
|
|
if (userId !== id2) {
|
|
break;
|
|
}
|
|
if (r13.type === PREMIUM) {
|
|
const isNoneSubscription2 = isNoneSubscription(r13.planId);
|
|
r16 = r13;
|
|
if (!isNoneSubscription2) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
r16 = null;
|
|
}
|
|
return r16;
|
|
}
|
|
getPremiumTypeSubscription(r4 = true) {
|
|
let type;
|
|
const PREMIUM = SubscriptionTypes.PREMIUM;
|
|
if (r4 === void 0) {
|
|
r4 = true;
|
|
}
|
|
const r9 = r4 ? c2175_6 : c2175_5;
|
|
const r3 = r9 == null;
|
|
let r16 = null;
|
|
if (!r3) {
|
|
r16 = null;
|
|
const r8 = $forInKeys(r9);
|
|
let r0 = 0;
|
|
const length = r8.length;
|
|
if (r8 !== void 0) {
|
|
do {
|
|
r16 = null;
|
|
const r6 = r0 < length ? r8[r0++] : void 0;
|
|
if (r6 === void 0) {
|
|
break;
|
|
}
|
|
const r12 = r9[r6];
|
|
const userId = r12.userId;
|
|
const id2 = AuthenticationStore.getId();
|
|
r16 = null;
|
|
if (userId !== id2) {
|
|
break;
|
|
}
|
|
type = r12.type;
|
|
r16 = r12;
|
|
} while (type !== PREMIUM);
|
|
}
|
|
}
|
|
return r16;
|
|
}
|
|
getSubscriptions(r1 = true) {
|
|
return r1 ? c2175_6 : c2175_5;
|
|
}
|
|
getSubscriptionById(a0) {
|
|
let r6 = c2175_5 == null ? void 0 : c2175_5[a0];
|
|
if (r6 == null) {
|
|
r6 = void 0;
|
|
}
|
|
return r6;
|
|
}
|
|
getActiveGuildSubscriptions() {
|
|
return c2175_8;
|
|
}
|
|
getActiveApplicationSubscriptions() {
|
|
return c2175_9;
|
|
}
|
|
getSubscriptionForPlanIds(a0, r5 = true) {
|
|
let c13671_0 = new Set(a0);
|
|
const r13 = r5 ? c2175_6 : c2175_5;
|
|
const r1 = r13 == null;
|
|
let r15 = null;
|
|
if (!r1) {
|
|
let r21 = Object.values(r13).find((item) => item.items.some((item) => c13671_0.has(item.planId)));
|
|
if (r21 == null) {
|
|
r21 = null;
|
|
}
|
|
r15 = r21;
|
|
}
|
|
return r15;
|
|
}
|
|
getMostRecentPremiumTypeSubscription() {
|
|
return fromServer;
|
|
}
|
|
getPreviousPremiumTypeSubscription() {
|
|
return fromServer2;
|
|
}
|
|
getIsSubscriptionEligibleForReward() {
|
|
return eligible;
|
|
}
|
|
getIsFetchingSubscriptionRewardEligibility() {
|
|
return c2175_13;
|
|
}
|
|
getIsFetchingMostRecentSubscription() {
|
|
return c2175_15;
|
|
}
|
|
getLastLazyPerkSync() {
|
|
return lastLazyPerkSync;
|
|
}
|
|
getPremiumGroupSubscription() {
|
|
const PREMIUM = SubscriptionTypes.PREMIUM;
|
|
const r3 = c2175_6 == null;
|
|
let r15 = null;
|
|
if (!r3) {
|
|
r15 = null;
|
|
for (const key in c2175_6) {
|
|
r15 = null;
|
|
const r12 = c2175_6[key];
|
|
const userId = r12.userId;
|
|
const id2 = AuthenticationStore.getId();
|
|
r15 = null;
|
|
if (userId !== id2) {
|
|
break;
|
|
}
|
|
if (r12.type === PREMIUM) {
|
|
const r19 = r12.hasAnyPremiumGroup && r12.statusAllowsPerks;
|
|
r15 = r12;
|
|
if (r19) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
r15 = null;
|
|
}
|
|
return r15;
|
|
}
|
|
}
|
|
const subscriptionStore = new SubscriptionStore(Dispatcher, {
|
|
BILLING_SUBSCRIPTION_FETCH_SUCCESS: function handleSubscriptionsFetch({ subscriptions, lastLazyPerkSync: lastLazyPerkSync2 }) {
|
|
const r6 = {};
|
|
let c13672_0 = r6;
|
|
const r5 = {};
|
|
let c13672_1 = r5;
|
|
const r4 = [];
|
|
let c13672_2 = r4;
|
|
const r3 = [];
|
|
let c13672_3 = r3;
|
|
const id = AuthenticationStore.getId();
|
|
subscriptions.forEach((subscription) => {
|
|
if (subscription.user_id === id) {
|
|
const fromServer3 = SubscriptionRecord.createFromServer(subscription);
|
|
c13672_0[fromServer3.id] = fromServer3;
|
|
if (fromServer3.status !== SubscriptionStatusTypes.UNPAID) {
|
|
c13672_1[fromServer3.id] = fromServer3;
|
|
if (fromServer3.type === SubscriptionTypes.GUILD && fromServer3.status !== SubscriptionStatusTypes.ENDED) {
|
|
c13672_2.push(fromServer3);
|
|
}
|
|
if (fromServer3.type === SubscriptionTypes.APPLICATION && fromServer3.status !== SubscriptionStatusTypes.ENDED) {
|
|
c13672_3.push(fromServer3);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
c2175_5 = r6;
|
|
c2175_6 = r5;
|
|
c2175_8 = r4;
|
|
c2175_9 = r3;
|
|
lastLazyPerkSync = lastLazyPerkSync2;
|
|
},
|
|
BILLING_SUBSCRIPTION_UPDATE_SUCCESS: function handleSubscriptionUpdate({ subscription }) {
|
|
let r48, r77;
|
|
if (subscription.user_id === AuthenticationStore.getId()) {
|
|
const fromServer3 = SubscriptionRecord.createFromServer(subscription);
|
|
const r20 = {
|
|
...c2175_5
|
|
};
|
|
r20[fromServer3.id] = fromServer3;
|
|
c2175_5 = r20;
|
|
if (fromServer3.status !== SubscriptionStatusTypes.UNPAID) {
|
|
const r26 = {
|
|
...c2175_6
|
|
};
|
|
r26[fromServer3.id] = fromServer3;
|
|
c2175_6 = r26;
|
|
}
|
|
if (c2175_8 != null && fromServer3.type === SubscriptionTypes.GUILD) {
|
|
let env13673;
|
|
L12: {
|
|
const r9 = c2175_8;
|
|
const r35 = env13673 = {};
|
|
env13673[0] = fromServer3;
|
|
const r10 = r9.findIndex($mk72858(r35));
|
|
if (r10 === -1) {
|
|
r48 = [fromServer3, ...r9];
|
|
} else {
|
|
const r38 = [...r9];
|
|
if (fromServer3.status !== SubscriptionStatusTypes.UNPAID && fromServer3.status !== SubscriptionStatusTypes.ENDED) {
|
|
r38[r10] = fromServer3;
|
|
r48 = r38;
|
|
break L12;
|
|
}
|
|
r38.splice(r10, 1);
|
|
r48 = r38;
|
|
}
|
|
}
|
|
c2175_8 = r48;
|
|
}
|
|
if (c2175_9 != null && fromServer3.type === SubscriptionTypes.APPLICATION) {
|
|
let env13674;
|
|
L22: {
|
|
const r60 = env13674 = {};
|
|
env13674[0] = fromServer3;
|
|
const r63 = c2175_9.findIndex($mk72858(r60));
|
|
if (r63 === -1) {
|
|
r77 = [fromServer3, ...c2175_9];
|
|
} else {
|
|
const r65 = [...c2175_9];
|
|
if (fromServer3.status !== SubscriptionStatusTypes.UNPAID && fromServer3.status !== SubscriptionStatusTypes.ENDED) {
|
|
r65[r63] = fromServer3;
|
|
r77 = r65;
|
|
break L22;
|
|
}
|
|
r65.splice(r63, 1);
|
|
r77 = r65;
|
|
}
|
|
}
|
|
c2175_8 = r77;
|
|
}
|
|
}
|
|
},
|
|
BILLING_MOST_RECENT_SUBSCRIPTION_FETCH_START: function handleMostRecentSubscriptionFetchStart() {
|
|
c2175_15 = true;
|
|
},
|
|
BILLING_MOST_RECENT_SUBSCRIPTION_FETCH_SUCCESS: function handleMostRecentSubscriptionFetch({ subscription }) {
|
|
c2175_10 = true;
|
|
c2175_15 = false;
|
|
if (subscription != null) {
|
|
if (subscription.user_id !== AuthenticationStore.getId()) {
|
|
c2175_10 = false;
|
|
return void 0;
|
|
}
|
|
fromServer = SubscriptionRecord.createFromServer(subscription);
|
|
}
|
|
},
|
|
BILLING_MOST_RECENT_SUBSCRIPTION_FETCH_FAIL: function handleMostRecentSubscriptionFetchFail() {
|
|
c2175_15 = false;
|
|
},
|
|
BILLING_PREVIOUS_PREMIUM_SUBSCRIPTION_FETCH_SUCCESS: function handlePreviousSubscriptionFetch({ subscription }) {
|
|
c2175_12 = true;
|
|
if (subscription != null) {
|
|
if (subscription.user_id !== AuthenticationStore.getId()) {
|
|
c2175_12 = false;
|
|
return void 0;
|
|
}
|
|
fromServer2 = SubscriptionRecord.createFromServer(subscription);
|
|
}
|
|
},
|
|
BILLING_SUBSCRIPTION_RESET: reset,
|
|
BILLING_SUBSCRIPTION_REWARD_ELIGIBILITY_FETCH_START: function handleSubscriptionRewardEligibilityFetchStart() {
|
|
c2175_13 = true;
|
|
},
|
|
BILLING_SUBSCRIPTION_REWARD_ELIGIBILITY_FETCH_SUCCESS: function handleSubscriptionRewardEligibilityFetch(a0) {
|
|
eligible = a0.eligible;
|
|
c2175_13 = false;
|
|
},
|
|
BILLING_SUBSCRIPTION_REWARD_ELIGIBILITY_FETCH_FAILURE: function handleSubscriptionRewardEligibilityFetchFailed(a0) {
|
|
if (a0 == null) {
|
|
HermesBuiltin.throwTypeError("Cannot destructure 'undefined' or 'null'.");
|
|
throw new Error("unreachable");
|
|
}
|
|
eligible = false;
|
|
c2175_13 = false;
|
|
},
|
|
LOGOUT: reset
|
|
});
|
|
export default subscriptionStore;
|
|
export function getSubscriptionOfType(a0, a1, r4 = true) {
|
|
const r9 = r4 ? c2175_6 : c2175_5;
|
|
if (r9 == null) {
|
|
return null;
|
|
}
|
|
for (const key in r9) {
|
|
const r16 = r9[key];
|
|
if (r16.userId !== AuthenticationStore.getId()) {
|
|
return null;
|
|
}
|
|
if (r16.type === a0) {
|
|
if (a1 != null && !a1(r16)) {
|
|
continue;
|
|
}
|
|
return r16;
|
|
}
|
|
}
|
|
return null;
|
|
}
|