diff --git a/src/models/inboxModel.ts b/src/models/inboxModel.ts index be6b0cd5..ab5c8b9d 100644 --- a/src/models/inboxModel.ts +++ b/src/models/inboxModel.ts @@ -4,8 +4,12 @@ import { typeCountSchema } from "@/src/models/inventoryModels/inventoryModel"; import { IMongoDate, IOid, ITypeCount } from "@/src/types/commonTypes"; export interface IMessageClient - extends Omit { + extends Omit< + IMessageDatabase, + "_id" | "globaUpgradeId" | "date" | "startDate" | "endDate" | "ownerId" | "attVisualOnly" | "expiry" + > { _id?: IOid; + globaUpgradeId?: IOid; // [sic] date: IMongoDate; startDate?: IMongoDate; endDate?: IMongoDate; @@ -14,6 +18,7 @@ export interface IMessageClient export interface IMessageDatabase extends IMessage { ownerId: Types.ObjectId; + globaUpgradeId?: Types.ObjectId; // [sic] date: Date; //created at attVisualOnly?: boolean; _id: Types.ObjectId; @@ -101,6 +106,7 @@ const giftSchema = new Schema( const messageSchema = new Schema( { ownerId: Schema.Types.ObjectId, + globaUpgradeId: Schema.Types.ObjectId, sndr: String, msg: String, cinematic: String, @@ -154,6 +160,10 @@ messageSchema.set("toJSON", { delete returnedObject.attVisualOnly; delete returnedObject.expiry; + if (messageDatabase.globaUpgradeId) { + messageClient.globaUpgradeId = toOid(messageDatabase.globaUpgradeId); + } + messageClient.date = toMongoDate(messageDatabase.date); if (messageDatabase.startDate && messageDatabase.endDate) { diff --git a/src/services/configWatcherService.ts b/src/services/configWatcherService.ts index d2aec57a..599552f8 100644 --- a/src/services/configWatcherService.ts +++ b/src/services/configWatcherService.ts @@ -71,7 +71,17 @@ export const validateConfig = (): void => { export const syncConfigWithDatabase = (): void => { // Event messages are deleted after endDate. Since we don't use beginDate/endDate and instead have config toggles, we need to delete the messages once those bools are false. + // Also, for some reason, I can't just do `Inbox.deleteMany(...)`; - it needs this whole circus. + if (!config.worldState?.creditBoost) { + void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666672" }).then(() => {}); + } + if (!config.worldState?.affinityBoost) { + void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666673" }).then(() => {}); + } + if (!config.worldState?.resourceBoost) { + void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666674" }).then(() => {}); + } if (!config.worldState?.galleonOfGhouls) { - void Inbox.deleteMany({ goalTag: "GalleonRobbery" }).then(() => {}); // For some reason, I can't just do `Inbox.deleteMany(...)`; it needs this whole circus. + void Inbox.deleteMany({ goalTag: "GalleonRobbery" }).then(() => {}); } }; diff --git a/src/services/inboxService.ts b/src/services/inboxService.ts index 7129adf3..bd66857d 100644 --- a/src/services/inboxService.ts +++ b/src/services/inboxService.ts @@ -55,20 +55,77 @@ export const createNewEventMessages = async (req: Request): Promise => { } // 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. - if (config.worldState?.galleonOfGhouls) { - 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" - }); - } + 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;