forked from OpenWF/SpaceNinjaServer
		
	chore(webui): don't refresh inventory for sell on the tab that issued it (#2506)
Reviewed-on: OpenWF/SpaceNinjaServer#2506 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									b0e80fcfa8
								
							
						
					
					
						commit
						90ab560620
					
				@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -43,7 +43,7 @@ export const stopWsServers = (promises: Promise<void>[]): 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);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -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",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user