From 90ab5606203f4e4b3501c6740ee5a108dc8a4b93 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Fri, 18 Jul 2025 15:36:10 -0700 Subject: [PATCH] chore(webui): don't refresh inventory for sell on the tab that issued it (#2506) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2506 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/controllers/api/sellController.ts | 4 ++-- src/controllers/custom/configController.ts | 4 ++-- src/services/wsService.ts | 14 ++++++++++---- static/webui/script.js | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/controllers/api/sellController.ts b/src/controllers/api/sellController.ts index c82d3b6b..0dd52bf6 100644 --- a/src/controllers/api/sellController.ts +++ b/src/controllers/api/sellController.ts @@ -15,7 +15,7 @@ import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes"; import { ExportDojoRecipes } from "warframe-public-export-plus"; import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; -import { sendWsBroadcastTo } from "@/src/services/wsService"; +import { sendWsBroadcastEx } from "@/src/services/wsService"; export const sellController: RequestHandler = async (req, res) => { const payload = JSON.parse(String(req.body)) as ISellRequest; @@ -295,7 +295,7 @@ export const sellController: RequestHandler = async (req, res) => { res.json({ inventoryChanges: inventoryChanges // "inventoryChanges" for this response instead of the usual "InventoryChanges" }); - sendWsBroadcastTo(accountId, { update_inventory: true }); + sendWsBroadcastEx({ update_inventory: true }, accountId, parseInt(String(req.query.wsid))); }; interface ISellRequest { diff --git a/src/controllers/custom/configController.ts b/src/controllers/custom/configController.ts index 2a1aca25..fa1b4a2c 100644 --- a/src/controllers/custom/configController.ts +++ b/src/controllers/custom/configController.ts @@ -2,7 +2,7 @@ import { RequestHandler } from "express"; import { config, syncConfigWithDatabase } from "@/src/services/configService"; import { getAccountForRequest, isAdministrator } from "@/src/services/loginService"; import { saveConfig } from "@/src/services/configWriterService"; -import { sendWsBroadcastExcept } from "@/src/services/wsService"; +import { sendWsBroadcastEx } from "@/src/services/wsService"; export const getConfigController: RequestHandler = async (req, res) => { const account = await getAccountForRequest(req); @@ -25,7 +25,7 @@ export const setConfigController: RequestHandler = async (req, res) => { const [obj, idx] = configIdToIndexable(id); obj[idx] = value; } - sendWsBroadcastExcept(parseInt(String(req.query.wsid)), { config_reloaded: true }); + sendWsBroadcastEx({ config_reloaded: true }, undefined, parseInt(String(req.query.wsid))); syncConfigWithDatabase(); await saveConfig(); res.end(); diff --git a/src/services/wsService.ts b/src/services/wsService.ts index 209b1bc9..1b49ae3e 100644 --- a/src/services/wsService.ts +++ b/src/services/wsService.ts @@ -43,7 +43,7 @@ export const stopWsServers = (promises: Promise[]): void => { let lastWsid: number = 0; interface IWsCustomData extends ws { - id?: number; + id: number; accountId?: string; } @@ -181,18 +181,24 @@ export const sendWsBroadcastTo = (accountId: string, data: IWsMsgToClient): void } }; -export const sendWsBroadcastExcept = (wsid: number | undefined, data: IWsMsgToClient): void => { +export const sendWsBroadcastEx = (data: IWsMsgToClient, accountId?: string, excludeWsid?: number): void => { const msg = JSON.stringify(data); if (wsServer) { for (const client of wsServer.clients) { - if ((client as IWsCustomData).id != wsid) { + if ( + (!accountId || (client as IWsCustomData).accountId == accountId) && + (client as IWsCustomData).id != excludeWsid + ) { client.send(msg); } } } if (wssServer) { for (const client of wssServer.clients) { - if ((client as IWsCustomData).id != wsid) { + if ( + (!accountId || (client as IWsCustomData).accountId == accountId) && + (client as IWsCustomData).id != excludeWsid + ) { client.send(msg); } } diff --git a/static/webui/script.js b/static/webui/script.js index 530c88fd..6ab0fe65 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -1746,7 +1746,7 @@ function disposeOfGear(category, oid) { ]; revalidateAuthz().then(() => { $.post({ - url: "/api/sell.php?" + window.authz, + url: "/api/sell.php?" + window.authz + "&wsid=" + wsid, contentType: "text/plain", data: JSON.stringify(data) }); @@ -1768,7 +1768,7 @@ function disposeOfItems(category, type, count) { ]; revalidateAuthz().then(() => { $.post({ - url: "/api/sell.php?" + window.authz, + url: "/api/sell.php?" + window.authz + "&wsid=" + wsid, contentType: "text/plain", data: JSON.stringify(data) }); @@ -2202,7 +2202,7 @@ function doRemoveUnrankedMods() { req.done(inventory => { window.itemListPromise.then(itemMap => { $.post({ - url: "/api/sell.php?" + window.authz, + url: "/api/sell.php?" + window.authz + "&wsid=" + wsid, contentType: "text/plain", data: JSON.stringify({ SellCurrency: "SC_RegularCredits",