Browse Source

[wip] start prepending every id with team id in order to prepare multi-source

B Thibault 8 years ago
parent
commit
f83bfb8aa5
2 changed files with 21 additions and 21 deletions
  1. 17 17
      srv/src/slack.js
  2. 4 4
      srv/src/slackData.js

+ 17 - 17
srv/src/slack.js

@@ -140,12 +140,12 @@ Slack.prototype.sendCommand = function(room, cmd, arg) {
         +"?token=" +this.token
         +"&command=" +encodeURIComponent(cmd.name)
         +"&disp=" +encodeURIComponent(cmd.name)
-        +"&channel=" +room.id
+        +"&channel=" +room.remoteId
         +"&text=" +arg);
 }
 
 Slack.prototype.sendTyping = function(room) {
-    this.rtm.send('{"id":' +this.rtmId++ +',"type":"typing","channel":"' +room.id +'"}');
+    this.rtm.send('{"id":' +this.rtmId++ +',"type":"typing","channel":"' +room.remoteId +'"}');
 }
 
 Slack.prototype.getSlashCommands = function(cb) {
@@ -234,7 +234,7 @@ Slack.prototype.onMessage = function(msg, t) {
     }
     this.data.onMessage(msg, t);
     if ((msg["channel"] || msg["channel_id"] || (msg["item"] && msg["item"]["channel"])) && msg["type"] && UPDATE_LIVE.indexOf(msg["type"]) !== -1) {
-        var channelId = msg["channel"] || msg["channel_id"] || msg["item"]["channel"]
+        var channelId = this.data.team.id +(msg["channel"] || msg["channel_id"] || msg["item"]["channel"])
             ,channel = this.data.channels[msg["channel"]]
             ,histo = this.history[channelId];
         if (histo) {
@@ -245,7 +245,7 @@ Slack.prototype.onMessage = function(msg, t) {
             if (channel)
                 channel.setLastMsg(lastMsg, t);
         } else if (channel) {
-            this.fetchHistory(this.data.channels[this.data.team.id +'|' +msg["channel"]]);
+            this.fetchHistory(channel);
         }
     }
 };
@@ -257,16 +257,16 @@ Slack.prototype.onMessage = function(msg, t) {
 Slack.prototype.markRead = function(chan, ts) {
     var apiURI;
 
-    if (chan.id[0] === 'C')
+    if (chan.remoteId[0] === 'C')
         apiURI = SLACK_ENDPOINT+GETAPI.read.channel;
-    else if (chan.id[0] === 'G')
+    else if (chan.remoteId[0] === 'G')
         apiURI = SLACK_ENDPOINT+GETAPI.read.group;
-    else if (chan.id[0] === 'D')
+    else if (chan.remoteId[0] === 'D')
         apiURI = SLACK_ENDPOINT+GETAPI.read.im;
 
     httpsRequest(apiURI
         +"?token=" +this.token
-        +"&channel="+chan.id
+        +"&channel="+chan.remoteId
         +"&ts="+ts);
 };
 
@@ -339,7 +339,7 @@ Slack.prototype.openUploadFileStream = function(channel, contentType, callback)
         ,method: 'POST'
         ,path: SLACK_ENDPOINT_PATH +GETAPI.postFile
             +"?token=" +this.token
-            +"&channels=" +channel.id
+            +"&channels=" +channel.remoteId
         ,headers: {
             "Content-Type": contentType
         }
@@ -402,7 +402,7 @@ Slack.prototype.openUploadFileStream = function(channel, contentType, callback)
         ,method: 'POST'
         ,path: SLACK_ENDPOINT_PATH +GETAPI.postFile
             +"?token=" +this.token
-            +"&channels=" +channel.id
+            +"&channels=" +channel.remoteId
         ,headers: {
             "Content-Type": contentType
         }
@@ -436,7 +436,7 @@ Slack.prototype.addReaction = function(channel, msgId, reaction) {
     httpsRequest(SLACK_ENDPOINT +GETAPI.addReaction
         +"?token=" +this.token
         +"&name=" +reaction
-        +"&channel="+channel.id
+        +"&channel="+channel.remoteId
         +"&timestamp="+msgId);
 }
 
@@ -449,7 +449,7 @@ Slack.prototype.removeReaction = function(channel, msgId, reaction) {
     httpsRequest(SLACK_ENDPOINT +GETAPI.removeReaction
         +"?token=" +this.token
         +"&name=" +reaction
-        +"&channel="+channel.id
+        +"&channel="+channel.remoteId
         +"&timestamp="+msgId);
 }
 
@@ -460,7 +460,7 @@ Slack.prototype.removeReaction = function(channel, msgId, reaction) {
 Slack.prototype.sendMeMsg = function(channel, text) {
     httpsRequest(SLACK_ENDPOINT +GETAPI.postMeMsg
         +"?token=" +this.token
-        +"&channel=" +channel.id
+        +"&channel=" +channel.remoteId
         +"&text=" +text.join("\n")
         +"&as_user=true");
 };
@@ -474,7 +474,7 @@ Slack.prototype.sendMsg = function(channel, text, attachments) {
     if (attachments) {
         httpsRequest(SLACK_ENDPOINT +GETAPI.postMsg
             +"?token=" +this.token
-            +"&channel=" +channel.id
+            +"&channel=" +channel.remoteId
             +"&text=" +text.join("\n")
             + (attachments ? ("&attachments=" +encodeURIComponent(JSON.stringify(attachments))) : "")
             +"&as_user=true");
@@ -490,7 +490,7 @@ Slack.prototype.sendMsg = function(channel, text, attachments) {
             user: this.data.self.id,
             text: fullDecodedText
         };
-        this.rtm.send('{"id":' +this.rtmId++ +',"type":"message","channel":"' +channel.id +'", "text":' +JSON.stringify(fullDecodedText) +'}');
+        this.rtm.send('{"id":' +this.rtmId++ +',"type":"message","channel":"' +channel.remoteId +'", "text":' +JSON.stringify(fullDecodedText) +'}');
     }
 };
 
@@ -501,7 +501,7 @@ Slack.prototype.sendMsg = function(channel, text, attachments) {
 Slack.prototype.removeMsg = function(channel, msgId) {
     httpsRequest(SLACK_ENDPOINT +GETAPI.removeMsg
         +"?token=" +this.token
-        +"&channel=" +channel.id
+        +"&channel=" +channel.remoteId
         +"&ts=" +msgId
         +"&as_user=true");
 };
@@ -514,7 +514,7 @@ Slack.prototype.removeMsg = function(channel, msgId) {
 Slack.prototype.editMsg = function(channel, msgId, text) {
     httpsRequest(SLACK_ENDPOINT +GETAPI.editMsg
         +"?token=" +this.token
-        +"&channel=" +channel.id
+        +"&channel=" +channel.remoteId
         +"&ts=" +msgId
         +"&text=" +text.join("\n")
         +"&as_user=true");

+ 4 - 4
srv/src/slackData.js

@@ -253,16 +253,16 @@ SlackData.prototype.commandFactory = function(data) {
 **/
 SlackData.prototype.onMessage = function(msg, t) {
     if (msg["type"] === "presence_change") {
-        var member = this.users[msg["user"]];
+        var member = this.users[this.team.id +'|' +msg["user"]];
         if (member)
             member.setPresence(msg["presence"], t);
         this.staticV = Math.max(this.staticV, t);
     } else if (msg["type"] === "user_typing") {
-        this.typing[msg["channel"]] = this.typing[msg["channel"]] || {};
-        this.typing[msg["channel"]][msg["user"]] = t;
+        this.typing[this.team.id +'|' +msg["channel"]] = this.typing[this.team.id +'|' +msg["channel"]] || {};
+        this.typing[this.team.id +'|' +msg["channel"]][this.team.id +'|' +msg["user"]] = t;
         this.staticV = Math.max(this.staticV, t);
     } else if (msg["type"] === "im_marked" || msg["type"] === "channel_marked" || msg["type"] === "group_marked") {
-        var channel = this.channels[msg["channel"]];
+        var channel = this.channels[this.team.id +'|' +msg["channel"]];
         if (channel) {
             channel.lastRead = parseFloat(msg["ts"]);
             this.staticV = channel.version = Math.max(channel.version, t);