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

293 lines
11 KiB
TypeScript

// Metro module 6262 (f6263).
import UserSettingsProtoStore from "../../user_settings/UserSettingsProtoStore";
import PromotionRecord from "../../../records/PromotionRecord";
import MarketingComponentRecord from "./MarketingComponentRecord";
import { PromotionTypes } from "./constants";
import Module589 from "../../../_bundle/Module589";
import Dispatcher from "../../../Dispatcher";
let c3979_5, c3979_7, c3979_8, c3979_9, c3979_10, c3979_11, locale, emptyPromotionsByType, latestActiveOutboundPromotionStartDate, c3979_15, claimedOutboundPromotionCodes2, c3979_17, getLatestActiveOutboundPromotionStartDate, initializeFromUserSettings;
const createEmptyPromotionsByType = function createEmptyPromotionsByType() {
const r1 = {};
r1[PromotionTypes.THIRD_PARTY] = {};
r1[PromotionTypes.BOGO] = {};
r1[PromotionTypes.THIRD_PARTY_DIRECT_FULFILLMENT] = {};
r1[PromotionTypes.MARKETING_MOMENT] = {};
r1[PromotionTypes.THIRD_PARTY_INBOUND] = {};
r1[PromotionTypes.THIRD_PARTY_OUTBOUND] = {};
r1[PromotionTypes.GIFT_PROMOTION] = {};
r1[PromotionTypes.THIRD_PARTY_OUTBOUND_RECURRING] = {};
return r1;
};
getLatestActiveOutboundPromotionStartDate = function getLatestActiveOutboundPromotionStartDate() {
let r2 = null;
for (const item of Object.values(emptyPromotionsByType[PromotionTypes.THIRD_PARTY_OUTBOUND])) {
if (r2 == null || item.startDate > r2) {
r2 = item.startDate;
}
}
const r42 = r2;
let r44 = r42 == null ? void 0 : r42.toISOString();
if (r44 == null) {
r44 = null;
}
return r44;
};
initializeFromUserSettings = function initializeFromUserSettings() {
const userContent = UserSettingsProtoStore.settings.userContent;
let r7 = userContent == null ? void 0 : userContent.lastDismissedOutboundPromotionStartDate?.value;
if (r7 == null) {
r7 = null;
}
latestActiveOutboundPromotionStartDate = r7;
};
c3979_5 = {
hasFetchedConsumedInboundPromotionId: false,
consumedInboundPromotionId: null,
lastSeenOutboundPromotionStartDate: null
};
c3979_7 = null;
c3979_8 = false;
c3979_9 = null;
c3979_10 = false;
c3979_11 = null;
locale = null;
emptyPromotionsByType = createEmptyPromotionsByType();
latestActiveOutboundPromotionStartDate = null;
c3979_15 = new Map();
claimedOutboundPromotionCodes2 = [];
c3979_17 = false;
class PromotionsStore extends Module589.PersistedStore {
static displayName = "PromotionsStore";
static persistKey = "PromotionsPersistedStore";
static migrations = [(a0) => {
try {
delete a0["bogoPromotion"];
} catch ($e) {}
return a0;
}];
initialize(a0) {
if (a0 != null) {
c3979_5 = a0;
}
this.waitFor(UserSettingsProtoStore);
this.syncWith([UserSettingsProtoStore], initializeFromUserSettings);
}
get outboundPromotions() {
return Object.values(emptyPromotionsByType[PromotionTypes.THIRD_PARTY_OUTBOUND]);
}
get outboundRecurringPromotions() {
return Object.values(emptyPromotionsByType[PromotionTypes.THIRD_PARTY_OUTBOUND_RECURRING]);
}
get lastSeenOutboundPromotionStartDate() {
return c3979_5.lastSeenOutboundPromotionStartDate;
}
get lastDismissedOutboundPromotionStartDate() {
return latestActiveOutboundPromotionStartDate;
}
get lastFetchedActivePromotions() {
return c3979_11;
}
get lastFetchedActivePromotionsLocale() {
return locale;
}
get isFetchingActivePromotions() {
return c3979_10;
}
get hasFetchedConsumedInboundPromotionId() {
return c3979_5.hasFetchedConsumedInboundPromotionId;
}
get consumedInboundPromotionId() {
return c3979_5.consumedInboundPromotionId;
}
get bogoPromotion() {
return c3979_7;
}
get isFetchingActiveBogoPromotion() {
return c3979_8;
}
get lastFetchedActiveBogoPromotion() {
return c3979_9;
}
get promotionsByType() {
return emptyPromotionsByType;
}
getPromotionByTypeAndId(a0, a1) {
const r3 = emptyPromotionsByType[a0];
return r3 == null ? void 0 : r3[a1];
}
getPromotionByTypeAndKey(a0, c15639_0) {
return Object.values(emptyPromotionsByType[a0]).find((item) => item.promotionKey === c15639_0);
}
getState() {
return c3979_5;
}
getMarketingComponentByType(a0) {
let r5 = c3979_15.get(a0);
if (r5 == null) {
r5 = null;
}
return r5;
}
hasPromotion(c15640_0) {
return Object.values(emptyPromotionsByType).some((item) => Object.values(item).some((item) => item.promotionKey === c15640_0));
}
getPromotionsByPartner(c15641_0) {
return {
oneTime: Object.values(emptyPromotionsByType[PromotionTypes.THIRD_PARTY_OUTBOUND]).filter((item) => item.partnerId === c15641_0),
recurring: Object.values(emptyPromotionsByType[PromotionTypes.THIRD_PARTY_OUTBOUND_RECURRING]).filter((item) => item.partnerId === c15641_0)
};
}
getGiftPromotion() {
const r11 = emptyPromotionsByType[PromotionTypes.GIFT_PROMOTION];
const r15 = Object.keys(r11);
return r15.length !== 0 ? r11[r15[0]] : null;
}
getGiftPromotionRewardSkuIds() {
let r5 = this.getGiftPromotion()?.rewardSkuIds;
if (r5 == null) {
r5 = [];
}
return r5;
}
getMarketingMomentPromotion() {
const r13 = emptyPromotionsByType[PromotionTypes.MARKETING_MOMENT];
const r16 = Object.keys(r13);
if (r16.length === 0) {
return null;
}
const r19 = r13[r16[0]];
return r19.endDate < new Date() ? null : r19;
}
getMarketingMomentRewardSkuIds() {
let r5 = this.getMarketingMomentPromotion()?.rewardSkuIds;
if (r5 == null) {
r5 = [];
}
return r5;
}
getActiveBogoRewardPromotion() {
let c15642_0 = new Date();
let r23 = Object.values(emptyPromotionsByType[PromotionTypes.MARKETING_MOMENT]).find((item) => item.hasBogoReward && item.endDate >= c15642_0);
if (r23 == null) {
r23 = null;
}
return r23;
}
get claimedOutboundPromotionCodes() {
return claimedOutboundPromotionCodes2;
}
get claimedOutboundPromotionCodesLoaded() {
return c3979_17;
}
}
const promotionsStore = new PromotionsStore(Dispatcher, {
ACTIVE_PROMOTIONS_FETCH_SUCCESS: function handleActivePromotionsFetchSuccess({ promotions, consumedInboundPromotionId: consumedInboundPromotionId2 }) {
emptyPromotionsByType = createEmptyPromotionsByType();
c3979_15 = new Map();
promotions.forEach((promotion) => {
emptyPromotionsByType[promotion.promotion_type][promotion.id] = PromotionRecord.createFromServer(promotion);
const marketing_components = promotion.marketing_components;
if (marketing_components != null) {
marketing_components.forEach((marketing_component) => {
c3979_15.set(marketing_component.component_type, MarketingComponentRecord.createFromServer(marketing_component));
});
}
});
c3979_11 = Date.now();
c3979_10 = false;
if (!c3979_5.hasFetchedConsumedInboundPromotionId) {
c3979_5.hasFetchedConsumedInboundPromotionId = true;
c3979_5.consumedInboundPromotionId = consumedInboundPromotionId2;
}
},
ACTIVE_PROMOTIONS_FETCH: function handleActivePromotionsFetchStart({ locale: locale2 }) {
c3979_10 = true;
locale = locale2;
},
ACTIVE_PROMOTIONS_FETCH_FAIL: function handleActivePromotionsFetchFail() {
emptyPromotionsByType = createEmptyPromotionsByType();
c3979_15 = new Map();
c3979_10 = false;
},
ACTIVE_PROMOTIONS_CLEAR: function handleActivePromotionsClear() {
emptyPromotionsByType = createEmptyPromotionsByType();
c3979_15 = new Map();
c3979_7 = null;
c3979_10 = false;
c3979_11 = Date.now();
},
ACTIVE_BOGO_PROMOTION_FETCH_SUCCESS: function handleActiveBogoPromotionFetchSuccess({ activePromotion }) {
c3979_7 = {
id: activePromotion.id,
startDate: activePromotion.startDate.toISOString(),
endDate: activePromotion.endDate.toISOString()
};
c3979_9 = Date.now();
c3979_8 = false;
},
ACTIVE_BOGO_PROMOTION_FETCH: function handleActiveBogoPromotionFetchStart() {
c3979_8 = true;
},
ACTIVE_BOGO_PROMOTION_FETCH_FAIL: function handleActiveBogoPromotionFetchFail() {
c3979_7 = null;
c3979_8 = false;
},
OUTBOUND_PROMOTION_NOTICE_DISMISS: function handleDismissOutboundPromotionNotice() {
if (Object.values(emptyPromotionsByType[PromotionTypes.THIRD_PARTY_OUTBOUND]).length === 0) {
return false;
}
const latestActiveOutboundPromotionStartDate2 = getLatestActiveOutboundPromotionStartDate();
if (latestActiveOutboundPromotionStartDate2 != null) {
latestActiveOutboundPromotionStartDate = latestActiveOutboundPromotionStartDate2;
}
},
OUTBOUND_PROMOTIONS_SEEN: function handleOutboundPromotionsSeen() {
if (Object.values(emptyPromotionsByType[PromotionTypes.THIRD_PARTY_OUTBOUND]).length === 0) {
return false;
}
const latestActiveOutboundPromotionStartDate2 = getLatestActiveOutboundPromotionStartDate();
if (latestActiveOutboundPromotionStartDate2 != null) {
latestActiveOutboundPromotionStartDate = latestActiveOutboundPromotionStartDate2;
c3979_5.lastSeenOutboundPromotionStartDate = latestActiveOutboundPromotionStartDate2;
}
},
CLAIMED_OUTBOUND_PROMOTION_CODES_FETCH_SUCCESS: function handleClaimedOutboundPromotionCodesFetchSuccess(a0) {
claimedOutboundPromotionCodes2 = a0.claimedOutboundPromotionCodes;
c3979_17 = true;
},
CLAIMED_OUTBOUND_PROMOTION_CODES_FETCH_FAIL: function handleClaimedOutboundPromotionCodesFetchFail() {
claimedOutboundPromotionCodes2 = [];
c3979_17 = true;
},
CLAIMED_OUTBOUND_PROMOTION_CODE_ADD: function handleClaimedOutboundPromotionCodeAdd({ claimedOutboundPromotionCode }) {
if (claimedOutboundPromotionCodes2.some((item) => item.promotion.id === claimedOutboundPromotionCode.promotion.id)) {
return false;
}
claimedOutboundPromotionCodes2 = [...claimedOutboundPromotionCodes2, claimedOutboundPromotionCode];
},
LOGOUT: function handleLogout() {
c3979_5 = {
hasFetchedConsumedInboundPromotionId: false,
consumedInboundPromotionId: null,
lastSeenOutboundPromotionStartDate: null
};
c3979_10 = false;
c3979_11 = null;
c3979_8 = false;
c3979_9 = null;
emptyPromotionsByType = createEmptyPromotionsByType();
c3979_7 = null;
c3979_15.clear();
claimedOutboundPromotionCodes2 = [];
c3979_17 = false;
},
PREMIUM_MARKETING_PREVIEW: function handlePremiumMarketingPreview({ data }) {
const fromServer = MarketingComponentRecord.createFromServer(data);
c3979_15.set(fromServer.componentType, fromServer);
if (data.promotion != null) {
emptyPromotionsByType[data.promotion.promotion_type][data.promotion.id] = PromotionRecord.createFromServer(data.promotion);
}
}
});
export default promotionsStore;