This commit is contained in:
janisslsm committed 2026-11-01 12:12:55 +02:00
1 parent 1781d25a15
commit 732c0ad767
33051 files changed
+2591613 -3019689

No files matched your search

@@ -0,0 +1,112 @@
// 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;
@@ -0,0 +1,486 @@
// Metro module 16655 (f16656).
import _slicedToArray from "../../../_bundle/_slicedToArray";
import ActionSheetStore from "../../action_sheet/native/ActionSheetStore";
import ChannelRTCStore from "../../calls/ChannelRTCStore";
import { getIsChannelDetailsSearchActive, useChannelDetailsStore } from "../../main_tabs_v2/native/sidebar/details/stores/ChannelDetailsStore";
import VoicePanelStore from "../../voice_panel/VoicePanelStore";
import { isTextChannel } from "../../../records/ChannelRecord";
import ChannelStore from "../../../stores/ChannelStore";
import SelectedChannelStore from "../../../stores/SelectedChannelStore";
import AlertStore from "../../../stores/native/AlertStore";
import AppStateStore from "../../../stores/native/AppStateStore";
import QuestStore from "../QuestStore";
import { MIN_QUEST_CONTENT_VISIBILITY_PERCENTAGE } from "../lib/analytics/ContentImpressionTrackerConstants";
import { MessageStates } from "../../../Constants";
import { getQuestLogger } from "../lib/getQuestLogger";
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
import LRUCache from "../../../_bundle/LRUCache";
import { CodedLinkType } from "../../coded_links/CodedLink";
import { QuestContent } from "../QuestTypes";
import { AdCreativeType } from "../../../_bundle/Module6013";
import { QuestContentImpression } from "../lib/analytics/ContentImpressionTracker";
import { isChannelFocused } from "../../panels/isChannelFocused.native";
import { getCurrentNavigationRouteName, getOpenModalKey } from "../../main_tabs_v2/helpers/NavigationRouteUtils.native";
import { AppStates } from "../../../ConstantsIOS";
import { ChannelTypes } from "../../../_bundle/Module692";
import { useAlertStore } from "../../../design/components/AlertModal/native/useAlertStore.native";
import { getQuestStatus } from "../lib/analytics/AnalyticsTypes";
import { getRootNavigationRef } from "../../main_tabs_v2/RootNavigationRef.native";
let questLogger, prototype, QuestMobileEmbedVisibilityManager;
const log = function log() {
Array.prototype.slice.call(arguments, 0);
let r8 = questLogger;
if (questLogger == null) {
r8 = getQuestLogger({
location: "QuestMobileEmbedVisibilityManager"
});
}
questLogger = r8;
};
const QuestMobileEmbedVisibilityManager2 = class QuestMobileEmbedVisibilityManager extends AutomaticLifecycleManager {
constructor() {
super(...arguments);
const _this = this;
this.impressionCache = new LRUCache({
max: 50
});
this.questStatuses = {};
this.chatChannelId = void 0;
this.previousChatChannelId = void 0;
this.channelsWithChatOpen = {};
this.handleVisibleMessagesChanged = ({ payload }) => {
const visibleMessages = payload.visibleMessages;
payload.source;
log();
const visibleEmbeds = [];
for (const item of visibleMessages) {
const { message, percentVisible, state } = item;
if (!(message.codedLinks.length <= 0 || [MessageStates.SENDING, MessageStates.SEND_FAILED].includes(state))) {
message.id;
message.content;
const r16 = Math;
log(r16.round(100 * percentVisible));
if (percentVisible > MIN_QUEST_CONTENT_VISIBILITY_PERCENTAGE) {
visibleEmbeds.push.apply(visibleEmbeds, [..._this.findQuestEmbedsInMessage(message)]);
}
}
}
_this.updateImpressionsForVisibleEmbeds({
visibleEmbeds
});
};
this.findQuestEmbedsInMessage = (a0) => {
const r0 = [];
let c28488_1 = r0;
let c28488_2 = new Set();
a0.codedLinks.forEach((codedLink, index) => {
if (codedLink.type === CodedLinkType.QUESTS_EMBED) {
const code = codedLink.code;
if (!c28488_2.has(code)) {
c28488_1.push({
questId: code,
questContentPosition: index,
messageId: a0.id,
channelId: a0.channel_id
});
c28488_2.add(code);
}
}
});
return r0;
};
this.updateImpressionsForVisibleEmbeds = ({ visibleEmbeds }) => {
for (const item of visibleEmbeds) {
const { questId, questContentPosition, messageId, channelId } = item;
const quest = QuestStore.getQuest(questId);
if (quest != null) {
const quest2 = quest;
_this.ensureImpression({
quest: quest2,
questContent: QuestContent.QUEST_EMBED_MOBILE,
triggeredByStatusChange: false,
questContentPosition,
channelId,
messageId,
questId: quest2.id,
isQuestEnrollmentBlocked: QuestStore.questEnrollmentBlockedUntil != null,
sourceQuestContent: QuestContent.QUEST_EMBED_MOBILE,
adCreativeType: AdCreativeType.QUEST
});
}
}
_this.stopMany({
visibleEmbeds,
shouldDeleteHiddenEmbeds: true
});
};
this.ensureImpression = ({ quest, ...rest }) => {
const cacheKey = _this.getCacheKey(rest);
const r9 = _this.impressionCache.get(cacheKey);
if (!(r9 != null && r9?.isRunning)) {
let r20 = r9;
if (r20 != null) {
r20 = r9.clone({
triggeredByStatusChange: rest.triggeredByStatusChange
});
}
if (r20 == null) {
r20 = new QuestContentImpression({
adContentIds: [quest.id],
...rest
});
}
if (_this.isChatViewable && !r20.isRunning) {
r20.start();
}
_this.impressionCache.set(cacheKey, r20);
}
};
this.stopOne = ({ key, shouldDelete }) => {
const r8 = _this.impressionCache.get(key);
let r11 = r8?.isRunning;
if (r11 == null) {
r11 = false;
}
if (r8 != null) {
r8.stop();
}
if (shouldDelete) {
log();
_this.impressionCache.del(key);
}
return r11;
};
this.stopMany = function stopMany(r1 = {
visibleEmbeds: [],
shouldDeleteHiddenEmbeds: false
}) {
const { visibleEmbeds = [], shouldDeleteHiddenEmbeds = false } = r1;
const set = new Set(visibleEmbeds.map((visibleEmbed) => _this.getCacheKey(visibleEmbed)));
for (const item of _this.impressionCache.keys()) {
const key = item;
if (!set.has(item)) {
_this.stopOne({
key,
shouldDelete: shouldDeleteHiddenEmbeds
});
}
}
};
this.getCacheKey = (a0) => a0.channelId + ":" + a0.messageId + ":" + a0.questId;
this.parseCacheKey = (a0) => {
const r8 = _slicedToArray(a0.split(":"), 3);
return {
channelId: r8[0],
messageId: r8[1],
questId: r8[2]
};
};
this.isOnChannelNavigationRoute = () => {
let r7 = isChannelFocused();
const currentNavigationRouteName = getCurrentNavigationRouteName();
if (r7) {
r7 = currentNavigationRouteName === "channel";
}
return r7;
};
this.isSearchShowing = () => _this.chatChannelId != null && getIsChannelDetailsSearchActive(_this.chatChannelId);
this.getIsChatViewable = () => {
if (_this.chatChannelId == null) {
log();
return false;
}
if (ActionSheetStore.isOpen()) {
log();
return false;
}
if (AppStateStore.getState() !== AppStates.ACTIVE) {
log();
return false;
}
const type = ChannelStore.getChannel(_this.chatChannelId)?.type;
const chatOpen = ChannelRTCStore.getChatOpen(_this.chatChannelId);
const r36 = type === ChannelTypes.GUILD_STAGE_VOICE && chatOpen;
const openModalKey = getOpenModalKey();
const r43 = `voice-channel-${_this.chatChannelId}`;
if (openModalKey != null && openModalKey !== r43) {
log();
return false;
}
if (_this.isSearchShowing()) {
log();
return false;
}
if (AlertStore.getAlert() == null && !(useAlertStore.getState().alerts.length > 0)) {
const r63 = type === ChannelTypes.GUILD_VOICE && chatOpen;
let r64 = type != null && isTextChannel(type);
const isAnyVoicePanelOpen = VoicePanelStore.getState().isAnyVoicePanelOpen();
const isOnChannelNavigationRoute2 = _this.isOnChannelNavigationRoute();
if (r64) {
r64 = isOnChannelNavigationRoute2;
}
if (r64) {
r64 = !isAnyVoicePanelOpen;
}
if (r64) {
r64 = !r36;
}
if (r64) {
r64 = !r63;
}
if (!r64) {
r64 = r36;
}
if (!r64) {
r64 = r63;
}
log(_this.chatChannelId);
return r64;
}
log();
return false;
};
this.updateImpressionsForChatBecameViewable = () => {
log();
for (const item of _this.impressionCache.keys()) {
const key = item;
const r38 = _this.impressionCache.get(item);
if (r38 != null) {
const channelId = _this.parseCacheKey(key).channelId;
if (r38.isRunning) {
log(_this.chatChannelId);
_this.stopOne({
key,
shouldDelete: false
});
}
if (channelId === _this.chatChannelId) {
log(_this.chatChannelId);
const r64 = r38.clone({
triggeredByStatusChange: false
});
r64.start();
_this.impressionCache.set(key, r64);
}
}
}
};
this.refreshImpressions = () => {
if (_this.isChatViewable) {
_this.updateImpressionsForChatBecameViewable();
} else {
log();
_this.stopMany();
}
};
this.checkChatViewable = () => {
const isChatViewable = _this.getIsChatViewable();
let r0 = isChatViewable !== _this.isChatViewable;
if (r0) {
log();
_this.isChatViewable = isChatViewable;
_this.refreshImpressions();
r0 = true;
}
return r0;
};
this.checkIsOnChannelNavigationRoute = () => {
const isOnChannelNavigationRoute2 = _this.isOnChannelNavigationRoute();
if (isOnChannelNavigationRoute2 !== _this.wasOnChannelNavigationRoute) {
log();
_this.checkChatViewable();
_this.wasOnChannelNavigationRoute = isOnChannelNavigationRoute2;
}
};
this.checkSearchShowing = () => {
const isSearchShowing2 = _this.isSearchShowing();
if (isSearchShowing2 !== _this.wasSearchShowing) {
log();
_this.checkChatViewable();
_this.wasSearchShowing = isSearchShowing2;
}
};
this.onChannelChanged = (a0) => {
_this.previousChatChannelId = _this.chatChannelId;
_this.chatChannelId = a0;
_this.previousChatChannelId;
log(_this.chatChannelId);
_this.stopMany({
shouldDeleteHiddenEmbeds: true
});
if (!_this.checkChatViewable()) {
_this.refreshImpressions();
}
};
this.checkOpenModalKey = () => {
const openModalKey = getOpenModalKey();
if (openModalKey !== _this.previouslyOpenModalKey) {
log(_this.previouslyOpenModalKey);
_this.checkChatViewable();
_this.previouslyOpenModalKey = openModalKey;
}
};
this.handleQuestStoreChanged = () => {
log();
const set = new Set(QuestStore.quests.keys());
for (const item of _this.impressionCache.keys()) {
const key = item;
const r49 = _this.parseCacheKey(item);
if (set.has(r49.questId)) {
const r57 = QuestStore.quests.get(r49.questId);
const r62 = _this.questStatuses[r49.questId];
const r64 = r57 != null ? getQuestStatus(r57) : null;
if (r64 !== r62) {
_this.questStatuses[r49.questId] = r64;
if (_this.isChatViewable) {
const r82 = _this.impressionCache.get(key);
if (r82?.isRunning === true) {
if (r57 != null) {
const r95 = r82.clone({
triggeredByStatusChange: true
});
r95.start();
_this.impressionCache.set(key, r95);
} else {
_this.stopOne({
key,
shouldDelete: true
});
}
}
}
}
}
}
};
this.handleSelectedChannelStoreChanged = () => {
log();
const channelId = SelectedChannelStore.getChannelId();
if (channelId !== _this.chatChannelId) {
const channel = ChannelStore.getChannel(_this.chatChannelId);
const r18 = channel?.type != null && [ChannelTypes.GUILD_STAGE_VOICE, ChannelTypes.GUILD_VOICE].includes(channel?.type);
if (!(_this.chatChannelId != null && r18)) {
log(_this.chatChannelId);
_this.onChannelChanged(channelId);
}
}
};
this.handleActionSheetStoreChanged = () => {
log();
const isOpen = ActionSheetStore.isOpen();
if (isOpen !== _this.wasActionSheetOpen) {
log();
_this.checkChatViewable();
_this.wasActionSheetOpen = isOpen;
}
};
this.handleAppStateStoreChanged = () => {
log();
const wasAppActive = AppStateStore.getState() === AppStates.ACTIVE;
if (_this.wasAppActive !== wasAppActive) {
log();
_this.checkChatViewable();
_this.wasAppActive = wasAppActive;
}
};
this.handleVoicePanelStoreChanged = () => {
log();
const isAnyVoicePanelOpen = VoicePanelStore.getState().isAnyVoicePanelOpen();
if (isAnyVoicePanelOpen !== _this.wasAnyVoicePanelOpen) {
log();
_this.checkChatViewable();
_this.wasAnyVoicePanelOpen = isAnyVoicePanelOpen;
}
};
this.handleChannelDetailsStoreChanged = () => {
_this.checkSearchShowing();
};
this.handleChannelRTCStoreChanged = () => {
log();
const allChatOpen = ChannelRTCStore.getAllChatOpen();
const r7 = Set;
const r36 = [...Object.keys(_this.channelsWithChatOpen), ...Object.keys(allChatOpen)];
for (const item of new r7(r36)) {
const channel = ChannelStore.getChannel(item);
if (channel?.type == null) {
continue;
}
if (![ChannelTypes.GUILD_STAGE_VOICE, ChannelTypes.GUILD_VOICE].includes(channel?.type)) {
continue;
}
let r76 = _this.channelsWithChatOpen[item];
if (r76 == null) {
r76 = false;
}
const r77 = r76;
let r79 = allChatOpen[item];
if (r79 == null) {
r79 = false;
}
const r80 = r79;
if (r77 !== r79) {
if (r80 && item !== _this.chatChannelId) {
_this.onChannelChanged(item);
break;
}
if (!r80) {
if (_this.previousChatChannelId !== _this.chatChannelId) {
_this.onChannelChanged(_this.previousChatChannelId);
break;
}
}
_this.checkChatViewable();
break;
}
}
_this.channelsWithChatOpen = {
...allChatOpen
};
};
this.handleNavigationStateChanged = () => {
log();
_this.checkIsOnChannelNavigationRoute();
_this.checkOpenModalKey();
};
this.handleAlertStoreChanged = () => {
const wasAlertOpen = AlertStore.getAlert() != null || useAlertStore.getState().alerts.length > 0;
if (wasAlertOpen !== _this.wasAlertOpen) {
log();
_this.checkChatViewable();
_this.wasAlertOpen = wasAlertOpen;
}
};
this.unsubscribeFromVoicePanelStore = () => {};
this.unsubscribeFromChannelDetailsStore = () => {};
this.unsubscribeFromAlertStore = () => {};
this.stores = new Map().set(QuestStore, this.handleQuestStoreChanged).set(SelectedChannelStore, this.handleSelectedChannelStoreChanged).set(ActionSheetStore, this.handleActionSheetStoreChanged).set(AppStateStore, this.handleAppStateStoreChanged).set(ChannelRTCStore, this.handleChannelRTCStoreChanged).set(AlertStore, this.handleAlertStoreChanged);
this.actions = {
QUESTS_VISIBLE_MOBILE_MESSAGES_CHANGED: this.handleVisibleMessagesChanged
};
}
_initialize() {
const rootNavigationRef = getRootNavigationRef();
if (rootNavigationRef != null) {
rootNavigationRef.addListener("state", this.handleNavigationStateChanged);
}
this.unsubscribeFromVoicePanelStore = VoicePanelStore.subscribe(this.handleVoicePanelStoreChanged);
this.unsubscribeFromChannelDetailsStore = useChannelDetailsStore.subscribe(this.handleChannelDetailsStoreChanged);
this.unsubscribeFromAlertStore = useAlertStore.subscribe(this.handleAlertStoreChanged);
Reflect.get(Object.getPrototypeOf(prototype), "_initialize", this).call(this);
}
_terminate() {
const rootNavigationRef = getRootNavigationRef();
if (rootNavigationRef != null) {
rootNavigationRef.removeListener("state", this.handleNavigationStateChanged);
}
this.unsubscribeFromVoicePanelStore();
this.unsubscribeFromChannelDetailsStore();
this.unsubscribeFromAlertStore();
Reflect.get(Object.getPrototypeOf(prototype), "_terminate", this).call(this);
}
};
const prototype2 = QuestMobileEmbedVisibilityManager2.prototype;
QuestMobileEmbedVisibilityManager = QuestMobileEmbedVisibilityManager2;
prototype = prototype2;
const questMobileEmbedVisibilityManager = new QuestMobileEmbedVisibilityManager();
export default questMobileEmbedVisibilityManager;
@@ -0,0 +1,383 @@
// Metro module 16727 (f16728).
import EmbeddedActivitiesStore from "../../activities/EmbeddedActivitiesStore";
import FramesStore from "../../frames/FramesStore";
import RunningGameStore_native from "../../game_detection/RunningGameStore.native";
import ApplicationStreamingStore from "../../../stores/ApplicationStreamingStore";
import DetectableGameStore from "../../../stores/DetectableGameStore";
import SortedVoiceStateStore from "../../../stores/views/SortedVoiceStateStore";
import QuestStore from "../QuestStore";
import UnenrolledActivityQuestStore from "../UnenrolledActivityQuestStore";
import { QuestsExperimentLocations, DISCORD_APPLICATION_ID } from "../QuestConstants";
import Durations from "../../../utils/Durations";
import { getQuestLogger } from "../lib/getQuestLogger";
import * as _QuestDataUtils from "../utils/QuestDataUtils";
import { getEligibleQuestsForApplicationId } from "../utils/QuestMatchingUtils";
import { QuestVariants } from "../../../_bundle/Module5034";
import { sendHeartbeat } from "../QuestActionCreators";
import { ROBLOX_APPLICATION_ID } from "../../roblox_subgame_detection/RobloxSubgameTypes";
import { isRobloxSubgame } from "../../roblox_subgame_detection/RobloxSubgameUtils";
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
import { FirstPartyQuestTaskTypes, FirstPartyQuestTaskTypesSets } from "../../../_bundle/Module5040";
import { getQuestTaskDetails, getDesktopApplicationIds, getStreamingApplicationId, getPlayActivityApplicationId } from "../utils/QuestTaskUtils";
import { encodeStreamKey } from "../../go_live/utils/StreamKeyUtils";
import { assertNever } from "../../../utils/GlobalUtils";
import { removeExecutablePathPrefix } from "../../game_detection/GameAnalyticsUtils";
import { isPlayAnyActivityQuest } from "../utils/QuestUtils";
function $mk118584($env) {
return (a0) => {
let r1 = a0 != null;
if (r1) {
r1 = a0.config.features.includes(QuestVariants.MANUAL_HEARTBEAT_INITIALIZATION);
}
return !r1;
};
}
let handleEmbeddedActivityLaunchSuccess, isQuestRobloxRelated, c12056_13, c12056_14, c12056_15, c12056_19;
let env12056 = {};
const isQuestProgressable = function isQuestProgressable(a0) {
const isQuestExpired = _QuestDataUtils.isQuestExpired(a0);
return (isQuestExpired ? !isQuestExpired : a0.userStatus != null) && a0.userStatus.enrolledAt != null && a0.userStatus.completedAt == null;
};
handleEmbeddedActivityLaunchSuccess = function handleEmbeddedActivityLaunchSuccess(a0) {
const autoEnroll = UnenrolledActivityQuestStore.getState().autoEnroll;
for (const item of getEligibleQuestsForApplicationId(QuestStore.quests, a0)) {
if (!autoEnroll) {
continue;
}
const features = item.config.features;
if (!features.includes(QuestVariants.MOBILE_ACTIVITY_QUEST)) {
continue;
}
return require(dependencyMap[16]).enrollInQuest(item.id, {
questContent: require(dependencyMap[17]).QuestContent.RUNNING_ACTIVITY,
questContentCTA: require(dependencyMap[18]).QuestContentCTA.START_QUEST,
sourceQuestContent: require(dependencyMap[17]).QuestContent.RUNNING_ACTIVITY
});
}
};
isQuestRobloxRelated = function isQuestRobloxRelated(a0, a1) {
return a1 != null && (a0.some((item) => item === ROBLOX_APPLICATION_ID) && isRobloxSubgame(a1));
};
c12056_13 = 1 * Durations.Millis.MINUTE;
c12056_14 = 1 * Durations.Millis.SECOND;
c12056_15 = getQuestLogger({
location: QuestsExperimentLocations.QUESTS_MANAGER
});
class QuestProgressManager extends AutomaticLifecycleManager {
constructor() {
let c23395_0, c23395_1;
super(...arguments);
const _this = this;
const heartbeats = {};
heartbeats[FirstPartyQuestTaskTypes.PLAY_ON_DESKTOP] = new Map();
heartbeats[FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP] = new Map();
heartbeats[FirstPartyQuestTaskTypes.PLAY_ACTIVITY] = new Map();
this.heartbeats = heartbeats;
this.calculateHeartbeatDurationMs = (a0) => {
const r7 = QuestStore.quests.get(a0);
if (r7 != null && r7.config != null && r7.userStatus != null) {
const questTaskDetails = getQuestTaskDetails(r7, FirstPartyQuestTaskTypesSets.DESKTOP);
const r33 = Math.max(0, (questTaskDetails.targetSeconds - questTaskDetails.progressSeconds) * Durations.Millis.SECOND);
let r34 = c12056_13;
if (r33 <= r34) {
r34 = r33 + c12056_14;
}
return r34;
}
return c12056_13;
};
this.initiateHeartbeat = (a0, a1, c28507_2) => {
let maybeSendHeartbeat2;
const questId = a0;
const r11 = _this.heartbeats[a1];
let c28507_3 = r11;
if (r11.has(a0)) {
c12056_15.log(`~ initiateHeartbeat -> Heartbeat already initiated for questId: ${a0}`);
} else {
maybeSendHeartbeat2 = () => {
const activelyProgressingQuests = _this.getActivelyProgressingQuests(a1);
if (activelyProgressingQuests.has(questId)) {
const r30 = activelyProgressingQuests.get(questId);
let applicationId = r30?.applicationId;
if (applicationId == null) {
applicationId = c28507_2?.applicationId;
}
const executableFingerprint = r30?.executableFingerprint;
let executablePath = r30?.executablePath;
if (executablePath == null) {
executablePath = c28507_2?.executablePath;
}
if (a1 === FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP) {
const currentUserActiveStream = ApplicationStreamingStore.getCurrentUserActiveStream();
if (currentUserActiveStream == null) {
c12056_15.log(`~ initiateHeartbeat -> Attempted to beat for stream quest but no active stream, terminating heartbeat for questId: ${questId}`);
_this.terminateHeartbeat(questId, a1);
return void 0;
}
const streamKey = encodeStreamKey(currentUserActiveStream);
c12056_15.log(`~ initiateHeartbeat -> Sending heartbeat for questId: ${questId}`);
sendHeartbeat({
questId,
streamKey,
applicationId,
executablePath,
executableFingerprint
});
} else {
c12056_15.log(`~ initiateHeartbeat -> Sending heartbeat for questId: ${questId}`);
sendHeartbeat({
questId,
applicationId,
executablePath,
executableFingerprint
});
}
c28507_3.set(questId, window.setTimeout(maybeSendHeartbeat2, _this.calculateHeartbeatDurationMs(questId)));
} else {
c12056_15.log(`~ initiateHeartbeat -> Quest ${questId} is no longer actively progressing, terminating heartbeat`);
_this.terminateHeartbeat(questId, a1);
}
};
c12056_15.log(`~ initiateHeartbeat -> Initiating heartbeat for Quest ${a0}`);
maybeSendHeartbeat2();
}
};
this.terminateHeartbeat = (a0, a1) => {
const r10 = _this.heartbeats[a1];
const r12 = r10.get(a0);
if (r12 != null) {
c12056_15.log(`~ terminateHeartbeat -> Terminating heartbeat for questId: ${a0}`);
window.clearTimeout(r12);
r10.delete(a0);
const r29 = QuestStore.quests.get(a0);
let r1 = r29 != null;
if (r1) {
const isQuestExpired = _QuestDataUtils.isQuestExpired(r29);
r1 = (isQuestExpired ? !isQuestExpired : r29.userStatus != null) && r29.userStatus.enrolledAt != null && r29.userStatus.completedAt == null;
}
if (r1) {
c12056_15.log(`~ terminateHeartbeat -> Sending terminal heartbeat for questId: ${a0}`);
sendHeartbeat({
questId: a0,
terminal: true
});
}
}
};
this.handleSendHeartbeatSuccess = ({ questId: questId3, userStatus }) => {
c12056_15.log(`~ handleSendHeartbeatSuccess -> Heartbeat succeeded for questId: ${questId3})`);
if (userStatus.completedAt != null) {
c12056_15.log(`~ handleSendHeartbeatSuccess -> Quest ${questId3} completed, terminating any heartbeats for it`);
for (const item of Object.keys(_this.heartbeats)) {
_this.terminateHeartbeat(questId3, item);
}
}
};
this.handleSendHeartbeatFailure = (a0) => {
c12056_15.log(`~ handleSendHeartbeatFailure -> Heartbeat failed for questId: ${a0.questId}`);
};
const actions = {
QUESTS_FETCH_CURRENT_QUESTS_SUCCESS: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ON_DESKTOP, FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP], "QUESTS_FETCH_CURRENT_QUESTS_SUCCESS"),
QUESTS_ENROLL_SUCCESS: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ON_DESKTOP, FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP, FirstPartyQuestTaskTypes.PLAY_ACTIVITY], "QUESTS_ENROLL_SUCCESS", (a0) => !(a0 != null && a0.config.features.includes(QuestVariants.MANUAL_HEARTBEAT_INITIALIZATION))),
QUESTS_SEND_HEARTBEAT_SUCCESS: this.handleSendHeartbeatSuccess,
QUESTS_SEND_HEARTBEAT_FAILURE: this.handleSendHeartbeatFailure,
QUESTS_PREVIEW_UPDATE_SUCCESS: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ON_DESKTOP, FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP, FirstPartyQuestTaskTypes.PLAY_ACTIVITY], "QUESTS_PREVIEW_UPDATE_SUCCESS"),
RUNNING_GAMES_CHANGE: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ON_DESKTOP], "RUNNING_GAMES_CHANGE"),
RUNNING_NON_GAMES_CHANGE: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ON_DESKTOP], "RUNNING_NON_GAMES_CHANGE"),
STREAM_START: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP], "STREAM_START"),
STREAM_CREATE: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP], "STREAM_CREATE"),
STREAM_CLOSE: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP], "STREAM_CLOSE"),
PASSIVE_UPDATE_V2: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP], "PASSIVE_UPDATE_V2"),
VOICE_STATE_UPDATES: () => _this.syncHeartbeats([FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP], "VOICE_STATE_UPDATES"),
EMBEDDED_ACTIVITY_LAUNCH_SUCCESS: (a0) => {
handleEmbeddedActivityLaunchSuccess(a0.applicationId);
},
FRAME_LAUNCH: null,
FRAME_STOP: null,
EMBEDDED_ACTIVITY_UPDATE_V2: null,
QUEST_APPLICATION_START_TIMER: null
};
c23395_0 = void 0;
c23395_1 = this;
c23395_0 = async (c31107_0) => {
let c31107_2;
let env31840;
c31107_2 = void 0;
const r9 = env31840 = {
$parent: env12056
};
let c31107_1 = r9;
env31840[0] = void 0;
env31840[0] = c31107_0.applicationId;
await void 0;
await (0, handleEmbeddedActivityLaunchSuccess)(env31840[0]);
c23395_1.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ACTIVITY], "FRAME_LAUNCH", $mk118584(env12056));
};
actions.FRAME_LAUNCH = function FRAME_LAUNCH(a0) {
return c23395_0.apply(this, arguments);
};
actions.FRAME_STOP = () => {
_this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ACTIVITY], "FRAME_STOP");
};
actions.EMBEDDED_ACTIVITY_UPDATE_V2 = () => {
_this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ACTIVITY], "EMBEDDED_ACTIVITY_UPDATE_V2", (a0) => !(a0 != null && a0.config.features.includes(QuestVariants.MANUAL_HEARTBEAT_INITIALIZATION)));
};
actions.QUEST_APPLICATION_START_TIMER = ({ questId: questId2 }) => {
_this.syncHeartbeats([FirstPartyQuestTaskTypes.PLAY_ACTIVITY], "QUEST_APPLICATION_START_TIMER", (a0) => a0 != null && a0.id === questId2 && (a0 != null && a0.config.features.includes(QuestVariants.MANUAL_HEARTBEAT_INITIALIZATION)));
};
this.actions = actions;
}
syncHeartbeats(a0, a1, a2) {}
getActivelyProgressingQuests(a0) {
if (FirstPartyQuestTaskTypes.PLAY_ON_DESKTOP === a0) {
return this.getActivelyProgressingPlayOnDesktopQuests();
}
if (FirstPartyQuestTaskTypes.STREAM_ON_DESKTOP === a0) {
return this.getActivelyProgressingStreamOnDesktopQuests();
}
if (FirstPartyQuestTaskTypes.PLAY_ACTIVITY === a0) {
return this.getActivelyProgressingActivityQuests();
}
assertNever(a0);
}
getActivelyProgressingPlayOnDesktopQuests() {
let r30;
const map = new Map();
let c23396_0 = map;
const runningGames = RunningGameStore_native.getRunningGames();
const runningNonGames = RunningGameStore_native.getRunningNonGames();
const quests = QuestStore.quests;
c12056_15.log("~ getActivelyProgressingPlayOnDesktopQuestIds -> Running games: ", runningGames, "Running non-games: ", runningNonGames);
const r41 = {};
let c23396_2 = r41;
let r43 = runningGames[Symbol.iterator]();
const next = r43.next;
while (true) {
const r47 = r43 === void 0 ? void 0 : (r30 = next.call(r43)).done ? r43 = void 0 : r30.value;
if (r43 === void 0) {
for (const item of runningNonGames) {
if (item.id != null) {
r41[item.id] = item;
}
}
const _loop = function _loop(a0) {
const r9 = c23396_2[a0];
const executablePath = removeExecutablePathPrefix(r9.exePath);
for (const item of quests.values()) {
const desktopApplicationIds = getDesktopApplicationIds(item);
if (isQuestProgressable(item) && desktopApplicationIds != null) {
const applicationId = desktopApplicationIds.find((desktopApplicationId) => desktopApplicationId === a0);
if (applicationId != null) {
c23396_0.set(item.id, {
applicationId,
executablePath,
executableFingerprint: r9.executableFingerprint
});
} else if (isQuestRobloxRelated(desktopApplicationIds, r9)) {
c23396_0.set(item.id, {
applicationId: require(dependencyMap[19]).ROBLOX_APPLICATION_ID,
executablePath,
executableFingerprint: r9.executableFingerprint
});
}
}
}
};
for (const item2 of Object.keys(r41)) {
_loop(item2);
}
c12056_15.log("~ getActivelyProgressingPlayOnDesktopQuestIds -> Actively progressing questIds: ", Array.from(map.keys()));
return map;
} else {
try {
if (!r47.isLauncher) {
if (r47.id == null) {
const overrideForGame = RunningGameStore_native.getOverrideForGame(r47);
if (r47.distributor == null && overrideForGame != null) {
continue;
}
const r62 = DetectableGameStore.findGame(r47);
if (r62?.id != null) {
r41[r62.id] = r47;
}
} else {
r41[r47.id] = r47;
}
}
} catch (r69) {
if (r43 !== void 0 && typeof r43.return === "function") {
try {
r43.return();
} catch {}
}
throw r69;
}
}
}
}
getActivelyProgressingStreamOnDesktopQuests() {
const map = new Map();
const currentUserActiveStream = ApplicationStreamingStore.getCurrentUserActiveStream();
if (currentUserActiveStream == null) {
return map;
}
if (SortedVoiceStateStore.countVoiceStatesForChannel(currentUserActiveStream.channelId) < 2) {
return map;
}
const streamerActiveStreamMetadata = ApplicationStreamingStore.getStreamerActiveStreamMetadata();
if (streamerActiveStreamMetadata == null) {
return map;
}
c12056_15.log("~ getActivelyProgressingStreamOnDesktopQuestIds -> Active stream metadata: ", streamerActiveStreamMetadata);
const id = streamerActiveStreamMetadata.id;
if (id == null) {
return map;
}
for (const item of QuestStore.quests.values()) {
const streamingApplicationId = getStreamingApplicationId(item);
if (isQuestProgressable(item) && streamingApplicationId != null && streamingApplicationId === id) {
map.set(item.id, {
applicationId: id
});
}
}
c12056_15.log("~ getActivelyProgressingStreamOnDesktopQuestIds -> Actively progressing questIds: ", Array.from(map.keys()));
return map;
}
getActivelyProgressingActivityQuests() {
const map = new Map();
const selfEmbeddedActivities = EmbeddedActivitiesStore.getSelfEmbeddedActivities();
const connectedFrame = FramesStore.getConnectedFrame();
const set = new Set(selfEmbeddedActivities.keys());
if (connectedFrame != null) {
set.add(connectedFrame.applicationId);
}
c12056_15.log("~ getActivelyProgressingActivityQuestIds -> Running activity applicationIds: ", Array.from(set));
if (set.size === 0) {
return map;
}
for (const item2 of set) {
const applicationId = item2;
for (const item of QuestStore.quests.values()) {
const playActivityApplicationId = getPlayActivityApplicationId(item);
if (isQuestProgressable(item) && playActivityApplicationId != null && playActivityApplicationId === applicationId) {
map.set(item.id, {
applicationId
});
}
}
}
for (const item3 of QuestStore.quests.values()) {
if (isQuestProgressable(item3) && isPlayAnyActivityQuest(item3)) {
map.set(item3.id, {
applicationId: DISCORD_APPLICATION_ID
});
}
}
c12056_15.log("~ getActivelyProgressingActivityQuestIds -> Actively progressing questIds: ", Array.from(map.keys()));
return map;
}
}
c12056_19 = QuestProgressManager;
const r75 = new QuestProgressManager();
export default r75;