195 lines
7.1 KiB
TypeScript
195 lines
7.1 KiB
TypeScript
// Metro module 12758 (f12759).
|
|
import { SEARCH_RESULTS_CATEGORY_PREFIX, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, SEARCH_RESULTS_QUERY_PREFIX } from "./GlobalDiscoveryServersConstants";
|
|
import { APIError } from "../../errors/index";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c8790_5 = new Map();
|
|
let c8790_6 = new Map();
|
|
class SearchState {
|
|
constructor({ query }) {
|
|
const r5 = {
|
|
__proto__: new.target.prototype,
|
|
guildIds: [],
|
|
error: null,
|
|
offset: null,
|
|
total: null,
|
|
isFetching: false,
|
|
isInitialFetchComplete: false,
|
|
lastFetchTimestamp: null
|
|
};
|
|
r5.query = query;
|
|
return r5;
|
|
}
|
|
handleSearchStart() {
|
|
this.error = null;
|
|
this.isFetching = true;
|
|
}
|
|
handleSearchFailure(a0) {
|
|
this.isFetching = false;
|
|
this.isInitialFetchComplete = true;
|
|
this.error = new APIError(a0);
|
|
}
|
|
handleSearchSuccess({ total, guilds }) {
|
|
this.error = null;
|
|
this.isFetching = false;
|
|
this.isInitialFetchComplete = true;
|
|
this.lastFetchTimestamp = Date.now();
|
|
if (total != null) {
|
|
this.total = total;
|
|
}
|
|
const guildIds = [...this.guildIds];
|
|
let c20196_0 = guildIds;
|
|
guilds.forEach((guild) => c20196_0.push(guild.id));
|
|
this.guildIds = guildIds;
|
|
this.offset = guildIds.length;
|
|
}
|
|
}
|
|
class GlobalDiscoveryServersSearchResultsStore extends Module589.Store {
|
|
static displayName = "GlobalDiscoveryServersSearchResultsStore";
|
|
getGuild(a0) {
|
|
return c8790_6.get(a0);
|
|
}
|
|
getGuildIds(a0) {
|
|
const r15 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
return r15 != null ? r15.guildIds : null;
|
|
}
|
|
getIsFetching(a0) {
|
|
const r15 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
return r15 != null ? r15.isFetching : null;
|
|
}
|
|
getIsInitialFetchComplete(a0) {
|
|
const r15 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
return r15 != null ? r15.isInitialFetchComplete : null;
|
|
}
|
|
getOffset(a0) {
|
|
const r15 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
return r15 != null ? r15.offset : null;
|
|
}
|
|
getTotal(a0) {
|
|
const r15 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
return r15 != null ? r15.total : null;
|
|
}
|
|
getLastFetchTimestamp(a0) {
|
|
const r15 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
return r15 != null ? r15.lastFetchTimestamp : null;
|
|
}
|
|
getError(a0) {
|
|
const r15 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
return r15 != null ? r15.error : null;
|
|
}
|
|
getErrorMessage(a0) {
|
|
const r16 = c8790_5.get([SEARCH_RESULTS_QUERY_PREFIX, a0.query, SEARCH_RESULTS_CATEGORY_PREFIX, a0.categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, a0.languageCode].join("-"));
|
|
const r1 = r16 != null;
|
|
let r17 = null;
|
|
if (r1) {
|
|
const error = r16.error;
|
|
r17 = error == null ? void 0 : error.getAnyErrorMessage();
|
|
}
|
|
return r17;
|
|
}
|
|
}
|
|
const globalDiscoveryServersSearchResultsStore = new GlobalDiscoveryServersSearchResultsStore(Dispatcher, {
|
|
CONNECTION_OPEN: function handleConnectionOpen() {
|
|
c8790_5.clear();
|
|
c8790_6.clear();
|
|
},
|
|
GLOBAL_DISCOVERY_SERVERS_SEARCH_START: function handleGlobalDiscoveryServersSearchStart({ query, categoryId, languageCode, reset }) {
|
|
const r15 = [SEARCH_RESULTS_QUERY_PREFIX, query, SEARCH_RESULTS_CATEGORY_PREFIX, categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, languageCode].join("-");
|
|
if (reset) {
|
|
c8790_5.delete(r15);
|
|
}
|
|
const r21 = [SEARCH_RESULTS_QUERY_PREFIX, query, SEARCH_RESULTS_CATEGORY_PREFIX, categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, languageCode].join("-");
|
|
let r24 = c8790_5.get(r21);
|
|
if (r24 == null) {
|
|
const r30 = {
|
|
__proto__: SearchState.prototype,
|
|
guildIds: [],
|
|
error: null,
|
|
offset: null,
|
|
total: null,
|
|
isFetching: false,
|
|
isInitialFetchComplete: false,
|
|
lastFetchTimestamp: null
|
|
};
|
|
r30.query = query;
|
|
r24 = r30;
|
|
}
|
|
c8790_5.set(r21, r24);
|
|
r24.handleSearchStart();
|
|
},
|
|
GLOBAL_DISCOVERY_SERVERS_SEARCH_SUCCESS: function handleGlobalDiscoveryServersSearchSuccess({ query, categoryId, languageCode, total, guilds }) {
|
|
const r17 = [SEARCH_RESULTS_QUERY_PREFIX, query, SEARCH_RESULTS_CATEGORY_PREFIX, categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, languageCode].join("-");
|
|
let r20 = c8790_5.get(r17);
|
|
if (r20 == null) {
|
|
const r25 = {
|
|
__proto__: SearchState.prototype,
|
|
guildIds: [],
|
|
error: null,
|
|
offset: null,
|
|
total: null,
|
|
isFetching: false,
|
|
isInitialFetchComplete: false,
|
|
lastFetchTimestamp: null
|
|
};
|
|
r25.query = query;
|
|
r20 = r25;
|
|
}
|
|
c8790_5.set(r17, r20);
|
|
r20.handleSearchSuccess({
|
|
total,
|
|
guilds
|
|
});
|
|
guilds.forEach((guild) => {
|
|
c8790_6.set(guild.id, guild);
|
|
});
|
|
},
|
|
GLOBAL_DISCOVERY_SERVERS_SEARCH_FAILURE: function handleGlobalDiscoveryServersSearchFailure({ query, categoryId, languageCode, error }) {
|
|
const r15 = [SEARCH_RESULTS_QUERY_PREFIX, query, SEARCH_RESULTS_CATEGORY_PREFIX, categoryId, SEARCH_RESULTS_LANGUAGE_CODE_PREFIX, languageCode].join("-");
|
|
let r18 = c8790_5.get(r15);
|
|
if (r18 == null) {
|
|
const r24 = {
|
|
__proto__: SearchState.prototype,
|
|
guildIds: [],
|
|
error: null,
|
|
offset: null,
|
|
total: null,
|
|
isFetching: false,
|
|
isInitialFetchComplete: false,
|
|
lastFetchTimestamp: null
|
|
};
|
|
r24.query = query;
|
|
r18 = r24;
|
|
}
|
|
c8790_5.set(r15, r18);
|
|
r18.handleSearchFailure(error);
|
|
},
|
|
GLOBAL_DISCOVERY_SERVERS_SEARCH_CLEAR: function handleGlobalDiscoveryServersSearchClear({ ignoreQueries }) {
|
|
let c20197_0 = new Set(ignoreQueries);
|
|
c8790_5.forEach((item, index) => {
|
|
if (item.query != null && !c20197_0.has(item.query)) {
|
|
c8790_5.delete(index);
|
|
}
|
|
});
|
|
},
|
|
GUILD_PROFILE_FETCH_SUCCESS: function handleGuildProfileFetchSuccess({ guildId, profile }) {
|
|
const r6 = c8790_6.get(guildId);
|
|
if (r6 == null) {
|
|
return false;
|
|
}
|
|
let memberCount = profile.memberCount;
|
|
if (memberCount == null) {
|
|
memberCount = r6.memberCount;
|
|
}
|
|
let onlineCount = profile.onlineCount;
|
|
if (onlineCount == null) {
|
|
onlineCount = r6.presenceCount;
|
|
}
|
|
c8790_6.set(guildId, {
|
|
...r6,
|
|
memberCount,
|
|
presenceCount: onlineCount
|
|
});
|
|
}
|
|
});
|
|
export default globalDiscoveryServersSearchResultsStore;
|