Sfoglia il codice sorgente

[add] refactored live out of SlackData (context)

B Thibault 8 anni fa
parent
commit
589fae02d9
1 ha cambiato i file con 60 aggiunte e 0 eliminazioni
  1. 60 0
      srv/src/slackHistory.js

+ 60 - 0
srv/src/slackHistory.js

@@ -0,0 +1,60 @@
+
+/**
+ * @constructor
+**/
+function SlackHistory(target) {
+    this.id = target.id;
+    this.target = target;
+    this.v = 0;
+    this.messages = [];
+}
+
+SlackData.prototype.setHistory = function(target, data) {
+    if (!this.history[target.id])
+        this.history[target.id] = new SlackHistory(target);
+    this.history[target.id].update(data);
+};
+
+
+    /*
+    var fetchHistory = {}
+        ,doFetch = false;
+    for (var i in this.channels)
+        if (!this.history[i]) {
+            doFetch = true;
+            fetchHistory[i] = this.channels[i];
+        }
+    for (var i in this.users)
+        if (!this.history[this.users[i].ims.id]) {
+            doFetch = true;
+            fetchHistory[i] = this.users[i].ims.id;
+        }
+    //TODO fetch group history
+    if (!doFetch)
+        callback();
+    else for (var i in fetchHistory) {
+        var _this = this;
+        this.slack.fetchHistory(i, function(currentUpdated, data) {
+            if (data != null) {
+                _this.setHistory(fetchHistory[currentUpdated], data);
+                fetchHistory[currentUpdated] = null;
+                for (var i in fetchHistory) {
+                    if (fetchHistory[i])
+                        return;
+                }
+            }
+        });
+    }
+    */
+
+SlackHistory.prototype.update = function(messages) {
+    // TODO
+};
+
+SlackHistory.prototype.getUpdates = function(knownVersion) {
+    // TODO
+};
+
+
+module.exports.SlackHistory = SlackHistory;
+