363 lines
12 KiB
TypeScript
363 lines
12 KiB
TypeScript
// Metro module 4226 (f4227).
|
|
import _slicedToArray from "../../_bundle/_slicedToArray";
|
|
import ApplicationRecord from "../../records/ApplicationRecord";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c2443_2, c2443_3, c2443_4, c2443_5, c2443_6, c2443_7, c2443_8, c2443_9, handleAppWithBot;
|
|
const addApplication = function addApplication(a0) {
|
|
const r5 = c2443_3.get(a0.id);
|
|
c2443_6.set(a0.id, Date.now());
|
|
const r31 = r5 != null ? r5.mergeFromApplicationUpdate(a0) : a0;
|
|
c2443_3.set(a0.id, r31);
|
|
c2443_5.set(a0.name.toLowerCase(), r31);
|
|
for (const aliase of a0.aliases) {
|
|
c2443_5.set(aliase.toLowerCase(), r31);
|
|
}
|
|
if (a0.linkedGames != null) {
|
|
for (const linkedGame of a0.linkedGames) {
|
|
const r63 = linkedGame;
|
|
if (linkedGame.application != null) {
|
|
addApplication(r63.application instanceof ApplicationRecord ? r63.application : ApplicationRecord.createFromServer(r63.application));
|
|
}
|
|
}
|
|
}
|
|
c2443_7.delete(a0.id);
|
|
};
|
|
const handleWishlistAction = function handleWishlistAction(a0) {
|
|
const applications = a0.wishlistData.applications;
|
|
if (applications != null && applications.length !== 0) {
|
|
for (const item of applications) {
|
|
addApplication(item);
|
|
}
|
|
return void 0;
|
|
}
|
|
return false;
|
|
};
|
|
handleAppWithBot = function handleAppWithBot({ userId, applicationId }) {
|
|
const r4 = c2443_9.botUserIdToAppUsage[userId];
|
|
c2443_9.botUserIdToAppUsage[userId] = r4 == null ? {
|
|
applicationId,
|
|
lastUsedMs: Date.now()
|
|
} : {
|
|
applicationId,
|
|
lastUsedMs: r4.lastUsedMs
|
|
};
|
|
const map = new Map();
|
|
for (const item of Object.entries(c2443_9.botUserIdToAppUsage)) {
|
|
const r47 = _slicedToArray(item, 2);
|
|
map.set(r47[0], r47[1]);
|
|
}
|
|
const r59 = Array.from(map.entries()).sort((a, b) => b[1].lastUsedMs - a[1].lastUsedMs);
|
|
const length = r59.length;
|
|
let r61 = 0;
|
|
if (0 < length) {
|
|
do {
|
|
const r65 = r61;
|
|
if (10 <= r65) {
|
|
delete c2443_9.botUserIdToAppUsage[r59[r65][0]];
|
|
}
|
|
r61 = r65 + 1;
|
|
} while (r61 < r59.length);
|
|
}
|
|
};
|
|
const handleApplicationWidgetConfigFetchSuccess = function handleApplicationWidgetConfigFetchSuccess({ applications }) {
|
|
if (applications.length === 0) {
|
|
return false;
|
|
}
|
|
for (const item of applications) {
|
|
addApplication(ApplicationRecord.createFromServer(item));
|
|
}
|
|
return true;
|
|
};
|
|
const handleEntitlementsFetched = function handleEntitlementsFetched({ entitlements }) {
|
|
let r0 = false;
|
|
for (const item of entitlements) {
|
|
const sku = item.sku;
|
|
if (sku?.application != null) {
|
|
addApplication(ApplicationRecord.createFromServer(sku.application));
|
|
r0 = true;
|
|
}
|
|
}
|
|
return r0;
|
|
};
|
|
c2443_2 = [];
|
|
c2443_3 = new Map();
|
|
c2443_4 = new Map();
|
|
c2443_5 = new Map();
|
|
c2443_6 = new Map();
|
|
c2443_7 = new Map();
|
|
c2443_8 = new Set();
|
|
c2443_9 = {
|
|
botUserIdToAppUsage: {}
|
|
};
|
|
class ApplicationStore extends Module589.PersistedStore {
|
|
static displayName = "ApplicationStore";
|
|
static persistKey = "ApplicationStore";
|
|
initialize(a0) {
|
|
if (a0 != null && typeof a0.botUserIdToAppUsage === "object") {
|
|
const botUserIdToAppUsage = a0.botUserIdToAppUsage;
|
|
for (const key in botUserIdToAppUsage) {
|
|
const r16 = a0.botUserIdToAppUsage[key];
|
|
const { applicationId, lastUsedMs } = r16;
|
|
if ((typeof applicationId === "string" ? applicationId.length > 0 : typeof applicationId === "string") && typeof lastUsedMs === "number" && lastUsedMs > 0) {
|
|
c2443_9.botUserIdToAppUsage[key] = {
|
|
applicationId,
|
|
lastUsedMs
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
getState() {
|
|
return c2443_9;
|
|
}
|
|
_getAllApplications() {
|
|
return Array.from(c2443_3.values());
|
|
}
|
|
getGuildApplication(a0, a1) {
|
|
if (a0 != null) {
|
|
for (const item of c2443_3.values()) {
|
|
if (item.guildId !== a0) {
|
|
continue;
|
|
}
|
|
if (item.type !== a1) {
|
|
continue;
|
|
}
|
|
return item;
|
|
}
|
|
}
|
|
}
|
|
getGuildApplicationIds(a0) {
|
|
let r5;
|
|
if (a0 == null) {
|
|
r5 = c2443_2;
|
|
} else {
|
|
r5 = c2443_4.get(a0);
|
|
if (r5 == null) {
|
|
r5 = c2443_2;
|
|
}
|
|
}
|
|
return r5;
|
|
}
|
|
getApplication(a0) {
|
|
if (a0 != null) {
|
|
return c2443_3.get(a0);
|
|
}
|
|
}
|
|
getApplicationByName(a0) {
|
|
if (a0 != null) {
|
|
const r4 = a0.toLowerCase();
|
|
return c2443_5.has(r4) ? c2443_5.get(r4) : void 0;
|
|
}
|
|
}
|
|
getApplicationLastUpdated(a0) {
|
|
return c2443_6.get(a0);
|
|
}
|
|
isFetchingApplication(a0) {
|
|
return c2443_7.get(a0) === true;
|
|
}
|
|
isHydrated(a0) {
|
|
return c2443_8.has(a0);
|
|
}
|
|
didFetchingApplicationFail(a0) {
|
|
return c2443_7.get(a0) === false;
|
|
}
|
|
getFetchingOrFailedFetchingIds() {
|
|
return Array.from(c2443_7.keys());
|
|
}
|
|
getAppIdForBotUserId(a0) {
|
|
if (a0 != null) {
|
|
return c2443_9.botUserIdToAppUsage[a0]?.applicationId;
|
|
}
|
|
}
|
|
}
|
|
const applicationStore = new ApplicationStore(Dispatcher, {
|
|
LOGOUT: function handleLogout() {
|
|
c2443_3.clear();
|
|
c2443_4.clear();
|
|
c2443_5.clear();
|
|
c2443_6.clear();
|
|
c2443_7.clear();
|
|
c2443_8.clear();
|
|
},
|
|
OVERLAY_INITIALIZE: function handleOverlayInitialize(a0) {
|
|
for (const application of a0.applications) {
|
|
addApplication(new ApplicationRecord(application));
|
|
}
|
|
},
|
|
APPLICATION_FETCH: function handleApplicationFetch({ applicationId }) {
|
|
const r7 = c2443_7.get(applicationId);
|
|
c2443_7.set(applicationId, true);
|
|
return r7 !== true;
|
|
},
|
|
APPLICATION_FETCH_SUCCESS: function handleApplicationFetchSuccess(a0) {
|
|
const application = a0.application;
|
|
if (a0.isHydrated === true) {
|
|
c2443_8.add(application.id);
|
|
}
|
|
addApplication(ApplicationRecord.createFromServer(application));
|
|
},
|
|
APPLICATION_FETCH_FAIL: function handleApplicationFetchFail({ applicationId }) {
|
|
const r7 = c2443_7.get(applicationId);
|
|
c2443_7.set(applicationId, false);
|
|
return r7 !== false;
|
|
},
|
|
APPLICATIONS_FETCH: function handleApplicationsFetch({ applicationIds }) {
|
|
let r0 = false;
|
|
for (const item of applicationIds) {
|
|
const r27 = c2443_7.get(item);
|
|
c2443_7.set(item, true);
|
|
r0 = r27 !== true;
|
|
}
|
|
return r0;
|
|
},
|
|
APPLICATIONS_FETCH_SUCCESS: function handleApplicationsFetchSuccess({ applications, isHydrated: isHydrated2 }) {
|
|
for (const item of applications) {
|
|
if (isHydrated2 === true) {
|
|
c2443_8.add(item.id);
|
|
}
|
|
addApplication(ApplicationRecord.createFromServer(item));
|
|
}
|
|
},
|
|
APPLICATIONS_FETCH_FAIL: function handleApplicationsFetchFail({ applicationIds }) {
|
|
let r0 = false;
|
|
for (const item of applicationIds) {
|
|
const r27 = c2443_7.get(item);
|
|
c2443_7.set(item, false);
|
|
r0 = r27 !== false;
|
|
}
|
|
return r0;
|
|
},
|
|
APPLICATION_UPDATE: function handleUpdateApplication(a0) {
|
|
addApplication(ApplicationRecord.createFromServer(a0.application));
|
|
},
|
|
APPLICATION_SUBSCRIPTIONS_FETCH_ENTITLEMENTS_SUCCESS: handleEntitlementsFetched,
|
|
ENTITLEMENTS_FETCH_FOR_USER_SUCCESS: handleEntitlementsFetched,
|
|
ENTITLEMENTS_GIFTABLE_FETCH_SUCCESS: handleEntitlementsFetched,
|
|
GUILD_APPLICATIONS_FETCH_SUCCESS: function handleGuildApplicationsFetchSuccess({ guildId, applications }) {
|
|
const r3 = [];
|
|
for (const item of applications) {
|
|
r3.push(item.id);
|
|
addApplication(ApplicationRecord.createFromServer(item));
|
|
}
|
|
c2443_4.set(guildId, r3);
|
|
},
|
|
BILLING_PAYMENTS_FETCH_SUCCESS: function handleFetchPayments({ payments }) {
|
|
const set = new Set();
|
|
for (const item of payments) {
|
|
const application = item.sku?.application;
|
|
if (!(application == null || set.has(application.id))) {
|
|
addApplication(ApplicationRecord.createFromServer(application));
|
|
}
|
|
}
|
|
return set.size > 0;
|
|
},
|
|
PAYMENT_UPDATE: function handleUpdatePayment({ payment }) {
|
|
if (payment.sku?.application == null) {
|
|
return false;
|
|
}
|
|
addApplication(ApplicationRecord.createFromServer(payment.sku.application));
|
|
},
|
|
INVITE_RESOLVE_SUCCESS: function handleResolveInvite({ invite }) {
|
|
if (invite.target_application == null) {
|
|
return false;
|
|
}
|
|
addApplication(ApplicationRecord.createFromServer(invite.target_application));
|
|
},
|
|
GIFT_CODE_RESOLVE_SUCCESS: function handleGiftCodeResolveSuccess({ giftCode }) {
|
|
const store_listing = giftCode.store_listing;
|
|
if ((store_listing == null ? void 0 : store_listing.sku.application) == null) {
|
|
return false;
|
|
}
|
|
addApplication(ApplicationRecord.createFromServer(giftCode.store_listing.sku.application));
|
|
},
|
|
LIBRARY_FETCH_SUCCESS: function handleLibraryApplicationsFetch(a0) {
|
|
for (const libraryApplication of a0.libraryApplications) {
|
|
addApplication(ApplicationRecord.createFromServer(libraryApplication.application));
|
|
}
|
|
},
|
|
STORE_LISTING_FETCH_SUCCESS: function handleStoreListingFetch({ storeListing }) {
|
|
if (storeListing.sku.application == null) {
|
|
return false;
|
|
}
|
|
addApplication(ApplicationRecord.createFromServer(storeListing.sku.application));
|
|
},
|
|
LOAD_MESSAGES_SUCCESS: function handleLoadMessages(a0) {
|
|
a0.messages.forEach(({ attachments }) => {
|
|
if (attachments != null) {
|
|
attachments.forEach((attachment) => {
|
|
if (attachment.application != null) {
|
|
addApplication(ApplicationRecord.createFromServer(attachment.application));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
},
|
|
USER_PROFILE_FETCH_SUCCESS: function handleProfileFetchSuccess({ userProfile }) {
|
|
const { user, application } = userProfile;
|
|
if (user.bot && application != null) {
|
|
handleAppWithBot({
|
|
userId: user.id,
|
|
applicationId: application.id
|
|
});
|
|
}
|
|
},
|
|
APP_DM_OPEN: function handleAppDMOpen({ botUserId }) {
|
|
const r4 = c2443_9.botUserIdToAppUsage[botUserId];
|
|
if (r4 != null) {
|
|
c2443_9.botUserIdToAppUsage[botUserId] = {
|
|
...r4,
|
|
lastUsedMs: Date.now()
|
|
};
|
|
}
|
|
},
|
|
USER_AUTHORIZED_APPS_UPDATE: function handleAuthorizedAppsUpdate(a0) {
|
|
for (const item of Object.values(a0.tokens)) {
|
|
if (item != null) {
|
|
addApplication(ApplicationRecord.createFromServer(item.application));
|
|
const bot = item.application.bot;
|
|
if (bot != null) {
|
|
handleAppWithBot({
|
|
userId: bot.id,
|
|
applicationId: item.application.id
|
|
});
|
|
}
|
|
}
|
|
}
|
|
},
|
|
LOAD_NOTIFICATION_CENTER_ITEMS_SUCCESS: function handleNotificationCenterItemsSuccess(a0) {
|
|
a0.items.forEach((item) => {
|
|
if (item.application != null) {
|
|
addApplication(ApplicationRecord.createFromServer(item.application));
|
|
}
|
|
});
|
|
},
|
|
OAUTH2_TOKEN_CREATE: function handleOAuth2TokenCreate(a0) {
|
|
addApplication(ApplicationRecord.createFromServer(a0.application));
|
|
},
|
|
WISHLIST_FETCH_SUCCESS: handleWishlistAction,
|
|
WISHLIST_ADD_SKU_SUCCESS: handleWishlistAction,
|
|
WISHLIST_REMOVE_SKU_SUCCESS: handleWishlistAction,
|
|
SOCIAL_LAYER_STOREFRONT_LOAD_SUCCESS: function handleSocialLayerStorefrontLoadSuccess(a0) {
|
|
const application = a0.storefront.application;
|
|
if (application == null) {
|
|
return false;
|
|
}
|
|
addApplication(application);
|
|
},
|
|
WISHLIST_RECOMMENDATIONS_FETCH_SUCCESS: function handleWishlistRecommendationsFetchSuccess(a0) {
|
|
const applications = a0.data.applications;
|
|
if (applications != null && applications.length !== 0) {
|
|
for (const item of applications) {
|
|
addApplication(item);
|
|
}
|
|
return void 0;
|
|
}
|
|
return false;
|
|
},
|
|
APPLICATION_WIDGET_CONFIG_FEATURED_FETCH_SUCCESS: handleApplicationWidgetConfigFetchSuccess,
|
|
APPLICATION_WIDGET_CONFIG_DEVELOPER_FETCH_SUCCESS: handleApplicationWidgetConfigFetchSuccess,
|
|
APPLICATION_WIDGET_CONFIG_FETCH_SUCCESS: handleApplicationWidgetConfigFetchSuccess
|
|
});
|
|
export default applicationStore;
|