// Metro module 13566 (f13567). import QuestStore from "../../../quests/QuestStore"; import { AnalyticEvents, RPCErrors, RPCCommands } from "../../../../Constants"; import { OAuth2Scopes } from "../../../../_bundle/Module8174"; import { validatePostMessageTransport, validateApplication } from "../../RPCHelpers"; import { getActivityApplicationId, getPlayActivityApplicationId } from "../../../quests/utils/QuestTaskUtils"; import RPCError from "../../RPCError"; import AnalyticsUtils from "../../../../utils/AnalyticsUtils"; import Dispatcher from "../../../../Dispatcher"; import { getEligibleQuestsForApplicationId } from "../../../quests/utils/QuestMatchingUtils"; const r19 = {}; r19[RPCCommands.GET_QUEST_ENROLLMENT_STATUS] = { scope: OAuth2Scopes.IDENTIFY, handler: (a0) => { const socket = a0.socket; const quest_id = a0.args.quest_id; validatePostMessageTransport(socket.transport); const r22 = validateApplication(socket.application); const quest = QuestStore.getQuest(quest_id); const activityApplicationId = getActivityApplicationId(quest); if (quest != null && activityApplicationId != null && activityApplicationId === r22) { const enrolledAt = quest.userStatus?.enrolledAt; let enrolled_at = quest.userStatus?.enrolledAt; if (enrolled_at == null) { enrolled_at = null; } return { quest_id, is_enrolled: enrolledAt != null, enrolled_at }; } throw new RPCError({ errorCode: RPCErrors.INVALID_COMMAND }, `Quest not found: ${quest_id}`); } }; r19[RPCCommands.QUEST_START_TIMER] = { scope: OAuth2Scopes.IDENTIFY, handler: (a0) => { const socket = a0.socket; const quest_id = a0.args.quest_id; validatePostMessageTransport(socket.transport); const application_id = validateApplication(socket.application); const quest = QuestStore.getQuest(quest_id); const playActivityApplicationId = getPlayActivityApplicationId(quest); if (quest != null && playActivityApplicationId != null && playActivityApplicationId === application_id) { if (quest.userStatus?.enrolledAt == null) { throw new RPCError({ errorCode: RPCErrors.INVALID_COMMAND }, "User is not enrolled in quest"); } AnalyticsUtils.track(AnalyticEvents.RPC_QUEST_START_TIMER_CALLED, { application_id, quest_id }); Dispatcher.dispatch({ type: "QUEST_APPLICATION_START_TIMER", questId: quest_id, applicationId: application_id }); return { success: true }; } throw new RPCError({ errorCode: RPCErrors.INVALID_COMMAND }, `Quest not found: ${quest_id}`); } }; r19[RPCCommands.GET_QUEST] = { scope: OAuth2Scopes.IDENTIFY, handler: ({ socket }) => { validatePostMessageTransport(socket.transport); const eligibleQuestsForApplicationId = getEligibleQuestsForApplicationId(QuestStore.quests, validateApplication(socket.application), true); if (eligibleQuestsForApplicationId.length === 0) { throw new RPCError({ errorCode: RPCErrors.INVALID_COMMAND }, "No eligible quests found"); } return eligibleQuestsForApplicationId.map((item) => { let enrolled_at = item.userStatus?.enrolledAt; if (enrolled_at == null) { enrolled_at = null; } let completed_at = item.userStatus?.completedAt; if (completed_at == null) { completed_at = null; } return { quest_id: item.id, enrolled_at, completed_at, external_cta_url: item.config.ctaConfig.link }; }).sort((a, b) => a.enrolled_at == null ? b.enrolled_at == null ? 0 : a.enrolled_at == null ? 1 : b.enrolled_at == null ? -1 : new Date(a.enrolled_at).getTime() - new Date(b.enrolled_at).getTime() : a.enrolled_at == null ? 1 : b.enrolled_at == null ? -1 : new Date(a.enrolled_at).getTime() - new Date(b.enrolled_at).getTime())[0]; } }; export default r19;