// 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;