Browse Source

[bugfix] removed useless duplicate add

B Thibault 8 years ago
parent
commit
ce124d619c
1 changed files with 5 additions and 12 deletions
  1. 5 12
      srv/src/slack.js

+ 5 - 12
srv/src/slack.js

@@ -148,17 +148,11 @@ Slack.prototype.onMessage = function(msg) {
     this.data.onMessage(msg);
     if (msg["channel"] && msg["type"] === "message") {
         var histo = this.history[msg["channel"]];
-        if (!histo) {
-            if (this.data.getChannel(msg["channel"])) {
-                this.fetchHistory(msg["channel"], ((histo) => {
-                    histo.push(msg);
-                    this.data.liveV = Math.max(this.data.liveV, parseFloat(msg["ts"]));
-                }).bind(this));
-            }
-        }
-        else {
+        if (histo) {
             histo.push(msg);
             this.data.liveV = Math.max(this.data.liveV, parseFloat(msg["ts"]));
+        } else if (this.data.getChannel(msg["channel"])) {
+            this.fetchHistory(msg["channel"]);
         }
     }
 };
@@ -203,7 +197,7 @@ Slack.getOauthToken = function(code, cb) {
     });
 };
 
-Slack.prototype.fetchHistory = function(targetId, callback) {
+Slack.prototype.fetchHistory = function(targetId) {
     var _this = this
         ,baseUrl = "";
 
@@ -227,8 +221,7 @@ Slack.prototype.fetchHistory = function(targetId, callback) {
                 history = _this.history[targetId] = new SlackHistory(targetId, HISTORY_LENGTH, resp.messages);
                 history.isNew = true;
             }
-            if (callback)
-                callback(history);
+            //TODO update this.data.liveV
         }
     });
 };