113 lines
4.8 KiB
TypeScript
113 lines
4.8 KiB
TypeScript
// Metro module 16653 (f16654).
|
|
import QuestStore from "../QuestStore";
|
|
import Durations from "../../../utils/Durations";
|
|
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
|
|
import { getIsEligibleForQuests } from "../lib/QuestsEligibility";
|
|
import SentryUtils_native from "../../../utils/SentryUtils.native";
|
|
import { fetchQuestHomeHero, fetchCurrentQuests, fetchQuestToDeliver } from "../QuestActionCreators";
|
|
import { isMac } from "../../../utils/PlatformUtils";
|
|
import DiscordAppState_native from "../../app_state/DiscordAppState.native";
|
|
import NewAdRequestBehaviorExperiment from "../experiments/NewAdRequestBehaviorExperiment";
|
|
import { AdPlacement } from "../QuestTypes";
|
|
import { getQuestFetchReconnectJitterConfig, DEFAULT_QUEST_FETCH_JITTER_CONFIG } from "../experiments/QuestFetchReconnectJitterExperiment";
|
|
const DAY = Durations.Millis.DAY;
|
|
let c11991_5 = 30 * Durations.Millis.MINUTE;
|
|
let c11991_6 = 5 * Durations.Millis.MINUTE;
|
|
Durations.Millis.HOUR;
|
|
let c11991_7 = 5 * Durations.Millis.MINUTE;
|
|
class QuestFetchManager extends AutomaticLifecycleManager {
|
|
instantiatedAt = Date.now();
|
|
initialFetchTimerId = null;
|
|
initialQuestHomeHeroFetchTimerId = null;
|
|
recurringFetchTimerId = null;
|
|
lastFetchAttemptedAt = 0;
|
|
lastFetchedQuestForLocaleChangeAt = 0;
|
|
hasHandledConnectionOpen = false;
|
|
handleQuestsFetchCurrentQuestsBegin = () => {
|
|
this.lastFetchAttemptedAt = Date.now();
|
|
};
|
|
handlePostConnectionOpen = () => {
|
|
const r6 = window;
|
|
r6.clearTimeout(this.initialFetchTimerId);
|
|
window.clearTimeout(this.initialQuestHomeHeroFetchTimerId);
|
|
window.clearTimeout(this.recurringFetchTimerId);
|
|
this.recurringFetchTimerId = window.setInterval(() => {
|
|
const r5 = Date.now();
|
|
if (r5 - this.lastFetchAttemptedAt > DAY) {
|
|
this._fetch("post_connect_recurring");
|
|
}
|
|
}, c11991_5);
|
|
const isEligibleForQuests = getIsEligibleForQuests();
|
|
const hasHandledConnectionOpen = this.hasHandledConnectionOpen;
|
|
this.hasHandledConnectionOpen = true;
|
|
const r35 = hasHandledConnectionOpen && isEligibleForQuests ? getQuestFetchReconnectJitterConfig({
|
|
location: "QuestFetchManager"
|
|
}) : DEFAULT_QUEST_FETCH_JITTER_CONFIG;
|
|
const { questFetchJitterMs, questHomeHeroJitterMs } = r35;
|
|
const r45 = Math.floor(Math.random() * questFetchJitterMs);
|
|
this.initialFetchTimerId = window.setTimeout(() => {
|
|
if (!(Date.now() - QuestStore.lastFetchedCurrentQuests <= c11991_7)) {
|
|
this._fetch("post_connect_initial");
|
|
}
|
|
}, r45);
|
|
if (isEligibleForQuests) {
|
|
this.initialQuestHomeHeroFetchTimerId = window.setTimeout(() => {
|
|
try {
|
|
fetchQuestHomeHero();
|
|
} catch ($e) {}
|
|
}, r45 + Math.floor(Math.random() * questHomeHeroJitterMs));
|
|
}
|
|
};
|
|
handleRunningGamesChange = () => {};
|
|
handleUserSettingsProtoUpdate = ({ partial, settings, wasSaved }) => {
|
|
if (!(!("localization" in settings.proto) || !partial || wasSaved || Date.now() - this.lastFetchedQuestForLocaleChangeAt <= c11991_6)) {
|
|
this.lastFetchedQuestForLocaleChangeAt = Date.now();
|
|
this._fetch("user_settings");
|
|
}
|
|
};
|
|
handleStartSession = () => {
|
|
this.hasHandledConnectionOpen = false;
|
|
};
|
|
handleLogout = () => {
|
|
const r6 = window;
|
|
r6.clearTimeout(this.initialFetchTimerId);
|
|
window.clearTimeout(this.initialQuestHomeHeroFetchTimerId);
|
|
window.clearTimeout(this.recurringFetchTimerId);
|
|
this.lastFetchAttemptedAt = 0;
|
|
this.lastFetchedQuestForLocaleChangeAt = 0;
|
|
this.hasHandledConnectionOpen = false;
|
|
};
|
|
actions = {
|
|
QUESTS_FETCH_CURRENT_QUESTS_BEGIN: this.handleQuestsFetchCurrentQuestsBegin,
|
|
POST_CONNECTION_OPEN: this.handlePostConnectionOpen,
|
|
RUNNING_GAMES_CHANGE: this.handleRunningGamesChange,
|
|
RUNNING_NON_GAMES_CHANGE: this.handleRunningGamesChange,
|
|
USER_SETTINGS_PROTO_UPDATE: this.handleUserSettingsProtoUpdate,
|
|
START_SESSION: this.handleStartSession,
|
|
LOGOUT: this.handleLogout
|
|
};
|
|
_fetch(a0) {
|
|
if (getIsEligibleForQuests() && !QuestStore.isFetchingCurrentQuests) {
|
|
SentryUtils_native.addBreadcrumb({
|
|
category: "quests.fetch",
|
|
message: "QuestFetchManager._fetch triggered",
|
|
data: {
|
|
callerSource: a0,
|
|
storeSize: QuestStore.quests.size,
|
|
lastFetchedCurrentQuests: QuestStore.lastFetchedCurrentQuests,
|
|
msSinceLastFetch: Date.now() - QuestStore.lastFetchedCurrentQuests,
|
|
isFetchingCurrentQuests: QuestStore.isFetchingCurrentQuests
|
|
}
|
|
});
|
|
fetchCurrentQuests();
|
|
if (!(isMac() && DiscordAppState_native.getState() !== "focused" || NewAdRequestBehaviorExperiment.getConfig({
|
|
location: "QuestFetchManager"
|
|
}).enableNewRequestBehavior)) {
|
|
fetchQuestToDeliver(AdPlacement.MOBILE_HOME_DOCK_AREA, a0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const questFetchManager = new QuestFetchManager();
|
|
export default questFetchManager;
|