chore: move createNewEventMessages from inboxService to inboxController #2828
@ -1,13 +1,13 @@
|
|||||||
import type { RequestHandler } from "express";
|
import type { Request, RequestHandler } from "express";
|
||||||
import { Inbox } from "../../models/inboxModel.ts";
|
import { Inbox } from "../../models/inboxModel.ts";
|
||||||
import {
|
import {
|
||||||
createMessage,
|
createMessage,
|
||||||
createNewEventMessages,
|
|
||||||
deleteAllMessagesRead,
|
deleteAllMessagesRead,
|
||||||
deleteAllMessagesReadNonCin,
|
deleteAllMessagesReadNonCin,
|
||||||
deleteMessageRead,
|
deleteMessageRead,
|
||||||
getAllMessagesSorted,
|
getAllMessagesSorted,
|
||||||
getMessage
|
getMessage,
|
||||||
|
type IMessageCreationTemplate
|
||||||
} from "../../services/inboxService.ts";
|
} from "../../services/inboxService.ts";
|
||||||
import { getAccountForRequest, getAccountFromSuffixedName, getSuffixedName } from "../../services/loginService.ts";
|
import { getAccountForRequest, getAccountFromSuffixedName, getSuffixedName } from "../../services/loginService.ts";
|
||||||
import {
|
import {
|
||||||
@ -22,6 +22,9 @@ import { ExportFlavour } from "warframe-public-export-plus";
|
|||||||
import { handleStoreItemAcquisition } from "../../services/purchaseService.ts";
|
import { handleStoreItemAcquisition } from "../../services/purchaseService.ts";
|
||||||
import { fromStoreItem, isStoreItem } from "../../services/itemDataService.ts";
|
import { fromStoreItem, isStoreItem } from "../../services/itemDataService.ts";
|
||||||
import type { IOid } from "../../types/commonTypes.ts";
|
import type { IOid } from "../../types/commonTypes.ts";
|
||||||
|
import { unixTimesInMs } from "../../constants/timeConstants.ts";
|
||||||
|
import { config } from "../../services/configService.ts";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
export const inboxController: RequestHandler = async (req, res) => {
|
export const inboxController: RequestHandler = async (req, res) => {
|
||||||
const { deleteId, lastMessage: latestClientMessageId, messageId } = req.query;
|
const { deleteId, lastMessage: latestClientMessageId, messageId } = req.query;
|
||||||
@ -135,6 +138,119 @@ export const inboxController: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createNewEventMessages = async (req: Request): Promise<void> => {
|
||||||
|
const account = await getAccountForRequest(req);
|
||||||
|
const newEventMessages: IMessageCreationTemplate[] = [];
|
||||||
|
|
||||||
|
// Baro
|
||||||
|
const baroIndex = Math.trunc((Date.now() - 910800000) / (unixTimesInMs.day * 14));
|
||||||
|
const baroStart = baroIndex * (unixTimesInMs.day * 14) + 910800000;
|
||||||
|
const baroActualStart = baroStart + unixTimesInMs.day * (config.worldState?.baroAlwaysAvailable ? 0 : 12);
|
||||||
|
if (Date.now() >= baroActualStart && account.LatestEventMessageDate.getTime() < baroActualStart) {
|
||||||
|
newEventMessages.push({
|
||||||
|
sndr: "/Lotus/Language/G1Quests/VoidTraderName",
|
||||||
|
sub: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceTitle",
|
||||||
|
msg: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceMessage",
|
||||||
|
icon: "/Lotus/Interface/Icons/Npcs/BaroKiTeerPortrait.png",
|
||||||
|
startDate: new Date(baroActualStart),
|
||||||
|
endDate: new Date(baroStart + unixTimesInMs.day * 14),
|
||||||
|
CrossPlatform: true,
|
||||||
|
arg: [
|
||||||
|
{
|
||||||
|
Key: "NODE_NAME",
|
||||||
|
Tag: ["EarthHUB", "MercuryHUB", "SaturnHUB", "PlutoHUB"][baroIndex % 4]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
date: new Date(baroActualStart)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// BUG: Deleting the inbox message manually means it'll just be automatically re-created. This is because we don't use startDate/endDate for these config-toggled events.
|
||||||
|
const promises = [];
|
||||||
|
if (config.worldState?.creditBoost) {
|
||||||
|
promises.push(
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666672" }))) {
|
||||||
|
newEventMessages.push({
|
||||||
|
globaUpgradeId: new Types.ObjectId("5b23106f283a555109666672"),
|
||||||
|
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
||||||
|
sub: "/Lotus/Language/Items/EventDoubleCreditsName",
|
||||||
|
msg: "/Lotus/Language/Items/EventDoubleCreditsDesc",
|
||||||
|
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
||||||
|
startDate: new Date(),
|
||||||
|
CrossPlatform: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (config.worldState?.affinityBoost) {
|
||||||
|
promises.push(
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666673" }))) {
|
||||||
|
newEventMessages.push({
|
||||||
|
globaUpgradeId: new Types.ObjectId("5b23106f283a555109666673"),
|
||||||
|
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
||||||
|
sub: "/Lotus/Language/Items/EventDoubleAffinityName",
|
||||||
|
msg: "/Lotus/Language/Items/EventDoubleAffinityDesc",
|
||||||
|
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
||||||
|
startDate: new Date(),
|
||||||
|
CrossPlatform: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (config.worldState?.resourceBoost) {
|
||||||
|
promises.push(
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666674" }))) {
|
||||||
|
newEventMessages.push({
|
||||||
|
globaUpgradeId: new Types.ObjectId("5b23106f283a555109666674"),
|
||||||
|
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
||||||
|
sub: "/Lotus/Language/Items/EventDoubleResourceName",
|
||||||
|
msg: "/Lotus/Language/Items/EventDoubleResourceDesc",
|
||||||
|
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
||||||
|
startDate: new Date(),
|
||||||
|
CrossPlatform: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (config.worldState?.galleonOfGhouls) {
|
||||||
|
promises.push(
|
||||||
|
(async (): Promise<void> => {
|
||||||
|
if (!(await Inbox.exists({ ownerId: account._id, goalTag: "GalleonRobbery" }))) {
|
||||||
|
newEventMessages.push({
|
||||||
|
sndr: "/Lotus/Language/Bosses/BossCouncilorVayHek",
|
||||||
|
sub: "/Lotus/Language/Events/GalleonRobberyIntroMsgTitle",
|
||||||
|
msg: "/Lotus/Language/Events/GalleonRobberyIntroMsgDesc",
|
||||||
|
icon: "/Lotus/Interface/Icons/Npcs/VayHekPortrait.png",
|
||||||
|
transmission: "/Lotus/Sounds/Dialog/GalleonOfGhouls/DGhoulsWeekOneInbox0010VayHek",
|
||||||
|
att: ["/Lotus/Upgrades/Skins/Events/OgrisOldSchool"],
|
||||||
|
startDate: new Date(),
|
||||||
|
goalTag: "GalleonRobbery"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
if (newEventMessages.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await createMessage(account._id, newEventMessages);
|
||||||
|
|
||||||
|
const latestEventMessage = newEventMessages.reduce((prev, current) =>
|
||||||
|
prev.startDate! > current.startDate! ? prev : current
|
||||||
|
);
|
||||||
|
account.LatestEventMessageDate = new Date(latestEventMessage.startDate!);
|
||||||
|
await account.save();
|
||||||
|
};
|
||||||
|
|
||||||
// 33.6.0 has query arguments like lastMessage={"$oid":"68112baebf192e786d1502bb"} instead of lastMessage=68112baebf192e786d1502bb
|
// 33.6.0 has query arguments like lastMessage={"$oid":"68112baebf192e786d1502bb"} instead of lastMessage=68112baebf192e786d1502bb
|
||||||
const parseOid = (oid: string): string => {
|
const parseOid = (oid: string): string => {
|
||||||
if (oid[0] == "{") {
|
if (oid[0] == "{") {
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
import type { IMessageDatabase } from "../models/inboxModel.ts";
|
import type { IMessageDatabase } from "../models/inboxModel.ts";
|
||||||
import { Inbox } from "../models/inboxModel.ts";
|
import { Inbox } from "../models/inboxModel.ts";
|
||||||
import { getAccountForRequest } from "./loginService.ts";
|
import type { HydratedDocument, Types } from "mongoose";
|
||||||
import type { HydratedDocument } from "mongoose";
|
|
||||||
import { Types } from "mongoose";
|
|
||||||
import type { Request } from "express";
|
|
||||||
import { unixTimesInMs } from "../constants/timeConstants.ts";
|
|
||||||
import { config } from "./configService.ts";
|
|
||||||
|
|
||||||
export const getAllMessagesSorted = async (accountId: string): Promise<HydratedDocument<IMessageDatabase>[]> => {
|
export const getAllMessagesSorted = async (accountId: string): Promise<HydratedDocument<IMessageDatabase>[]> => {
|
||||||
const inbox = await Inbox.find({ ownerId: accountId }).sort({ date: -1 });
|
const inbox = await Inbox.find({ ownerId: accountId }).sort({ date: -1 });
|
||||||
@ -33,119 +28,6 @@ export const deleteAllMessagesReadNonCin = async (accountId: string): Promise<vo
|
|||||||
await Inbox.deleteMany({ ownerId: accountId, r: true, cinematic: null });
|
await Inbox.deleteMany({ ownerId: accountId, r: true, cinematic: null });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createNewEventMessages = async (req: Request): Promise<void> => {
|
|
||||||
const account = await getAccountForRequest(req);
|
|
||||||
const newEventMessages: IMessageCreationTemplate[] = [];
|
|
||||||
|
|
||||||
// Baro
|
|
||||||
const baroIndex = Math.trunc((Date.now() - 910800000) / (unixTimesInMs.day * 14));
|
|
||||||
const baroStart = baroIndex * (unixTimesInMs.day * 14) + 910800000;
|
|
||||||
const baroActualStart = baroStart + unixTimesInMs.day * (config.worldState?.baroAlwaysAvailable ? 0 : 12);
|
|
||||||
if (Date.now() >= baroActualStart && account.LatestEventMessageDate.getTime() < baroActualStart) {
|
|
||||||
newEventMessages.push({
|
|
||||||
sndr: "/Lotus/Language/G1Quests/VoidTraderName",
|
|
||||||
sub: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceTitle",
|
|
||||||
msg: "/Lotus/Language/CommunityMessages/VoidTraderAppearanceMessage",
|
|
||||||
icon: "/Lotus/Interface/Icons/Npcs/BaroKiTeerPortrait.png",
|
|
||||||
startDate: new Date(baroActualStart),
|
|
||||||
endDate: new Date(baroStart + unixTimesInMs.day * 14),
|
|
||||||
CrossPlatform: true,
|
|
||||||
arg: [
|
|
||||||
{
|
|
||||||
Key: "NODE_NAME",
|
|
||||||
Tag: ["EarthHUB", "MercuryHUB", "SaturnHUB", "PlutoHUB"][baroIndex % 4]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
date: new Date(baroActualStart)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// BUG: Deleting the inbox message manually means it'll just be automatically re-created. This is because we don't use startDate/endDate for these config-toggled events.
|
|
||||||
const promises = [];
|
|
||||||
if (config.worldState?.creditBoost) {
|
|
||||||
promises.push(
|
|
||||||
(async (): Promise<void> => {
|
|
||||||
if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666672" }))) {
|
|
||||||
newEventMessages.push({
|
|
||||||
globaUpgradeId: new Types.ObjectId("5b23106f283a555109666672"),
|
|
||||||
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
|
||||||
sub: "/Lotus/Language/Items/EventDoubleCreditsName",
|
|
||||||
msg: "/Lotus/Language/Items/EventDoubleCreditsDesc",
|
|
||||||
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
|
||||||
startDate: new Date(),
|
|
||||||
CrossPlatform: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (config.worldState?.affinityBoost) {
|
|
||||||
promises.push(
|
|
||||||
(async (): Promise<void> => {
|
|
||||||
if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666673" }))) {
|
|
||||||
newEventMessages.push({
|
|
||||||
globaUpgradeId: new Types.ObjectId("5b23106f283a555109666673"),
|
|
||||||
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
|
||||||
sub: "/Lotus/Language/Items/EventDoubleAffinityName",
|
|
||||||
msg: "/Lotus/Language/Items/EventDoubleAffinityDesc",
|
|
||||||
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
|
||||||
startDate: new Date(),
|
|
||||||
CrossPlatform: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (config.worldState?.resourceBoost) {
|
|
||||||
promises.push(
|
|
||||||
(async (): Promise<void> => {
|
|
||||||
if (!(await Inbox.exists({ ownerId: account._id, globaUpgradeId: "5b23106f283a555109666674" }))) {
|
|
||||||
newEventMessages.push({
|
|
||||||
globaUpgradeId: new Types.ObjectId("5b23106f283a555109666674"),
|
|
||||||
sndr: "/Lotus/Language/Menu/Mailbox_WarframeSender",
|
|
||||||
sub: "/Lotus/Language/Items/EventDoubleResourceName",
|
|
||||||
msg: "/Lotus/Language/Items/EventDoubleResourceDesc",
|
|
||||||
icon: "/Lotus/Interface/Icons/Npcs/Lotus_d.png",
|
|
||||||
startDate: new Date(),
|
|
||||||
CrossPlatform: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (config.worldState?.galleonOfGhouls) {
|
|
||||||
promises.push(
|
|
||||||
(async (): Promise<void> => {
|
|
||||||
if (!(await Inbox.exists({ ownerId: account._id, goalTag: "GalleonRobbery" }))) {
|
|
||||||
newEventMessages.push({
|
|
||||||
sndr: "/Lotus/Language/Bosses/BossCouncilorVayHek",
|
|
||||||
sub: "/Lotus/Language/Events/GalleonRobberyIntroMsgTitle",
|
|
||||||
msg: "/Lotus/Language/Events/GalleonRobberyIntroMsgDesc",
|
|
||||||
icon: "/Lotus/Interface/Icons/Npcs/VayHekPortrait.png",
|
|
||||||
transmission: "/Lotus/Sounds/Dialog/GalleonOfGhouls/DGhoulsWeekOneInbox0010VayHek",
|
|
||||||
att: ["/Lotus/Upgrades/Skins/Events/OgrisOldSchool"],
|
|
||||||
startDate: new Date(),
|
|
||||||
goalTag: "GalleonRobbery"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await Promise.all(promises);
|
|
||||||
|
|
||||||
if (newEventMessages.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await createMessage(account._id, newEventMessages);
|
|
||||||
|
|
||||||
const latestEventMessage = newEventMessages.reduce((prev, current) =>
|
|
||||||
prev.startDate! > current.startDate! ? prev : current
|
|
||||||
);
|
|
||||||
account.LatestEventMessageDate = new Date(latestEventMessage.startDate!);
|
|
||||||
await account.save();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createMessage = async (
|
export const createMessage = async (
|
||||||
accountId: string | Types.ObjectId,
|
accountId: string | Types.ObjectId,
|
||||||
messages: IMessageCreationTemplate[]
|
messages: IMessageCreationTemplate[]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user