decord/source/modules/rpc/server/commands/quests.tsx

236 lines
8.6 KiB
TypeScript
Raw Normal View History

2026-08-24 06:08:38 +00:00
// Module ID: 13943
// Function ID: 13944
// Dependencies: [7491, 676, 4379, 8794, 7514, 8789, 698, 709, 10746, 2]
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
// Module 13943
import expandEventPropertiesDefault from "expandEventProperties" /* 698 */;
import dispatcherDefault from "dispatcher" /* 709 */;
import getApplicationIdsByTaskTypes from "getApplicationIdsByTaskTypes" /* 7514 */;
import prototypeDefault from "prototype" /* 8789 */;
import recurseReplaceContentTree from "recurseReplaceContentTree" /* 8794 */;
import questMatchesActivity from "questMatchesActivity" /* 10746 */;
import closure_3 from "initializeState" /* 7491 */;
import ME from "ME" /* 676 */;
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-29 08:29:29 +00:00
({ RPCCommands, RPCErrors: c4, AnalyticEvents: c5 } = ME);
2026-07-20 16:05:17 +00:00
let obj = {};
obj = {
2026-07-23 10:11:24 +00:00
scope: require("set").OAuth2Scopes.IDENTIFY,
2026-07-20 16:05:17 +00:00
handler(socket) {
socket = socket.socket;
const quest_id = socket.args.quest_id;
2026-08-24 06:08:38 +00:00
let obj = recurseReplaceContentTree;
2026-07-20 16:05:17 +00:00
const result = obj.validatePostMessageTransport(socket.transport);
2026-08-24 06:08:38 +00:00
const obj2 = recurseReplaceContentTree;
2026-07-20 16:05:17 +00:00
const quest = store.getQuest(quest_id);
2026-08-24 06:08:38 +00:00
const validateApplicationResult = recurseReplaceContentTree.validateApplication(socket.application);
const activityApplicationId = getApplicationIdsByTaskTypes.getActivityApplicationId(quest);
2026-07-20 16:05:17 +00:00
if (null != quest) {
if (null != activityApplicationId) {
if (activityApplicationId === validateApplicationResult) {
2026-07-29 08:29:29 +00:00
obj = { quest_id: null, is_enrolled: null, enrolled_at: null };
obj[0] = quest_id;
2026-07-20 16:05:17 +00:00
const userStatus = quest.userStatus;
let enrolledAt;
2026-07-29 08:29:29 +00:00
if (userStatus != null) {
2026-07-20 16:05:17 +00:00
enrolledAt = userStatus.enrolledAt;
}
2026-07-29 08:29:29 +00:00
obj[1] = null != enrolledAt;
2026-07-20 16:05:17 +00:00
const userStatus2 = quest.userStatus;
let enrolledAt1;
2026-07-29 08:29:29 +00:00
if (userStatus2 != null) {
2026-07-20 16:05:17 +00:00
enrolledAt1 = userStatus2.enrolledAt;
}
2026-07-29 08:29:29 +00:00
if (enrolledAt1 == null) {
enrolledAt1 = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[2] = enrolledAt1;
2026-07-20 16:05:17 +00:00
return obj;
}
}
}
obj = { errorCode: constants.INVALID_COMMAND };
2026-08-24 06:08:38 +00:00
let tmp8 = prototypeDefault;
2026-07-20 16:05:17 +00:00
tmp8 = new tmp8(obj, "Quest not found: " + quest_id);
throw tmp8;
}
};
obj[RPCCommands.GET_QUEST_ENROLLMENT_STATUS] = obj;
obj = {
2026-07-23 10:11:24 +00:00
scope: require("set").OAuth2Scopes.IDENTIFY,
2026-07-20 16:05:17 +00:00
handler(socket) {
socket = socket.socket;
const quest_id = socket.args.quest_id;
2026-08-24 06:08:38 +00:00
let obj = recurseReplaceContentTree;
2026-07-20 16:05:17 +00:00
const result = obj.validatePostMessageTransport(socket.transport);
2026-08-24 06:08:38 +00:00
obj1 = recurseReplaceContentTree;
2026-07-20 16:05:17 +00:00
const validateApplicationResult = obj1.validateApplication(socket.application);
const quest = store.getQuest(quest_id);
2026-08-24 06:08:38 +00:00
let obj2 = getApplicationIdsByTaskTypes;
2026-07-20 16:05:17 +00:00
const playActivityApplicationId = obj2.getPlayActivityApplicationId(quest);
if (null != quest) {
if (null != playActivityApplicationId) {
if (playActivityApplicationId === validateApplicationResult) {
const userStatus = quest.userStatus;
let enrolledAt;
2026-07-29 08:29:29 +00:00
if (userStatus != null) {
2026-07-20 16:05:17 +00:00
enrolledAt = userStatus.enrolledAt;
}
if (null == enrolledAt) {
2026-07-29 08:29:29 +00:00
obj = { errorCode: null };
obj[0] = constants.INVALID_COMMAND;
2026-08-24 06:08:38 +00:00
const tmp16 = new prototypeDefault(obj, "User is not enrolled in quest");
2026-07-29 08:29:29 +00:00
throw tmp16;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
obj = { application_id: null, quest_id: null };
obj[0] = validateApplicationResult;
obj[1] = quest_id;
2026-08-24 06:08:38 +00:00
expandEventPropertiesDefault.track(constants2.RPC_QUEST_START_TIMER_CALLED, obj);
const obj4 = expandEventPropertiesDefault;
2026-07-29 08:29:29 +00:00
obj1 = { type: "QUEST_APPLICATION_START_TIMER", questId: null, applicationId: null };
obj1[1] = quest_id;
obj1[2] = validateApplicationResult;
2026-08-24 06:08:38 +00:00
dispatcherDefault.dispatch(obj1);
2026-07-29 08:29:29 +00:00
return { success: true };
2026-07-20 16:05:17 +00:00
}
}
}
}
2026-07-29 08:29:29 +00:00
obj2 = { errorCode: constants.INVALID_COMMAND };
2026-08-24 06:08:38 +00:00
let tmp18 = prototypeDefault;
2026-07-29 08:29:29 +00:00
tmp18 = new tmp18(obj2, "Quest not found: " + quest_id);
throw tmp18;
2026-07-20 16:05:17 +00:00
}
};
obj[RPCCommands.QUEST_START_TIMER] = obj;
obj[RPCCommands.GET_QUEST] = {
2026-07-23 10:11:24 +00:00
scope: require("set").OAuth2Scopes.IDENTIFY,
2026-07-20 16:05:17 +00:00
handler(socket) {
socket = socket.socket;
2026-08-24 06:08:38 +00:00
let obj = recurseReplaceContentTree;
2026-07-20 16:05:17 +00:00
const result = obj.validatePostMessageTransport(socket.transport);
2026-08-24 06:08:38 +00:00
const obj2 = recurseReplaceContentTree;
const validateApplicationResult = recurseReplaceContentTree.validateApplication(socket.application);
const eligibleQuestsForApplicationId = questMatchesActivity.getEligibleQuestsForApplicationId(store.quests, validateApplicationResult, true);
2026-07-20 16:05:17 +00:00
if (0 === eligibleQuestsForApplicationId.length) {
2026-07-29 08:29:29 +00:00
obj = { errorCode: null };
obj[0] = constants.INVALID_COMMAND;
2026-08-24 06:08:38 +00:00
const tmp9 = new prototypeDefault(obj, "No eligible quests found");
2026-07-29 08:29:29 +00:00
throw tmp9;
2026-07-20 16:05:17 +00:00
} else {
const mapped = eligibleQuestsForApplicationId.map((id) => {
2026-07-29 08:29:29 +00:00
const obj = { quest_id: id.id, enrolled_at: null, completed_at: null, external_cta_url: null };
2026-07-20 16:05:17 +00:00
const userStatus = id.userStatus;
let enrolledAt;
2026-07-29 08:29:29 +00:00
if (userStatus != null) {
2026-07-20 16:05:17 +00:00
enrolledAt = userStatus.enrolledAt;
}
2026-07-29 08:29:29 +00:00
if (enrolledAt == null) {
enrolledAt = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[1] = enrolledAt;
2026-07-20 16:05:17 +00:00
const userStatus2 = id.userStatus;
let completedAt;
2026-07-29 08:29:29 +00:00
if (userStatus2 != null) {
2026-07-20 16:05:17 +00:00
completedAt = userStatus2.completedAt;
}
2026-07-29 08:29:29 +00:00
if (completedAt == null) {
completedAt = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[2] = completedAt;
obj[3] = id.config.ctaConfig.link;
2026-07-20 16:05:17 +00:00
return obj;
});
return mapped.sort((enrolled_at, enrolled_at2) => {
if (null != enrolled_at.enrolled_at) {
let num2 = 1;
if (null != enrolled_at.enrolled_at) {
let num3 = -1;
if (null != enrolled_at2.enrolled_at) {
const _Date = Date;
const date = new Date(enrolled_at.enrolled_at);
const _Date2 = Date;
const time = date.getTime();
const date1 = new Date(enrolled_at2.enrolled_at);
num3 = time - date1.getTime();
}
num2 = num3;
}
let num = num2;
} else {
num = 0;
}
return num;
})[0];
}
2026-08-24 06:08:38 +00:00
const obj3 = questMatchesActivity;
2026-07-20 16:05:17 +00:00
}
};
2026-07-23 10:11:24 +00:00
let obj1 = {
scope: require("set").OAuth2Scopes.IDENTIFY,
2026-07-20 16:05:17 +00:00
handler(socket) {
socket = socket.socket;
2026-08-24 06:08:38 +00:00
let obj = recurseReplaceContentTree;
2026-07-20 16:05:17 +00:00
const result = obj.validatePostMessageTransport(socket.transport);
2026-08-24 06:08:38 +00:00
const obj2 = recurseReplaceContentTree;
const validateApplicationResult = recurseReplaceContentTree.validateApplication(socket.application);
const eligibleQuestsForApplicationId = questMatchesActivity.getEligibleQuestsForApplicationId(store.quests, validateApplicationResult, true);
2026-07-20 16:05:17 +00:00
if (0 === eligibleQuestsForApplicationId.length) {
2026-07-29 08:29:29 +00:00
obj = { errorCode: null };
obj[0] = constants.INVALID_COMMAND;
2026-08-24 06:08:38 +00:00
const tmp9 = new prototypeDefault(obj, "No eligible quests found");
2026-07-29 08:29:29 +00:00
throw tmp9;
2026-07-20 16:05:17 +00:00
} else {
const mapped = eligibleQuestsForApplicationId.map((id) => {
2026-07-29 08:29:29 +00:00
const obj = { quest_id: id.id, enrolled_at: null, completed_at: null, external_cta_url: null };
2026-07-20 16:05:17 +00:00
const userStatus = id.userStatus;
let enrolledAt;
2026-07-29 08:29:29 +00:00
if (userStatus != null) {
2026-07-20 16:05:17 +00:00
enrolledAt = userStatus.enrolledAt;
}
2026-07-29 08:29:29 +00:00
if (enrolledAt == null) {
enrolledAt = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[1] = enrolledAt;
2026-07-20 16:05:17 +00:00
const userStatus2 = id.userStatus;
let completedAt;
2026-07-29 08:29:29 +00:00
if (userStatus2 != null) {
2026-07-20 16:05:17 +00:00
completedAt = userStatus2.completedAt;
}
2026-07-29 08:29:29 +00:00
if (completedAt == null) {
completedAt = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[2] = completedAt;
obj[3] = id.config.ctaConfig.link;
2026-07-20 16:05:17 +00:00
return obj;
});
return mapped.sort((enrolled_at, enrolled_at2) => {
if (null != enrolled_at.enrolled_at) {
let num2 = 1;
if (null != enrolled_at.enrolled_at) {
let num3 = -1;
if (null != enrolled_at2.enrolled_at) {
const _Date = Date;
const date = new Date(enrolled_at.enrolled_at);
const _Date2 = Date;
const time = date.getTime();
const date1 = new Date(enrolled_at2.enrolled_at);
num3 = time - date1.getTime();
}
num2 = num3;
}
let num = num2;
} else {
num = 0;
}
return num;
})[0];
}
2026-08-24 06:08:38 +00:00
const obj3 = questMatchesActivity;
2026-07-20 16:05:17 +00:00
}
};
2026-07-23 10:11:24 +00:00
let result = require("set").fileFinishedImporting("modules/rpc/server/commands/quests.tsx");
2026-07-20 16:05:17 +00:00
export default obj;