From 4d4741b83c5a5e0e303ee2c3c66e7a47f815e137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximili=C3=A1n=20Maliar?= <12786043+arik123@users.noreply.github.com> Date: Wed, 7 Apr 2021 08:07:52 +0200 Subject: [PATCH] Remove deep equal --- lib/polling.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/polling.js b/lib/polling.js index dc3dc9a..1dd2ddc 100644 --- a/lib/polling.js +++ b/lib/polling.js @@ -4,7 +4,6 @@ const TradeOfferManager = require('./index.js'); const ETradeOfferState = TradeOfferManager.ETradeOfferState; const EOfferFilter = TradeOfferManager.EOfferFilter; const EConfirmationMethod = TradeOfferManager.EConfirmationMethod; -const deepEqual = require('deep-equal'); const minimumPollInterval = 1000; @@ -60,8 +59,6 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { return; } - var origPollData = JSON.parse(JSON.stringify(this.pollData)); // deep clone - /*if (fullUpdate) { // We can only purge stuff if this is a full update; otherwise, lack of an offer's presence doesn't mean Steam forgot about it var trackedIds = sent.map(offerId).concat(received.map(offerId)); // OfferIDs that are active in Steam's memory @@ -108,6 +105,8 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { }); }*/ + let changed = false; + var timestamps = this.pollData.timestamps || {}; var offers = this.pollData.sent || {}; var hasGlitchedOffer = false; @@ -132,8 +131,10 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { this.emit('unknownOfferSent', offer); offers[offer.id] = offer.state; timestamps[offer.id] = offer.created.getTime() / 1000; + changed = true; } } else if (offer.state != offers[offer.id]) { + changed = true; if (!offer.isGlitched()) { // We sent this offer, and it has now changed state if (offer.fromRealTimeTrade && offer.state == ETradeOfferState.Accepted) { @@ -162,6 +163,7 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { } if (cancelTime && (Date.now() - offer.updated.getTime() >= cancelTime)) { + changed = true; offer.cancel((err) => { if (!err) { this.emit('sentOfferCanceled', offer, 'cancelTime'); @@ -182,6 +184,7 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { } if (pendingCancelTime && (Date.now() - offer.created.getTime() >= pendingCancelTime)) { + changed = true; offer.cancel((err) => { if (!err) { this.emit('sentPendingOfferCanceled', offer); @@ -208,6 +211,7 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { // Make sure it's old enough if (Date.now() - oldest.updated.getTime() >= this.cancelOfferCountMinAge) { + changed = true; oldest.cancel((err) => { if (!err) { this.emit('sentOfferCanceled', oldest, 'cancelOfferCount'); @@ -225,7 +229,7 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { hasGlitchedOffer = true; return; } - + changed = true; if (offer.fromRealTimeTrade) { // This is a real-time trade offer if (!offers[offer.id] && (offer.state == ETradeOfferState.CreatedNeedsConfirmation || (offer.state == ETradeOfferState.Active && offer.confirmationMethod != EConfirmationMethod.None))) { @@ -264,7 +268,7 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { this.emit('pollSuccess'); // If something has changed, emit the event - if (!deepEqual(origPollData, this.pollData)) { + if (changed) { this.emit('pollData', this.pollData); }