Ver código fonte

[bugfix] self presence update and init

B Thibault 8 anos atrás
pai
commit
db5d970860
4 arquivos alterados com 18 adições e 5 exclusões
  1. 1 0
      cli/resources.js
  2. 8 3
      srv/src/slack.js
  3. 8 0
      srv/src/slackData.js
  4. 1 2
      srv/src/template/index.js

+ 1 - 0
cli/resources.js

@@ -3,6 +3,7 @@ var R = {
         chanList: "chanList",
         context: "chatCtx",
         chatList: "chatList",
+        roomInfoPopin: "ctxRoomInfo",
         mainSection: "chatSystemContainer",
         currentRoom: {
             title: "currentRoomTitle",

+ 8 - 3
srv/src/slack.js

@@ -28,6 +28,7 @@ const SLACK_ENDPOINT = "https://slack.com/api/"
         ,removeMsg: "chat.delete"
         ,postFile: "files.upload"
         ,setActive: "users.setActive"
+        ,setPresence: "users.setPresence"
         ,emojiList: "emoji.list"
         ,slashList: "commands.list"
         ,slashExec: "chat.command"
@@ -112,9 +113,12 @@ Slack.prototype.connect = function(cb) {
 Slack.prototype.sendCommand = function(room, cmd, arg) {
     if (cmd.name === "/away") {
         // intercept away commands
-        // FIXME set presence
-        // Should be idempotent
-        console.log("SET AWAY", !this.data.self.presence);
+        // TODO should be idempotent
+        httpsRequest(
+            SLACK_ENDPOINT
+            +GETAPI.setPresence
+            +"?token=" +this.token
+            +"&presence=" +(this.data.self.presence ? "away": "auto"));
     } else {
         httpsRequest(
             SLACK_ENDPOINT
@@ -228,6 +232,7 @@ Slack.prototype.onMessage = function(msg, t) {
                 _this.data.updateStatic(msgContent, now);
                 _this.connected = true;
                 _this.unstackPendingMessages();
+                _this.ping();
             });
         });
     } else if (this.connected) {

+ 8 - 0
srv/src/slackData.js

@@ -251,6 +251,9 @@ SlackData.prototype.updateStatic = function(data, t) {
         this.updateGroups(data["groups"], t);
     if (data["mpims"])
         this.updateGroups(data["mpims"], t);
+    if (data["self"] && data["self"]["manual_presence"]) {
+        this.self.setPresence(data["self"]["manual_presence"], t);
+    }
 };
 
 SlackData.prototype.updateGroups = function(groupsData, t) {
@@ -308,6 +311,11 @@ SlackData.prototype.onMessage = function(msg, t) {
         if (member)
             member.setPresence(msg["presence"], t);
         this.staticV = Math.max(this.staticV, t);
+    } else if (msg["type"] === "manual_presence_change") {
+        if (this.self) {
+            this.self.setPresence(msg["presence"], t);
+            this.staticV = Math.max(this.staticV, t);
+        }
     } else if (msg["type"] === "user_typing") {
         var chanId = this.team.id +'|' +msg["channel"];
         if (!this.typing[chanId])

+ 1 - 2
srv/src/template/index.js

@@ -28,9 +28,8 @@ module.exports.exec = function(req, res) {
               <div class="chat-context-rooms" id="chatList">
                   <div class="chan-search-wrapper"><input type="search" id="chanSearch" class="chan-search-input" /></div>
                   <ul class="chat-context-channellist" id="chanList"></ul>
-                  <div class="chat-context-imlist"></div>
               </div>
-              <div class="chat-context-roominfo hidden"></div>
+              <div id="ctxRoomInfo" class="chat-context-roominfo hidden"></div>
               <nav class="chat-context-menu">
                   <a id="ctxMenuSettings" href="javascript:void(0);"></a>
               </nav>