From ce4d7ae026cd4bb978a350cd0db4b5d30f043442 Mon Sep 17 00:00:00 2001 From: Alexander Corn Date: Thu, 8 Sep 2016 19:23:15 -0400 Subject: [PATCH] Pull trade offer ID directly from listing page --- classes/CConfirmation.js | 15 +++++++++++++++ components/confirmations.js | 25 ++++++++----------------- index.js | 6 ++++++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/classes/CConfirmation.js b/classes/CConfirmation.js index c705823..a6b8fd1 100644 --- a/classes/CConfirmation.js +++ b/classes/CConfirmation.js @@ -1,17 +1,32 @@ +var SteamCommunity = require('../index.js'); + module.exports = CConfirmation; function CConfirmation(community, data) { Object.defineProperty(this, "_community", {"value": community}); this.id = data.id; + this.type = data.type; + this.creator = data.creator; this.key = data.key; this.title = data.title; this.receiving = data.receiving; this.time = data.time; this.icon = data.icon; + this.offerID = this.type == SteamCommunity.ConfirmationType.Trade ? this.creator : null; } CConfirmation.prototype.getOfferID = function(time, key, callback) { + if (this.type && this.creator) { + if (this.type != SteamCommunity.ConfirmationType.Trade) { + callback(new Error("Not a trade confirmation")); + return; + } + + callback(null, this.creator); + return; + } + this._community.getConfirmationOfferID(this.id, time, key, callback); }; diff --git a/components/confirmations.js b/components/confirmations.js index 87b09ca..6c16ea4 100644 --- a/components/confirmations.js +++ b/components/confirmations.js @@ -52,6 +52,8 @@ SteamCommunity.prototype.getConfirmations = function(time, key, callback) { var img = conf.find('.mobileconf_list_entry_icon img'); confs.push(new CConfirmation(self, { "id": conf.data('confid'), + "type": conf.data('type'), + "creator": conf.data('creator'), "key": conf.data('key'), "title": conf.find('.mobileconf_list_entry_description>div:nth-of-type(1)').text().trim(), "receiving": conf.find('.mobileconf_list_entry_description>div:nth-of-type(2)').text().trim(), @@ -294,24 +296,13 @@ SteamCommunity.prototype.checkConfirmations = function() { return; // No new ones } - // We have new confirmations! Grab a key to get details. - self._confirmationCheckerGetKey('details', function(err, key) { - newOnes.forEach(function(conf) { - self._knownConfirmations[conf.id] = conf; // Add it to our list of known confirmations - - if(err) { - self._confirmationQueue.push(conf); - } else { - // Get its offer ID, if we can - conf.getOfferID(key.time, key.key, function(err, offerID) { - conf.offerID = offerID ? offerID : null; - self._confirmationQueue.push(conf); - }); - } - }); - - resetTimer(); + // We have new confirmations! + newOnes.forEach(function(conf) { + self._knownConfirmations[conf.id] = conf; // Add it to our list of known confirmations + self._confirmationQueue.push(conf); }); + + resetTimer(); }); }); diff --git a/index.js b/index.js index af29e84..9dbcae5 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,12 @@ require('util').inherits(SteamCommunity, require('events').EventEmitter); module.exports = SteamCommunity; SteamCommunity.SteamID = SteamID; +SteamCommunity.ConfirmationType = { + // 1 is unknown, possibly "Invalid" + "Trade": 2, + "MarketListing": 3 + // 4 is opt-out or other like account confirmation? +}; function SteamCommunity(options) { options = options || {};