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

224 lines
6.6 KiB
TypeScript

// Metro module 6564 (f6565).
import LocaleStore from "../../user_settings/LocaleStore";
import PromotionRecord from "../../../records/PromotionRecord";
import PromotionsStore from "./PromotionsStore";
import { PREMIUM_SUBSCRIPTION_APPLICATION } from "../PremiumConstants";
import { Endpoints } from "../../../Constants";
import Dispatcher from "../../../Dispatcher";
import { MarketingComponentPlatform } from "../../../_bundle/Module6565";
import { HTTP, rejectWithMigratedError } from "../../../_bundle/sendRequest";
import { fetchUserEntitlementsForApplication } from "../../../actions/EntitlementActionCreators";
import { PreloadedUserSettingsActionCreators, UserSettingsDelay } from "../../user_settings/UserSettingsProtoActionCreators";
import { StringValue } from "../../../_bundle/Module1337";
import { claimedOutboundPromotionCodeFromServer } from "./PromotionUtils";
const fetchActivePromotions = async function fetchActivePromotions() {
let promotion_id, c25921_1, c25921_2, c25921_3;
let c25921_4 = 0;
const r13 = void 0;
L18: {
try {
let env29799;
c25921_2 = r13;
const r32 = env29799 = {};
c25921_1 = r32;
env29799[0] = void 0;
env29799[1] = void 0;
env29799[2] = void 0;
c25921_4 = 1;
Dispatcher.dispatch({
type: "ACTIVE_PROMOTIONS_FETCH",
locale: LocaleStore.locale
});
env29799[0] = await HTTP.get({
url: Endpoints.PROMOTIONS,
query: {
locale: LocaleStore.locale,
platform: MarketingComponentPlatform.MOBILE
},
oldFormErrors: true,
rejectWithError: true
});
env29799[1] = PromotionsStore.consumedInboundPromotionId;
if (!PromotionsStore.hasFetchedConsumedInboundPromotionId) {
env29799[2] = (await fetchUserEntitlementsForApplication(PREMIUM_SUBSCRIPTION_APPLICATION, false)).find((item) => item.promotion_id != null && item.consumed === true);
const promotion_id2 = env29799[2]?.promotion_id;
promotion_id = promotion_id2;
if (promotion_id2 == null) {
promotion_id = null;
}
env29799[1] = promotion_id;
}
Dispatcher.dispatch({
type: "ACTIVE_PROMOTIONS_FETCH_SUCCESS",
promotions: env29799[0].body,
consumedInboundPromotionId: env29799[1]
});
c25921_4 = 0;
} catch ($e) {
const r30 = $e;
let r8 = r30;
c25921_3 = r30;
if (c25921_4 !== 0) {
while (true) {
try {
c25921_4 = 0;
Dispatcher.dispatch({
type: "ACTIVE_PROMOTIONS_FETCH_FAIL"
});
break L18;
} catch (r126) {
r8 = r126;
c25921_3 = r126;
if (c25921_4 === 0) {
break;
}
}
}
}
throw r8;
}
}
};
export function dismissOutboundPromotionNotice() {
Dispatcher.dispatch({
type: "OUTBOUND_PROMOTION_NOTICE_DISMISS"
});
const lastDismissedOutboundPromotionStartDate = PromotionsStore.lastDismissedOutboundPromotionStartDate;
if (lastDismissedOutboundPromotionStartDate != null) {
PreloadedUserSettingsActionCreators.updateAsync("userContent", (a0) => {
a0.lastDismissedOutboundPromotionStartDate = StringValue.create({
value: lastDismissedOutboundPromotionStartDate
});
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
}
}
export async function fetchActiveBogoPromotion() {
let c25922_3 = 0;
let c29800_0;
L13: {
L12: {
try {
c29800_0 = void 0;
if (PromotionsStore.isFetchingActiveBogoPromotion) {
break L13;
}
c25922_3 = 1;
Dispatcher.dispatch({
type: "ACTIVE_BOGO_PROMOTION_FETCH"
});
c29800_0 = (await HTTP.get({
url: Endpoints.BOGO_PROMOTIONS,
query: {
locale: LocaleStore.locale
},
rejectWithError: true
})).body;
Dispatcher.dispatch({
type: "ACTIVE_BOGO_PROMOTION_FETCH_SUCCESS",
activePromotion: PromotionRecord.createFromServer(c29800_0)
});
c25922_3 = 0;
} catch ($e) {
let r8 = $e;
if (c25922_3 !== 0) {
while (true) {
try {
c25922_3 = 0;
Dispatcher.dispatch({
type: "ACTIVE_BOGO_PROMOTION_FETCH_FAIL"
});
break L12;
} catch ($e) {
r8 = $e;
if (c25922_3 === 0) {
break;
}
}
}
}
throw r8;
}
}
return void 0;
}
}
export async function fetchClaimedOutboundPromotionCodes() {
let c25923_2 = 0;
let c29801_0;
L10: {
try {
c29801_0 = void 0;
c25923_2 = 1;
c29801_0 = (await HTTP.get({
url: Endpoints.CLAIMED_OUTBOUND_PROMOTION_CODES,
query: {
locale: LocaleStore.locale
},
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
})).body.map(claimedOutboundPromotionCodeFromServer);
Dispatcher.dispatch({
type: "CLAIMED_OUTBOUND_PROMOTION_CODES_FETCH_SUCCESS",
claimedOutboundPromotionCodes: c29801_0
});
c25923_2 = 0;
} catch ($e) {
let r24 = $e;
if (c25923_2 !== 0) {
while (true) {
try {
c25923_2 = 0;
Dispatcher.dispatch({
type: "CLAIMED_OUTBOUND_PROMOTION_CODES_FETCH_FAIL"
});
break L10;
} catch ($e) {
r24 = $e;
if (c25923_2 === 0) {
break;
}
}
}
}
throw r24;
}
}
}
export function addClaimedOutboundPromotionCode(a0) {
Dispatcher.dispatch({
type: "CLAIMED_OUTBOUND_PROMOTION_CODE_ADD",
claimedOutboundPromotionCode: a0
});
}
const r35 = {
fetchActivePromotions,
fetchClaimedOutboundPromotionCodes,
addClaimedOutboundPromotionCode,
dismissOutboundPromotionNotice,
markOutboundPromotionsSeen: () => {
Dispatcher.dispatch({
type: "OUTBOUND_PROMOTIONS_SEEN"
});
},
fetchActiveBogoPromotion
};
export default r35;
export function maybeFetchActivePromotions(r4 = true) {
let isFetchingActivePromotions = PromotionsStore.isFetchingActivePromotions;
if (!isFetchingActivePromotions) {
if (r4) {
r4 = PromotionsStore.lastFetchedActivePromotions != null;
}
isFetchingActivePromotions = r4;
}
if (!isFetchingActivePromotions) {
fetchActivePromotions();
}
}
export function clearActivePromotions() {
Dispatcher.dispatch({
type: "ACTIVE_PROMOTIONS_CLEAR"
});
}
export { fetchActivePromotions };