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

160 lines
6.1 KiB
TypeScript

// Metro module 6566 (f6567).
import UserSettingsProtoStore from "../../user_settings/UserSettingsProtoStore";
import PromotionRecord from "../../../records/PromotionRecord";
import PromotionsStore from "./PromotionsStore";
import { PromotionFlags } from "../PremiumConstants";
import { Endpoints, Platforms, AnalyticEvents } from "../../../Constants";
import { ActivityPlatform } from "../../activities/Constants";
import { isThemeDark } from "../../../design/shared";
import { HTTP, rejectWithMigratedError } from "../../../_bundle/sendRequest";
import * as _PlatformUtils from "../../../utils/PlatformUtils";
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
import { DismissibleContent } from "../../../_bundle/Module1358";
import { isTimeRecurringSnowflakeBoundDismissibleContentDismissed } from "../../dismissible_content/DismissibleContentUtils";
import { DEDICATED_SURFACE_PARTNER_IDS, PromotionTypes } from "./constants";
function $mk78816($env) {
return (a0) => {
let r0 = a0.id !== $env[0];
if (r0) {
const r8 = $env.$parent;
r0 = !(0, r8[0])(r8[2][11]).hasFlag(a0.flags, r8[7].SUPPRESS_NOTIFICATION);
}
if (r0) {
let r18 = a0.partnerId != null;
if (r18) {
const r19 = $env.$parent;
r18 = (0, r19[0])(r19[2][15]).DEDICATED_SURFACE_PARTNER_IDS.has(a0.partnerId);
}
r0 = !r18;
}
return r0;
};
}
function $mk78817($env) {
return ({ id }) => {
const r6 = $env.$parent;
return (0, r6[1])(r6[2][13]).compare(id, $env[1]) === 1;
};
}
function $mk78818() {
return (a0, a1) => new Date(a0.startDate) < new Date(a1.startDate) ? -1 : 1;
}
let env4226 = {};
export function claimedOutboundPromotionCodeFromServer(a0) {
return {
code: a0.code,
userId: a0.user_id,
claimedAt: a0.claimed_at,
promotion: PromotionRecord.createFromServer(a0.promotion)
};
}
ActivityPlatform;
export function getPromotionImageURL(a0, a1) {
const r9 = isThemeDark(a1) ? "logo-dark" : "logo-light";
const CDN_HOST = window.GLOBAL_ENV.CDN_HOST;
return CDN_HOST != null ? `https://${CDN_HOST}/promotions/${a0}/${r9}?size=256` : `${location.protocol}${window.GLOBAL_ENV.API_ENDPOINT}/promotions/${a0}/${r9}?size=256`;
}
export async function claimOutboundPromotion(c25924_0) {
let c29802_0 = c25924_0.promotionId;
let c29802_1 = c25924_0.promotionTitle;
let c29802_2 = c25924_0.partnerId;
let c29802_3 = c25924_0.analyticsLocations;
await void 0;
let c29802_4 = await HTTP.post({
url: Endpoints.CLAIM_OUTBOUND_PROMOTION_CODE(c29802_0),
rejectWithError: rejectWithMigratedError()
});
let c29802_5 = c29802_4.body;
let c29802_6 = _PlatformUtils.isIOS() ? Platforms.IOS : Platforms.ANDROID;
const OUTBOUND_PROMOTION_CLAIMED = AnalyticEvents.OUTBOUND_PROMOTION_CLAIMED;
let name = c29802_1;
if (c29802_1 == null) {
name = null;
}
let partner = c29802_2;
if (c29802_2 == null) {
partner = null;
}
AnalyticsUtils.track(OUTBOUND_PROMOTION_CLAIMED, {
platform: c29802_6,
status: c29802_4.status,
location_stack: c29802_3,
promotion_id: c29802_0,
name,
partner
});
return (0, claimedOutboundPromotionCodeFromServer)(c29802_5);
}
export function getOutboundPromotionRedemptionUrl(a0, a1) {
let r7;
if (a1.outboundRedemptionUrlFormat != null && a1.outboundRedemptionUrlFormat !== "") {
r7 = a1.outboundRedemptionUrlFormat.replace("{code}", encodeURIComponent(a0));
} else {
r7 = a1.outboundRedemptionPageLink;
if (r7 == null) {
r7 = "";
}
}
return r7;
}
export function getNextUnseenOutboundPromotionId() {
let env15801;
const r4 = env15801 = {
$parent: env4226
};
const outboundPromotions = PromotionsStore.outboundPromotions;
env15801[0] = PromotionsStore.consumedInboundPromotionId;
const r12 = outboundPromotions.filter($mk78816(r4));
const userContent = UserSettingsProtoStore.settings.userContent;
const r16 = userContent == null ? void 0 : userContent.recurringDismissibleContentStates[DismissibleContent.THIRD_PARTY_OUTBOUND_PROMO_NAGBAR]?.lastDismissedObjectId;
env15801[1] = r16;
const r25 = r16 != null ? r12.filter($mk78817(r4)) : r12;
return r25.length !== 0 ? r25.sort($mk78818())[0].id : null;
}
export function shouldShowOutboundPromotionNotice() {
let env15802;
const r5 = env15802 = {
$parent: env4226
};
const outboundPromotions = PromotionsStore.outboundPromotions;
env15802[0] = PromotionsStore.consumedInboundPromotionId;
const r13 = outboundPromotions.filter($mk78816(r5));
const userContent = UserSettingsProtoStore.settings.userContent;
const r17 = userContent == null ? void 0 : userContent.recurringDismissibleContentStates[DismissibleContent.THIRD_PARTY_OUTBOUND_PROMO_NAGBAR]?.lastDismissedObjectId;
env15802[1] = r17;
const r25 = r17 != null ? r13.filter($mk78817(r5)) : r13;
const r29 = r25.length !== 0 ? r25.sort($mk78818())[0].id : null;
return r29 != null && !isTimeRecurringSnowflakeBoundDismissibleContentDismissed(DismissibleContent.THIRD_PARTY_OUTBOUND_PROMO_NAGBAR, r29, {
cooldownDurationMs: 259200000
});
}
export function isDedicatedSurfacePromotion(a0) {
return a0.partnerId != null && DEDICATED_SURFACE_PARTNER_IDS.has(a0.partnerId);
}
export function shouldShowOutboundPromotionOnPlatform(a0) {
const isIOS = _PlatformUtils.isIOS();
return isIOS ? !a0.hasFlag(PromotionFlags.IS_BLOCKED_IOS) : !isIOS;
}
export function getClaimedOutboundPromotionCodeMap(a0) {
const r0 = {};
for (const item of a0) {
r0[item.promotion.id] = item.code;
}
return r0;
}
export function getClaimedEndedOutboundPromotions(a0, a1) {
let c15803_0 = new Set(a1.map((item) => item.id));
return a0.filter(({ promotion }) => {
const r10 = c15803_0.has(promotion.id);
let r0 = (r10 ? !r10 : !(promotion.promotionType === PromotionTypes.THIRD_PARTY_OUTBOUND_RECURRING)) && !(promotion.partnerId != null && DEDICATED_SURFACE_PARTNER_IDS.has(promotion.partnerId));
if (r0) {
const isIOS = _PlatformUtils.isIOS();
r0 = isIOS ? !promotion.hasFlag(PromotionFlags.IS_BLOCKED_IOS) : !isIOS;
}
return r0;
});
}
export function isRecurringPromotion(a0) {
return a0.promotionType === PromotionTypes.THIRD_PARTY_OUTBOUND_RECURRING;
}