484 lines
12 KiB
TypeScript
484 lines
12 KiB
TypeScript
// Metro module 12520 (f12521).
|
|
import UserRecord from "../../../records/UserRecord";
|
|
import SubscriptionGroupMemberRecord from "./records/SubscriptionGroupMemberRecord";
|
|
import { Endpoints } from "../../../Constants";
|
|
import Dispatcher from "../../../Dispatcher";
|
|
import { HTTP } from "../../../_bundle/sendRequest";
|
|
import Module38 from "../../../_bundle/Module38";
|
|
import { HermesBuiltin } from "../../../_hermes/prelude";
|
|
function $mk116403($env) {
|
|
return (a0) => Object.assign(new UserRecord(a0), {
|
|
eligible: true
|
|
});
|
|
}
|
|
function $mk116404($env) {
|
|
return (a0) => Object.assign(new UserRecord(a0), {
|
|
eligible: false
|
|
});
|
|
}
|
|
let env8653 = {};
|
|
export async function fetchPremiumGroupMembership() {
|
|
let r93;
|
|
let c27302_3 = 0;
|
|
let c30526_0;
|
|
try {
|
|
c30526_0 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_MEMBERSHIP_FETCH_START"
|
|
});
|
|
c27302_3 = 1;
|
|
c30526_0 = (await HTTP.get({
|
|
url: Endpoints.PREMIUM_GROUP_MEMBERSHIP,
|
|
rejectWithError: true
|
|
})).body;
|
|
if (c30526_0 != null) {
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_MEMBERSHIP_FETCH_SUCCESS",
|
|
membership: {
|
|
subscriptionId: c30526_0.subscription_id,
|
|
memberType: c30526_0.member_type,
|
|
subscriptionStatus: c30526_0.subscription_status,
|
|
currentPeriodEnd: new Date(c30526_0.current_period_end)
|
|
}
|
|
});
|
|
} else {
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_MEMBERSHIP_NOT_FOUND"
|
|
});
|
|
}
|
|
r93 = c30526_0;
|
|
c27302_3 = 0;
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c27302_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c27302_3 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_MEMBERSHIP_FETCH_FAILURE"
|
|
});
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c27302_3 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r93;
|
|
}
|
|
export async function fetchEligibleUsers(c27303_0, index, search_query, c27303_3) {
|
|
let env30527;
|
|
const r29 = env30527 = {
|
|
$parent: env8653
|
|
};
|
|
let c27303_7 = r29;
|
|
env30527[0] = void 0;
|
|
env30527[1] = void 0;
|
|
env30527[2] = void 0;
|
|
env30527[3] = void 0;
|
|
const r37 = {
|
|
url: Endpoints.BILLING_SUBSCRIPTION_ELIGIBLE_USERS(c27303_0),
|
|
query: null,
|
|
rejectWithError: true
|
|
};
|
|
let limit = c27303_3;
|
|
if (c27303_3 == null) {
|
|
limit = 10;
|
|
}
|
|
r37.query = {
|
|
index,
|
|
limit,
|
|
search_query,
|
|
include_ineligible: true
|
|
};
|
|
env30527[0] = (await HTTP.get(r37)).body;
|
|
env30527[1] = env30527[0].users;
|
|
env30527[2] = env30527[0].next_index;
|
|
env30527[3] = env30527[0].ineligible_users;
|
|
let c27303_5 = 0;
|
|
const r19 = env30527[1].map($mk116403(env8653));
|
|
const users = [];
|
|
c27303_5 = HermesBuiltin.arraySpread(users, r19, c27303_5);
|
|
const r70 = env30527[3];
|
|
let c27303_6 = r70;
|
|
if (r70 == null) {
|
|
c27303_6 = [];
|
|
}
|
|
c27303_5 = HermesBuiltin.arraySpread(users, c27303_6.map($mk116404(env8653)), c27303_5);
|
|
return {
|
|
users,
|
|
nextIndex: env30527[2]
|
|
};
|
|
}
|
|
export async function inviteUsersToSubscriptionGroup(c27304_0, user_ids) {
|
|
let r75;
|
|
let c27304_5 = 0;
|
|
let c30528_0, c30528_1;
|
|
try {
|
|
c30528_0 = c27304_0;
|
|
c30528_1 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITE_USERS_START"
|
|
});
|
|
c27304_5 = 1;
|
|
c30528_1 = await HTTP.post({
|
|
url: Endpoints.BILLING_SUBSCRIPTION_INVITES(c27304_0),
|
|
body: {
|
|
user_ids
|
|
},
|
|
rejectWithError: true
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITE_USERS_SUCCESS",
|
|
subscriptionId: c30528_0
|
|
});
|
|
r75 = {
|
|
invitedUsers: c30528_1.body.invited_users,
|
|
ineligibleUsers: c30528_1.body.ineligible_users
|
|
};
|
|
c27304_5 = 0;
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c27304_5 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c27304_5 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITE_USERS_FAILURE"
|
|
});
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c27304_5 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r75;
|
|
}
|
|
export async function removeUserFromSubscriptionGroup(c27305_0, c27305_1) {
|
|
let r69, r87;
|
|
let c27305_4;
|
|
let c27305_5 = 0;
|
|
let c30529_0, c30529_1, c30529_2;
|
|
try {
|
|
c30529_0 = c27305_0;
|
|
c30529_1 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_REMOVE_MEMBER_START"
|
|
});
|
|
c27305_5 = 1;
|
|
c30529_1 = await HTTP.del({
|
|
url: Endpoints.BILLING_SUBSCRIPTION_REMOVE_USER(c27305_0, c27305_1),
|
|
rejectWithError: true
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_REMOVE_MEMBER_SUCCESS",
|
|
subscriptionId: c30529_0
|
|
});
|
|
r69 = c30529_1;
|
|
c27305_5 = 0;
|
|
} catch ($e) {
|
|
const r27 = $e;
|
|
let r8 = r27;
|
|
c27305_4 = r27;
|
|
if (c27305_5 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r78 = c27305_4;
|
|
c27305_5 = 0;
|
|
c30529_2 = r78;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_REMOVE_MEMBER_FAILURE"
|
|
});
|
|
r87 = c30529_2;
|
|
} catch (r74) {
|
|
r8 = r74;
|
|
c27305_4 = r74;
|
|
if (c27305_5 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return r87;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r69;
|
|
}
|
|
export async function fetchSubscriptionGroupMembers(c27306_0) {
|
|
let r104;
|
|
let c27306_1, c27306_2, c27306_3;
|
|
let c27306_4 = 0;
|
|
const r13 = env8653;
|
|
try {
|
|
let env30530;
|
|
c27306_2 = r13;
|
|
const r32 = env30530 = {};
|
|
c27306_1 = r32;
|
|
env30530[0] = void 0;
|
|
env30530[1] = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_MEMBERS_FETCH_START"
|
|
});
|
|
c27306_4 = 1;
|
|
env30530[0] = (await HTTP.get({
|
|
url: Endpoints.BILLING_SUBSCRIPTION_MEMBERS(c27306_0),
|
|
rejectWithError: true
|
|
})).body.map(SubscriptionGroupMemberRecord.createFromServer);
|
|
env30530[1] = env30530[0].find((item) => item.isPrimary());
|
|
Module38(env30530[1] != null, "Primary member not found in premium group");
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_MEMBERS_FETCH_SUCCESS",
|
|
members: {
|
|
primary: env30530[1].user,
|
|
members: env30530[0].filter((item) => item.isMember()).map((item) => item.user),
|
|
invitedUsers: env30530[0].filter((item) => item.isInvited()).map((item) => item.user)
|
|
}
|
|
});
|
|
r104 = env30530[0];
|
|
c27306_4 = 0;
|
|
} catch ($e) {
|
|
const r30 = $e;
|
|
let r8 = r30;
|
|
c27306_3 = r30;
|
|
if (c27306_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c27306_4 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_MEMBERS_FETCH_FAILURE"
|
|
});
|
|
} catch (r109) {
|
|
r8 = r109;
|
|
c27306_3 = r109;
|
|
if (c27306_4 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return [];
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r104;
|
|
}
|
|
export async function acceptSubscriptionGroupInvite(c27307_0, c27307_1, subscriptionGroupMemberId) {
|
|
let r70, r89;
|
|
let c27307_5;
|
|
let c27307_6 = 0;
|
|
let c30531_0, c30531_1, c30531_2;
|
|
try {
|
|
c30531_0 = subscriptionGroupMemberId;
|
|
c30531_1 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_ACCEPT_INVITE_START",
|
|
subscriptionGroupMemberId
|
|
});
|
|
c27307_6 = 1;
|
|
c30531_1 = await HTTP.patch({
|
|
url: Endpoints.BILLING_SUBSCRIPTION_INVITE(c27307_0, c27307_1),
|
|
rejectWithError: true
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_ACCEPT_INVITE_SUCCESS",
|
|
subscriptionGroupMemberId: c30531_0
|
|
});
|
|
r70 = c30531_1;
|
|
c27307_6 = 0;
|
|
} catch ($e) {
|
|
const r27 = $e;
|
|
let r8 = r27;
|
|
c27307_5 = r27;
|
|
if (c27307_6 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r79 = c27307_5;
|
|
c27307_6 = 0;
|
|
c30531_2 = r79;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_ACCEPT_INVITE_FAIL",
|
|
subscriptionGroupMemberId: c30531_0
|
|
});
|
|
r89 = c30531_2;
|
|
} catch (r75) {
|
|
r8 = r75;
|
|
c27307_5 = r75;
|
|
if (c27307_6 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return r89;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r70;
|
|
}
|
|
export async function removeSubscriptionGroupInvite(c27308_0, c27308_1, subscriptionGroupMemberId2) {
|
|
let r73, r98;
|
|
let c27308_5;
|
|
let c27308_6 = 0;
|
|
let c30532_0, c30532_1, c30532_2, c30532_3;
|
|
try {
|
|
c30532_0 = c27308_0;
|
|
c30532_1 = subscriptionGroupMemberId2;
|
|
c30532_2 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_REMOVE_INVITE_START",
|
|
subscriptionGroupMemberId: subscriptionGroupMemberId2
|
|
});
|
|
c27308_6 = 1;
|
|
c30532_2 = await HTTP.del({
|
|
url: Endpoints.BILLING_SUBSCRIPTION_INVITE(c27308_0, c27308_1),
|
|
rejectWithError: true
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_REMOVE_INVITE_SUCCESS",
|
|
subscriptionId: c30532_0,
|
|
subscriptionGroupMemberId: c30532_1
|
|
});
|
|
r73 = c30532_2;
|
|
c27308_6 = 0;
|
|
} catch ($e) {
|
|
const r28 = $e;
|
|
let r8 = r28;
|
|
c27308_5 = r28;
|
|
if (c27308_6 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r82 = c27308_5;
|
|
c27308_6 = 0;
|
|
c30532_3 = r82;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_REMOVE_INVITE_FAILURE",
|
|
subscriptionGroupMemberId: c30532_1,
|
|
errorCode: c30532_3.body?.code,
|
|
subscriptionId: c30532_0
|
|
});
|
|
r98 = c30532_3;
|
|
} catch (r78) {
|
|
r8 = r78;
|
|
c27308_5 = r78;
|
|
if (c27308_6 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return r98;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r73;
|
|
}
|
|
export async function fetchPremiumGroupInvites() {
|
|
let c27309_3 = 0;
|
|
let c30533_0;
|
|
L10: {
|
|
try {
|
|
c30533_0 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITES_FETCH_START"
|
|
});
|
|
c27309_3 = 1;
|
|
c30533_0 = (await HTTP.get({
|
|
url: Endpoints.PREMIUM_GROUP_INVITES,
|
|
rejectWithError: true
|
|
})).body;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITES_FETCH_SUCCESS",
|
|
invites: c30533_0
|
|
});
|
|
c27309_3 = 0;
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c27309_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c27309_3 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITES_FETCH_FAIL"
|
|
});
|
|
break L10;
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c27309_3 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
}
|
|
}
|
|
export async function fetchPremiumGroupInvite(subscriptionGroupMemberId3) {
|
|
let status, c27310_4;
|
|
let c27310_5 = 0;
|
|
let c30534_0, c30534_1, c30534_2;
|
|
L10: {
|
|
try {
|
|
c30534_0 = subscriptionGroupMemberId3;
|
|
c30534_1 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITE_FETCH_START",
|
|
subscriptionGroupMemberId: subscriptionGroupMemberId3
|
|
});
|
|
c27310_5 = 1;
|
|
c30534_1 = (await HTTP.get({
|
|
url: Endpoints.PREMIUM_GROUP_INVITE(subscriptionGroupMemberId3),
|
|
rejectWithError: true
|
|
})).body;
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITE_FETCH_SUCCESS",
|
|
subscriptionGroupMemberId: c30534_0,
|
|
invite: c30534_1
|
|
});
|
|
c27310_5 = 0;
|
|
} catch ($e) {
|
|
const r26 = $e;
|
|
let r8 = r26;
|
|
c27310_4 = r26;
|
|
if (c27310_5 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r79 = c27310_4;
|
|
c27310_5 = 0;
|
|
c30534_2 = r79;
|
|
status = c30534_2?.status;
|
|
if (status == null) {
|
|
status = 0;
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "PREMIUM_GROUP_INVITE_FETCH_FAIL",
|
|
subscriptionGroupMemberId: c30534_0,
|
|
status
|
|
});
|
|
break L10;
|
|
} catch (r75) {
|
|
r8 = r75;
|
|
c27310_4 = r75;
|
|
if (c27310_5 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
}
|
|
}
|