From a8e41c95e73a9b3e26d7390561dbc9ea3ef51870 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Mon, 29 Sep 2025 23:59:26 -0700 Subject: [PATCH] chore: move createNewEventMessages from inboxService to inboxController (#2828) This function wasn't used anywhere else and caused a recursive include in inboxService. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2828 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/controllers/api/inboxController.ts | 122 ++++++++++++++++++++++++- src/services/inboxService.ts | 120 +----------------------- 2 files changed, 120 insertions(+), 122 deletions(-) diff --git a/src/controllers/api/inboxController.ts b/src/controllers/api/inboxController.ts index 4f269794..d4308e65 100644 --- a/src/controllers/api/inboxController.ts +++ b/src/controllers/api/inboxController.ts @@ -1,13 +1,13 @@ -import type { RequestHandler } from "express"; +import type { Request, RequestHandler } from "express"; import { Inbox } from "../../models/inboxModel.ts"; import { createMessage, - createNewEventMessages, deleteAllMessagesRead, deleteAllMessagesReadNonCin, deleteMessageRead, getAllMessagesSorted, - getMessage + getMessage, + type IMessageCreationTemplate } from "../../services/inboxService.ts"; import { getAccountForRequest, getAccountFromSuffixedName, getSuffixedName } from "../../services/loginService.ts"; import { @@ -22,6 +22,9 @@ import { ExportFlavour } from "warframe-public-export-plus"; import { handleStoreItemAcquisition } from "../../services/purchaseService.ts"; import { fromStoreItem, isStoreItem } from "../../services/itemDataService.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) => { const { deleteId, lastMessage: latestClientMessageId, messageId } = req.query; @@ -135,6 +138,119 @@ export const inboxController: RequestHandler = async (req, res) => { } }; +const createNewEventMessages = async (req: Request): Promise => { + 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 => { + 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 => { + 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 => { + 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 => { + 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 const parseOid = (oid: string): string => { if (oid[0] == "{") { diff --git a/src/services/inboxService.ts b/src/services/inboxService.ts index c5d80fba..327afd9f 100644 --- a/src/services/inboxService.ts +++ b/src/services/inboxService.ts @@ -1,11 +1,6 @@ import type { IMessageDatabase } from "../models/inboxModel.ts"; import { Inbox } from "../models/inboxModel.ts"; -import { getAccountForRequest } from "./loginService.ts"; -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"; +import type { HydratedDocument, Types } from "mongoose"; export const getAllMessagesSorted = async (accountId: string): Promise[]> => { const inbox = await Inbox.find({ ownerId: accountId }).sort({ date: -1 }); @@ -33,119 +28,6 @@ export const deleteAllMessagesReadNonCin = async (accountId: string): Promise => { - 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 => { - 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 => { - 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 => { - 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 => { - 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 ( accountId: string | Types.ObjectId, messages: IMessageCreationTemplate[]