Files
discord-decomp/modules/global_discovery_servers/GlobalDiscoveryServersFeaturedSearchManager.tsx
T
2026-11-01 12:12:55 +02:00

222 lines
7.5 KiB
TypeScript

// Metro module 16667 (f16668).
import GlobalDiscoveryServersSearchResultsStore from "./GlobalDiscoveryServersSearchResultsStore";
import { DISCOVERY_ALL_CATEGORIES_ID } from "./GlobalDiscoveryServersConstants";
import { Endpoints } from "../../Constants";
import AutomaticLifecycleManager from "../../lib/AutomaticLifecycleManager";
import { isStaleFeaturedGuilds, fromDiscoverableGuildServer } from "./GlobalDiscoveryServersUtils";
import Dispatcher from "../../Dispatcher";
import { HTTP, rejectWithMigratedError } from "../../_bundle/sendRequest";
import Module1464 from "../../_bundle/Module1464";
import { GlobalDiscoveryServersLimits } from "../../_bundle/Module16669";
import { trackGuildDiscoveryGetFeaturedGuildsFailed } from "../../utils/GuildDiscoveryUtils";
class GlobalDiscoveryServersFeaturedSearchManager extends AutomaticLifecycleManager {
constructor() {
let c23374_0, c23374_1;
let c23375_0, c23375_1;
super(...arguments);
const _this = this;
this.actions = {
POST_CONNECTION_OPEN: () => _this.handleConnectionOpen()
};
this.queue = new Set();
this.isFetchEnabled = false;
this.handleConnectionOpen = () => {
_this.isFetchEnabled = true;
_this.queue.forEach((item) => {
if (item === DISCOVERY_ALL_CATEGORIES_ID) {
_this.fetchFeaturedGuilds();
} else {
_this.fetchCategoryFeaturedGuilds({
categoryId: item
});
}
});
};
c23374_0 = void 0;
c23374_1 = this;
c23374_0 = async (c31096_0) => {
let forceRefresh, c31096_4;
let c31096_5 = 0;
let c31836_0, c31836_1, c31836_2, c31836_3;
L20: {
L10: {
try {
c31836_0 = void 0;
c31836_1 = void 0;
c31836_2 = void 0;
if (c23374_1.isFetchEnabled) {
forceRefresh = c31096_0?.forceRefresh;
if (forceRefresh == null) {
forceRefresh = false;
}
const lastFetchTimestamp = GlobalDiscoveryServersSearchResultsStore.getLastFetchTimestamp({
categoryId: DISCOVERY_ALL_CATEGORIES_ID
});
if (!forceRefresh && !isStaleFeaturedGuilds(lastFetchTimestamp)) {
break L10;
}
Dispatcher.dispatch({
type: "GLOBAL_DISCOVERY_SERVERS_SEARCH_START",
categoryId: DISCOVERY_ALL_CATEGORIES_ID,
reset: true
});
c31096_5 = 1;
c31836_0 = await HTTP.get({
url: Endpoints.GUILD_DISCOVERY,
query: Module1464.stringify({
offset: 0,
limit: GlobalDiscoveryServersLimits.FEATURED_DEFAULT_LIMIT
}),
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
c31836_1 = c31836_0.body.total;
c31836_2 = c31836_0.body.guilds.map(fromDiscoverableGuildServer);
Dispatcher.dispatch({
type: "GLOBAL_DISCOVERY_SERVERS_SEARCH_SUCCESS",
categoryId: DISCOVERY_ALL_CATEGORIES_ID,
guilds: c31836_2,
total: c31836_1
});
c31096_5 = 0;
break L20;
}
c23374_1.queue.add(DISCOVERY_ALL_CATEGORIES_ID);
} catch ($e) {
const r29 = $e;
let r7 = r29;
c31096_4 = r29;
if (c31096_5 !== 0) {
while (true) {
try {
const r136 = c31096_4;
c31096_5 = 0;
c31836_3 = r136;
Dispatcher.dispatch({
type: "GLOBAL_DISCOVERY_SERVERS_SEARCH_FAILURE",
categoryId: DISCOVERY_ALL_CATEGORIES_ID,
error: c31836_3
});
trackGuildDiscoveryGetFeaturedGuildsFailed({
categoryId: DISCOVERY_ALL_CATEGORIES_ID
});
break L20;
} catch (r132) {
r7 = r132;
c31096_4 = r132;
if (c31096_5 === 0) {
break;
}
}
}
}
throw r7;
}
}
return void 0;
}
};
this.fetchFeaturedGuilds = function() {
return c23374_0.apply(this, arguments);
};
c23375_0 = void 0;
c23375_1 = this;
c23375_0 = async (c31097_0) => {
let c31097_3;
let c31097_4 = 0;
let c31837_0, c31837_1, c31837_2, c31837_3, c31837_4, c31837_5, c31837_6;
L15: {
try {
c31837_0 = void 0;
c31837_1 = void 0;
c31837_0 = c31097_0.categoryId;
const forceRefresh2 = c31097_0.forceRefresh;
if (forceRefresh2 !== void 0) {
c31837_1 = forceRefresh2;
c31837_2 = void 0;
c31837_3 = void 0;
c31837_4 = void 0;
c31837_5 = void 0;
} else {
c31837_1 = false;
c31837_2 = void 0;
c31837_3 = void 0;
c31837_4 = void 0;
c31837_5 = void 0;
}
await void 0;
if (c23375_1.isFetchEnabled) {
c31837_2 = GlobalDiscoveryServersSearchResultsStore.getLastFetchTimestamp({
categoryId: c31837_0
});
if (!c31837_1) {
if (!isStaleFeaturedGuilds(c31837_2)) {
break L15;
}
}
Dispatcher.dispatch({
type: "GLOBAL_DISCOVERY_SERVERS_SEARCH_START",
categoryId: c31837_0,
reset: true
});
c31097_4 = 1;
c31837_3 = await HTTP.get({
url: Endpoints.GUILD_DISCOVERY,
query: Module1464.stringify({
categories: [c31837_0]
}),
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
c31837_4 = c31837_3.body.total;
c31837_5 = c31837_3.body.guilds.map(fromDiscoverableGuildServer);
Dispatcher.dispatch({
type: "GLOBAL_DISCOVERY_SERVERS_SEARCH_SUCCESS",
categoryId: c31837_0,
guilds: c31837_5,
total: c31837_4
});
c31097_4 = 0;
} else {
c23375_1.queue.add(c31837_0);
}
} catch ($e) {
const r30 = $e;
let r7 = r30;
c31097_3 = r30;
if (c31097_4 !== 0) {
while (true) {
try {
const r160 = c31097_3;
c31097_4 = 0;
c31837_6 = r160;
Dispatcher.dispatch({
type: "GLOBAL_DISCOVERY_SERVERS_SEARCH_FAILURE",
categoryId: c31837_0,
error: c31837_6
});
trackGuildDiscoveryGetFeaturedGuildsFailed({
categoryId: c31837_0
});
break L15;
} catch (r156) {
r7 = r156;
c31097_3 = r156;
if (c31097_4 === 0) {
break;
}
}
}
}
throw r7;
}
}
};
this.fetchCategoryFeaturedGuilds = function() {
return c23375_0.apply(this, arguments);
};
}
}
const globalDiscoveryServersFeaturedSearchManager = new GlobalDiscoveryServersFeaturedSearchManager();
export default globalDiscoveryServersFeaturedSearchManager;