Files
discord-decomp/records/EntitlementRecord.tsx
T
2026-11-01 12:12:55 +02:00

128 lines
4.2 KiB
TypeScript

// Metro module 4227 (f4228).
import Record from "../lib/Record";
import SKURecord from "../modules/skus/SKURecord";
import UserRecord from "./UserRecord";
import { EntitlementTypes } from "../Constants";
import PremiumUtils from "../utils/PremiumUtils";
import { EntitlementTenantFulfillmentStatus } from "../_bundle/Module4232";
import { $callWithNewTarget } from "../_hermes/prelude";
class EntitlementRecord extends Record {
constructor(a0) {
super();
this.id = a0.id;
this.skuId = a0.skuId;
this.applicationId = a0.applicationId;
this.user = a0.user;
this.userId = a0.userId;
this.gifterId = a0.gifterId;
this.type = a0.type;
this.branches = a0.branches;
this.startsAt = a0.startsAt;
this.endsAt = a0.endsAt;
this.subscriptionId = a0.subscriptionId;
this.subscriptionPlanId = a0.subscriptionPlanId;
this.parentId = a0.parentId;
this.consumed = a0.consumed;
this.giftCodeBatchId = a0.giftCodeBatchId;
this.giftStyle = a0.giftStyle;
this.guildId = a0.guildId;
this.deleted = a0.deleted;
this.sourceType = a0.sourceType;
this.fulfillmentStatus = a0.fulfillmentStatus;
}
static createFromServer(a0) {
const { id, sku_id, application_id } = a0;
const user = a0.user != null ? new UserRecord(a0.user) : null;
const { user_id, gifter_user_id, type } = a0;
let branches = a0.branches;
if (branches == null) {
branches = [];
}
const startsAt = a0.starts_at != null ? new Date(a0.starts_at) : null;
const endsAt = a0.ends_at != null ? new Date(a0.ends_at) : null;
const subscription_id = a0.subscription_id;
const subscriptionPlanId = a0.subscription_plan != null ? a0.subscription_plan.id : null;
const parentId = a0.parent_id != null ? a0.parent_id : null;
const consumed = a0.consumed != null ? a0.consumed : null;
let gift_code_batch_id = a0.gift_code_batch_id;
if (gift_code_batch_id == null) {
gift_code_batch_id = null;
}
const { gift_style, guild_id, deleted } = a0;
if (a0.sku != null) {
SKURecord.createFromServer(a0.sku);
}
let source_type = a0.source_type;
if (source_type == null) {
source_type = null;
}
let fulfillment_status = a0.fulfillment_status;
if (fulfillment_status == null) {
fulfillment_status = null;
}
const prototypeOf = Object.getPrototypeOf(EntitlementRecord);
const r65 = Object.create(EntitlementRecord.prototype);
const r67 = $callWithNewTarget(prototypeOf, r65, EntitlementRecord);
const r68 = r67 instanceof Object ? r67 : r65;
r68.id = id;
r68.skuId = sku_id;
r68.applicationId = application_id;
r68.user = user;
r68.userId = user_id;
r68.gifterId = gifter_user_id;
r68.type = type;
r68.branches = branches;
r68.startsAt = startsAt;
r68.endsAt = endsAt;
r68.subscriptionId = subscription_id;
r68.subscriptionPlanId = subscriptionPlanId;
r68.parentId = parentId;
r68.consumed = consumed;
r68.giftCodeBatchId = gift_code_batch_id;
r68.giftStyle = gift_style;
r68.guildId = guild_id;
r68.deleted = deleted;
r68.sourceType = source_type;
r68.fulfillmentStatus = fulfillment_status;
return r68;
}
get isGiftable() {
return this.type === EntitlementTypes.USER_GIFT && this.gifterId == null;
}
isValid(a0, a1, r4 = null) {
if (!this.isGiftable && !this.deleted) {
if (this.type === EntitlementTypes.PREMIUM_SUBSCRIPTION) {
const r16 = a1.get(this.skuId);
if (r16 != null && !r16.premium) {
return false;
}
if (!PremiumUtils.canInstallPremiumApplications(a0)) {
return false;
}
}
const date = new Date();
if (this.startsAt != null && date < this.startsAt) {
return false;
}
if (this.endsAt != null && date >= this.endsAt) {
return false;
}
if (r4 != null) {
if (this.branches.length === 0) {
if (this.applicationId !== r4) {
return false;
}
} else if (!this.branches.includes(r4)) {
return false;
}
}
return true;
}
return false;
}
isFulfilled() {
return this.fulfillmentStatus === EntitlementTenantFulfillmentStatus.FULFILLED;
}
}
export default EntitlementRecord;