Jelajahi Sumber

[wip] prepare multi-sourced chat

B Thibault 8 tahun lalu
induk
melakukan
e37685b99d

+ 3 - 3
cli/contextBackground.js

@@ -179,10 +179,10 @@ var createContextBackground = (function() {
 
             isLoading = true;
             callbacks.push(cb);
-            for (var userId in SLACK.context.users) {
-                if (!SLACK.context.users[userId].deleted && !SLACK.context.users[userId].isBot)
+            for (var userId in DATA.context.users) {
+                if (!DATA.context.users[userId].deleted && !DATA.context.users[userId].isBot)
                     userImgs.push({
-                        src: "api/avatar?user=" +userId
+                        src: DATA.context.users[userId].getSmallIcon()
                     });
             }
 

+ 5 - 5
cli/data.js

@@ -3,7 +3,7 @@ var
     /**
      * @type {SlackWrapper}
     **/
-    SLACK
+    DATA
 
     /**
      * @type {Array.<Room>}
@@ -72,7 +72,7 @@ SlackWrapper.prototype.update = function(data) {
 };
 
 setInterval(function() {
-    if (SLACK.context.cleanTyping(Date.now()))
+    if (DATA.context.cleanTyping(Date.now()))
         onTypingUpdated();
 }, 1000);
 
@@ -81,7 +81,7 @@ setInterval(function() {
  * @return {boolean}
 **/
 function isHighlighted(text) {
-    var highlights = SLACK.context.self.prefs.highlights;
+    var highlights = DATA.context.self.prefs.highlights;
     for (var i =0, nbHighlights = highlights.length; i < nbHighlights; i++)
         if (text.indexOf(highlights[i]) !== -1) {
             return true;
@@ -95,7 +95,7 @@ function isHighlighted(text) {
 **/
 function onMsgReceived(chan, msg) {
     if (chan !== SELECTED_ROOM || !window.hasFocus) {
-        var selfReg = new RegExp("<@" +SLACK.context.self.id)
+        var selfReg = new RegExp("<@" +DATA.context.self.id) // FIXME remove context id
             ,highligted = false
             ,areNew = false
             ,newHighlited = false;
@@ -147,5 +147,5 @@ function markRoomAsRead(room) {
     roomLi.classList.remove(R.klass.unreadHi);
 }
 
-SLACK = new SlackWrapper();
+DATA = new SlackWrapper();
 

+ 4 - 4
cli/dom.js

@@ -109,7 +109,7 @@ function createReactionDom(chanId, msgId, reaction, users) {
             ,userNames = [];
 
         for (var i =0, nbUser = users.length; i < nbUser; i++) {
-            var user = SLACK.context.users[users[i]];
+            var user = DATA.context.users[users[i]];
             if (user)
                 userNames.push(user.name);
         }
@@ -180,7 +180,7 @@ function doCreateMessageDom(msg, skipAttachment) {
         }
         hover.appendChild(hoverReaction);
 
-        if (msg.userId === SLACK.context.self.id) {
+        if (msg.userId === DATA.context.self.id) {
             var hoverEdit = document.createElement("li");
             hoverEdit.className = R.klass.msg.hover.edit;
             if (domEdit)
@@ -202,7 +202,7 @@ function doCreateMessageDom(msg, skipAttachment) {
 
     } else {
         hoverReply.style.backgroundImage = 'url("repl.svg")';
-        if (msg.userId === SLACK.context.self.id) {
+        if (msg.userId === DATA.context.self.id) {
             var hoverEdit = document.createElement("li");
             hoverEdit.className = R.klass.msg.hover.edit;
             hoverEdit.style.backgroundImage = 'url("edit.svg")';
@@ -248,7 +248,7 @@ function createMessageGroupDom(user, userName) {
     authorName.className = R.klass.msg.authorname;
     if (user) {
         authorName.textContent = user.name;
-        dom.authorImg.src = 'api/avatar?user=' +user.id;
+        dom.authorImg.src = user.getSmallIcon();
     } else {
         authorName.textContent = userName || "?";
         dom.authorImg.src = "";

+ 4 - 4
cli/emojiBar.js

@@ -96,7 +96,7 @@ var EMOJI_BAR = (function() {
             /** @type {Object.<string, *>} */
             var foundEmojis = window['searchEmojis'](queryString);
 
-            sortedEmojiNames = sortEmojis(foundEmojis, SLACK.context.self.prefs.favoriteEmojis);
+            sortedEmojiNames = sortEmojis(foundEmojis, DATA.context.self.prefs.favoriteEmojis);
             for (var i in emojiCache.unicode) {
                 if (emojiCache.unicode[i].visible) {
                     // We remove every item to reorder them (add them in order)
@@ -124,13 +124,13 @@ var EMOJI_BAR = (function() {
                 customEmojis.removeChild(emojiCache.custom[i].dom);
             }
         }
-        sortedEmojiNames = sortEmojis(SLACK.context.emojis.data, SLACK.context.self.prefs.favoriteEmojis);
+        sortedEmojiNames = sortEmojis(DATA.context.emojis.data, DATA.context.self.prefs.favoriteEmojis);
         for (var i =0, nbEmojis = sortedEmojiNames.length; i < nbEmojis; i++) {
             var emojiName = sortedEmojiNames[i].name;
-            if ((queryString === '' || emojiName.substr(0, queryString.length) === queryString) && SLACK.context.emojis.data[emojiName].substr(0, 6) !== 'alias:') {
+            if ((queryString === '' || emojiName.substr(0, queryString.length) === queryString) && DATA.context.emojis.data[emojiName].substr(0, 6) !== 'alias:') {
                 var e = emojiCache.custom[emojiName];
                 if (!e)
-                    e = emojiCache.custom[emojiName] = makeCustomEmoji(emojiName, SLACK.context.emojis.data[emojiName]);
+                    e = emojiCache.custom[emojiName] = makeCustomEmoji(emojiName, DATA.context.emojis.data[emojiName]);
                 if (!e.visible) {
                     e.visible = true;
                     customEmojis.appendChild(e.dom);

+ 32 - 29
cli/ui.js

@@ -22,7 +22,7 @@ var
 
 function onContextUpdated() {
     var chanListFram = document.createDocumentFragment()
-        ,sortedChans = Object.keys(SLACK.context.channels || {})
+        ,sortedChans = Object.keys(DATA.context.channels || {})
         ,starred = []
         ,channels = []
         ,privs = []
@@ -32,10 +32,10 @@ function onContextUpdated() {
         if (a[0] !== b[0]) {
             return a[0] - b[0];
         }
-        return SLACK.context.channels[a].name.localeCompare(SLACK.context.channels[b].name);
+        return DATA.context.channels[a].name.localeCompare(DATA.context.channels[b].name);
     });
     sortedChans.forEach(function(chanId) {
-        var chan = SLACK.context.channels[chanId];
+        var chan = DATA.context.channels[chanId];
         if (!chan.archived && chan.isMember !== false) {
             if (chan instanceof PrivateMessageRoom) {
                 if (!chan.user.deleted) {
@@ -88,9 +88,9 @@ function onContextUpdated() {
 }
 
 function onTypingUpdated() {
-    var typing = SLACK.context.typing;
-    for (var chanId in SLACK.context.self.channels) {
-        if (!SLACK.context.self.channels[chanId].archived) {
+    var typing = DATA.context.typing;
+    for (var chanId in DATA.context.self.channels) {
+        if (!DATA.context.self.channels[chanId].archived) {
             var dom = document.getElementById("room_" +chanId);
             if (typing[chanId])
                 dom.classList.add(R.klass.chatList.typing);
@@ -98,8 +98,8 @@ function onTypingUpdated() {
                 dom.classList.remove(R.klass.chatList.typing);
         }
     }
-    for (var userId in SLACK.context.users) {
-        var ims = SLACK.context.users[userId].privateRoom;
+    for (var userId in DATA.context.users) {
+        var ims = DATA.context.users[userId].privateRoom;
         if (ims && !ims.archived) {
             var dom = document.getElementById("room_" +ims.id);
             if (dom) {
@@ -114,13 +114,13 @@ function onTypingUpdated() {
 }
 
 function updateTypingChat() {
-    var typing = SLACK.context.typing;
+    var typing = DATA.context.typing;
     document.getElementById(R.id.typing).textContent = "";
     if (SELECTED_ROOM && typing[SELECTED_ROOM.id]) {
         var areTyping = document.createDocumentFragment()
             ,isOutOfSync = false;
         for (var i in typing[SELECTED_ROOM.id]) {
-            var member = SLACK.context.users[i];
+            var member = DATA.context.users[i];
             if (member)
                 areTyping.appendChild(makeUserIsTypingDom(member));
             else
@@ -216,12 +216,12 @@ function onEditingUpdated() {
  * @param {string} reaction
 **/
 window['toggleReaction'] = function(chanId, msgId, reaction) {
-    var hist = SLACK.history[chanId];
+    var hist = DATA.history[chanId];
     if (!hist)
         return;
     var msg = hist.getMessageById(msgId);
     if (msg) {
-        if (msg.hasReactionForUser(reaction, SLACK.context.self.id)) {
+        if (msg.hasReactionForUser(reaction, DATA.context.self.id)) {
             removeReaction(chanId, msgId, reaction);
         } else {
             addReaction(chanId, msgId, reaction);
@@ -238,7 +238,7 @@ function tryGetCustomEmoji(emoji) {
     var loop = {};
 
     while (!loop[emoji]) {
-        var emojisrc= SLACK.context.emojis.data[emoji];
+        var emojisrc= DATA.context.emojis.data[emoji];
         if (emojisrc) {
             if (emojisrc.substr(0, 6) == "alias:") {
                 loop[emoji] = true;
@@ -291,8 +291,8 @@ function updateTitle() {
         setFavicon(hasHl, hasHl);
     } else {
         var hasUnread = 0;
-        for (var chanId in SLACK.context.channels) {
-            var i = SLACK.context.channels[chanId];
+        for (var chanId in DATA.context.channels) {
+            var i = DATA.context.channels[chanId];
             if (i.lastMsg > i.lastRead)
                 hasUnread++;
         }
@@ -300,8 +300,8 @@ function updateTitle() {
             title = "(" +hasUnread +") - ";
         setFavicon(0, hasUnread);
     }
-    if (SLACK.context.team)
-        title += SLACK.context.team.name;
+    if (DATA.context.team)
+        title += DATA.context.team.name;
     document.title = title;
 }
 
@@ -332,8 +332,8 @@ function onRoomUpdated() {
         ,currentMsgGroupDom;
 
     MSG_GROUPS = [];
-    if (SLACK.history[currentRoomId])
-        SLACK.history[currentRoomId].messages.forEach(function(msg) {
+    if (DATA.history[currentRoomId])
+        DATA.history[currentRoomId].messages.forEach(function(msg) {
             if (!msg.removed) {
                 var dom = msg.getDom()
                     ,newGroupDom = false;
@@ -359,7 +359,7 @@ function onRoomUpdated() {
                     currentMsgGroupDom = null;
                 } else {
                     if (newGroupDom || !currentMsgGroupDom) {
-                        currentMsgGroupDom = createMessageGroupDom(SLACK.context.users[msg.userId], msg.username);
+                        currentMsgGroupDom = createMessageGroupDom(DATA.context.users[msg.userId], msg.username);
                         MSG_GROUPS.push(currentMsgGroupDom);
                         chatFrag.appendChild(currentMsgGroupDom);
                     }
@@ -395,24 +395,27 @@ function chatClickDelegate(e) {
     while (target !== e.currentTarget && target) {
         if (target.classList.contains(R.klass.msg.hover.container)) {
             return;
-        } else if (target.parentElement && target.classList.contains(R.klass.msg.attachment.actionItem)) {
+        }
+        if (target.parentElement && target.classList.contains(R.klass.msg.attachment.actionItem)) {
             var messageId = getMessageId(e, target)
                 ,attachmentIndex = target.dataset["attachmentIndex"]
                 ,actionIndex = target.dataset["actionIndex"];
 
             if (messageId && attachmentIndex !== undefined && actionIndex !== undefined) {
                 messageId = parseFloat(messageId.split("_")[1]);
-                var msg = SLACK.history[SELECTED_ROOM.id].getMessage(messageId);
+                var msg = DATA.history[SELECTED_ROOM.id].getMessage(messageId);
 
                 if (msg && msg.attachments[attachmentIndex] && msg.attachments[attachmentIndex].actions && msg.attachments[attachmentIndex].actions[actionIndex]) {
                     confirmAction(SELECTED_ROOM.id, msg, msg.attachments[attachmentIndex], msg.attachments[attachmentIndex].actions[actionIndex]);
                 }
+                return;
             }
-        } else if (target.parentElement && target.parentElement.classList.contains(R.klass.msg.hover.container)) {
+        }
+        if (target.parentElement && target.parentElement.classList.contains(R.klass.msg.hover.container)) {
             var messageId = getMessageId(e, target);
             if (messageId) {
                 messageId = parseFloat(messageId.split("_")[1]);
-                var msg = SLACK.history[SELECTED_ROOM.id].getMessage(messageId);
+                var msg = DATA.history[SELECTED_ROOM.id].getMessage(messageId);
 
                 if (msg && target.classList.contains(R.klass.msg.hover.reply)) {
                     if (EDITING) {
@@ -477,12 +480,12 @@ function focusInput() {
 
 function setRoomFromHashBang() {
     var hashId = document.location.hash.substr(1)
-        ,room = SLACK.context.channels[hashId];
+        ,room = DATA.context.channels[hashId];
 
     if (room && room !== SELECTED_ROOM)
         selectRoom(room);
     else {
-        var user = SLACK.context.users[hashId];
+        var user = DATA.context.users[hashId];
         if (user && user.ims)
             selectRoom(user.ims);
     }
@@ -581,7 +584,7 @@ document.addEventListener('DOMContentLoaded', function() {
     document.getElementById(R.id.message.input).addEventListener('input', function() {
         if (SELECTED_ROOM) {
             var now = Date.now();
-            if (lastKeyDown + 3000 < now && (SLACK.context.self.presence || (SELECTED_ROOM instanceof PrivateMessageRoom))) {
+            if (lastKeyDown + 3000 < now && (DATA.context.self.presence || (SELECTED_ROOM instanceof PrivateMessageRoom))) {
                 sendTyping(SELECTED_ROOM);
                 lastKeyDown = now;
             }
@@ -593,8 +596,8 @@ document.addEventListener('DOMContentLoaded', function() {
                 endCmd = endCmd === -1 ? input.length : endCmd;
                 var inputCmd = input.substr(0, endCmd);
 
-                for (var i in SLACK.context.commands.data) {
-                    var currentCmd = SLACK.context.commands.data[i]
+                for (var i in DATA.context.commands.data) {
+                    var currentCmd = DATA.context.commands.data[i]
                     if ((!inputFinished && currentCmd.name.substr(0, endCmd) === inputCmd) ||
                         (inputFinished && currentCmd.name === inputCmd))
                         commands.push(currentCmd);

+ 12 - 6
cli/uiMessage.js

@@ -85,14 +85,14 @@ var AbstractUiMessage = (function() {
         if (link[0] === '@') {
             isInternal = true;
             //FIXME pointer back from message to team to prepend team id to remote userId
-            var user = SLACK.context.users[link.substr(1)];
+            var user = DATA.context.users[link.substr(1)];
             if (user) {
                 text = '@' +user.name;
             }
         } else if (link[0] === '#') {
             isInternal = true;
             //FIXME pointer back from message to team to prepend team id to remote userId
-            var chan = SLACK.context.channels[link.substr(1)];
+            var chan = DATA.context.channels[link.substr(1)];
             if (chan) {
                 text = '#' +chan.name;
             }
@@ -109,7 +109,7 @@ var AbstractUiMessage = (function() {
 
     _formatText = function(_this, text) {
         return formatText(text, {
-            highlight: [ "fromage" ],
+            highlights: DATA.context.self.prefs.highlights,
             emojiFormatFunction: function(emoji) {
                 if (emoji[0] === ':' && emoji[emoji.length -1] === ':')
                     emoji = emoji.substr(1, emoji.length -2);
@@ -186,7 +186,7 @@ var AbstractUiMessage = (function() {
 
         /** @param {UiMessage|UiMeMessage|UiNoticeMessage} _this */
         updateDom: function(_this) {
-            var sender = SLACK.context.users[_this.userId];
+            var sender = DATA.context.users[_this.userId];
 
             updateCommon(_this, sender);
             updateAttachments(_this, _this.channelId);
@@ -330,10 +330,15 @@ function UiNoticeMessage(channelId, ev, ts) {
 
     /** @type {string} @const */
     this.channelId = channelId;
-    this.dom = AbstractUiMessage.dom;
+
+    /** @type {Element} */
+    this.dom;
+
     /** @type {Element} */
     this.domWrapper = null;
-    this.uiNeedRefresh = AbstractUiMessage.uiNeedRefresh;
+
+    /** @type {boolean} */
+    this.uiNeedRefresh = true;
 }
 UiNoticeMessage.prototype = Object.create(NoticeMessage.prototype);
 UiNoticeMessage.prototype.constructor = UiNoticeMessage;
@@ -371,6 +376,7 @@ UiNoticeMessage.prototype.createDom = function() {
     this.dom.classList.add(R.klass.msg.notice);
     this.domWrapper.className = R.klass.msg.notice;
     this.domWrapper.textContent = locale.onlyVisible;
+    this.domWrapper.appendChild(this.dom);
     return this;
 };
 

+ 6 - 6
cli/workflow.js

@@ -66,12 +66,12 @@ function poll(callback) {
             callback(success, resp);
         }
     };
-    xhr.open('GET', 'api?v=' +SLACK.lastServerVersion, true);
+    xhr.open('GET', 'api?v=' +DATA.lastServerVersion, true);
     xhr.send(null);
 }
 
 function outOfSync() {
-    SLACK.lastServerVersion = 0;
+    DATA.lastServerVersion = 0;
 }
 
 /**
@@ -91,7 +91,7 @@ function sendTyping(room) {
 function onPollResponse(success, response) {
     if (success) {
         if (response) {
-            SLACK.update(response);
+            DATA.update(response);
         }
         startPolling();
     } else {
@@ -113,7 +113,7 @@ function selectRoom(room) {
     document.body.classList.remove(R.klass.noRoomSelected);
     SELECTED_ROOM = room;
     onRoomSelected();
-    if (SELECTED_ROOM.lastMsg && !SLACK.history[SELECTED_ROOM.id])
+    if (SELECTED_ROOM.lastMsg && !DATA.history[SELECTED_ROOM.id])
         fetchHistory(SELECTED_ROOM, function(success) {});
 }
 
@@ -206,7 +206,7 @@ function sendMsg(chan, msg, replyTo) {
     var xhr = new XMLHttpRequest();
     var url = 'api/msg?room=' +chan.id +"&text=" +encodeURIComponent(msg);
     if (replyTo) {
-        var sender = SLACK.context.users[replyTo.userId]
+        var sender = DATA.context.users[replyTo.userId]
             ,footer = "Message";
 
         if (chan.id[0] === 'C') {
@@ -244,7 +244,7 @@ function onTextEntered(input, skipCommand) {
         var endCmd = input.indexOf(' ')
             ,cmd = input.substr(0, endCmd === -1 ? undefined : endCmd)
             ,args = endCmd === -1 ? "" : input.substr(endCmd)
-            ,cmdObject = SLACK.context.commands.data[cmd];
+            ,cmdObject = DATA.context.commands.data[cmd];
 
         if (cmdObject) {
             doCommand(SELECTED_ROOM, cmdObject, args.trim());

+ 91 - 176
srv/public/slack.min.js

@@ -1,176 +1,91 @@
-function ChatInfo(id){this.id=id;this.name;this.version=0}ChatInfo.prototype.toStatic=function(t){return t>=this.version?undefined:{"id":this.id,"name":this.name}};ChatInfo.prototype.update=function(data,t){if(data["name"]!==undefined)this.name=data["name"];this.version=Math.max(this.version,t)};function Command(data){this.desc=data["desc"];this.name=data["name"];this.type=data["type"];this.usage=data["usage"];this.category=data["category"]}
-Command.prototype.toStatic=function(t){return{"desc":this.desc,"name":this.name,"type":this.type,"usage":this.usage,"category":this.category}};function SelfPreferences(){this.favoriteEmojis={};this.highlights=[]}
-SelfPreferences.prototype.update=function(prefs,t){this.favoriteEmojis=JSON.parse(prefs["emoji_use"]);if(prefs["highlight_words"])this.highlights=(prefs["highlight_words"]||"").split(",").filter(function(i){return i.trim()!==""});else if(prefs["highlights"])this.highlights=prefs["highlights"];this.version=Math.max(this.version,t)};SelfPreferences.prototype.toStatic=function(t){return this.version>t?null:{"emoji_use":JSON.stringify(this.favoriteEmojis),"highlights":this.highlights}};
-function ChatContext(){this.team=null;this.channels={};this.users={};this.self=null;this.emojis={version:0,data:{}};this.commands={version:0,data:{}};this.typing={};this.staticV=0;this.liveV=0}ChatContext.prototype.userFactory=function(userData){return new Chatter(userData["id"])};ChatContext.prototype.roomFactory=function(roomData){return roomData["pv"]?new PrivateMessageRoom(roomData["id"],this.users[roomData["user"]]):new Room(roomData["id"])};ChatContext.prototype.teamFactory=function(id){return new ChatInfo(id)};
-ChatContext.prototype.commandFactory=function(data){return new Command(data)};
-ChatContext.prototype.updateStatic=function(data,t,idPrefix){idPrefix=idPrefix||"";if(data["team"]){if(!this.team)this.team=this.teamFactory(data["team"]["id"]);this.team.update(data["team"],t)}if(data["users"])for(var i=0,nbUsers=data["users"].length;i<nbUsers;i++){var userObj=this.users[idPrefix+data["users"][i]["id"]];if(!userObj)userObj=this.users[idPrefix+data["users"][i]["id"]]=this.userFactory(data["users"][i]);userObj.update(data["users"][i],t)}if(data["channels"])for(var i=0,nbChan=data["channels"].length;i<
-nbChan;i++){var chanObj=this.channels[idPrefix+data["channels"][i]["id"]];if(!chanObj)chanObj=this.channels[idPrefix+data["channels"][i]["id"]]=this.roomFactory(data["channels"][i]);chanObj.update(data["channels"][i],this,t,idPrefix)}if(data["emojis"]){this.emojis.data=data["emojis"];this.emojis.version=t}if(data["commands"]!==undefined){this.commands.data={};for(var i in data["commands"])this.commands.data[i]=this.commandFactory(data["commands"][i]);this.commands.version=t}this.staticV=Math.max(this.staticV,
-t);if(data["self"]){this.self=this.users[idPrefix+data["self"]["id"]]||null;if(this.self){if(!this.self.prefs)this.self.prefs=new SelfPreferences;this.self.prefs.update(data["self"]["prefs"],t)}else this.staticV=0}if(data["typing"]!==undefined){this.typing={};for(var i in data["typing"]){this.typing[i]={};for(var j in data["typing"][i])this.typing[i][j]=t}}};
-ChatContext.prototype.toStatic=function(t,now){var channels=[],users=[];var res={"team":this.team.toStatic(t),"self":{"id":this.self.id,"prefs":this.self.prefs.toStatic(t)},"emojis":this.emojis.version>t?this.emojis.data:undefined};if(this.commands.version>t){res["commands"]={};for(var i in this.commands.data)res["commands"][i]=this.commands.data[i].toStatic(t)}for(var chanId in this.channels){var chan=this.channels[chanId].toStatic(t);if(chan)channels.push(chan)}if(channels.length)res["channels"]=
-channels;for(var userId in this.users){var user=this.users[userId].toStatic(t);if(user)users.push(user)}if(users.length)res["users"]=users;for(var typingChan in this.typing){var tChan=null;for(var typingUser in this.typing[typingChan])if(this.typing[typingChan][typingUser]+3E3>=now){if(!tChan)tChan={};tChan[typingUser]=1}else delete this.typing[typingChan][typingUser];if(tChan){if(res["typing"]===undefined)res["typing"]={};res["typing"][typingChan]=tChan}else delete this.typing[typingChan]}return res};
-ChatContext.prototype.cleanTyping=function(now){var updated=false;for(var typingChan in this.typing){var chanEmpty=true;for(var typingUser in this.typing[typingChan])if(this.typing[typingChan][typingUser]+3E3<now){delete this.typing[typingChan][typingUser];updated=true}else chanEmpty=false;if(chanEmpty){delete this.typing[typingChan];updated=true}}return updated};
-(function(){if(typeof module!=="undefined"){module.exports.ChatContext=ChatContext;module.exports.ChatInfo=ChatInfo;module.exports.Command=Command}})();function Room(id){this.id=id;this.name;this.created;this.creator;this.archived;this.isMember;this.starred=false;this.lastRead=0;this.lastMsg=0;this.users={};this.topic;this.topicTs;this.topicCreator;this.purpose;this.purposeTs;this.purposeCreator;this.version=0;this.isPrivate}Room.prototype.setLastMsg=function(lastMsg,t){if(this.lastMsg<lastMsg){this.lastMsg=lastMsg;this.version=t;return true}return false};
-Room.prototype.toStatic=function(t){if(t>=this.version)return null;var res={"id":this.id,"name":this.name,"created":this.created,"creator":this.creator?this.creator.id:undefined,"is_archived":this.archived,"is_member":this.isMember,"last_read":this.lastRead,"last_msg":this.lastMsg,"is_private":this.isPrivate,"is_starred":this.starred||undefined};if(this.isMember){res["members"]=this.users?Object.keys(this.users):[];res["topic"]={"value":this.topic,"creator":this.topicCreator?this.topicCreator.id:
-null,"last_set":this.topicTs};res["purpose"]={"value":this.purpose,"creator":this.purposeCreator?this.purposeCreator.id:null,"last_set":this.purposeTs}}return res};
-Room.prototype.update=function(chanData,ctx,t,idPrefix){idPrefix=idPrefix||"";if(chanData["name"]!==undefined)this.name=chanData["name"];if(chanData["created"]!==undefined)this.created=chanData["created"];if(chanData["creator"]!==undefined)this.creator=ctx.users[chanData["creator"]];if(chanData["is_archived"]!==undefined)this.archived=chanData["is_archived"];if(chanData["is_member"]!==undefined)this.isMember=chanData["is_member"];if(chanData["last_read"]!==undefined)this.lastRead=Math.max(parseFloat(chanData["last_read"]),
-this.lastRead);if(chanData["last_msg"]!==undefined)this.lastMsg=parseFloat(chanData["last_msg"]);if(chanData["is_private"]!==undefined)this.isPrivate=chanData["is_private"];if(chanData["latest"])this.lastMsg=parseFloat(chanData["latest"]["ts"]);if(chanData["is_starred"]!==undefined)this.starred=chanData["is_starred"];if(chanData["members"]){this.users={};if(chanData["members"])for(var i=0,nbMembers=chanData["members"].length;i<nbMembers;i++){var member=ctx.users[idPrefix+chanData["members"][i]];this.users[member.id]=
-member;member.channels[this.id]=this}}if(chanData["topic"]){this.topic=chanData["topic"]["value"];this.topicCreator=ctx.users[chanData["topic"]["creator"]];this.topicTs=chanData["topic"]["last_set"]}if(chanData["purpose"]){this.purpose=chanData["purpose"]["value"];this.purposeCreator=ctx.users[chanData["purpose"]["creator"]];this.purposeTs=chanData["purpose"]["last_set"]}this.version=Math.max(this.version,t)};
-function PrivateMessageRoom(id,user){Room.call(this,id);this.user=user;this.name=this.user.name;this.isPrivate=true;user.privateRoom=this}PrivateMessageRoom.prototype=Object.create(Room.prototype);PrivateMessageRoom.prototype.constructor=PrivateMessageRoom;PrivateMessageRoom.prototype.toStatic=function(t){return t>=this.version?null:{"id":this.id,"created":this.created,"user":this.user.id,"last_read":this.lastRead,"last_msg":this.lastMsg,"pv":true,"is_starred":this.starred||undefined}};
-(function(){if(typeof module!=="undefined"){module.exports.Room=Room;module.exports.PrivateMessageRoom=PrivateMessageRoom}})();function Message(e,ts){this.userId=e["user"];this.username=e["username"];this.id=e["id"]||e["ts"];this.ts=parseFloat(e["ts"]);this.text="";this.attachments=[];this.starred=false;this.pinned=false;this.edited=false;this.removed=false;this.reactions={};this.version=ts;this.update(e,ts)}function MeMessage(e,ts){Message.call(this,e,ts)}function NoticeMessage(e,ts){Message.call(this,e,ts)}
-Message.prototype.update=function(e,ts){if(e){this.text=e["text"]||"";if(e["attachments"])this.attachments=e["attachments"];this.starred=!!e["is_starred"];this.pinned=false;this.edited=!!e["edited"];this.removed=!!e["removed"];if(e["reactions"]){var reactions={};e["reactions"].forEach(function(r){reactions[r["name"]]=[];r["users"].forEach(function(userId){reactions[r["name"]].push(userId)})});this.reactions=reactions}}else this.removed=true;this.version=ts};
-Message.prototype.toStatic=function(){var reactions=[];for(var reaction in this.reactions)reactions.push({"name":reaction,"users":this.reactions[reaction]});return{"id":this.id,"user":this.userId,"username":this.username,"ts":this.ts,"text":this.text,"attachments":this.attachments.length?this.attachments:undefined,"is_starred":this.is_starred||undefined,"edited":this.edited||undefined,"removed":this.removed||undefined,"reactions":reactions,"isMeMessage":this instanceof MeMessage||undefined,"isNotice":this instanceof
-NoticeMessage||undefined,"v":this.version}};Message.prototype.addReaction=function(reaction,userId,ts){if(!this.reactions[reaction])this.reactions[reaction]=[];if(this.reactions[reaction].indexOf(userId)===-1){this.reactions[reaction].push(userId);this.version=ts;return true}return false};
-Message.prototype.removeReaction=function(reaction,userId,ts){var updated=false;if(this.reactions[reaction])if(this.reactions[reaction].length===1&&this.reactions[reaction][0]===userId){delete this.reactions[reaction];updated=true}else this.reactions[reaction]=this.reactions[reaction].filter(function(i){if(i!==userId)return true;updated=true;return false});if(updated)this.version=ts;return updated};
-Message.prototype.hasReactionForUser=function(reaction,userId){if(this.reactions[reaction])return this.reactions[reaction].indexOf(userId)!==-1;return false};function RoomHistory(room,keepMessages,evts,now){this.id=typeof room==="string"?room:room.id;this.messages=[];this.v=0;this.keepMessages=keepMessages;if(evts)this.pushAll(evts,now)}RoomHistory.prototype.pushAll=function(evts,t){var result=0;evts.forEach(function(e){result=Math.max(this.push(e,t),result)}.bind(this));this.resort();return result};
-RoomHistory.prototype.messageFactory=function(ev,ts){if(ev["isMeMessage"]===true)return new MeMessage(ev,ts);if(ev["isNotice"]===true)return new NoticeMessage(ev,ts);return new Message(ev,ts)};
-RoomHistory.prototype.push=function(e,t){var exists=false,ts;for(var i=0,nbMsg=this.messages.length;i<nbMsg;i++){var msgObj=this.messages[i];if(msgObj.id===e["id"]){ts=msgObj.update(e,t);exists=true;break}}if(!exists){var msgObj=this.messageFactory(e,t);this.messages.push(msgObj);ts=msgObj.ts}while(this.messages.length>this.keepMessages)this.messages.shift();return ts||0};RoomHistory.prototype.lastMessage=function(){return this.messages[this.messages.length-1]};
-RoomHistory.prototype.addReaction=function(reaction,userId,msgId,ts){var msg=this.getMessageById(msgId);if(msg)msg.addReaction(reaction,userId,ts);return msg};RoomHistory.prototype.removeReaction=function(reaction,userId,msgId,ts){var msg=this.getMessageById(msgId);if(msg)msg.removeReaction(reaction,userId,ts);return msg};
-RoomHistory.prototype.getMessage=function(ts){for(var i=0,nbMessages=this.messages.length;i<nbMessages&&ts>=this.messages[i].ts;i++)if(this.messages[i].ts===ts)return this.messages[i];return null};RoomHistory.prototype.getMessageById=function(id){for(var i=0,nbMessages=this.messages.length;i<nbMessages;i++)if(this.messages[i].id==id)return this.messages[i];return null};
-RoomHistory.prototype.toStatic=function(knownVersion){var result=[];for(var i=this.messages.length-1;i>=0;i--)if(this.messages[i].version>knownVersion)result.push(this.messages[i].toStatic());return result};RoomHistory.prototype.resort=function(){this.messages.sort(function(a,b){return a.ts-b.ts})};MeMessage.prototype=Object.create(Message.prototype);MeMessage.prototype.constructor=MeMessage;NoticeMessage.prototype=Object.create(Message.prototype);NoticeMessage.prototype.constructor=NoticeMessage;
-(function(){if(typeof module!=="undefined")module.exports={Message:Message,MeMessage:MeMessage,NoticeMessage:NoticeMessage,RoomHistory:RoomHistory}})();function Chatter(id){this.id=id;this.name;this.deleted;this.status;this.realName;this.presence;this.email;this.firstName;this.lastName;this.channels={};this.prefs=null;this.isBot;this.privateRoom=null;this.version=0}Chatter.prototype.toStatic=function(t){return t>=this.version?null:{"id":this.id,"name":this.name,"deleted":this.deleted,"status":this.status,"real_name":this.realName,"isPresent":this.presence,"isBot":this.isBot,"profile":{"email":this.email,"first_name":this.firstName,"last_name":this.lastName}}};
-Chatter.prototype.update=function(userData,t){if(userData["name"]!==undefined)this.name=userData["name"];if(userData["deleted"]!==undefined)this.deleted=userData["deleted"];if(userData["status"]!==undefined)this.status=userData["status"];if(userData["real_name"]!==undefined)this.realName=userData["real_name"];else if(userData["profile"]&&userData["profile"]["real_name"]!==undefined)this.realName=userData["profile"]["real_name"];if(userData["presence"]!==undefined)this.presence=userData["presence"]!==
-"away";if(userData["isPresent"]!==undefined)this.presence=userData["isPresent"];if(userData["isBot"])this.isBot=userData["isBot"];if(userData["profile"]){this.email=userData["profile"]["email"];this.firstName=userData["profile"]["first_name"];this.lastName=userData["profile"]["last_name"]}this.version=Math.max(this.version,t)};(function(){if(typeof module!=="undefined")module.exports.Chatter=Chatter})();var lang={},locale;function initLang(lg){if(!lg){for(var i=0,nbLang=navigator.languages.length;i<nbLang;i++)if(lang.hasOwnProperty(navigator.languages[i])){lg=navigator.languages[i];break}if(!lg)lg="en"}locale=lang[lg];console.log("Loading language pack: "+lg);if(locale.dom)for(var i in locale.dom)document.getElementById(i).textContent=locale.dom[i]};lang["fr"]={unknownMember:"Utilisateur inconnu",unknownChannel:"Channel inconnu",newMessage:"Nouveau message",netErrorShort:"Reseau",edited:"(edit&eacute;)",onlyVisible:"(visible seulement par vous)",starred:"Favoris",channels:"Discutions",privateMessageRoom:"Discutions priv\u00e9es",ok:"Ok",dissmiss:"Annuler",formatDate:function(ts){if(typeof ts!=="string")ts=parseFloat(ts);var today=new Date,yesterday=new Date,dateObj=new Date(ts*1E3);today.setHours(0);today.setMinutes(0);today.setSeconds(0);today.setMilliseconds(0);
-yesterday.setTime(today.getTime());yesterday.setDate(yesterday.getDate()-1);if(dateObj.getTime()>today.getTime())return dateObj.toLocaleTimeString();if(dateObj.getTime()>yesterday.getTime())return"hier, "+dateObj.toLocaleTimeString();return dateObj.toLocaleString()},dom:{"fileUploadCancel":"Annuler","neterror":"Impossible de se connecter au chat !"}};lang["en"]={unknownMember:"Unknown member",unknownChannel:"Unknown channel",newMessage:"New message",netErrorShort:"Network",edited:"(edited)",onlyVisible:"(only visible to you)",starred:"Starred",channels:"Channels",privateMessageRoom:"Direct messages",ok:"Ok",dissmiss:"Cancel",formatDate:function(ts){if(typeof ts!=="string")ts=parseFloat(ts);var today=new Date,yesterday=new Date,dateObj=new Date(ts*1E3);today.setHours(0);today.setMinutes(0);today.setSeconds(0);today.setMilliseconds(0);yesterday.setTime(today.getTime());
-yesterday.setDate(yesterday.getDate()-1);if(dateObj.getTime()>today.getTime())return dateObj.toLocaleTimeString();if(dateObj.getTime()>yesterday.getTime())return"yesterday, "+dateObj.toLocaleTimeString();return dateObj.toLocaleString()},dom:{"fileUploadCancel":"Cancel","neterror":"Cannot connect to chat !"}};var formatText=function(){var text;var root;var opts={highlights:[],emojiFormatFunction:identity,textFilter:identity,linkFilter:linkidentity};function MsgTextLeaf(_parent){this.text="";this._parent=_parent}function MsgBranch(_parent,triggerIndex,trigger){this.triggerIndex=triggerIndex;this.lastNode=null;this.subNodes=[];this.trigger=trigger||"";this.isLink=this.trigger==="<";this.isBold=this.trigger==="*";this.isItalic=this.trigger==="_";this.isStrike=this.trigger==="~"||this.trigger==="-";this.isQuote=
-this.trigger===">"||this.trigger==="&gt;";this.isEmoji=this.trigger===":";this.isCode=this.trigger==="`";this.isCodeBlock=this.trigger==="```";this.isEol=this.trigger==="\n";this.isHighlight=trigger!==undefined&&opts.highlights.indexOf(trigger)!==-1;this._parent=_parent;this.prevTwin=null;this.terminated=this.isEol||this.isHighlight?triggerIndex+trigger.length-1:false;if(this.isHighlight){this.lastNode=new MsgTextLeaf(this);this.subNodes.push(this.lastNode);this.lastNode.text=trigger}}MsgBranch.prototype.checkIsBold=
-function(){return this.isBold&&!!this.terminated||this._parent instanceof MsgBranch&&this._parent.checkIsBold()};MsgBranch.prototype.checkIsItalic=function(){return this.isItalic&&!!this.terminated||this._parent instanceof MsgBranch&&this._parent.checkIsItalic()};MsgBranch.prototype.checkIsStrike=function(){return this.isStrike&&!!this.terminated||this._parent instanceof MsgBranch&&this._parent.checkIsStrike()};MsgBranch.prototype.checkIsQuote=function(){return this.isQuote&&!!this.terminated||this._parent instanceof
-MsgBranch&&this._parent.checkIsQuote()};MsgBranch.prototype.checkIsEmoji=function(){return this.isEmoji&&!!this.terminated||this._parent instanceof MsgBranch&&this._parent.checkIsEmoji()};MsgBranch.prototype.checkIsHighlight=function(){return this.isHighlight&&!!this.terminated||this._parent instanceof MsgBranch&&this._parent.checkIsHighlight()};MsgBranch.prototype.checkIsCode=function(){return this.isCode&&!!this.terminated||this._parent instanceof MsgBranch&&this._parent.checkIsCode()};MsgBranch.prototype.checkIsCodeBlock=
-function(){return this.isCodeBlock&&!!this.terminated||this._parent instanceof MsgBranch&&this._parent.checkIsCodeBlock()};MsgBranch.prototype.containsUnterminatedBranch=function(){for(var i=0,nbBranches=this.subNodes.length;i<nbBranches;i++)if(this.subNodes[i]instanceof MsgBranch&&(!this.subNodes[i].terminated||this.subNodes[i].containsUnterminatedBranch()))return true;return false};MsgBranch.prototype.finishWith=function(i){if(this.trigger==="<"&&text[i]===">")return true;var prevIsAlphadec=isAlphadec(text[i-
-1]);if(!this.isQuote&&text.substr(i,this.trigger.length)===this.trigger){if(!prevIsAlphadec&&(this.isBold||this.isItalic||this.isStrike))return false;if(this.lastNode&&this.containsUnterminatedBranch())return this.lastNode.makeNewBranchFromThis();else if(this.hasContent())return true}if(text[i]==="\n"&&this.isQuote)return true;return false};MsgBranch.prototype.hasContent=function(){var _this=this;while(_this){for(var i=0,nbNodes=_this.subNodes.length;i<nbNodes;i++)if(_this.subNodes[i]instanceof MsgBranch||
-_this.subNodes[i].text.length)return true;_this=_this.prevTwin}return false};MsgBranch.prototype.makeNewBranchFromThis=function(){var other=new MsgBranch(this._parent,this.triggerIndex,this.trigger);other.prevTwin=this;if(this.lastNode&&this.lastNode instanceof MsgBranch){other.lastNode=this.lastNode.makeNewBranchFromThis();other.subNodes=[other.lastNode]}return other};MsgBranch.prototype.isAcceptable=function(i){if(this.isEmoji&&(text[i]===" "||text[i]==="\t"))return false;if((this.isEmoji||this.isLink||
-this.isBold||this.isItalic||this.isStrike||this.isCode)&&text[i]==="\n")return false;return true};MsgBranch.prototype.isNewToken=function(i){if(this.isCode||this.isEmoji||this.isCodeBlock||this.isLink)return null;if(!this.lastNode||this.lastNode.terminated||this.lastNode instanceof MsgTextLeaf){var nextIsAlphadec=isAlphadec(text[i+1]);if(text.substr(i,3)==="```")return"```";if(isBeginingOfLine()){if(text.substr(i,4)==="&gt;")return"&gt;";if(text[i]===">")return text[i]}if(["`","\n"].indexOf(text[i])!==
--1)return text[i];if(["*","~","-","_"].indexOf(text[i])!==-1&&(nextIsAlphadec||["*","~","-","_","<","&"].indexOf(text[i+1])!==-1))return text[i];if([":"].indexOf(text[i])!==-1&&nextIsAlphadec)return text[i];if(["<"].indexOf(text[i])!==-1)return text[i];for(var highlightIndex=0,nbHighlight=opts.highlights.length;highlightIndex<nbHighlight;highlightIndex++){var highlight=opts.highlights[highlightIndex];if(text.substr(i,highlight.length)===highlight)return highlight}}return null};MsgTextLeaf.prototype.isBeginingOfLine=
-function(){if(this.text.trim()!=="")return false;return undefined};MsgBranch.prototype.isBeginingOfLine=function(){for(var i=this.subNodes.length-1;i>=0;i--){var isNewLine=this.subNodes[i].isBeginingOfLine();if(isNewLine!==undefined)return isNewLine}if(this.isEol||this.isQuote)return true;return undefined};function isAlphadec(c){return c>="A"&&c<="Z"||c>="a"&&c<="z"||c>="0"&&c<="9"||"\u00e0\u00e8\u00ec\u00f2\u00f9\u00c0\u00c8\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00fd\u00c1\u00c9\u00cd\u00d3\u00da\u00dd\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e3\u00f1\u00f5\u00c3\u00d1\u00d5\u00e4\u00eb\u00ef\u00f6\u00fc\u00ff\u00c4\u00cb\u00cf\u00d6\u00dc\u0178\u00e7\u00c7\u00df\u00d8\u00f8\u00c5\u00e5\u00c6\u00e6\u0153".indexOf(c)!==
--1}function isBeginingOfLine(){var isNewLine=root.isBeginingOfLine();return isNewLine===undefined?true:isNewLine}MsgTextLeaf.prototype.addChar=function(i){this.text+=text[i];return 1};MsgBranch.prototype.addChar=function(i){var isFinished=this.lastNode&&!this.lastNode.terminated&&this.lastNode.finishWith?this.lastNode.finishWith(i):null;if(isFinished){var lastTriggerLen=this.lastNode.trigger.length;this.lastNode.terminate(i);if(isFinished instanceof MsgBranch){this.lastNode=isFinished;this.subNodes.push(isFinished)}return lastTriggerLen}else if(!this.lastNode||
-this.lastNode.terminated||this.lastNode instanceof MsgTextLeaf||this.lastNode.isAcceptable(i)){var isNewToken=this.isNewToken(i);if(isNewToken){this.lastNode=new MsgBranch(this,i,isNewToken);this.subNodes.push(this.lastNode);return this.lastNode.trigger.length}else{if(!this.lastNode||this.lastNode.terminated){this.lastNode=new MsgTextLeaf(this);this.subNodes.push(this.lastNode)}return this.lastNode.addChar(i)}}else{var revertTo=this.lastNode.triggerIndex+1;root.cancelTerminate(this.lastNode.triggerIndex);
-this.lastNode=new MsgTextLeaf(this);this.lastNode.addChar(revertTo-1);this.subNodes.pop();this.subNodes.push(this.lastNode);return revertTo-i}};MsgBranch.prototype.terminate=function(terminateAtIndex){var _this=this;while(_this){_this.terminated=terminateAtIndex;_this=_this.prevTwin}};MsgBranch.prototype.cancelTerminate=function(unTerminatedIndex){if(this.terminated&&this.terminated>=unTerminatedIndex)this.terminated=false;this.subNodes.forEach(function(node){if(node instanceof MsgBranch)node.cancelTerminate(unTerminatedIndex)})};
-MsgTextLeaf.prototype.innerHTML=function(){if(this._parent.checkIsEmoji()){var _parent=this._parent;while(_parent&&!_parent.isEmoji)_parent=_parent._parent;if(_parent){var fallback=_parent.trigger+this.text+_parent.trigger;var formatted=opts.emojiFormatFunction(fallback);return formatted?formatted:fallback}var formatted=opts.emojiFormatFunction(this.text);return formatted?formatted:this.text}if(this._parent.checkIsCodeBlock())return this.text.replace(/\n/g,"<br/>");return opts.textFilter(this.text)};
-MsgTextLeaf.prototype.outerHTML=function(){var tagName="span",classList=[],innerHTML,params="";if(this._parent.checkIsCodeBlock()){classList.push("codeblock");innerHTML=this.innerHTML()}else if(this._parent.checkIsCode()){classList.push("code");innerHTML=this.innerHTML()}else{if(this._parent.isLink){var link=opts.linkFilter(this.text);tagName="a";params=' href="'+link.link+'"';if(link.isExternal)params+=' target="_blank"';innerHTML=opts.textFilter(link.text)}else innerHTML=this.innerHTML();if(this._parent.checkIsBold())classList.push("bold");
-if(this._parent.checkIsItalic())classList.push("italic");if(this._parent.checkIsStrike())classList.push("strike");if(this._parent.checkIsEmoji())classList.push("emoji");if(this._parent.checkIsHighlight())classList.push("highlight")}return"<"+tagName+params+(classList.length?' class="'+classList.join(" ")+'"':"")+">"+innerHTML+"</"+tagName+">"};MsgBranch.prototype.outerHTML=function(){var html="";if(this.isQuote)html+='<span class="quote">';if(this.isEol)html+="<br/>";this.subNodes.forEach(function(node){html+=
-node.outerHTML()});if(this.isQuote)html+="</span>";return html};function getFirstUnterminated(_root){_root=_root||root;for(var i=0,nbBranches=_root.subNodes.length;i<nbBranches;i++){var branch=_root.subNodes[i];if(branch instanceof MsgBranch)if(!branch.terminated)return branch;else{var unTerminatedChild=getFirstUnterminated(branch);if(unTerminatedChild)return unTerminatedChild}}return null}function revertTree(branch,next){if(branch._parent instanceof MsgBranch){branch._parent.subNodes.splice(branch._parent.subNodes.indexOf(branch)+
-(next?1:0));branch._parent.lastNode=branch._parent.subNodes[branch._parent.subNodes.length-1];revertTree(branch._parent,true)}}MsgBranch.prototype.implicitClose=function(i){if(this.isQuote&&!this.terminated)this.terminate(i);this.subNodes.forEach(function(node){if(node instanceof MsgBranch)node.implicitClose(i)})};function eof(){root.implicitClose(text.length);var unterminated=getFirstUnterminated();if(unterminated){revertTree(unterminated,false);root.cancelTerminate(unterminated.triggerIndex);var textNode=
-new MsgTextLeaf(unterminated._parent);textNode.addChar(unterminated.triggerIndex);unterminated._parent.subNodes.push(textNode);unterminated._parent.lastNode=textNode;return unterminated.triggerIndex+1}else;}function identity(a){return a}function linkidentity(str){return{link:str,text:str,isInternal:false}}function _parse(_text,_opts){if(!_opts)_opts={};opts.highlights=_opts.highlights||[];opts.emojiFormatFunction=_opts.emojiFormatFunction||identity;opts.textFilter=_opts.textFilter||identity;opts.linkFilter=
-_opts.linkFilter||linkidentity;text=_text;root=new MsgBranch(this,0);var i=0,textLen=text.length;do{while(i<textLen)i+=root.addChar(i);i=eof()}while(i!==undefined);return root.outerHTML()}return _parse}();window["_formatText"]=function(str,opts){return formatText(str,{highlights:opts?opts["highlights"]:undefined})};if(typeof module!=="undefined")module.exports.formatText=formatText;function ConfirmDialog(title,content){this.title=title;this.content=content;this.dom=this.createDom();this.domOverlay=this.createDomOverlay();this.confirmHandlers=[];this.dissmissHandler=[]}
-ConfirmDialog.prototype.createDom=function(){var dom=document.createElement("div"),domTitle=document.createElement("header"),titleLabel=document.createElement("span"),closeButton=document.createElement("span"),domBody=document.createElement("div"),domButtons=document.createElement("footer");var _this=this;dom.confirmButton=document.createElement("span");dom.dissmissButton=document.createElement("span");titleLabel.textContent=this.title;if(typeof this.content=="string")domBody.innerHTML=this.content;
-else domBody.appendChild(this.content);domTitle.className=R.klass.dialog.title;titleLabel.className=R.klass.dialog.titleLabel;closeButton.className=R.klass.dialog.closeButton;closeButton.textContent="x";domTitle.appendChild(titleLabel);domTitle.appendChild(closeButton);dom.appendChild(domTitle);domBody.className=R.klass.dialog.body;dom.appendChild(domBody);dom.dissmissButton.className=R.klass.button;dom.dissmissButton.textContent=locale.dissmiss;dom.dissmissButton.addEventListener("click",function(){_this.buttonClicked(false)});
-closeButton.addEventListener("click",function(){_this.buttonClicked(false)});dom.confirmButton.addEventListener("click",function(){_this.buttonClicked(true)});domButtons.appendChild(dom.dissmissButton);dom.confirmButton.className=R.klass.button;dom.confirmButton.textContent=locale.ok;domButtons.appendChild(dom.confirmButton);domButtons.className=R.klass.buttonContainer+" "+R.klass.dialog.buttonBar;dom.appendChild(domButtons);dom.className=R.klass.dialog.container;return dom};
-ConfirmDialog.prototype.buttonClicked=function(confirmed){(confirmed?this.confirmHandlers:this.dissmissHandler).forEach(function(handler){handler()});this.close()};ConfirmDialog.prototype.createDomOverlay=function(){var dom=document.createElement("div");dom.className=R.klass.dialog.overlay;dom.addEventListener("click",function(){this.buttonClicked(false)}.bind(this));return dom};
-ConfirmDialog.prototype.setButtonText=function(confirmText,dissmissText){this.dom.confirmButton.textContent=confirmText;this.dom.dissmissButton.textContent=dissmissText;return this};ConfirmDialog.prototype.spawn=function(domParent){domParent=domParent||document.body;domParent.appendChild(this.domOverlay);domParent.appendChild(this.dom);return this};ConfirmDialog.prototype.close=function(){this.dom.remove();this.domOverlay.remove();return this};
-ConfirmDialog.prototype.onConfirm=function(handler){this.confirmHandlers.push(handler);return this};ConfirmDialog.prototype.onDissmiss=function(handler){this.dissmissHandler.push(handler);return this};var R={id:{chanList:"chanList",context:"slackCtx",chatList:"chatList",currentRoom:{title:"currentRoomTitle",content:"chatWindow"},typing:"whoistyping",message:{form:"msgForm",slashComplete:"slashList",input:"msgInput",replyTo:"replyToContainer",file:{bt:"attachFile",formContainer:"fileUploadContainer",fileInput:"fileUploadInput",form:"fileUploadForm",error:"fileUploadError",cancel:"fileUploadCancel"},emoji:"emojiButton"},favicon:"linkFavicon"},klass:{selected:"selected",hidden:"hidden",button:"button",
-buttonContainer:"button-container",noRoomSelected:"no-room-selected",noNetwork:"no-network",unread:"unread",unreadHi:"unreadHi",replyingTo:"replyingTo",presenceAway:"away",typing:{container:"typing-container",dot1:"typing-dot1",dot2:"typing-dot2",dot3:"typing-dot3"},emoji:{emoji:"emoji",small:"emoji-small",medium:"emoji-medium",custom:"emoji-custom"},commands:{item:"slack-command-item",header:"slack-command-header",name:"slack-command-name",usage:"slack-command-usage",desc:"slack-command-desc"},emojibar:{container:"emojibar",
-emojis:"emojibar-emojis",close:"emojibar-close",header:"emojibar-header",list:"emojibar-list",item:"emojibar-list-item",search:"emojibar-search",overlay:"emojibar-overlay",detail:{container:"emojibar-detail",img:"emojibar-detail-img",name:"emojibar-detail-name"}},chatList:{entry:"slack-context-room",typeChannel:"slack-channel",typePrivate:"slack-group",typeDirect:"slack-ims",typing:"slack-context-typing"},msg:{item:"slackmsg-item",notice:"slackmsg-notice",firstUnread:"slackmsg-first-unread",content:"slackmsg-content",
-meMessage:"slackmsg-me_message",ts:"slackmsg-ts",author:"slackmsg-author",authorname:"slackmsg-author-name",authorAvatar:"slackmsg-author-img",authorMessages:"slackmsg-author-messages",msg:"slackmsg-msg",editedStatus:"edited",edited:"slackmsg-edited",authorGroup:"slackmsg-authorGroup",sameTs:"slackmsg-same-ts",hover:{container:"slackmsg-hover",reply:"slackmsg-hover-reply",reaction:"slackmsg-hover-reaction",edit:"slackmsg-hover-edit",remove:"slackmsg-hover-remove"},replyTo:{close:"replyto-close"},
-link:"slackmsg-link",linkuser:"slackmsg-link-user",linkchan:"slackmsg-link-chan",attachment:{container:"slackmsg-attachment",list:"slackmsg-attachments",hasThumb:"has-thumb",pretext:"slackmsg-attachment-pretext",block:"slackmsg-attachment-block",title:"slackmsg-attachment-title",content:"slackmsg-attachment-content",text:"slackmsg-attachment-text",thumbImg:"slackmsg-attachment-thumb",img:"slackmsg-attachment-img",actions:"slackmsg-attachment-actions",actionItem:"slackmsg-attachment-actions-item",
-field:{container:"slackmsg-attachment-fields",item:"field",title:"field-title",text:"field-text",longField:"field-long"},footer:"slackmsg-attachment-footer",footerText:"slackmsg-attachment-footer-text",footerIcon:"slackmsg-attachment-footer-icon"},reactions:{container:"slackmsg-reactions",item:"slackmsg-reaction-item"},style:{bold:"slackmsg-style-bold",code:"slackmsg-style-code",longCode:"slackmsg-style-longcode",italic:"slackmsg-style-italic",strike:"slackmsg-style-strike",quote:"slackmsg-style-quote"}},
-dialog:{container:"dialog",overlay:"dialog-overlay",title:"dialog-title",titleLabel:"dialog-title-label",closeButton:"dialog-title-close",body:"dialog-body",buttonBar:"dialog-footer"}}};var NOTIFICATION_COOLDOWN=30*1E3,NOTIFICATION_DELAY=5*1E3,MSG_GROUPS=[],lastNotificationSpawn=0;
-function onContextUpdated(){var chanListFram=document.createDocumentFragment(),sortedChans=Object.keys(SLACK.context.channels||{}),starred=[],channels=[],privs=[],priv=[];sortedChans.sort(function(a,b){if(a[0]!==b[0])return a[0]-b[0];return SLACK.context.channels[a].name.localeCompare(SLACK.context.channels[b].name)});sortedChans.forEach(function(chanId){var chan=SLACK.context.channels[chanId];if(!chan.archived&&chan.isMember!==false)if(chan instanceof PrivateMessageRoom){if(!chan.user.deleted){var chanListItem=
-createImsListItem(chan);if(chanListItem)if(chan.starred)starred.push(chanListItem);else priv.push(chanListItem)}}else{var chanListItem=createChanListItem(chan);if(chanListItem)if(chan.starred)starred.push(chanListItem);else if(chan.isPrivate)privs.push(chanListItem);else channels.push(chanListItem)}});if(starred.length)chanListFram.appendChild(createChanListHeader(locale.starred));starred.forEach(function(dom){chanListFram.appendChild(dom)});if(channels.length)chanListFram.appendChild(createChanListHeader(locale.channels));
-channels.forEach(function(dom){chanListFram.appendChild(dom)});privs.forEach(function(dom){chanListFram.appendChild(dom)});if(priv.length)chanListFram.appendChild(createChanListHeader(locale.privateMessageRoom));priv.forEach(function(dom){chanListFram.appendChild(dom)});document.getElementById(R.id.chanList).textContent="";document.getElementById(R.id.chanList).appendChild(chanListFram);setRoomFromHashBang();updateTitle();createContextBackground(function(imgData){document.getElementById(R.id.context).style.backgroundImage=
-"url("+imgData+")"})}
-function onTypingUpdated(){var typing=SLACK.context.typing;for(var chanId in SLACK.context.self.channels)if(!SLACK.context.self.channels[chanId].archived){var dom=document.getElementById("room_"+chanId);if(typing[chanId])dom.classList.add(R.klass.chatList.typing);else dom.classList.remove(R.klass.chatList.typing)}for(var userId in SLACK.context.users){var ims=SLACK.context.users[userId].privateRoom;if(ims&&!ims.archived){var dom=document.getElementById("room_"+ims.id);if(dom)if(typing[ims.id])dom.classList.add(R.klass.chatList.typing);else dom.classList.remove(R.klass.chatList.typing)}}updateTypingChat()}
-function updateTypingChat(){var typing=SLACK.context.typing;document.getElementById(R.id.typing).textContent="";if(SELECTED_ROOM&&typing[SELECTED_ROOM.id]){var areTyping=document.createDocumentFragment(),isOutOfSync=false;for(var i in typing[SELECTED_ROOM.id]){var member=SLACK.context.users[i];if(member)areTyping.appendChild(makeUserIsTypingDom(member));else isOutOfSync=true}if(isOutOfSync)outOfSync();document.getElementById(R.id.typing).appendChild(areTyping)}}
-function onNetworkStateUpdated(isNetworkWorking){isNetworkWorking?document.body.classList.remove(R.klass.noNetwork):document.body.classList.add(R.klass.noNetwork);updateTitle()}
-function onRoomSelected(){var name=SELECTED_ROOM.name||(SELECTED_ROOM.user?SELECTED_ROOM.user.name:undefined);if(!name){var members=[];SELECTED_ROOM.users.forEach(function(i){members.push(i.name)});name=members.join(", ")}var roomLi=document.getElementById("room_"+SELECTED_ROOM.id);document.getElementById(R.id.currentRoom.title).textContent=name;onRoomUpdated();focusInput();document.getElementById(R.id.message.file.formContainer).classList.add(R.klass.hidden);markRoomAsRead(SELECTED_ROOM);if(REPLYING_TO){REPLYING_TO=
-null;onReplyingToUpdated()}if(EDITING){EDITING=null;onReplyingToUpdated()}updateTypingChat()}
-function onReplyingToUpdated(){if(REPLYING_TO){document.body.classList.add(R.klass.replyingTo);var domParent=document.getElementById(R.id.message.replyTo),closeLink=document.createElement("a");closeLink.addEventListener("click",function(){REPLYING_TO=null;onReplyingToUpdated()});closeLink.className=R.klass.msg.replyTo.close;closeLink.textContent="x";domParent.textContent="";domParent.appendChild(closeLink);domParent.appendChild(REPLYING_TO.duplicateDom());focusInput()}else{document.body.classList.remove(R.klass.replyingTo);
-document.getElementById(R.id.message.replyTo).textContent="";focusInput()}}
-function onEditingUpdated(){if(EDITING){document.body.classList.add(R.klass.replyingTo);var domParent=document.getElementById(R.id.message.replyTo),closeLink=document.createElement("a");closeLink.addEventListener("click",function(){EDITING=null;onEditingUpdated()});closeLink.className=R.klass.msg.replyTo.close;closeLink.textContent="x";domParent.textContent="";domParent.appendChild(closeLink);domParent.appendChild(EDITING.duplicateDom());document.getElementById(R.id.message.input).value=EDITING.text;
-focusInput()}else{document.body.classList.remove(R.klass.replyingTo);document.getElementById(R.id.message.replyTo).textContent="";focusInput()}}window["toggleReaction"]=function(chanId,msgId,reaction){var hist=SLACK.history[chanId];if(!hist)return;var msg=hist.getMessageById(msgId);if(msg)if(msg.hasReactionForUser(reaction,SLACK.context.self.id))removeReaction(chanId,msgId,reaction);else addReaction(chanId,msgId,reaction)};
-function tryGetCustomEmoji(emoji){var loop={};while(!loop[emoji]){var emojisrc=SLACK.context.emojis.data[emoji];if(emojisrc)if(emojisrc.substr(0,6)=="alias:"){loop[emoji]=true;emoji=emojisrc.substr(6)}else{var dom=document.createElement("span");dom.className=R.klass.emoji.custom+" "+R.klass.emoji.emoji;dom.style.backgroundImage="url('"+emojisrc+"')";return dom}return emoji}return emoji}
-function makeEmojiDom(emojiCode){var emoji=tryGetCustomEmoji(emojiCode);if(typeof emoji==="string"&&"makeEmoji"in window)emoji=window["makeEmoji"](emoji);return typeof emoji==="string"?null:emoji}function setFavicon(unreadhi,unread){if(!unreadhi&&!unread)document.getElementById(R.id.favicon).href="favicon_ok.png";else document.getElementById(R.id.favicon).href="favicon.png?h="+unreadhi+"&m="+unread}function setNetErrorFavicon(){document.getElementById(R.id.favicon).href="favicon_err.png"}
-function updateTitle(){var hasHl=HIGHLIGHTED_CHANS.length,title="";if(NEXT_RETRY){title="!"+locale.netErrorShort+" - ";setNetErrorFavicon()}else if(hasHl){title="(!"+hasHl+") - ";setFavicon(hasHl,hasHl)}else{var hasUnread=0;for(var chanId in SLACK.context.channels){var i=SLACK.context.channels[chanId];if(i.lastMsg>i.lastRead)hasUnread++}if(hasUnread)title="("+hasUnread+") - ";setFavicon(0,hasUnread)}if(SLACK.context.team)title+=SLACK.context.team.name;document.title=title}
-function spawnNotification(){if(!("Notification"in window));else if(Notification.permission==="granted"){var now=Date.now();if(lastNotificationSpawn+NOTIFICATION_COOLDOWN<now){var n=new Notification(locale.newMessage);lastNotificationSpawn=now;setTimeout(function(){n.close()},NOTIFICATION_DELAY)}}else if(Notification.permission!=="denied")Notification.requestPermission()}
-function onRoomUpdated(){var chatFrag=document.createDocumentFragment(),currentRoomId=SELECTED_ROOM.id,prevMsg=null,firstTsCombo=0,prevMsgDom=null,currentMsgGroupDom;MSG_GROUPS=[];if(SLACK.history[currentRoomId])SLACK.history[currentRoomId].messages.forEach(function(msg){if(!msg.removed){var dom=msg.getDom(),newGroupDom=false;if(prevMsg&&prevMsg.userId===msg.userId&&msg.userId)if(Math.abs(firstTsCombo-msg.ts)<30&&!(msg instanceof MeMessage))prevMsgDom.classList.add(R.klass.msg.sameTs);else firstTsCombo=
-msg.ts;else{firstTsCombo=msg.ts;newGroupDom=true}if((!prevMsg||prevMsg.ts<=SELECTED_ROOM.lastRead)&&msg.ts>SELECTED_ROOM.lastRead)dom.classList.add(R.klass.msg.firstUnread);else dom.classList.remove(R.klass.msg.firstUnread);if(msg instanceof MeMessage){prevMsg=null;prevMsgDom=null;firstTsCombo=0;newGroupDom=true;chatFrag.appendChild(dom);currentMsgGroupDom=null}else{if(newGroupDom||!currentMsgGroupDom){currentMsgGroupDom=createMessageGroupDom(SLACK.context.users[msg.userId],msg.username);MSG_GROUPS.push(currentMsgGroupDom);
-chatFrag.appendChild(currentMsgGroupDom)}prevMsg=msg;prevMsgDom=dom;currentMsgGroupDom.content.appendChild(dom)}}else msg.removeDom()});var content=document.getElementById(R.id.currentRoom.content);content.textContent="";content.appendChild(chatFrag);content.scrollTop=content.scrollHeight-content.clientHeight;if(window.hasFocus)markRoomAsRead(SELECTED_ROOM)}
-function chatClickDelegate(e){var target=e.target,getMessageId=function(e,target){target=target||e.target;while(target!==e.currentTarget&&target){if(target.classList.contains(R.klass.msg.item))return target.id;target=target.parentElement}};while(target!==e.currentTarget&&target){if(target.classList.contains(R.klass.msg.hover.container))return;else if(target.parentElement&&target.classList.contains(R.klass.msg.attachment.actionItem)){var messageId=getMessageId(e,target),attachmentIndex=target.dataset["attachmentIndex"],
-actionIndex=target.dataset["actionIndex"];if(messageId&&attachmentIndex!==undefined&&actionIndex!==undefined){messageId=parseFloat(messageId.split("_")[1]);var msg=SLACK.history[SELECTED_ROOM.id].getMessage(messageId);if(msg&&msg.attachments[attachmentIndex]&&msg.attachments[attachmentIndex].actions&&msg.attachments[attachmentIndex].actions[actionIndex])confirmAction(SELECTED_ROOM.id,msg,msg.attachments[attachmentIndex],msg.attachments[attachmentIndex].actions[actionIndex])}}else if(target.parentElement&&
-target.parentElement.classList.contains(R.klass.msg.hover.container)){var messageId=getMessageId(e,target);if(messageId){messageId=parseFloat(messageId.split("_")[1]);var msg=SLACK.history[SELECTED_ROOM.id].getMessage(messageId);if(msg&&target.classList.contains(R.klass.msg.hover.reply)){if(EDITING){EDITING=null;onEditingUpdated()}if(REPLYING_TO!==msg){REPLYING_TO=msg;onReplyingToUpdated()}}else if(msg&&target.classList.contains(R.klass.msg.hover.reaction))EMOJI_BAR.spawn(document.body,function(emoji){if(emoji)addReaction(SELECTED_ROOM.id,
-msg.id,emoji)});else if(msg&&target.classList.contains(R.klass.msg.hover.edit)){if(REPLYING_TO){REPLYING_TO=null;onReplyingToUpdated()}if(EDITING!==msg){EDITING=msg;onEditingUpdated()}}else if(msg&&target.classList.contains(R.klass.msg.hover.remove)){if(REPLYING_TO){REPLYING_TO=null;onReplyingToUpdated()}if(EDITING){EDITING=null;onEditingUpdated()}removeMsg(SELECTED_ROOM,msg)}}return}target=target.parentElement}}
-function confirmAction(roomId,msg,attachmentObject,actionObject){var confirmed=function(){var payload=getActionPayload(roomId,msg,attachmentObject,actionObject);sendCommand(payload,msg.userId)};if(actionObject["confirm"])(new ConfirmDialog(actionObject["confirm"]["title"],actionObject["confirm"]["text"])).setButtonText(actionObject["confirm"]["ok_text"],actionObject["confirm"]["dismiss_text"]).onConfirm(confirmed).spawn();else confirmed()}
-function focusInput(){document.getElementById(R.id.message.input).focus()}function setRoomFromHashBang(){var hashId=document.location.hash.substr(1),room=SLACK.context.channels[hashId];if(room&&room!==SELECTED_ROOM)selectRoom(room);else{var user=SLACK.context.users[hashId];if(user&&user.ims)selectRoom(user.ims)}}
-function updateAuthorAvatarImsOffset(){var chatDom=document.getElementById(R.id.currentRoom.content),chatTop=chatDom.getBoundingClientRect().top;MSG_GROUPS.forEach(function(group){var imgDom=group.authorImg,imgSize=imgDom.clientHeight,domRect=group.getBoundingClientRect(),_top=0;imgDom.style.top=Math.max(0,Math.min(chatTop-domRect.top,domRect.height-imgSize-imgSize/2))+"px"})}
-document.addEventListener("DOMContentLoaded",function(){initLang();document.getElementById(R.id.currentRoom.content).addEventListener("click",chatClickDelegate);window.addEventListener("hashchange",function(e){if(document.location.hash&&document.location.hash[0]==="#")setRoomFromHashBang()});document.getElementById(R.id.message.file.cancel).addEventListener("click",function(e){e.preventDefault();document.getElementById(R.id.message.file.error).classList.add(R.klass.hidden);document.getElementById(R.id.message.file.formContainer).classList.add(R.klass.hidden);
-document.getElementById(R.id.message.file.fileInput).value="";return false});document.getElementById(R.id.message.file.form).addEventListener("submit",function(e){e.preventDefault();var fileInput=document.getElementById(R.id.message.file.fileInput),filename=fileInput.value;if(filename){filename=filename.substr(filename.lastIndexOf("\\")+1);uploadFile(SELECTED_ROOM,filename,fileInput.files[0],function(errorMsg){var error=document.getElementById(R.id.message.file.error);if(errorMsg){error.textContent=
-errorMsg;error.classList.remove(R.klass.hidden)}else{error.classList.add(R.klass.hidden);document.getElementById(R.id.message.file.fileInput).value="";document.getElementById(R.id.message.file.formContainer).classList.add(R.klass.hidden)}})}return false});document.getElementById(R.id.message.file.bt).addEventListener("click",function(e){e.preventDefault();if(SELECTED_ROOM)document.getElementById(R.id.message.file.formContainer).classList.remove(R.klass.hidden);return false});document.getElementById(R.id.message.form).addEventListener("submit",
-function(e){e.preventDefault();var input=document.getElementById(R.id.message.input);if(SELECTED_ROOM&&input.value)if(onTextEntered(input.value)){input.value="";if(REPLYING_TO){REPLYING_TO=null;onReplyingToUpdated()}if(EDITING){EDITING=null;onReplyingToUpdated()}document.getElementById(R.id.message.slashComplete).textContent=""}focusInput();return false});window.addEventListener("blur",function(){window.hasFocus=false});window.addEventListener("focus",function(){window.hasFocus=true;lastNotificationSpawn=
-0;if(SELECTED_ROOM)markRoomAsRead(SELECTED_ROOM);focusInput()});document.getElementById(R.id.currentRoom.content).addEventListener("scroll",updateAuthorAvatarImsOffset);var lastKeyDown=0;document.getElementById(R.id.message.input).addEventListener("input",function(){if(SELECTED_ROOM){var now=Date.now();if(lastKeyDown+3E3<now&&(SLACK.context.self.presence||SELECTED_ROOM instanceof PrivateMessageRoom)){sendTyping(SELECTED_ROOM);lastKeyDown=now}var commands=[],input=this.value;if(this.value[0]==="/"){var endCmd=
-input.indexOf(" "),inputFinished=endCmd!==-1;endCmd=endCmd===-1?input.length:endCmd;var inputCmd=input.substr(0,endCmd);for(var i in SLACK.context.commands.data){var currentCmd=SLACK.context.commands.data[i];if(!inputFinished&&currentCmd.name.substr(0,endCmd)===inputCmd||inputFinished&&currentCmd.name===inputCmd)commands.push(currentCmd)}}commands.sort(function(a,b){return a.category.localeCompare(b.category)||a.name.localeCompare(b.name)});var slashDom=document.getElementById(R.id.message.slashComplete),
-slashFrag=document.createDocumentFragment(),prevService;slashDom.textContent="";for(var i=0,nbCmd=commands.length;i<nbCmd;i++){var command=commands[i];if(prevService!==command.category){prevService=command.category;slashFrag.appendChild(createSlashAutocompleteHeader(command.category))}slashFrag.appendChild(createSlashAutocompleteDom(command))}slashDom.appendChild(slashFrag)}});window.hasFocus=true;(function(){var emojiButton=document.getElementById(R.id.message.emoji);if("makeEmoji"in window){var emojiDom=
-window["makeEmoji"]("smile");if(emojiDom)emojiButton.innerHTML="<span class='"+R.klass.emoji.small+"'>"+emojiDom.outerHTML+"</span>";else emojiButton.style.backgroundImage='url("smile.svg")';emojiDom=window["makeEmoji"]("paperclip");if(emojiDom)document.getElementById(R.id.message.file.bt).innerHTML="<span class='"+R.klass.emoji.small+"'>"+emojiDom.outerHTML+"</span>";else document.getElementById(R.id.message.file.bt).style.backgroundImage='url("public/paperclip.svg")';emojiButton.addEventListener("click",
-function(){EMOJI_BAR.spawn(document.body,function(e){if(e)document.getElementById(R.id.message.input).value+=":"+e+":";focusInput()})})}else emojiButton.classList.add(R.klass.hidden)})();startPolling()});function createTypingDisplay(){var dom=document.createElement("span"),dot1=document.createElement("span"),dot2=document.createElement("span"),dot3=document.createElement("span");dom.className=R.klass.typing.container;dot1.className=R.klass.typing.dot1;dot2.className=R.klass.typing.dot2;dot3.className=R.klass.typing.dot3;dot1.textContent=dot2.textContent=dot3.textContent=".";dom.appendChild(dot1);dom.appendChild(dot2);dom.appendChild(dot3);return dom}
-function createChanListItem(chan){var dom=document.createElement("li"),link=document.createElement("a");dom.id="room_"+chan.id;link.href="#"+chan.id;if(chan.isPrivate){dom.className=R.klass.chatList.entry+" "+R.klass.chatList.typePrivate;dom.dataset["count"]=Object.keys(chan.users||{}).length}else dom.className=R.klass.chatList.entry+" "+R.klass.chatList.typeChannel;if(SELECTED_ROOM===chan)dom.classList.add(R.klass.selected);link.textContent=chan.name;dom.appendChild(createTypingDisplay());dom.appendChild(link);
-if(chan.lastMsg>chan.lastRead){dom.classList.add(R.klass.unread);if(HIGHLIGHTED_CHANS.indexOf(chan)>=0)dom.classList.add(R.klass.unreadHi)}return dom}var createChanListHeader=function(){var cache={};return function(title){var dom=cache[title];if(!dom){dom=cache[title]=document.createElement("header");dom.textContent=title}return dom}}();
-function createImsListItem(ims){var dom=document.createElement("li"),link=document.createElement("a");dom.id="room_"+ims.id;link.href="#"+ims.id;dom.className=R.klass.chatList.entry+" "+R.klass.chatList.typeDirect;link.textContent=ims.user.name;dom.appendChild(createTypingDisplay());dom.appendChild(link);if(!ims.user.presence)dom.classList.add(R.klass.presenceAway);if(SELECTED_ROOM===ims)dom.classList.add(R.klass.selected);if(ims.lastMsg>ims.lastRead){dom.classList.add(R.klass.unread);if(HIGHLIGHTED_CHANS.indexOf(ims)>=
-0)dom.classList.add(R.klass.unreadHi)}return dom}
-function createReactionDom(chanId,msgId,reaction,users){var emojiDom=makeEmojiDom(reaction);if(emojiDom){var dom=document.createElement("li"),a=document.createElement("a"),emojiContainer=document.createElement("span"),userList=document.createElement("span"),userNames=[];for(var i=0,nbUser=users.length;i<nbUser;i++){var user=SLACK.context.users[users[i]];if(user)userNames.push(user.name)}userNames.sort();userList.textContent=userNames.join(", ");emojiContainer.appendChild(emojiDom);emojiContainer.className=
-R.klass.emoji.small;a.href="javascript:toggleReaction('"+chanId+"', '"+msgId+"', '"+reaction+"')";a.appendChild(emojiContainer);a.appendChild(userList);dom.className=R.klass.msg.reactions.item;dom.appendChild(a);return dom}else console.warn("Reaction id not found: "+reaction);return null}
-function doCreateMessageDom(msg,skipAttachment){var channelId=msg.channelId;var dom=document.createElement("div"),msgBlock=document.createElement("div"),hover=document.createElement("ul"),hoverReply=document.createElement("li");dom.attachments=document.createElement("ul");dom.reactions=document.createElement("ul");dom.ts=document.createElement("div");dom.textDom=document.createElement("div");dom.authorName=document.createElement("span");dom.id=channelId+"_"+msg.id;dom.className=R.klass.msg.item;dom.ts.className=
-R.klass.msg.ts;dom.textDom.className=R.klass.msg.msg;dom.authorName.className=R.klass.msg.authorname;hover.className=R.klass.msg.hover.container;hoverReply.className=R.klass.msg.hover.reply;hover.appendChild(hoverReply);if("makeEmoji"in window){var hoverReaction=document.createElement("li"),domReply=window["makeEmoji"]("arrow_heading_down"),domReaction=window["makeEmoji"]("smile"),domEdit=window["makeEmoji"]("pencil2"),domRemove=window["makeEmoji"]("x");hoverReaction.className=R.klass.msg.hover.reaction;
-if(domReaction){hoverReaction.classList.add(R.klass.emoji.small);hoverReaction.appendChild(domReaction)}else hoverReaction.style.backgroundImage='url("smile.svg")';if(domReply){hoverReply.classList.add(R.klass.emoji.small);hoverReply.appendChild(domReply)}else hoverReply.style.backgroundImage='url("repl.svg")';hover.appendChild(hoverReaction);if(msg.userId===SLACK.context.self.id){var hoverEdit=document.createElement("li");hoverEdit.className=R.klass.msg.hover.edit;if(domEdit)hoverEdit.classList.add(R.klass.emoji.small);
-else hoverEdit.style.backgroundImage='url("edit.svg")';hoverEdit.appendChild(domEdit);hover.appendChild(hoverEdit);var hoverRemove=document.createElement("li");hoverRemove.className=R.klass.msg.hover.remove;if(domRemove)hoverRemove.classList.add(R.klass.emoji.small);else hoverRemove.style.backgroundImage='url("remove.svg")';hoverRemove.appendChild(domRemove);hover.appendChild(hoverRemove)}}else{hoverReply.style.backgroundImage='url("repl.svg")';if(msg.userId===SLACK.context.self.id){var hoverEdit=
-document.createElement("li");hoverEdit.className=R.klass.msg.hover.edit;hoverEdit.style.backgroundImage='url("edit.svg")';hover.appendChild(hoverEdit);var hoverRemove=document.createElement("li");hoverRemove.className=R.klass.msg.hover.remove;hoverRemove.style.backgroundImage='url("remove.svg")';hover.appendChild(hoverRemove)}}msgBlock.appendChild(dom.authorName);msgBlock.appendChild(dom.textDom);msgBlock.appendChild(dom.ts);msgBlock.appendChild(dom.attachments);var edited=document.createElement("div");
-edited.innerHTML=locale.edited;edited.className=R.klass.msg.edited;msgBlock.appendChild(edited);msgBlock.appendChild(dom.reactions);msgBlock.className=R.klass.msg.content;dom.attachments.className=R.klass.msg.attachment.list;dom.reactions.className=R.klass.msg.reactions.container;dom.appendChild(msgBlock);dom.appendChild(hover);return dom}
-function createMessageGroupDom(user,userName){var dom=document.createElement("div"),authorBlock=document.createElement("div"),authorName=document.createElement("span");dom.authorImg=document.createElement("img");dom.authorImg.className=R.klass.msg.authorAvatar;authorName.className=R.klass.msg.authorname;if(user){authorName.textContent=user.name;dom.authorImg.src="api/avatar?user="+user.id}else{authorName.textContent=userName||"?";dom.authorImg.src=""}authorBlock.appendChild(dom.authorImg);authorBlock.appendChild(authorName);
-authorBlock.className=R.klass.msg.author;dom.className=R.klass.msg.authorGroup;dom.appendChild(authorBlock);dom.content=document.createElement("div");dom.content.className=R.klass.msg.authorMessages;dom.appendChild(dom.content);return dom}function getColor(colorText){var colorMap={"good":"#2fa44f","warning":"#de9e31","danger":"#d50200"};if(colorText)if(colorText[0]==="#")return colorText;else if(colorMap[colorText])return colorMap[colorText];return"#e3e4e6"}
-function createAttachmentDom(channelId,msg,attachment,attachmentIndex){var rootDom=document.createElement("li"),attachmentBlock=document.createElement("div"),pretext=document.createElement("div"),titleBlock=document.createElement("a"),authorBlock=document.createElement("div"),authorImg=document.createElement("img"),authorName=document.createElement("a"),textBlock=document.createElement("div"),textDom=document.createElement("div"),thumbImgDom=document.createElement("div"),imgDom=document.createElement("img"),
-footerBlock=document.createElement("div");rootDom.className=R.klass.msg.attachment.container;attachmentBlock.style.borderColor=getColor(attachment["color"]||"");attachmentBlock.className=R.klass.msg.attachment.block;pretext.className=R.klass.msg.attachment.pretext;if(attachment["pretext"])pretext.innerHTML=msg.formatText(attachment["pretext"]);else pretext.classList.add(R.klass.hidden);titleBlock.target="_blank";if(attachment["title"]){titleBlock.innerHTML=msg.formatText(attachment["title"]);if(attachment["title_link"])titleBlock.href=
-attachment["title_link"];titleBlock.className=R.klass.msg.attachment.title}else titleBlock.className=R.klass.hidden+" "+R.klass.msg.attachment.title;authorName.target="_blank";authorBlock.className=R.klass.msg.author;if(attachment["author_name"]){authorName.innerHTML=msg.formatText(attachment["author_name"]);authorName.href=attachment["author_link"]||"";authorName.className=R.klass.msg.authorname;authorImg.className=R.klass.msg.authorAvatar;if(attachment["author_icon"]){authorImg.src=attachment["author_icon"];
-authorBlock.appendChild(authorImg)}authorBlock.appendChild(authorName)}thumbImgDom.className=R.klass.msg.attachment.thumbImg;if(attachment["thumb_url"]){var img=document.createElement("img");img.src=attachment["thumb_url"];thumbImgDom.appendChild(img);attachmentBlock.classList.add(R.klass.msg.attachment.hasThumb);if(attachment["video_html"])thumbImgDom.dataset["video"]=attachment["video_html"]}else thumbImgDom.classList.add(R.klass.hidden);textBlock.className=R.klass.msg.attachment.content;var textContent=
-msg.formatText(attachment["text"]||"");textDom.className=R.klass.msg.attachment.text;if(textContent&&textContent!="")textDom.innerHTML=textContent;else textDom.classList.add(R.klass.hidden);imgDom.className=R.klass.msg.attachment.img;if(attachment["image_url"])imgDom.src=attachment["image_url"];else imgDom.classList.add(R.klass.hidden);footerBlock.className=R.klass.msg.attachment.footer;if(attachment["footer"]){var footerText=document.createElement("span");footerText.className=R.klass.msg.attachment.footerText;
-footerText.innerHTML=msg.formatText(attachment["footer"]);if(attachment["footer_icon"]){var footerIcon=document.createElement("img");footerIcon.src=attachment["footer_icon"];footerIcon.className=R.klass.msg.attachment.footerIcon;footerBlock.appendChild(footerIcon)}footerBlock.appendChild(footerText)}if(attachment["ts"]){var footerTs=document.createElement("span");footerTs.className=R.klass.msg.ts;footerTs.innerHTML=locale.formatDate(attachment["ts"]);footerBlock.appendChild(footerTs)}textBlock.appendChild(thumbImgDom);
-textBlock.appendChild(textDom);attachmentBlock.appendChild(titleBlock);attachmentBlock.appendChild(authorBlock);attachmentBlock.appendChild(textBlock);attachmentBlock.appendChild(imgDom);if(attachment["fields"]&&attachment["fields"].length){var fieldsContainer=document.createElement("ul");attachmentBlock.appendChild(fieldsContainer);fieldsContainer.className=R.klass.msg.attachment.field.container;attachment["fields"].forEach(function(fieldData){var fieldDom=createFieldDom(msg,fieldData["title"]||
-"",fieldData["value"]||"",!!fieldData["short"]);if(fieldDom)fieldsContainer.appendChild(fieldDom)})}if(attachment["actions"]&&attachment["actions"].length){var buttons;buttons=document.createElement("ul");buttons.className=R.klass.msg.attachment.actions+" "+R.klass.buttonContainer;attachmentBlock.appendChild(buttons);for(var i=0,nbAttachments=attachment["actions"].length;i<nbAttachments;i++){var action=attachment["actions"][i];if(action){var button=createActionButtonDom(attachmentIndex,i,action);
-if(button)buttons.appendChild(button)}}}attachmentBlock.appendChild(footerBlock);rootDom.appendChild(pretext);rootDom.appendChild(attachmentBlock);return rootDom}
-function createFieldDom(msg,title,text,isShort){var fieldDom=document.createElement("li"),titleDom=document.createElement("div"),textDom=document.createElement("div");fieldDom.className=R.klass.msg.attachment.field.item;if(!isShort)fieldDom.classList.add(R.klass.msg.attachment.field.longField);titleDom.className=R.klass.msg.attachment.field.title;titleDom.textContent=title;textDom.className=R.klass.msg.attachment.field.text;textDom.innerHTML=msg.formatText(text);fieldDom.appendChild(titleDom);fieldDom.appendChild(textDom);
-return fieldDom}function createActionButtonDom(attachmentIndex,actionIndex,action){var li=document.createElement("li"),color=getColor(action["style"]);li.textContent=action["text"];if(color!==getColor())li.style.color=color;li.style.borderColor=color;li.dataset["attachmentIndex"]=attachmentIndex;li.dataset["actionIndex"]=actionIndex;li.className=R.klass.msg.attachment.actionItem+" "+R.klass.button;return li}
-function makeUserIsTypingDom(user){var dom=document.createElement("li"),userName=document.createElement("span");userName.textContent=user.name;dom.appendChild(createTypingDisplay());dom.appendChild(userName);return dom}function createSlashAutocompleteHeader(servicename){var lh=document.createElement("lh");lh.textContent=servicename;lh.className=R.klass.commands.header;return lh}
-function createSlashAutocompleteDom(cmd){var li=document.createElement("li"),name=document.createElement("span"),usage=document.createElement("span"),desc=document.createElement("span");name.textContent=cmd.name;usage.textContent=cmd.usage;desc.textContent=cmd.desc;li.appendChild(name);li.appendChild(usage);li.appendChild(desc);li.className=R.klass.commands.item;name.className=R.klass.commands.name;usage.className=R.klass.commands.usage;desc.className=R.klass.commands.desc;return li};var EMOJI_BAR=function(){var dom=document.createElement("div"),overlay=document.createElement("div"),emojisDom=document.createElement("div"),unicodeEmojis=document.createElement("ul"),customEmojis=document.createElement("ul"),searchBar=document.createElement("input"),emojiCache={unicode:{},custom:{}},emojiDetail=document.createElement("div"),emojiDetailImg=document.createElement("span"),emojiDetailName=document.createElement("span"),emojiSelectedHandler,isSupported=function(){return"searchEmojis"in
-window},makeHeader=function(imgSrc){var img=document.createElement("img"),dom=document.createElement("div");img.src=imgSrc;dom.appendChild(img);dom.className=R.klass.emojibar.header;return dom},wrapEmojiLi=function(emojiName,emojiDom){var dom=document.createElement("li");dom.appendChild(emojiDom);dom.className=R.klass.emojibar.item;dom.id="emojibar-"+emojiName;return{visible:false,dom:dom}},makeUnicodeEmojiLi=function(emojiName,emoji){var domEmoji=window["makeEmoji"](emoji),domParent=document.createElement("span");
-domParent.appendChild(domEmoji);domParent.className=R.klass.emoji.medium;return wrapEmojiLi(emojiName,domParent)},makeCustomEmoji=function(emojiName,emojiSrc){var domEmoji=document.createElement("span"),domParent=document.createElement("span");domEmoji.className=R.klass.emoji.emoji+" "+R.klass.emoji.custom;domEmoji.style.backgroundImage='url("'+emojiSrc+'")';domParent.appendChild(domEmoji);domParent.className=R.klass.emoji.medium;return wrapEmojiLi(emojiName,domParent)},sortEmojis=function(emojiObj,
-favoriteEmojis){var names=[],index=0;for(var i in emojiObj){var obj={name:i,pos:index,count:0};if(emojiObj[i].names)emojiObj[i].names.forEach(function(name){obj.count+=favoriteEmojis[name]||0});names.push(obj)}names=names.sort(function(a,b){var diff=b.count-a.count;if(diff)return diff;return a.pos-b.pos});return names},search=function(queryString){var emojiCount=0,toRemove=[],sortedEmojiNames;queryString=queryString===undefined?searchBar.value:queryString;if(isSupported()){var foundEmojis=window["searchEmojis"](queryString);
-sortedEmojiNames=sortEmojis(foundEmojis,SLACK.context.self.prefs.favoriteEmojis);for(var i in emojiCache.unicode)if(emojiCache.unicode[i].visible){emojiCache.unicode[i].visible=false;unicodeEmojis.removeChild(emojiCache.unicode[i].dom)}for(var i=0,nbEmojis=sortedEmojiNames.length;i<nbEmojis;i++){var emojiName=sortedEmojiNames[i].name,e=emojiCache.unicode[emojiName];if(!e)e=emojiCache.unicode[emojiName]=makeUnicodeEmojiLi(emojiName,foundEmojis[emojiName]);if(!e.visible){e.visible=true;unicodeEmojis.appendChild(e.dom)}emojiCount++}}for(var i in emojiCache.custom)if(emojiCache.custom[i].visible){emojiCache.custom[i].visible=
-false;customEmojis.removeChild(emojiCache.custom[i].dom)}sortedEmojiNames=sortEmojis(SLACK.context.emojis.data,SLACK.context.self.prefs.favoriteEmojis);for(var i=0,nbEmojis=sortedEmojiNames.length;i<nbEmojis;i++){var emojiName=sortedEmojiNames[i].name;if((queryString===""||emojiName.substr(0,queryString.length)===queryString)&&SLACK.context.emojis.data[emojiName].substr(0,6)!=="alias:"){var e=emojiCache.custom[emojiName];if(!e)e=emojiCache.custom[emojiName]=makeCustomEmoji(emojiName,SLACK.context.emojis.data[emojiName]);
-if(!e.visible){e.visible=true;customEmojis.appendChild(e.dom)}emojiCount++}}return emojiCount},spawn=function(domParent,handler){if(isSupported()){emojiSelectedHandler=handler;domParent.appendChild(overlay);domParent.appendChild(dom);searchBar.value="";search();searchBar.focus();return true}return false},doClose=function(){if(dom.parentElement){dom.parentElement.removeChild(overlay);dom.parentElement.removeChild(dom);return true}return false},close=function(){var closed=doClose();if(!closed)return false;
-if(emojiSelectedHandler)emojiSelectedHandler(null);return true},onEmojiSelected=function(emojiName){if(doClose()&&emojiSelectedHandler)emojiSelectedHandler(emojiName)};overlay.addEventListener("click",function(e){var bounds=dom.getBoundingClientRect();if(e.screenY<bounds.top||e.screenY>bounds.bottom||e.screenX<bounds.left||e.screenX>bounds.right)close()});overlay.className=R.klass.emojibar.overlay;dom.className=R.klass.emojibar.container;emojisDom.className=R.klass.emojibar.emojis;emojiDetail.className=
-R.klass.emojibar.detail.container;emojiDetailImg.className=R.klass.emojibar.detail.img;emojiDetailName.className=R.klass.emojibar.detail.name;unicodeEmojis.className=customEmojis.className=R.klass.emojibar.list;searchBar.className=R.klass.emojibar.search;emojiDetail.appendChild(emojiDetailImg);emojiDetail.appendChild(emojiDetailName);emojisDom.appendChild(makeHeader(window["emojiProviderHeader"]));emojisDom.appendChild(unicodeEmojis);emojisDom.appendChild(makeHeader("emojicustom.png"));emojisDom.appendChild(customEmojis);
-dom.appendChild(emojisDom);dom.appendChild(emojiDetail);dom.appendChild(searchBar);searchBar.addEventListener("keyup",function(){search()});var makeDelegate=function(e,cb){var target=e.target;while(target!==dom&&target&&target.nodeName!=="LI")target=target.parentElement;if(target&&target.nodeName==="LI"&&target.id&&target.id.substr(0,"emojibar-".length)==="emojibar-"){var emojiId=target.id.substr("emojibar-".length);return cb(emojiId)}cb(null)};dom.addEventListener("mousemove",function(e){makeDelegate(e,
-function(emoji){var emojiCached=emoji?emojiCache.unicode[emoji]||emojiCache.custom[emoji]:null;if(emojiCached){emojiDetailImg.innerHTML=emojiCached.dom.outerHTML;emojiDetailName.textContent=":"+emoji+":"}else{emojiDetailImg.textContent="";emojiDetailName.textContent=""}})});dom.addEventListener("click",function(e){makeDelegate(e,function(emoji){if(emoji)onEmojiSelected(emoji)})});return{isSupported:isSupported,spawn:spawn,search:search,close:close}}();var SLACK,HIGHLIGHTED_CHANS=[];function SlackWrapper(){this.lastServerVersion=0;this.context=new ChatContext;this.history={}}
-SlackWrapper.prototype.update=function(data){var now=Date.now();if(data["v"])this.lastServerVersion=data["v"];if(data["static"])this.context.updateStatic(data["static"],Date.now());for(var chanId in this.context.channels){var i=this.context.channels[chanId];if(i.lastMsg===i.lastRead){var pos=HIGHLIGHTED_CHANS.indexOf(i);if(pos!==-1)HIGHLIGHTED_CHANS.splice(pos,1)}}if(data["live"]){for(var i in data["live"]){var history=this.history[i];if(!history)history=this.history[i]=new UiRoomHistory(i,250,data["live"][i],
-now);else history.pushAll(data["live"][i],now)}for(var roomId in data["live"]){var chan=this.context.channels[roomId];if(chan){if(this.history[roomId].messages.length)chan.lastMsg=Math.max(chan.lastMsg,this.history[roomId].lastMessage().ts);if(!chan.archived){onMsgReceived(chan,data["live"][roomId]);if(SELECTED_ROOM&&data["live"][SELECTED_ROOM.id])onRoomUpdated()}}else outOfSync()}}if(data["static"]){onContextUpdated();if(data["static"]["typing"])onTypingUpdated()}};
-setInterval(function(){if(SLACK.context.cleanTyping(Date.now()))onTypingUpdated()},1E3);function isHighlighted(text){var highlights=SLACK.context.self.prefs.highlights;for(var i=0,nbHighlights=highlights.length;i<nbHighlights;i++)if(text.indexOf(highlights[i])!==-1)return true;return false}
-function onMsgReceived(chan,msg){if(chan!==SELECTED_ROOM||!window.hasFocus){var selfReg=new RegExp("<@"+SLACK.context.self.id),highligted=false,areNew=false,newHighlited=false;msg.forEach(function(i){if(parseFloat(i["ts"])<=chan.lastRead)return;areNew=true;if(chan instanceof PrivateMessageRoom||i["text"]&&(i["text"].match(selfReg)||isHighlighted(i["text"]))){if(HIGHLIGHTED_CHANS.indexOf(chan)===-1){newHighlited=true;HIGHLIGHTED_CHANS.push(chan)}highligted=true}});if(areNew){updateTitle();var dom=
-document.getElementById("room_"+chan.id);if(dom){dom.classList.add(R.klass.unread);if(highligted)dom.classList.add(R.klass.unreadHi)}if(newHighlited&&!window.hasFocus)spawnNotification()}}}
-function markRoomAsRead(room){var highlightIndex=HIGHLIGHTED_CHANS.indexOf(room);if(room.lastMsg>room.lastRead){sendReadMArker(room,room.lastMsg);room.lastRead=room.lastMsg}if(highlightIndex>=0){HIGHLIGHTED_CHANS.splice(highlightIndex,1);updateTitle()}var roomLi=document.getElementById("room_"+room.id);roomLi.classList.remove(R.klass.unread);roomLi.classList.remove(R.klass.unreadHi)}SLACK=new SlackWrapper;var createContextBackground=function(){var canvas=document.createElement("canvas"),ctx=canvas.getContext("2d"),WIDTH=canvas.width=250,HEIGHT=canvas.height=290,MARGIN=20,NB_ITEM=3,ITEM_SIZE=(WIDTH-2*MARGIN)/NB_ITEM,ITEM_SPACING=.1*ITEM_SIZE,ITEM_INNER_SIZE=Math.floor(ITEM_SIZE-ITEM_SPACING*2),AVATAR_SIZE=ITEM_INNER_SIZE*.5,RESULT;var drawItem=function(background,avatar,x0,y0){var y0Index=Math.floor(y0),y1Index=Math.floor(y0+ITEM_SIZE),topColor=[background.data[y0Index*WIDTH*4+0],background.data[y0Index*
-WIDTH*4+1],background.data[y0Index*WIDTH*4+2]],botColor=[background.data[y1Index*WIDTH*4+0],background.data[y1Index*WIDTH*4+1],background.data[y1Index*WIDTH*4+2]],targetPcent=1.1,targetColor=(topColor[0]*targetPcent<<16|topColor[1]*targetPcent<<8|topColor[2]*targetPcent).toString(16);ctx.fillStyle="#"+targetColor;ctx.beginPath();ctx.moveTo(x0+ITEM_SIZE/2,y0+ITEM_SPACING);ctx.lineTo(x0-ITEM_SPACING+ITEM_SIZE,y0+ITEM_SIZE/2);ctx.lineTo(x0+ITEM_SIZE/2,y0-ITEM_SPACING+ITEM_SIZE);ctx.lineTo(x0+ITEM_SPACING,
-y0+ITEM_SIZE/2);ctx.closePath();ctx.fill();ctx.putImageData(blend(ctx.getImageData(x0+ITEM_SPACING,y0+ITEM_SPACING,ITEM_INNER_SIZE,ITEM_INNER_SIZE),avatar),x0+ITEM_SPACING,y0+ITEM_SPACING)};var blend=function(img,img2){var margin=(img.height-img2.height)/2;for(var i=0;i<img2.height;i++)for(var j=0;j<img2.width;j++){var img2Grey=img2.data[(i*img2.width+j)*4]/255,iImg=((i+margin)*img.width+j+margin)*4;img.data[iImg]*=img2Grey;img.data[iImg+1]*=img2Grey;img.data[iImg+2]*=img2Grey}return img};var drawBackground=
-function(){var grd=ctx.createLinearGradient(0,0,0,HEIGHT);grd.addColorStop(0,"#4D394B");grd.addColorStop(1,"#201820");ctx.fillStyle=grd;ctx.fillRect(0,0,WIDTH,HEIGHT);return ctx.getImageData(0,0,WIDTH,HEIGHT)};var filterImage=function(img){var pixelSum=0;for(var i=0;i<img.width*img.height*4;i+=4){img.data[i]=img.data[i+1]=img.data[i+2]=(img.data[i]+img.data[i+1]+img.data[i+2])/3;img.data[i+3]=50;pixelSum+=img.data[i]}if(pixelSum/(img.height*img.width)<50)for(var i=0;i<img.width*img.height*4;i+=4)img.data[i]=
-img.data[i+1]=img.data[i+2]=255-img.data[i];return img};var loadImgFromUrl=function(src,cb){var xhr=new XMLHttpRequest;xhr.responseType="blob";xhr.onreadystatechange=function(){if(xhr.readyState===4)if(xhr.response){var img=new Image;img.onload=function(){var imgCanvas=document.createElement("canvas");imgCanvas.height=imgCanvas.width=AVATAR_SIZE;var imgCtx=imgCanvas.getContext("2d");imgCtx.drawImage(img,0,0,AVATAR_SIZE,AVATAR_SIZE);cb(filterImage(imgCtx.getImageData(0,0,AVATAR_SIZE,AVATAR_SIZE)))};
-img.onerror=function(){cb(null)};img.src=window.URL.createObjectURL(xhr.response)}else cb(null)};xhr.open("GET",src,true);xhr.send(null)};var loadImages=function(userImgs,doneImgLoading){for(var i=0,nbImgs=userImgs.length;i<nbImgs;i++)if(userImgs[i].img===undefined){loadImgFromUrl(userImgs[i].src,function(img){userImgs[i].img=img;loadImages(userImgs,doneImgLoading)});return}var imgs=[];userImgs.forEach(function(i){if(i.img)imgs.push(i.img)});doneImgLoading(imgs)};var renderAvatars=function(background,
-imgs){imgs.sort(function(a,b){return Math.random()-.5});for(var imgIndex=0,i=MARGIN;i<WIDTH-MARGIN*2;i+=ITEM_SIZE)for(var j=0;j+ITEM_SIZE<=HEIGHT;j+=ITEM_SIZE){drawItem(background,imgs[imgIndex],i,j);imgIndex++;if(imgIndex===imgs.length){imgs.sort(function(a,b){if(!a.img)return 1;if(!b.img)return-1;return Math.random()-.5});imgIndex=0}}};var callbacks=[],isLoading=false;return function(cb){if(RESULT)cb(RESULT);else if(isLoading)callbacks.push(cb);else{var background=drawBackground(),userImgs=[];isLoading=
-true;callbacks.push(cb);for(var userId in SLACK.context.users)if(!SLACK.context.users[userId].deleted&&!SLACK.context.users[userId].isBot)userImgs.push({src:"api/avatar?user="+userId});loadImages(userImgs,function(imgs){renderAvatars(background,imgs);RESULT=canvas.toDataURL();callbacks.forEach(function(i){i(RESULT)})})}}}();var NEXT_RETRY=0,SELECTED_ROOM=null,REPLYING_TO=null,EDITING=null;function fetchHistory(room,cb){var xhr=new XMLHttpRequest;xhr.open("GET","api/hist?room="+room.id,true);xhr.send(null)}
-function poll(callback){var xhr=new XMLHttpRequest;xhr.timeout=1E3*60*1;xhr.onreadystatechange=function(e){if(xhr.readyState===4){if(xhr.status===0){if(NEXT_RETRY){NEXT_RETRY=0;onNetworkStateUpdated(true)}poll(callback);return}var resp=null,success=Math.floor(xhr.status/100)===2;if(success){if(NEXT_RETRY){NEXT_RETRY=0;onNetworkStateUpdated(true)}resp=xhr.response;try{resp=JSON.parse(resp)}catch(e){resp=null}}else if(NEXT_RETRY){NEXT_RETRY+=Math.floor((NEXT_RETRY||5)/2);NEXT_RETRY=Math.min(60,NEXT_RETRY)}else{NEXT_RETRY=
-5;onNetworkStateUpdated(false)}callback(success,resp)}};xhr.open("GET","api?v="+SLACK.lastServerVersion,true);xhr.send(null)}function outOfSync(){SLACK.lastServerVersion=0}function sendTyping(room){var xhr=new XMLHttpRequest,url="api/typing?room="+room.id;xhr.open("POST",url,true);xhr.send(null)}function onPollResponse(success,response){if(success){if(response)SLACK.update(response);startPolling()}else setTimeout(startPolling,NEXT_RETRY*1E3)}function startPolling(){poll(onPollResponse)}
-function selectRoom(room){if(SELECTED_ROOM)unselectRoom();document.getElementById("room_"+room.id).classList.add(R.klass.selected);document.body.classList.remove(R.klass.noRoomSelected);SELECTED_ROOM=room;onRoomSelected();if(SELECTED_ROOM.lastMsg&&!SLACK.history[SELECTED_ROOM.id])fetchHistory(SELECTED_ROOM,function(success){})}function unselectRoom(){document.getElementById("room_"+SELECTED_ROOM.id).classList.remove(R.klass.selected)}
-function uploadFile(chan,filename,file,callback){var fileReader=new FileReader,formData=new FormData,xhr=new XMLHttpRequest;formData.append("file",file);formData.append("filename",filename);xhr.onreadystatechange=function(){if(xhr.readyState===4)if(xhr.status===204)callback(null);else callback(xhr.statusText)};xhr.open("POST","api/file?room="+chan.id);xhr.send(formData)}
-function sendCommand(payload,serviceId,callback){var formData=new FormData,xhr=new XMLHttpRequest;formData.append("payload",payload);formData.append("service_id",serviceId);if(callback)xhr.onreadystatechange=function(){if(xhr.readyState===4)if(xhr.status===204)callback(null);else callback(xhr.statusText)};xhr.open("POST","api/attachmentAction");xhr.send(formData)}
-function getActionPayload(channelId,msg,attachment,action){var payload={"actions":[action],"attachment_id":attachment["id"],"callback_id":attachment["callback_id"],"channel_id":channelId,"is_ephemeral":msg instanceof NoticeMessage,"message_ts":msg["id"]};return JSON.stringify(payload)}function doCommand(chan,cmd,args){var xhr=new XMLHttpRequest,url="api/cmd?room="+chan.id+"&cmd="+encodeURIComponent(cmd.name.substr(1))+"&args="+encodeURIComponent(args);xhr.open("POST",url,true);xhr.send(null)}
-function sendMsg(chan,msg,replyTo){var xhr=new XMLHttpRequest;var url="api/msg?room="+chan.id+"&text="+encodeURIComponent(msg);if(replyTo){var sender=SLACK.context.users[replyTo.userId],footer="Message";if(chan.id[0]==="C")footer="Channel message";else if(chan.id[0]==="D")footer="Direct message";else if(chan.id[0]==="G")footer="Group message";var attachment={"fallback":replyTo.text,"author_name":"<@"+sender.id+"|"+sender.name+">","text":replyTo.text,"footer":footer,"ts":replyTo.ts};url+="&attachments="+
-encodeURIComponent(JSON.stringify([attachment]))}xhr.open("POST",url,true);xhr.send(null)}
-function onTextEntered(input,skipCommand){var success=true;if(EDITING){editMsg(SELECTED_ROOM,input,EDITING);return true}if(input[0]==="/"&&skipCommand!==true){var endCmd=input.indexOf(" "),cmd=input.substr(0,endCmd===-1?undefined:endCmd),args=endCmd===-1?"":input.substr(endCmd),cmdObject=SLACK.context.commands.data[cmd];if(cmdObject){doCommand(SELECTED_ROOM,cmdObject,args.trim());return true}return false}sendMsg(SELECTED_ROOM,input,REPLYING_TO);return true}
-function editMsg(chan,text,msg){var xhr=new XMLHttpRequest;var url="api/msg?room="+chan.id+"&ts="+msg.id+"&text="+encodeURIComponent(text);xhr.open("PUT",url,true);xhr.send(null)}function removeMsg(chan,msg){var xhr=new XMLHttpRequest;var url="api/msg?room="+chan.id+"&ts="+msg.id;xhr.open("DELETE",url,true);xhr.send(null)}function sendReadMArker(chan,ts){var xhr=new XMLHttpRequest;var url="api/markread?room="+chan.id+"&ts="+ts;xhr.open("POST",url,true);xhr.send(null)}
-function addReaction(channelId,msgId,reaction){var xhr=new XMLHttpRequest;var url="api/reaction?room="+channelId+"&msg="+msgId+"&reaction="+encodeURIComponent(reaction);xhr.open("POST",url,true);xhr.send(null)}function removeReaction(channelId,msgId,reaction){var xhr=new XMLHttpRequest;var url="api/reaction?room="+channelId+"&msg="+msgId+"&reaction="+encodeURIComponent(reaction);xhr.open("DELETE",url,true);xhr.send(null)};function UiRoomHistory(room,keepMessages,evts,now){RoomHistory.call(this,room,keepMessages,evts,now)}UiRoomHistory.prototype=Object.create(RoomHistory.prototype);UiRoomHistory.prototype.constructor=UiRoomHistory;UiRoomHistory.prototype.messageFactory=function(ev,ts){if(ev["isMeMessage"]===true)return new UiMeMessage(this.id,ev,ts);if(ev["isNotice"]===true)return new UiNoticeMessage(this.id,ev,ts);return new UiMessage(this.id,ev,ts)};function IUiMessage(){}IUiMessage.prototype.getDom=function(){};
-IUiMessage.prototype.removeDom=function(){};IUiMessage.prototype.invalidate=function(){};IUiMessage.prototype.createDom=function(){};IUiMessage.prototype.updateDom=function(){};IUiMessage.prototype.duplicateDom=function(){};
-var AbstractUiMessage=function(){var updateReactions=function(_this,channelId){var reactionFrag=document.createDocumentFragment();if(_this.reactions)for(var reaction in _this.reactions){var reac=createReactionDom(channelId,_this.id,reaction,_this.reactions[reaction]);if(reac)reactionFrag.appendChild(reac)}_this.dom.reactions.textContent="";_this.dom.reactions.appendChild(reactionFrag)},_linkFilter=function(msgContext,str){var sep=str.indexOf("|"),link,text,isInternal;if(sep===-1)link=str;else{link=
-str.substr(0,sep);text=str.substr(sep+1)}if(link[0]==="@"){isInternal=true;var user=SLACK.context.users[link.substr(1)];if(user)text="@"+user.name}else if(link[0]==="#"){isInternal=true;var chan=SLACK.context.channels[link.substr(1)];if(chan)text="#"+chan.name}else isInternal=false;return{link:link,text:text||link,isInternal:isInternal}},_formatText=function(_this,text){return formatText(text,{highlight:["fromage"],emojiFormatFunction:function(emoji){if(emoji[0]===":"&&emoji[emoji.length-1]===":")emoji=
-emoji.substr(1,emoji.length-2);var emojiDom=makeEmojiDom(emoji);if(emojiDom){var domParent=document.createElement("span");domParent.className=R.klass.emoji.small;domParent.appendChild(emojiDom);return domParent.outerHTML}return null},linkFilter:function(link){return _linkFilter(_this,link)}})},updateAttachments=function(_this,channelId){var attachmentFrag=document.createDocumentFragment();for(var i=0,nbAttachments=_this.attachments.length;i<nbAttachments;i++){var attachment=_this.attachments[i];if(attachment){var domAttachment=
-createAttachmentDom(channelId,_this,attachment,i);if(domAttachment)attachmentFrag.appendChild(domAttachment)}}_this.dom.attachments.textContent="";_this.dom.attachments.appendChild(attachmentFrag)},updateCommon=function(_this,sender){_this.dom.ts.innerHTML=locale.formatDate(_this.ts);_this.dom.textDom.innerHTML=_formatText(_this,_this.text);_this.dom.authorName.textContent=sender?sender.name:_this.username||"?"};return{invalidate:function(_this){_this.uiNeedRefresh=true;return _this},removeDom:function(_this){if(_this.dom&&
-_this.dom.parentElement){_this.dom.remove();delete _this.dom}return _this},getDom:function(_this){if(!_this.dom)_this.createDom().updateDom();else if(_this.uiNeedRefresh){_this.uiNeedRefresh=false;_this.updateDom()}return _this.dom},updateDom:function(_this){var sender=SLACK.context.users[_this.userId];updateCommon(_this,sender);updateAttachments(_this,_this.channelId);updateReactions(_this,_this.channelId);if(_this.edited)_this.dom.classList.add(R.klass.msg.editedStatus);return _this},duplicateDom:function(_this){return _this.dom.cloneNode(true)},
-formatText:function(_this,text){return _formatText(_this,text)}}}();function UiMeMessage(channelId,ev,ts){MeMessage.call(this,ev,ts);this.channelId=channelId;this.dom=AbstractUiMessage.dom;this.uiNeedRefresh=AbstractUiMessage.uiNeedRefresh}UiMeMessage.prototype=Object.create(MeMessage.prototype);UiMeMessage.prototype.constructor=UiMeMessage;UiMeMessage.prototype.invalidate=function(){return AbstractUiMessage.invalidate(this)};
-UiMeMessage.prototype.formatText=function(text){return AbstractUiMessage.formatText(this,text)};UiMeMessage.prototype.removeDom=function(){return AbstractUiMessage.removeDom(this)};UiMeMessage.prototype.getDom=function(){return AbstractUiMessage.getDom(this)};UiMeMessage.prototype.createDom=function(){this.dom=doCreateMessageDom(this,false);this.dom.classList.add(R.klass.msg.meMessage);return this};UiMeMessage.prototype.duplicateDom=function(){return AbstractUiMessage.duplicateDom(this)};
-UiMeMessage.prototype.updateDom=function(){AbstractUiMessage.updateDom(this);return this};UiMeMessage.prototype.update=function(ev,ts){MeMessage.prototype.update.call(this,ev,ts);this.invalidate()};function UiMessage(channelId,ev,ts){Message.call(this,ev,ts);this.channelId=channelId;this.dom=AbstractUiMessage.dom;this.uiNeedRefresh=AbstractUiMessage.uiNeedRefresh}UiMessage.prototype=Object.create(Message.prototype);UiMessage.prototype.constructor=UiMessage;UiMessage.prototype.invalidate=function(){return AbstractUiMessage.invalidate(this)};
-UiMessage.prototype.formatText=function(text){return AbstractUiMessage.formatText(this,text)};UiMessage.prototype.removeDom=function(){return AbstractUiMessage.removeDom(this)};UiMessage.prototype.getDom=function(){return AbstractUiMessage.getDom(this)};UiMessage.prototype.createDom=function(){this.dom=doCreateMessageDom(this,false);return this};UiMessage.prototype.duplicateDom=function(){return AbstractUiMessage.duplicateDom(this)};
-UiMessage.prototype.updateDom=function(){AbstractUiMessage.updateDom(this);return this};UiMessage.prototype.update=function(ev,ts){Message.prototype.update.call(this,ev,ts);this.invalidate()};function UiNoticeMessage(channelId,ev,ts){NoticeMessage.call(this,ev,ts);this.channelId=channelId;this.dom=AbstractUiMessage.dom;this.domWrapper=null;this.uiNeedRefresh=AbstractUiMessage.uiNeedRefresh}UiNoticeMessage.prototype=Object.create(NoticeMessage.prototype);UiNoticeMessage.prototype.constructor=UiNoticeMessage;
-UiNoticeMessage.prototype.invalidate=function(){return AbstractUiMessage.invalidate(this)};UiNoticeMessage.prototype.formatText=function(text){return AbstractUiMessage.formatText(this,text)};UiNoticeMessage.prototype.removeDom=function(){if(this.domWrapper&&this.domWrapper.parentElement){this.domWrapper.remove();delete this.domWrapper}if(this.dom)delete this.dom;return this};UiNoticeMessage.prototype.getDom=function(){AbstractUiMessage.getDom(this);return this.domWrapper};
-UiNoticeMessage.prototype.duplicateDom=function(){return this.domWrapper.cloneNode(true)};UiNoticeMessage.prototype.createDom=function(){this.dom=doCreateMessageDom(this,false);this.domWrapper=document.createElement("span");this.dom.classList.add(R.klass.msg.notice);this.domWrapper.className=R.klass.msg.notice;this.domWrapper.textContent=locale.onlyVisible;return this};UiNoticeMessage.prototype.updateDom=function(){AbstractUiMessage.updateDom(this);return this};
-UiNoticeMessage.prototype.update=function(ev,ts){NoticeMessage.prototype.update.call(this,ev,ts);this.invalidate()};function isObjectEmpty(o){for(var i in o)if(o.hasOwnProperty(i))return false;return true};
+"use strict";(function(){
+var n;function q(a){this.id=a;this.version=0}q.prototype.update=function(a,b){void 0!==a.name&&(this.name=a.name);this.version=Math.max(this.version,b)};function aa(a){this.a=a.desc;this.name=a.name;this.type=a.type;this.usage=a.usage;this.P=a.category}function ba(){this.a={};this.A=[]}
+ba.prototype.update=function(a,b){this.a=JSON.parse(a.emoji_use);a.highlight_words?this.A=(a.highlight_words||"").split(",").filter(function(a){return""!==a.trim()}):a.highlights&&(this.A=a.highlights);this.version=Math.max(this.version,b)};function ca(){this.s=null;this.l={};this.a={};this.b=null;this.m={version:0,data:{}};this.j={version:0,data:{}};this.f={};this.C=0}"undefined"!==typeof module&&(module.J.Ha=ca,module.J.Ia=q,module.J.Ka=aa);function t(a){this.id=a;this.G=!1;this.a=this.b=0;this.j={};this.version=0}
+t.prototype.update=function(a,b,c,d){d=d||"";void 0!==a.name&&(this.name=a.name);void 0!==a.is_archived&&(this.m=a.is_archived);void 0!==a.is_member&&(this.C=a.is_member);void 0!==a.last_read&&(this.b=Math.max(parseFloat(a.last_read),this.b));void 0!==a.last_msg&&(this.a=parseFloat(a.last_msg));void 0!==a.is_private&&(this.s=a.is_private);a.latest&&(this.a=parseFloat(a.latest.ts));void 0!==a.is_starred&&(this.G=a.is_starred);if(a.members&&(this.j={},a.members))for(var e=0,g=a.members.length;e<g;e++){var f=
+b.a[d+a.members[e]];this.j[f.id]=f;f.l[this.id]=this}this.version=Math.max(this.version,c)};function w(a,b){t.call(this,a);this.f=b;this.name=this.f.name;this.s=!0;b.j=this}w.prototype=Object.create(t.prototype);w.prototype.constructor=w;"undefined"!==typeof module&&(module.J.Pa=t,module.J.Oa=w);function y(a,b){this.F=a.user;this.username=a.username;this.id=a.id||a.ts;this.o=parseFloat(a.ts);this.text="";this.u=[];this.f=this.R=this.G=!1;this.B={};this.version=b;this.update(a,b)}function z(a,b){y.call(this,a,b)}function B(a,b){y.call(this,a,b)}
+y.prototype.update=function(a,b){if(a){if(this.text=a.text||"",a.attachments&&(this.u=a.attachments),this.G=!!a.is_starred,this.R=!!a.edited,this.f=!!a.removed,a.reactions){var c={};a.reactions.forEach(function(a){c[a.name]=[];a.users.forEach(function(b){c[a.name].push(b)})});this.B=c}}else this.f=!0;this.version=b};function E(a,b,c,d){this.id="string"===typeof a?a:a.id;this.a=[];this.f=b;c&&da(this,c,d)}
+function da(a,b,c){var d=0;b.forEach(function(a){d=Math.max(this.push(a,c),d)}.bind(a));ea(a)}E.prototype.b=function(a,b){return!0===a.isMeMessage?new z(a,b):!0===a.isNotice?new B(a,b):new y(a,b)};E.prototype.push=function(a,b){for(var c,d=!1,e,g=0,f=this.a.length;g<f;g++)if(c=this.a[g],c.id===a.id){e=c.update(a,b);d=!0;break}d||(c=this.b(a,b),this.a.push(c),e=c.o);for(;this.a.length>this.f;)this.a.shift();return e||0};
+function fa(a){for(var b=F.b[G.id],c=0,d=b.a.length;c<d&&a>=b.a[c].o;c++)if(b.a[c].o===a)return b.a[c];return null}function ea(a){a.a.sort(function(a,c){return a.o-c.o})}z.prototype=Object.create(y.prototype);z.prototype.constructor=z;B.prototype=Object.create(y.prototype);B.prototype.constructor=B;"undefined"!==typeof module&&(module.J={Ma:y,La:z,Na:B,Qa:E});function H(a){this.id=a;this.l={};this.j=this.a=null;this.version=0}H.prototype.update=function(a,b){void 0!==a.name&&(this.name=a.name);void 0!==a.deleted&&(this.f=a.deleted);void 0!==a.status&&(this.status=a.status);void 0!==a.presence&&(this.b="away"!==a.presence);void 0!==a.isPresent&&(this.b=a.isPresent);a.isBot&&(this.s=a.isBot);this.version=Math.max(this.version,b)};"undefined"!==typeof module&&(module.J.Ja=H);var J={},K;function ga(){if(!c){for(var a=0,b=navigator.languages.length;a<b;a++)if(J.hasOwnProperty(navigator.languages[a])){var c=navigator.languages[a];break}c||(c="en")}K=J[c];console.log("Loading language pack: "+c);if(K.c)for(a in K.c)document.getElementById(a).textContent=K.c[a]};J.fr={Ga:"Utilisateur inconnu",Fa:"Channel inconnu",xa:"Nouveau message",wa:"Reseau",R:"(edit&eacute;)",ya:"(visible seulement par vous)",G:"Favoris",l:"Discutions",Aa:"Discutions priv\u00e9es",ok:"Ok",va:"Annuler",ba:function(a){"string"!==typeof a&&(a=parseFloat(a));var b=new Date,c=new Date;a=new Date(1E3*a);b.setHours(0);b.setMinutes(0);b.setSeconds(0);b.setMilliseconds(0);c.setTime(b.getTime());c.setDate(c.getDate()-1);return a.getTime()>b.getTime()?a.toLocaleTimeString():a.getTime()>c.getTime()?
+"hier, "+a.toLocaleTimeString():a.toLocaleString()},c:{fileUploadCancel:"Annuler",neterror:"Impossible de se connecter au chat !"}};J.en={Ga:"Unknown member",Fa:"Unknown channel",xa:"New message",wa:"Network",R:"(edited)",ya:"(only visible to you)",G:"Starred",l:"Channels",Aa:"Direct messages",ok:"Ok",va:"Cancel",ba:function(a){"string"!==typeof a&&(a=parseFloat(a));var b=new Date,c=new Date;a=new Date(1E3*a);b.setHours(0);b.setMinutes(0);b.setSeconds(0);b.setMilliseconds(0);c.setTime(b.getTime());c.setDate(c.getDate()-1);return a.getTime()>b.getTime()?a.toLocaleTimeString():a.getTime()>c.getTime()?"yesterday, "+a.toLocaleTimeString():
+a.toLocaleString()},c:{fileUploadCancel:"Cancel",neterror:"Cannot connect to chat !"}};var ha=function(){function a(a){this.text="";this.h=a}function b(b,c,d){this.N=c;this.g=null;this.i=[];this.a=d||"";this.X="<"===this.a;this.ea="*"===this.a;this.ja="_"===this.a;this.Y="~"===this.a||"-"===this.a;this.f=">"===this.a||"&gt;"===this.a;this.m=":"===this.a;this.fa="`"===this.a;this.ta="```"===this.a;this.ga="\n"===this.a;this.ia=void 0!==d&&-1!==p.A.indexOf(d);this.h=b;this.Z=null;this.b=this.ga||this.ia?c+d.length-1:!1;this.ia&&(this.g=new a(this),this.i.push(this.g),this.g.text=d)}function c(a){return"A"<=
+a&&"Z">=a||"a"<=a&&"z">=a||"0"<=a&&"9">=a||-1!=="\u00e0\u00e8\u00ec\u00f2\u00f9\u00c0\u00c8\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00fd\u00c1\u00c9\u00cd\u00d3\u00da\u00dd\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e3\u00f1\u00f5\u00c3\u00d1\u00d5\u00e4\u00eb\u00ef\u00f6\u00fc\u00ff\u00c4\u00cb\u00cf\u00d6\u00dc\u0178\u00e7\u00c7\u00df\u00d8\u00f8\u00c5\u00e5\u00c6\u00e6\u0153".indexOf(a)}function d(a){a=a||h;for(var c=0,k=a.i.length;c<k;c++){var f=a.i[c];if(f instanceof
+b)if(f.b){if(f=d(f))return f}else return f}return null}function e(a,c){a.h instanceof b&&(a.h.i.splice(a.h.i.indexOf(a)+(c?1:0)),a.h.g=a.h.i[a.h.i.length-1],e(a.h,!0))}function g(a){return a}function f(a){return{link:a,text:a,Ea:!1}}var l,h,p={A:[],S:g,W:g,U:f};b.prototype.la=function(){return this.ea&&!!this.b||this.h instanceof b&&this.h.la()};b.prototype.oa=function(){return this.ja&&!!this.b||this.h instanceof b&&this.h.oa()};b.prototype.pa=function(){return this.Y&&!!this.b||this.h instanceof
+b&&this.h.pa()};b.prototype.ca=function(){return this.m&&!!this.b||this.h instanceof b&&this.h.ca()};b.prototype.na=function(){return this.ia&&!!this.b||this.h instanceof b&&this.h.na()};b.prototype.ma=function(){return this.fa&&!!this.b||this.h instanceof b&&this.h.ma()};b.prototype.C=function(){return this.ta&&!!this.b||this.h instanceof b&&this.h.C()};b.prototype.qa=function(){for(var a=0,c=this.i.length;a<c;a++)if(this.i[a]instanceof b&&(!this.i[a].b||this.i[a].qa()))return!0;return!1};b.prototype.ra=
+function(a){if("<"===this.a&&">"===l[a])return!0;var b=c(l[a-1]);if(!this.f&&l.substr(a,this.a.length)===this.a){if(!b&&(this.ea||this.ja||this.Y))return!1;if(this.g&&this.qa())return this.g.ua();if(this.Ba())return!0}return"\n"===l[a]&&this.f?!0:!1};b.prototype.Ba=function(){for(var a=this;a;){for(var c=0,d=a.i.length;c<d;c++)if(a.i[c]instanceof b||a.i[c].text.length)return!0;a=a.Z}return!1};b.prototype.ua=function(){var a=new b(this.h,this.N,this.a);a.Z=this;this.g&&this.g instanceof b&&(a.g=this.g.ua(),
+a.i=[a.g]);return a};b.prototype.Ca=function(a){return this.m&&(" "===l[a]||"\t"===l[a])||(this.m||this.X||this.ea||this.ja||this.Y||this.fa)&&"\n"===l[a]?!1:!0};b.prototype.Da=function(b){if(this.fa||this.m||this.ta||this.X)return null;if(!this.g||this.g.b||this.g instanceof a){var d=c(l[b+1]);if("```"===l.substr(b,3))return"```";var f=h.da();if(void 0===f||f){if("&gt;"===l.substr(b,4))return"&gt;";if(">"===l[b])return l[b]}if(-1!==["`","\n"].indexOf(l[b])||-1!==["*","~","-","_"].indexOf(l[b])&&
+(d||-1!=="*~-_<&".split("").indexOf(l[b+1]))||-1!==[":"].indexOf(l[b])&&d||-1!==["<"].indexOf(l[b]))return l[b];d=0;for(f=p.A.length;d<f;d++){var e=p.A[d];if(l.substr(b,e.length)===e)return e}}return null};a.prototype.da=function(){if(""!==this.text.trim())return!1};b.prototype.da=function(){for(var a=this.i.length-1;0<=a;a--){var b=this.i[a].da();if(void 0!==b)return b}if(this.ga||this.f)return!0};a.prototype.j=function(a){this.text+=l[a];return 1};b.prototype.j=function(c){var d=this.g&&!this.g.b&&
+this.g.ra?this.g.ra(c):null;if(d){var f=this.g.a.length;this.g.ka(c);d instanceof b&&(this.g=d,this.i.push(d));return f}if(!this.g||this.g.b||this.g instanceof a||this.g.Ca(c)){if(d=this.Da(c))return this.g=new b(this,c,d),this.i.push(this.g),this.g.a.length;if(!this.g||this.g.b)this.g=new a(this),this.i.push(this.g);return this.g.j(c)}d=this.g.N+1;h.s(this.g.N);this.g=new a(this);this.g.j(d-1);this.i.pop();this.i.push(this.g);return d-c};b.prototype.ka=function(a){for(var b=this;b;)b.b=a,b=b.Z};
+b.prototype.s=function(a){this.b&&this.b>=a&&(this.b=!1);this.i.forEach(function(c){c instanceof b&&c.s(a)})};a.prototype.innerHTML=function(){var a;if(this.h.ca()){for(a=this.h;a&&!a.m;)a=a.h;if(a){var b=a.a+this.text+a.a;return(a=p.S(b))?a:b}return(a=p.S(this.text))?a:this.text}return this.h.C()?this.text.replace(/\n/g,"<br/>"):p.W(this.text)};a.prototype.outerHTML=function(){var a="span",b=[],c="";if(this.h.C()){b.push("codeblock");var d=this.innerHTML()}else this.h.ma()?(b.push("code"),d=this.innerHTML()):
+(this.h.X?(d=p.U(this.text),a="a",c=' href="'+d.link+'"',d.Ra&&(c+=' target="_blank"'),d=p.W(d.text)):d=this.innerHTML(),this.h.la()&&b.push("bold"),this.h.oa()&&b.push("italic"),this.h.pa()&&b.push("strike"),this.h.ca()&&b.push("emoji"),this.h.na()&&b.push("highlight"));return"<"+a+c+(b.length?' class="'+b.join(" ")+'"':"")+">"+d+"</"+a+">"};b.prototype.outerHTML=function(){var a="";this.f&&(a+='<span class="quote">');this.ga&&(a+="<br/>");this.i.forEach(function(b){a+=b.outerHTML()});this.f&&(a+=
+"</span>");return a};b.prototype.sa=function(a){this.f&&!this.b&&this.ka(a);this.i.forEach(function(c){c instanceof b&&c.sa(a)})};return function(c,m){m||(m={});p.A=m.A||[];p.S=m.S||g;p.W=m.W||g;p.U=m.U||f;l=c;h=new b(this,0);m=0;c=l.length;do{for(;m<c;)m+=h.j(m);h.sa(l.length);if(m=d()){e(m,!1);h.s(m.N);var k=new a(m.h);k.j(m.N);m.h.i.push(k);m.h.g=k;m=m.N+1}else m=void 0}while(void 0!==m);return h.outerHTML()}}();window._formatText=function(a,b){return ha(a,{A:b?b.highlights:void 0})};
+"undefined"!==typeof module&&(module.J.w=ha);function ia(a,b){this.f=a;this.content=b;this.c=ja(this);this.b=ka(this);this.a=[];this.j=[]}
+function ja(a){var b=document.createElement("div"),c=document.createElement("header"),d=document.createElement("span"),e=document.createElement("span"),g=document.createElement("div"),f=document.createElement("footer");b.a=document.createElement("span");b.b=document.createElement("span");d.textContent=a.f;"string"==typeof a.content?g.innerHTML=a.content:g.appendChild(a.content);c.className=la;d.className=ma;e.className=na;e.textContent="x";c.appendChild(d);c.appendChild(e);b.appendChild(c);g.className=
+oa;b.appendChild(g);b.b.className=pa;b.b.textContent=K.va;b.b.addEventListener("click",function(){L(a,!1)});e.addEventListener("click",function(){L(a,!1)});b.a.addEventListener("click",function(){L(a,!0)});f.appendChild(b.b);b.a.className=pa;b.a.textContent=K.ok;f.appendChild(b.a);f.className=qa+" "+ra;b.appendChild(f);b.className=sa;return b}function L(a,b){(b?a.a:a.j).forEach(function(a){a()});a.close()}
+function ka(a){var b=document.createElement("div");b.className=ta;b.addEventListener("click",function(){L(this,!1)}.bind(a));return b}function ua(a,b,c){a.c.a.textContent=b;a.c.b.textContent=c;return a}ia.prototype.V=function(a){a=a||document.body;a.appendChild(this.b);a.appendChild(this.c);return this};ia.prototype.close=function(){this.c.remove();this.b.remove();return this};function va(a,b){a.a.push(b);return a};var pa="button",qa="button-container",sa="dialog",ta="dialog-overlay",la="dialog-title",ma="dialog-title-label",na="dialog-title-close",oa="dialog-body",ra="dialog-footer";var wa=[],xa=0;
+function ya(){var a=document.createDocumentFragment(),b=Object.keys(F.a.l||{}),c=[],d=[],e=[],g=[];b.sort(function(a,b){return a[0]!==b[0]?a[0]-b[0]:F.a.l[a].name.localeCompare(F.a.l[b].name)});b.forEach(function(a){a=F.a.l[a];if(!a.m&&!1!==a.C)if(a instanceof w){if(!a.f.f){var b=document.createElement("li");var f=document.createElement("a");b.id="room_"+a.id;f.href="#"+a.id;b.className="slack-context-room slack-ims";f.textContent=a.f.name;b.appendChild(za());b.appendChild(f);a.f.b||b.classList.add("away");
+G===a&&b.classList.add("selected");a.a>a.b&&(b.classList.add("unread"),0<=M.indexOf(a)&&b.classList.add("unreadHi"));b&&(a.G?c.push(b):g.push(b))}}else b=document.createElement("li"),f=document.createElement("a"),b.id="room_"+a.id,f.href="#"+a.id,a.s?(b.className="slack-context-room slack-group",b.dataset.count=Object.keys(a.j||{}).length):b.className="slack-context-room slack-channel",G===a&&b.classList.add("selected"),f.textContent=a.name,b.appendChild(za()),b.appendChild(f),a.a>a.b&&(b.classList.add("unread"),
+0<=M.indexOf(a)&&b.classList.add("unreadHi")),b&&(a.G?c.push(b):a.s?e.push(b):d.push(b))});c.length&&a.appendChild(Aa(K.G));c.forEach(function(b){a.appendChild(b)});d.length&&a.appendChild(Aa(K.l));d.forEach(function(b){a.appendChild(b)});e.forEach(function(b){a.appendChild(b)});g.length&&a.appendChild(Aa(K.Aa));g.forEach(function(b){a.appendChild(b)});document.getElementById("chanList").textContent="";document.getElementById("chanList").appendChild(a);Ba();N();Ca(function(a){document.getElementById("slackCtx").style.backgroundImage=
+"url("+a+")"})}function Da(){var a=F.a.f,b;for(b in F.a.b.l)if(!F.a.b.l[b].m){var c=document.getElementById("room_"+b);a[b]?c.classList.add("slack-context-typing"):c.classList.remove("slack-context-typing")}for(var d in F.a.a)(b=F.a.a[d].j)&&!b.m&&(c=document.getElementById("room_"+b.id))&&(a[b.id]?c.classList.add("slack-context-typing"):c.classList.remove("slack-context-typing"));Ea()}
+function Ea(){var a=F.a.f;document.getElementById("whoistyping").textContent="";if(G&&a[G.id]){var b=document.createDocumentFragment(),c=!1,d;for(d in a[G.id])(a=F.a.a[d])?b.appendChild(Fa(a)):c=!0;c&&(F.f=0);document.getElementById("whoistyping").appendChild(b)}}function Ga(a){a?document.body.classList.remove("no-network"):document.body.classList.add("no-network");N()}
+function Ha(){var a=G.name||(G.f?G.f.name:void 0);if(!a){var b=[];G.j.forEach(function(a){b.push(a.name)});a=b.join(", ")}document.getElementById("currentRoomTitle").textContent=a;Ia();O();document.getElementById("fileUploadContainer").classList.add("hidden");Ja();P&&(P=null,Q());R&&(R=null,Q());Ea()}
+function Q(){if(P){document.body.classList.add("replyingTo");var a=document.getElementById("replyToContainer"),b=document.createElement("a");b.addEventListener("click",function(){P=null;Q()});b.className="replyto-close";b.textContent="x";a.textContent="";a.appendChild(b);a.appendChild(P.I())}else document.body.classList.remove("replyingTo"),document.getElementById("replyToContainer").textContent="";O()}
+function S(){if(R){document.body.classList.add("replyingTo");var a=document.getElementById("replyToContainer"),b=document.createElement("a");b.addEventListener("click",function(){R=null;S()});b.className="replyto-close";b.textContent="x";a.textContent="";a.appendChild(b);a.appendChild(R.I());document.getElementById("msgInput").value=R.text}else document.body.classList.remove("replyingTo"),document.getElementById("replyToContainer").textContent="";O()}
+window.toggleReaction=function(a,b,c){var d=F.b[a];if(d){a:{for(var e=0,g=d.a.length;e<g;e++)if(d.a[e].id==b){d=d.a[e];break a}d=null}d&&(e=F.a.b.id,d.B[c]&&-1!==d.B[c].indexOf(e)?(d=new XMLHttpRequest,d.open("DELETE","api/reaction?room="+a+"&msg="+b+"&reaction="+encodeURIComponent(c),!0),d.send(null)):Ka(a,b,c))}};
+function La(a){a:{for(var b=a,c={};!c[b];){if(a=F.a.m.data[b])if("alias:"==a.substr(0,6))c[b]=!0,b=a.substr(6);else{b=document.createElement("span");b.className="emoji-custom emoji";b.style.backgroundImage="url('"+a+"')";a=b;break a}break}a=b}"string"===typeof a&&"makeEmoji"in window&&(a=window.makeEmoji(a));return"string"===typeof a?null:a}function Ma(a,b){document.getElementById("linkFavicon").href=a||b?"favicon.png?h="+a+"&m="+b:"favicon_ok.png"}
+function N(){var a=M.length,b="";if(T)b="!"+K.wa+" - ",document.getElementById("linkFavicon").href="favicon_err.png";else if(a)b="(!"+a+") - ",Ma(a,a);else{var a=0,c;for(c in F.a.l){var d=F.a.l[c];d.a>d.b&&a++}a&&(b="("+a+") - ");Ma(0,a)}F.a.s&&(b+=F.a.s.name);document.title=b}
+function Na(){if("Notification"in window)if("granted"===Notification.permission){var a=Date.now();if(xa+3E4<a){var b=new Notification(K.xa);xa=a;setTimeout(function(){b.close()},5E3)}}else"denied"!==Notification.permission&&Notification.requestPermission()}
+function Ia(){var a=document.createDocumentFragment(),b=G.id,c=null,d=0,e=null,g;wa=[];F.b[b]&&F.b[b].a.forEach(function(b){if(b.f)b.M();else{var f=b.K(),h=!1;c&&c.F===b.F&&b.F?30>Math.abs(d-b.o)&&!(b instanceof z)?e.classList.add("slackmsg-same-ts"):d=b.o:(d=b.o,h=!0);(!c||c.o<=G.b)&&b.o>G.b?f.classList.add("slackmsg-first-unread"):f.classList.remove("slackmsg-first-unread");if(b instanceof z)e=c=null,d=0,a.appendChild(f),g=null;else{if(h||!g){var h=F.a.a[b.F],p=b.username,k=document.createElement("div"),
+m=document.createElement("div"),u=document.createElement("span");k.O=document.createElement("img");k.O.className="slackmsg-author-img";u.className="slackmsg-author-name";h?(u.textContent=h.name,k.O.src="api/avatar?user="+h.id):(u.textContent=p||"?",k.O.src="");m.appendChild(k.O);m.appendChild(u);m.className="slackmsg-author";k.className="slackmsg-authorGroup";k.appendChild(m);k.content=document.createElement("div");k.content.className="slackmsg-author-messages";k.appendChild(k.content);g=k;wa.push(g);
+a.appendChild(g)}c=b;e=f;g.content.appendChild(f)}}});b=document.getElementById("chatWindow");b.textContent="";b.appendChild(a);b.scrollTop=b.scrollHeight-b.clientHeight;window.hasFocus&&Ja()}
+function Oa(a){function b(a,b){for(b=b||a.target;b!==a.currentTarget&&b;){if(b.classList.contains("slackmsg-item"))return b.id;b=b.parentElement}}for(var c,d,e=a.target;e!==a.currentTarget&&e&&!e.classList.contains("slackmsg-hover");){if(e.parentElement&&e.classList.contains("slackmsg-attachment-actions-item")){d=b(a,e);var g=e.dataset.attachmentIndex,f=e.dataset.actionIndex;if(d&&void 0!==g&&void 0!==f){d=parseFloat(d.split("_")[1]);(c=fa(d))&&c.u[g]&&c.u[g].actions&&c.u[g].actions[f]&&Pa(c,c.u[g],
+c.u[g].actions[f]);break}}if(e.parentElement&&e.parentElement.classList.contains("slackmsg-hover")){if(d=b(a,e))d=parseFloat(d.split("_")[1]),(c=fa(d))&&e.classList.contains("slackmsg-hover-reply")?(R&&(R=null,S()),P!==c&&(P=c,Q())):c&&e.classList.contains("slackmsg-hover-reaction")?Qa.V(document.body,function(a){a&&Ka(G.id,c.id,a)}):c&&e.classList.contains("slackmsg-hover-edit")?(P&&(P=null,Q()),R!==c&&(R=c,S())):c&&e.classList.contains("slackmsg-hover-remove")&&(P&&(P=null,Q()),R&&(R=null,S()),
+Ra(c));break}e=e.parentElement}}function Pa(a,b,c){function d(){var d=JSON.stringify({actions:[c],attachment_id:b.id,callback_id:b.callback_id,channel_id:e,is_ephemeral:a instanceof B,message_ts:a.id}),f=a.F,l=new FormData,h=new XMLHttpRequest;l.append("payload",d);l.append("service_id",f);h.open("POST","api/attachmentAction");h.send(l)}var e=G.id;c.confirm?va(ua(new ia(c.confirm.title,c.confirm.text),c.confirm.ok_text,c.confirm.dismiss_text),d).V():d()}
+function O(){document.getElementById("msgInput").focus()}function Ba(){var a=document.location.hash.substr(1),b=F.a.l[a];b&&b!==G?Sa(b):(a=F.a.a[a])&&a.m&&Sa(a.m)}function Ta(){var a=document.getElementById("chatWindow").getBoundingClientRect().top;wa.forEach(function(b){var c=b.O,d=c.clientHeight;b=b.getBoundingClientRect();c.style.top=Math.max(0,Math.min(a-b.top,b.height-d-d/2))+"px"})}
+document.addEventListener("DOMContentLoaded",function(){ga();document.getElementById("chatWindow").addEventListener("click",Oa);window.addEventListener("hashchange",function(){document.location.hash&&"#"===document.location.hash[0]&&Ba()});document.getElementById("fileUploadCancel").addEventListener("click",function(a){a.preventDefault();document.getElementById("fileUploadError").classList.add("hidden");document.getElementById("fileUploadContainer").classList.add("hidden");document.getElementById("fileUploadInput").value=
+"";return!1});document.getElementById("fileUploadForm").addEventListener("submit",function(a){a.preventDefault();a=document.getElementById("fileUploadInput");var b=a.value;b&&(b=b.substr(b.lastIndexOf("\\")+1),Ua(b,a.files[0],function(a){var b=document.getElementById("fileUploadError");a?(b.textContent=a,b.classList.remove("hidden")):(b.classList.add("hidden"),document.getElementById("fileUploadInput").value="",document.getElementById("fileUploadContainer").classList.add("hidden"))}));return!1});
+document.getElementById("attachFile").addEventListener("click",function(a){a.preventDefault();G&&document.getElementById("fileUploadContainer").classList.remove("hidden");return!1});document.getElementById("msgForm").addEventListener("submit",function(a){a.preventDefault();a=document.getElementById("msgInput");G&&a.value&&Va(a.value)&&(a.value="",P&&(P=null,Q()),R&&(R=null,Q()),document.getElementById("slashList").textContent="");O();return!1});window.addEventListener("blur",function(){window.hasFocus=
+!1});window.addEventListener("focus",function(){window.hasFocus=!0;xa=0;G&&Ja();O()});document.getElementById("chatWindow").addEventListener("scroll",Ta);var a=0;document.getElementById("msgInput").addEventListener("input",function(){if(G){var b=Date.now();a+3E3<b&&(F.a.b.b||G instanceof w)&&(Wa(),a=b);var b=[],c=this.value;if("/"===this.value[0]){var d=c.indexOf(" "),e=-1!==d,d=-1===d?c.length:d,c=c.substr(0,d);for(f in F.a.j.data){var g=F.a.j.data[f];(!e&&g.name.substr(0,d)===c||e&&g.name===c)&&
+b.push(g)}}b.sort(function(a,b){return a.P.localeCompare(b.P)||a.name.localeCompare(b.name)});var d=document.getElementById("slashList"),e=document.createDocumentFragment();d.textContent="";var f=0;for(c=b.length;f<c;f++){g=b[f];if(l!==g.P){var l=g.P;e.appendChild(Xa(g.P))}e.appendChild(Ya(g))}d.appendChild(e)}});window.hasFocus=!0;(function(){var a=document.getElementById("emojiButton");if("makeEmoji"in window){var c=window.makeEmoji("smile");c?a.innerHTML="<span class='emoji-small'>"+c.outerHTML+
+"</span>":a.style.backgroundImage='url("smile.svg")';(c=window.makeEmoji("paperclip"))?document.getElementById("attachFile").innerHTML="<span class='emoji-small'>"+c.outerHTML+"</span>":document.getElementById("attachFile").style.backgroundImage='url("public/paperclip.svg")';a.addEventListener("click",function(){Qa.V(document.body,function(a){a&&(document.getElementById("msgInput").value+=":"+a+":");O()})})}else a.classList.add("hidden")})();Za()});function za(){var a=document.createElement("span"),b=document.createElement("span"),c=document.createElement("span"),d=document.createElement("span");a.className="typing-container";b.className="typing-dot1";c.className="typing-dot2";d.className="typing-dot3";b.textContent=c.textContent=d.textContent=".";a.appendChild(b);a.appendChild(c);a.appendChild(d);return a}var Aa=function(){var a={};return function(b){var c=a[b];c||(c=a[b]=document.createElement("header"),c.textContent=b);return c}}();
+function $a(a){var b=a.b,c=document.createElement("div"),d=document.createElement("div"),e=document.createElement("ul"),g=document.createElement("li");c.u=document.createElement("ul");c.B=document.createElement("ul");c.o=document.createElement("div");c.ha=document.createElement("div");c.aa=document.createElement("span");c.id=b+"_"+a.id;c.className="slackmsg-item";c.o.className="slackmsg-ts";c.ha.className="slackmsg-msg";c.aa.className="slackmsg-author-name";e.className="slackmsg-hover";g.className=
+"slackmsg-hover-reply";e.appendChild(g);if("makeEmoji"in window){var f=document.createElement("li"),l=window.makeEmoji("arrow_heading_down"),h=window.makeEmoji("smile"),p=window.makeEmoji("pencil2"),b=window.makeEmoji("x");f.className="slackmsg-hover-reaction";h?(f.classList.add("emoji-small"),f.appendChild(h)):f.style.backgroundImage='url("smile.svg")';l?(g.classList.add("emoji-small"),g.appendChild(l)):g.style.backgroundImage='url("repl.svg")';e.appendChild(f);a.F===F.a.b.id&&(a=document.createElement("li"),
+a.className="slackmsg-hover-edit",p?a.classList.add("emoji-small"):a.style.backgroundImage='url("edit.svg")',a.appendChild(p),e.appendChild(a),a=document.createElement("li"),a.className="slackmsg-hover-remove",b?a.classList.add("emoji-small"):a.style.backgroundImage='url("remove.svg")',a.appendChild(b),e.appendChild(a))}else g.style.backgroundImage='url("repl.svg")',a.F===F.a.b.id&&(a=document.createElement("li"),a.className="slackmsg-hover-edit",a.style.backgroundImage='url("edit.svg")',e.appendChild(a),
+a=document.createElement("li"),a.className="slackmsg-hover-remove",a.style.backgroundImage='url("remove.svg")',e.appendChild(a));d.appendChild(c.aa);d.appendChild(c.ha);d.appendChild(c.o);d.appendChild(c.u);b=document.createElement("div");b.innerHTML=K.R;b.className="slackmsg-edited";d.appendChild(b);d.appendChild(c.B);d.className="slackmsg-content";c.u.className="slackmsg-attachments";c.B.className="slackmsg-reactions";c.appendChild(d);c.appendChild(e);return c}
+function ab(a){var b={good:"#2fa44f",warning:"#de9e31",danger:"#d50200"};if(a){if("#"===a[0])return a;if(b[a])return b[a]}return"#e3e4e6"}
+function bb(a,b,c){var d=document.createElement("li"),e=document.createElement("div"),g=document.createElement("div"),f=document.createElement("a"),l=document.createElement("div"),h=document.createElement("img"),p=document.createElement("a"),k=document.createElement("div"),m=document.createElement("div"),u=document.createElement("div"),r=document.createElement("img"),v=document.createElement("div");d.className="slackmsg-attachment";e.style.borderColor=ab(b.color||"");e.className="slackmsg-attachment-block";
+g.className="slackmsg-attachment-pretext";b.pretext?g.innerHTML=a.w(b.pretext):g.classList.add("hidden");f.target="_blank";b.title?(f.innerHTML=a.w(b.title),b.title_link&&(f.href=b.title_link),f.className="slackmsg-attachment-title"):f.className="hidden slackmsg-attachment-title";p.target="_blank";l.className="slackmsg-author";b.author_name&&(p.innerHTML=a.w(b.author_name),p.href=b.author_link||"",p.className="slackmsg-author-name",h.className="slackmsg-author-img",b.author_icon&&(h.src=b.author_icon,
+l.appendChild(h)),l.appendChild(p));u.className="slackmsg-attachment-thumb";b.thumb_url?(h=document.createElement("img"),h.src=b.thumb_url,u.appendChild(h),e.classList.add("has-thumb"),b.video_html&&(u.dataset.video=b.video_html)):u.classList.add("hidden");k.className="slackmsg-attachment-content";h=a.w(b.text||"");m.className="slackmsg-attachment-text";h&&""!=h?m.innerHTML=h:m.classList.add("hidden");r.className="slackmsg-attachment-img";b.image_url?r.src=b.image_url:r.classList.add("hidden");v.className=
+"slackmsg-attachment-footer";b.footer&&(h=document.createElement("span"),h.className="slackmsg-attachment-footer-text",h.innerHTML=a.w(b.footer),b.footer_icon&&(p=document.createElement("img"),p.src=b.footer_icon,p.className="slackmsg-attachment-footer-icon",v.appendChild(p)),v.appendChild(h));b.ts&&(h=document.createElement("span"),h.className="slackmsg-ts",h.innerHTML=K.ba(b.ts),v.appendChild(h));k.appendChild(u);k.appendChild(m);e.appendChild(f);e.appendChild(l);e.appendChild(k);e.appendChild(r);
+if(b.fields&&b.fields.length){var x=document.createElement("ul");e.appendChild(x);x.className="slackmsg-attachment-fields";b.fields.forEach(function(b){var c=b.title||"",d=b.value||"";b=!!b["short"];var e=document.createElement("li"),f=document.createElement("div"),g=document.createElement("div");e.className="field";b||e.classList.add("field-long");f.className="field-title";f.textContent=c;g.className="field-text";g.innerHTML=a.w(d);e.appendChild(f);e.appendChild(g);e&&x.appendChild(e)})}if(b.actions&&
+b.actions.length)for(f=document.createElement("ul"),f.className="slackmsg-attachment-actions "+qa,e.appendChild(f),l=0,k=b.actions.length;l<k;l++)(m=b.actions[l])&&(m=cb(c,l,m))&&f.appendChild(m);e.appendChild(v);d.appendChild(g);d.appendChild(e);return d}
+function cb(a,b,c){var d=document.createElement("li"),e=ab(c.style);d.textContent=c.text;e!==ab()&&(d.style.color=e);d.style.borderColor=e;d.dataset.attachmentIndex=a;d.dataset.actionIndex=b;d.className="slackmsg-attachment-actions-item "+pa;return d}function Fa(a){var b=document.createElement("li"),c=document.createElement("span");c.textContent=a.name;b.appendChild(za());b.appendChild(c);return b}
+function Xa(a){var b=document.createElement("lh");b.textContent=a;b.className="slack-command-header";return b}
+function Ya(a){var b=document.createElement("li"),c=document.createElement("span"),d=document.createElement("span"),e=document.createElement("span");c.textContent=a.name;d.textContent=a.usage;e.textContent=a.a;b.appendChild(c);b.appendChild(d);b.appendChild(e);b.className="slack-command-item";c.className="slack-command-name";d.className="slack-command-usage";e.className="slack-command-desc";return b};var Qa=function(){function a(a,b){for(a=a.target;a!==h&&a&&"LI"!==a.nodeName;)a=a.parentElement;a&&"LI"===a.nodeName&&a.id&&"emojibar-"===a.id.substr(0,9)?b(a.id.substr(9)):b(null)}function b(){if(!c())return!1;D&&D(null);return!0}function c(){return h.parentElement?(h.parentElement.removeChild(p),h.parentElement.removeChild(h),!0):!1}function d(a){var b=0;a=void 0===a?r.value:a;if(l()){var c=window.searchEmojis(a);var d=e(c);for(var f in v)v[f].visible&&(v[f].visible=!1,m.removeChild(v[f].c));f=
+0;for(var h=d.length;f<h;f++){var k=d[f].name;var A=v[k];if(!A){A=v;var p=k,C=k;k=window.makeEmoji(c[k]);var D=document.createElement("span");D.appendChild(k);D.className="emoji-medium";k=g(C,D);A=A[p]=k}A.visible||(A.visible=!0,m.appendChild(A.c));b++}}for(f in x)x[f].visible&&(x[f].visible=!1,u.removeChild(x[f].c));d=e(F.a.m.data);f=0;for(h=d.length;f<h;f++)k=d[f].name,""!==a&&k.substr(0,a.length)!==a||"alias:"===F.a.m.data[k].substr(0,6)||(A=x[k],A||(c=x,p=A=k,k=F.a.m.data[k],C=document.createElement("span"),
+D=document.createElement("span"),C.className="emoji emoji-custom",C.style.backgroundImage='url("'+k+'")',D.appendChild(C),D.className="emoji-medium",k=g(p,D),A=c[A]=k),A.visible||(A.visible=!0,u.appendChild(A.c)),b++);return b}function e(a){var b=F.a.b.a.a,c=[],d;for(d in a){var e={name:d,za:0,count:0};a[d].names&&a[d].names.forEach(function(a){e.count+=b[a]||0});c.push(e)}return c=c.sort(function(a,b){var c=b.count-a.count;return c?c:a.za-b.za})}function g(a,b){var c=document.createElement("li");
+c.appendChild(b);c.className="emojibar-list-item";c.id="emojibar-"+a;return{visible:!1,c:c}}function f(a){var b=document.createElement("img"),c=document.createElement("div");b.src=a;c.appendChild(b);c.className="emojibar-header";return c}function l(){return"searchEmojis"in window}var h=document.createElement("div"),p=document.createElement("div"),k=document.createElement("div"),m=document.createElement("ul"),u=document.createElement("ul"),r=document.createElement("input"),v={},x={},I=document.createElement("div"),
+C=document.createElement("span"),U=document.createElement("span"),D;p.addEventListener("click",function(a){var c=h.getBoundingClientRect();(a.screenY<c.top||a.screenY>c.bottom||a.screenX<c.left||a.screenX>c.right)&&b()});p.className="emojibar-overlay";h.className="emojibar";k.className="emojibar-emojis";I.className="emojibar-detail";C.className="emojibar-detail-img";U.className="emojibar-detail-name";m.className=u.className="emojibar-list";r.className="emojibar-search";I.appendChild(C);I.appendChild(U);
+k.appendChild(f(window.emojiProviderHeader));k.appendChild(m);k.appendChild(f("emojicustom.png"));k.appendChild(u);h.appendChild(k);h.appendChild(I);h.appendChild(r);r.addEventListener("keyup",function(){d()});h.addEventListener("mousemove",function(b){a(b,function(a){var b=a?v[a]||x[a]:null;b?(C.innerHTML=b.c.outerHTML,U.textContent=":"+a+":"):(C.textContent="",U.textContent="")})});h.addEventListener("click",function(b){a(b,function(a){a&&c()&&D&&D(a)})});return{isSupported:l,V:function(a,b){return l()?
+(D=b,a.appendChild(p),a.appendChild(h),r.value="",d(),r.focus(),!0):!1},search:d,close:b}}();var F,M=[];function db(){this.f=0;this.a=new ca;this.b={}}
+db.prototype.update=function(a){var b=Date.now();a.v&&(this.f=a.v);if(a["static"]){var c=this.a,d=a["static"],e=Date.now();var g=g||"";d.team&&(c.s||(c.s=new q(d.team.id)),c.s.update(d.team,e));if(d.users)for(var f=0,l=d.users.length;f<l;f++){var h=c.a[g+d.users[f].id];h||(h=c.a[g+d.users[f].id]=new H(d.users[f].id));h.update(d.users[f],e)}if(d.channels)for(f=0,l=d.channels.length;f<l;f++){h=c.l[g+d.channels[f].id];if(!h){var h=c.l,p=g+d.channels[f].id;var k=d.channels[f];k=k.pv?new w(k.id,c.a[k.user]):
+new t(k.id);h=h[p]=k}h.update(d.channels[f],c,e,g)}d.emojis&&(c.m.data=d.emojis,c.m.version=e);if(void 0!==d.commands){c.j.data={};for(f in d.commands)c.j.data[f]=new aa(d.commands[f]);c.j.version=e}c.C=Math.max(c.C,e);d.self&&(c.b=c.a[g+d.self.id]||null,c.b?(c.b.a||(c.b.a=new ba),c.b.a.update(d.self.prefs,e)):c.C=0);if(void 0!==d.typing)for(f in c.f={},d.typing){c.f[f]={};for(var m in d.typing[f])c.f[f][m]=e}}for(var u in this.a.l){var r=this.a.l[u];r.a===r.b&&(c=M.indexOf(r),-1!==c&&M.splice(c,
+1))}if(a.live){for(r in a.live)(u=this.b[r])?da(u,a.live[r],b):this.b[r]=new V(r,250,a.live[r],b);for(var v in a.live)(r=this.a.l[v])?(this.b[v].a.length&&(b=this.b[v],r.a=Math.max(r.a,b.a[b.a.length-1].o)),r.m||(eb(r,a.live[v]),G&&a.live[G.id]&&Ia())):F.f=0}a["static"]&&(ya(),a["static"].typing&&Da())};setInterval(function(){var a=F.a,b=Date.now(),c=!1,d;for(d in a.f){var e=!0,g;for(g in a.f[d])a.f[d][g]+3E3<b?(delete a.f[d][g],c=!0):e=!1;e&&(delete a.f[d],c=!0)}c&&Da()},1E3);
+function eb(a,b){if(a!==G||!window.hasFocus){var c=new RegExp("<@"+F.a.b.id),d=!1,e=!1,g=!1;b.forEach(function(b){if(!(parseFloat(b.ts)<=a.b)){e=!0;var f;if(!(f=a instanceof w)&&(f=b.text)&&!(f=b.text.match(c)))a:{f=F.a.b.a.A;for(var h=0,p=f.length;h<p;h++)if(-1!==b.text.indexOf(f[h])){f=!0;break a}f=!1}f&&(-1===M.indexOf(a)&&(g=!0,M.push(a)),d=!0)}});if(e){N();if(b=document.getElementById("room_"+a.id))b.classList.add("unread"),d&&b.classList.add("unreadHi");g&&!window.hasFocus&&Na()}}}
+function Ja(){var a=G,b=M.indexOf(a);if(a.a>a.b){var c=new XMLHttpRequest;c.open("POST","api/markread?room="+a.id+"&ts="+a.a,!0);c.send(null);a.b=a.a}0<=b&&(M.splice(b,1),N());a=document.getElementById("room_"+a.id);a.classList.remove("unread");a.classList.remove("unreadHi")}F=new db;var Ca=function(){function a(a,b){b.sort(function(){return Math.random()-.5});for(var c=0,d=20;d<h-40;d+=k)for(var e=0;e+k<=p;e+=k)g(a,b[c],d,e),c++,c===b.length&&(b.sort(function(a,b){return a.T?b.T?Math.random()-.5:-1:1}),c=0)}function b(a,d){for(var e=0,f=a.length;e<f;e++)if(void 0===a[e].T){c(a[e].src,function(c){a[e].T=c;b(a,d)});return}var g=[];a.forEach(function(a){a.T&&g.push(a.T)});d(g)}function c(a,b){var c=new XMLHttpRequest;c.responseType="blob";c.onreadystatechange=function(){if(4===
+c.readyState)if(c.response){var a=new Image;a.onload=function(){var c=document.createElement("canvas");c.height=c.width=r;c=c.getContext("2d");c.drawImage(a,0,0,r,r);for(var c=c.getImageData(0,0,r,r),d=0,e=0;e<c.width*c.height*4;e+=4)c.data[e]=c.data[e+1]=c.data[e+2]=(c.data[e]+c.data[e+1]+c.data[e+2])/3,c.data[e+3]=50,d+=c.data[e];if(50>d/(c.height*c.width))for(e=0;e<c.width*c.height*4;e+=4)c.data[e]=c.data[e+1]=c.data[e+2]=255-c.data[e];b(c)};a.onerror=function(){b(null)};a.src=window.URL.createObjectURL(c.response)}else b(null)};
+c.open("GET",a,!0);c.send(null)}function d(){var a=l.createLinearGradient(0,0,0,p);a.addColorStop(0,"#4D394B");a.addColorStop(1,"#201820");l.fillStyle=a;l.fillRect(0,0,h,p);return l.getImageData(0,0,h,p)}function e(a,b){for(var c=(a.height-b.height)/2,d=0;d<b.height;d++)for(var e=0;e<b.width;e++){var f=b.data[4*(d*b.width+e)]/255,g=4*((d+c)*a.width+e+c);a.data[g]*=f;a.data[g+1]*=f;a.data[g+2]*=f}return a}function g(a,b,c,d){var f=Math.floor(d);a=[a.data[f*h*4+0],a.data[f*h*4+1],a.data[f*h*4+2]];l.fillStyle=
+"#"+(1.1*a[0]<<16|1.1*a[1]<<8|1.1*a[2]).toString(16);l.beginPath();l.moveTo(c+k/2,d+m);l.lineTo(c-m+k,d+k/2);l.lineTo(c+k/2,d-m+k);l.lineTo(c+m,d+k/2);l.closePath();l.fill();l.putImageData(e(l.getImageData(c+m,d+m,u,u),b),c+m,d+m)}var f=document.createElement("canvas"),l=f.getContext("2d"),h=f.width=250,p=f.height=290,k=(h-40)/3,m=.1*k,u=Math.floor(k-2*m),r=.5*u,v,x=[],I=!1;return function(c){if(v)c(v);else if(I)x.push(c);else{var e=d(),g=[];I=!0;x.push(c);for(var h in F.a.a)F.a.a[h].f||F.a.a[h].s||
+g.push({src:"api/avatar?user="+F.a.a[h].id});b(g,function(b){a(e,b);v=f.toDataURL();x.forEach(function(a){a(v)})})}}}();var T=0,G=null,P=null,R=null;function fb(a){var b=new XMLHttpRequest;b.timeout=6E4;b.onreadystatechange=function(){if(4===b.readyState)if(b.status){var c=null,d=2===Math.floor(b.status/100);if(d){T&&(T=0,Ga(!0));c=b.response;try{c=JSON.parse(c)}catch(e){c=null}}else T?(T+=Math.floor((T||5)/2),T=Math.min(60,T)):(T=5,Ga(!1));a(d,c)}else T&&(T=0,Ga(!0)),fb(a)};b.open("GET","api?v="+F.f,!0);b.send(null)}function Wa(){var a=new XMLHttpRequest;a.open("POST","api/typing?room="+G.id,!0);a.send(null)}
+function gb(a,b){a?(b&&F.update(b),Za()):setTimeout(Za,1E3*T)}function Za(){fb(gb)}function Sa(a){G&&document.getElementById("room_"+G.id).classList.remove("selected");document.getElementById("room_"+a.id).classList.add("selected");document.body.classList.remove("no-room-selected");G=a;Ha();G.a&&!F.b[G.id]&&(a=new XMLHttpRequest,a.open("GET","api/hist?room="+G.id,!0),a.send(null))}
+function Ua(a,b,c){var d=G;new FileReader;var e=new FormData,g=new XMLHttpRequest;e.append("file",b);e.append("filename",a);g.onreadystatechange=function(){4===g.readyState&&(204===g.status?c(null):c(g.statusText))};g.open("POST","api/file?room="+d.id);g.send(e)}
+function Va(a){if(R){var b=new XMLHttpRequest;b.open("PUT","api/msg?room="+G.id+"&ts="+R.id+"&text="+encodeURIComponent(a),!0);b.send(null);return!0}if("/"===a[0]){var c=a.indexOf(" "),b=-1===c?"":a.substr(c);return(a=F.a.j.data[a.substr(0,-1===c?void 0:c)])?(c=new XMLHttpRequest,c.open("POST","api/cmd?room="+G.id+"&cmd="+encodeURIComponent(a.name.substr(1))+"&args="+encodeURIComponent(b.trim()),!0),c.send(null),!0):!1}var b=G,c=P,d=new XMLHttpRequest;a="api/msg?room="+b.id+"&text="+encodeURIComponent(a);
+if(c){var e=F.a.a[c.F],g="Message";"C"===b.id[0]?g="Channel message":"D"===b.id[0]?g="Direct message":"G"===b.id[0]&&(g="Group message");a+="&attachments="+encodeURIComponent(JSON.stringify([{fallback:c.text,author_name:"<@"+e.id+"|"+e.name+">",text:c.text,footer:g,ts:c.o}]))}d.open("POST",a,!0);d.send(null);return!0}function Ra(a){var b=new XMLHttpRequest;b.open("DELETE","api/msg?room="+G.id+"&ts="+a.id,!0);b.send(null)}
+function Ka(a,b,c){var d=new XMLHttpRequest;d.open("POST","api/reaction?room="+a+"&msg="+b+"&reaction="+encodeURIComponent(c),!0);d.send(null)};function V(a,b,c,d){E.call(this,a,b,c,d)}V.prototype=Object.create(E.prototype);V.prototype.constructor=V;V.prototype.b=function(a,b){return!0===a.isMeMessage?new W(this.id,a,b):!0===a.isNotice?new X(this.id,a,b):new Y(this.id,a,b)};
+var Z=function(){function a(a){return ha(a,{A:F.a.b.a.A,S:function(a){":"===a[0]&&":"===a[a.length-1]&&(a=a.substr(1,a.length-2));if(a=La(a)){var b=document.createElement("span");b.className="emoji-small";b.appendChild(a);return b.outerHTML}return null},U:function(a){var b=a.indexOf("|");if(-1===b)var c=a;else{c=a.substr(0,b);var g=a.substr(b+1)}"@"===c[0]?(a=!0,(b=F.a.a[c.substr(1)])&&(g="@"+b.name)):"#"===c[0]?(a=!0,(b=F.a.l[c.substr(1)])&&(g="#"+b.name)):a=!1;return{link:c,text:g||c,Ea:a}}})}return{D:function(a){a.L=
+!0;return a},M:function(a){a.c&&a.c.parentElement&&(a.c.remove(),delete a.c);return a},K:function(a){a.c?a.L&&(a.L=!1,a.H()):a.$().H();return a.c},H:function(b){var c=F.a.a[b.F];b.c.o.innerHTML=K.ba(b.o);b.c.ha.innerHTML=a(b.text);b.c.aa.textContent=c?c.name:b.username||"?";for(var c=document.createDocumentFragment(),d=0,e=b.u.length;d<e;d++){var g=b.u[d];g&&(g=bb(b,g,d))&&c.appendChild(g)}b.c.u.textContent="";b.c.u.appendChild(c);c=b.b;d=document.createDocumentFragment();if(b.B)for(var f in b.B){var e=
+c,g=b.id,l=f,h=b.B[f],p=La(l);if(p){for(var k=document.createElement("li"),m=document.createElement("a"),u=document.createElement("span"),r=document.createElement("span"),v=[],x=0,I=h.length;x<I;x++){var C=F.a.a[h[x]];C&&v.push(C.name)}v.sort();r.textContent=v.join(", ");u.appendChild(p);u.className="emoji-small";m.href="javascript:toggleReaction('"+e+"', '"+g+"', '"+l+"')";m.appendChild(u);m.appendChild(r);k.className="slackmsg-reaction-item";k.appendChild(m);e=k}else console.warn("Reaction id not found: "+
+l),e=null;e&&d.appendChild(e)}b.c.B.textContent="";b.c.B.appendChild(d);b.R&&b.c.classList.add("edited");return b},I:function(a){return a.c.cloneNode(!0)},w:function(b,c){return a(c)}}}();function W(a,b,c){y.call(this,b,c);this.b=a;this.c=Z.c;this.L=Z.L}W.prototype=Object.create(z.prototype);n=W.prototype;n.constructor=W;n.D=function(){return Z.D(this)};n.w=function(a){return Z.w(this,a)};n.M=function(){return Z.M(this)};n.K=function(){return Z.K(this)};
+n.$=function(){this.c=$a(this);this.c.classList.add("slackmsg-me_message");return this};n.I=function(){return Z.I(this)};n.H=function(){Z.H(this);return this};n.update=function(a,b){z.prototype.update.call(this,a,b);this.D()};function Y(a,b,c){y.call(this,b,c);this.b=a;this.c=Z.c;this.L=Z.L}Y.prototype=Object.create(y.prototype);n=Y.prototype;n.constructor=Y;n.D=function(){return Z.D(this)};n.w=function(a){return Z.w(this,a)};n.M=function(){return Z.M(this)};n.K=function(){return Z.K(this)};
+n.$=function(){this.c=$a(this);return this};n.I=function(){return Z.I(this)};n.H=function(){Z.H(this);return this};n.update=function(a,b){y.prototype.update.call(this,a,b);this.D()};function X(a,b,c){y.call(this,b,c);this.b=a;this.a=null;this.L=!0}X.prototype=Object.create(B.prototype);n=X.prototype;n.constructor=X;n.D=function(){return Z.D(this)};n.w=function(a){return Z.w(this,a)};n.M=function(){this.a&&this.a.parentElement&&(this.a.remove(),delete this.a);this.c&&delete this.c;return this};
+n.K=function(){Z.K(this);return this.a};n.I=function(){return this.a.cloneNode(!0)};n.$=function(){this.c=$a(this);this.a=document.createElement("span");this.c.classList.add("slackmsg-notice");this.a.className="slackmsg-notice";this.a.textContent=K.ya;this.a.appendChild(this.c);return this};n.H=function(){Z.H(this);return this};n.update=function(a,b){B.prototype.update.call(this,a,b);this.D()};
+})();

+ 8 - 0
srv/src/chatter.js

@@ -74,6 +74,14 @@ Chatter.prototype.update = function(userData, t) {
     this.version = Math.max(this.version, t);
 };
 
+Chatter.prototype.getSmallIcon = function() {
+    return "api/avatar?user=" +this.id;
+};
+
+Chatter.prototype.getLargeIcon = function() {
+    return "api/avatar?size=l&user=" +this.id;
+};
+
 /** @suppress {undefinedVars,checkTypes} */
 (function() {
     if (typeof module !== "undefined") {

+ 14 - 3
srv/src/context.js

@@ -92,20 +92,31 @@ SelfPreferences.prototype.toStatic = function(t) {
 function ChatContext() {
     /** @type {ChatInfo} */
     this.team = null;
+
+    /** @type {Object<string, ChatInfo>} */
+    this.teams = {};
+
     /** @type {Object.<string, Room>} */
     this.channels = {};
+
     /** @type {Object.<string, Chatter>} */
     this.users = {};
+
     /** @type {Chatter} */
-    this.self = null;
+    this.self = null; // FIXME move to team
+
     /** @type {{version: number, data: Object.<string, string>}} */
-    this.emojis = { version: 0, data: {} };
+    this.emojis = { version: 0, data: {} }; // FIXME move to team
+
     /** @type {{version: number, data: Object.<string, Command>}} */
-    this.commands = {version: 0, data: {} };
+    this.commands = {version: 0, data: {} }; // FIXME move to team
+
     /** @type {Object.<string, Object.<string, number>>} */
     this.typing = {};
+
     /** @type {number} */
     this.staticV = 0;
+
     /** @type {number} */
     this.liveV = 0;
 };

+ 52 - 53
srv/src/httpServ.js

@@ -1,10 +1,11 @@
-var http = require("http")
+const http = require("http")
     ,https = require("https")
     ,clientSession = require("client-sessions")
 
     ,Url = require("./url.js").Url
     ,config = require("../config.js")
     ,sessionManager = require("./session.js").SessionManager
+    ,MultiChatManager = require("./multichatManager.js").MultiChatManager
     ,Slack = require("./slack.js").Slack
     ,slackManager = require("./slackManager.js").SlackManager
     ,FaviconWriter = require("./faviconWriter.js").FaviconWriter;
@@ -120,22 +121,20 @@ Server.prototype.onRequest = function(req, res) {
         // Api / dynamic content
         var apiSuccess = false;
 
-        res.chatContext = slackManager.lazyGet(req.session, req.reqT);
+        res.chatContext = new MultiChatManager();
+        res.chatContext.push(slackManager.lazyGet(req.session, req.reqT));
+
         if (req.urlObj.match(["api", "hist"])) {
             if (!req.urlObj.queryTokens.room) {
                 res.writeHeader("400", "Bad request");
             } else {
-                var allFound = true;
-                req.urlObj.queryTokens.room.forEach(function(targetId) {
-                    if (!res.chatContext.data.channels[targetId]) {
-                        allFound = false;
-                    }
-                    res.chatContext.fetchHistory(res.chatContext.data.channels[targetId]);
-                });
-                if (allFound)
+                var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens.room[0]);
+                if (ctx) {
+                    ctx.fetchHistory(ctx.getChannel[targetId]);
                     res.writeHeader("204", "No Content");
-                else
+                } else {
                     res.writeHeader("404", "Channel not found");
+                }
             }
             sessionManager.saveSession(req.session);
             res.end();
@@ -144,12 +143,12 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var chan = res.chatContext.data.channels[req.urlObj.queryTokens.room[0]];
+                var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens.room[0]);
 
-                if (!chan) {
+                if (!ctx) {
                     res.writeHeader("404", "Chan not found");
                 } else {
-                    res.chatContext.sendTyping(chan);
+                    ctx.sendTyping(ctx.getChannel(req.urlObj.queryTokens.room[0]));
                     res.writeHeader("204", "No Content");
                 }
                 res.end();
@@ -160,10 +159,10 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var chan = res.chatContext.data.channels[req.urlObj.queryTokens.room[0]]
+                var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens.room[0])
                     ,cmd = res.chatContext.data.commands.data['/' +req.urlObj.queryTokens.cmd[0]];
 
-                if (!chan) {
+                if (!ctx) {
                     res.writeHeader("404", "Chan not found");
                 } else if (!cmd) {
                     res.writeHeader("404", "No such command");
@@ -171,7 +170,7 @@ Server.prototype.onRequest = function(req, res) {
                     var args = req.urlObj.queryTokens.args ? req.urlObj.queryTokens.args[0] : "";
                     if (args === true)
                         args = "";
-                    res.chatContext.sendCommand(chan, cmd, args);
+                    ctx.sendCommand(ctx.getChannel(req.urlObj.queryTokens.room[0]), cmd, args);
                     res.writeHeader("204", "No Content");
                 }
                 res.end();
@@ -181,14 +180,17 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var chan = res.chatContext.data.channels[req.urlObj.queryTokens.room[0]]
+                var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens.room[0])
                     ,ts = parseFloat(req.urlObj.queryTokens.ts[0]);
-                if (!chan)
+
+                if (!chan) {
                     res.writeHeader("404", "Chan Not Found");
-                else if (isNaN(ts))
+                } else if (isNaN(ts)) {
                     res.writeHeader("400", "Invalid date");
-                else
-                    res.chatContext.markRead(chan, ts);
+                } else {
+                    ctx.markRead(ctx.getChannel(req.urlObj.queryTokens.room[0]), ts);
+                    res.writeHeader("204", "No Content");
+                }
                 res.end();
             }
             sessionManager.saveSession(req.session);
@@ -197,12 +199,13 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var user = res.chatContext.data.users[req.urlObj.queryTokens.user[0]];
+                var user = res.chatContext.getUser(req.urlObj.queryTokens.user[0]);
                 if (!user) {
                     res.writeHeader("404", "User Not Found");
                     res.end();
                 } else {
-                    var url = user.icons.small;
+                    // FIXME size=l
+                    var url = user.getSmallIcon();
                     if (!config.isDebug)
                         res.setHeader('Cache-Control', 'private, max-age=' +60 * 60); // 1 hour cache for avatars
                     if (url.substr(0, 7) === "http://")
@@ -221,17 +224,18 @@ Server.prototype.onRequest = function(req, res) {
                 if (!req.urlObj.queryTokens.room || !req.urlObj.queryTokens.text) {
                     res.writeHeader("400", "Bad request");
                 } else {
-                    var chan = res.chatContext.data.channels[req.urlObj.queryTokens.room[0]];
-                    if (chan) {
+                    var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens.room[0]);
+
+                    if (ctx) {
                         var attachments = null;
                         if (req.urlObj.queryTokens.attachments) {
                             try { attachments = JSON.parse(decodeURIComponent(req.urlObj.queryTokens.attachments[0])); }
                             catch (e) {}
                         }
                         if (req.urlObj.queryTokens.me)
-                            res.chatContext.sendMeMsg(chan, req.urlObj.queryTokens.text);
+                            ctx.sendMeMsg(ctx.getChannel(req.urlObj.queryTokens.room[0]), req.urlObj.queryTokens.text);
                         else
-                            res.chatContext.sendMsg(chan, req.urlObj.queryTokens.text, attachments);
+                            ctx.sendMsg(ctx.getChannel(req.urlObj.queryTokens.room[0]), req.urlObj.queryTokens.text, attachments);
                         res.writeHeader("204", "No Content");
                     } else {
                         res.writeHeader("404", "Channel not found");
@@ -241,9 +245,9 @@ Server.prototype.onRequest = function(req, res) {
                 if (!req.urlObj.queryTokens.room || !req.urlObj.queryTokens.ts) {
                     res.writeHeader("400", "Bad request");
                 } else {
-                    var chan = res.chatContext.data.channels[req.urlObj.queryTokens.room[0]];
+                    var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens.room[0]);
                     if (chan) {
-                        res.chatContext.removeMsg(chan, req.urlObj.queryTokens.ts[0]);
+                        ctx.removeMsg(ctx.getChannel(req.urlObj.queryTokens.room[0]), req.urlObj.queryTokens.ts[0]);
                         res.writeHeader("204", "No Content");
                     } else {
                         res.writeHeader("404", "Channel not found");
@@ -253,9 +257,9 @@ Server.prototype.onRequest = function(req, res) {
                 if (!req.urlObj.queryTokens.room || !req.urlObj.queryTokens.ts || !req.urlObj.queryTokens.text) {
                     res.writeHeader("400", "Bad request");
                 } else {
-                    var chan = res.chatContext.data.channels[req.urlObj.queryTokens.room[0]];
-                    if (chan) {
-                        res.chatContext.editMsg(chan, req.urlObj.queryTokens.ts[0], req.urlObj.queryTokens.text);
+                    var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens.room[0]);
+                    if (ctx) {
+                        ctx.editMsg(ctx.getChannel(req.urlObj.queryTokens.room[0]), req.urlObj.queryTokens.ts[0], req.urlObj.queryTokens.text);
                         res.writeHeader("204", "No Content");
                     } else {
                         res.writeHeader("404", "Channel not found");
@@ -272,15 +276,15 @@ Server.prototype.onRequest = function(req, res) {
                 ,reaction = req.urlObj.queryTokens["reaction"] ? req.urlObj.queryTokens["reaction"][0] : undefined;
 
             if (chanId && msgId && reaction) {
-                var chan = res.chatContext.data.channels[chanId];
-                if (!chan) {
+                var ctx = res.chatContext.getChannelContext(chanId);
+                if (!ctx) {
                     res.writeHeader("404", "Channel Not Found");
                 } else if (req.method === 'POST') {
                     res.writeHeader("204", "No Content");
-                    res.chatContext.addReaction(chan, msgId, reaction);
+                    ctx.addReaction(chan, msgId, reaction);
                 } else if (req.method === 'DELETE') {
                     res.writeHeader("204", "No Content");
-                    res.chatContext.removeReaction(chan, msgId, reaction);
+                    ctx.removeReaction(chan, msgId, reaction);
                 } else {
                     res.writeHeader("405", "Method not allowed");
                 }
@@ -292,9 +296,9 @@ Server.prototype.onRequest = function(req, res) {
         } else if (req.urlObj.match(["api", "file"])) {
             sessionManager.saveSession(req.session);
             if (req.urlObj.queryTokens["room"]) {
-                var chan = res.chatContext.data.channels[req.urlObj.queryTokens["room"][0]];
-                if (chan) {
-                    var uploadRequest = res.chatContext.openUploadFileStream(chan, req.headers["content-type"], (errorMsg) => {
+                var ctx = res.chatContext.getChannelContext(req.urlObj.queryTokens["room"][0]);
+                if (ctx) {
+                    var uploadRequest = ctx.openUploadFileStream(chan, req.headers["content-type"], (errorMsg) => {
                         if (!errorMsg)
                             res.writeHeader("204", "No Content");
                         else
@@ -315,26 +319,21 @@ Server.prototype.onRequest = function(req, res) {
             }
         } else if (req.urlObj.match(["api", "attachmentAction"])) {
             sessionManager.saveSession(req.session);
+            // FIXME refactor from here chatContext => MultichatManager
+            // FIXME read payload, replace _POST['service_id'] and _POST['payload']['channel_id'] with remote_id
             res.chatContext.sendAction(req.headers["content-type"], req, (result) => {
                 res.end(result);
             });
         } else if (req.urlObj.match(["api"])) {
-            res.chatContext.onRequest(
+            res.chatContext.poll(
                 (req.urlObj.queryTokens.v ? req.urlObj.queryTokens.v[0] : 0) || 0
-                , (slack, newData) => {
+                , (newData) => {
                 if (!res.ended) {
                     try {
-                        if (!slack.connected) {
-                            res.writeHeader("403", {
-                                "Content-Type": "application/json"
-                            });
-                            res.end(slack.error);
-                        } else {
-                            res.writeHeader("200", {
-                                "Content-Type": "application/json"
-                            });
-                            res.end(JSON.stringify(newData));
-                        }
+                        res.writeHeader("200", {
+                            "Content-Type": "application/json"
+                        });
+                        res.end(JSON.stringify(newData));
                     } catch (e) {}
                 }
                 sessionManager.saveSession(req.session);

+ 3 - 0
srv/src/message.js

@@ -114,6 +114,9 @@ Message.prototype.toStatic = function() {
         ,"reactions": reactions
         ,"isMeMessage": this instanceof MeMessage || undefined
         ,"isNotice": this instanceof NoticeMessage || undefined
+
+        // FIXME debug purpose only
+        ,"v": this.version
     };
 };
 

+ 193 - 0
srv/src/multichatManager.js

@@ -0,0 +1,193 @@
+
+/** @interface */
+function ChatSystem() {
+};
+
+/**
+ * @param {string} chanId
+ * @return {boolean}
+**/
+ChatSystem.prototype.chanExists = function(chanId) {};
+
+ChatSystem.prototype.onRequest = function() {};
+
+/**
+ * @return {string|null}
+**/
+ChatSystem.prototype.getId = function() {};
+
+/**
+ * @param {string} chanId
+ * @return {Room}
+**/
+ChatSystem.prototype.getChannel = function(chanId) {};
+
+/**
+ * @param {string} userId
+ * @return {boolean}
+**/
+ChatSystem.prototype.userExists = function(userId) {};
+
+/**
+ * @param {string} userId
+ * @return {Chatter}
+**/
+ChatSystem.prototype.getUser = function(userId) {};
+
+/**
+ * Async fetch history
+ * @param {Room} chan
+ * @param {string} text
+**/
+ChatSystem.prototype.sendMeMsg = function(chan, text) {};
+
+/**
+ * Async fetch history
+ * @param {Room} chan
+ * @param {string} text
+ * @param {Object=} attachments
+**/
+ChatSystem.prototype.sendMsg = function(chan, text, attachments) {};
+
+/**
+ * Async fetch history
+ * @param {Room} chan
+ * @param {number} ts
+**/
+ChatSystem.prototype.removeMsg = function(chan, ts) {};
+
+/**
+ * Edit msg
+ * @param {Room} chan
+ * @param {number} ts
+ * @param {string} newText
+**/
+ChatSystem.prototype.editMsg = function(chan, ts, newText) {};
+
+/**
+ * Add reaction
+ * @param {Room} chan
+ * @param {number} ts
+ * @param {string} reaction
+**/
+ChatSystem.prototype.addReaction = function(chan, ts, reaction) {};
+
+/**
+ * Add reaction
+ * @param {Room} chan
+ * @param {number} ts
+ * @param {string} reaction
+**/
+ChatSystem.prototype.removeReaction = function(chan, ts, reaction) {};
+
+/**
+ * Add reaction
+ * @param {Room} chan
+ * @param {string} contentType
+ * @param {function(string|null)} callback
+**/
+ChatSystem.prototype.openUploadFileStream = function(chan, contentType, callback) {};
+
+/**
+ * Async fetch history
+ * @param {Room} chan
+**/
+ChatSystem.prototype.fetchHistory = function(chan) {};
+
+/**
+ * @param {Room} chan
+**/
+ChatSystem.prototype.sendTyping = function(chan) {};
+
+/**
+ * @param {Room} chan
+ * @param {number} ts
+**/
+ChatSystem.prototype.markRead = function(chan, ts) {};
+
+/**
+ * @param {Room} chan
+ * @param {string} cmd
+ * @param {string} args
+**/
+ChatSystem.prototype.sendCommand = function(chan, cmd, args) {};
+
+/**
+ * @constructor
+**/
+function MultiChatManager() {
+    this.contexts = [];
+}
+
+/**
+ * @param {ChatSystem} chatSystem
+**/
+MultiChatManager.prototype.push = function(chatSystem) {
+    this.contexts.push(chatSystem);
+};
+
+/**
+ * @param {string} chanId
+ * @return {ChatSystem|null}
+**/
+MultiChatManager.prototype.getChannelContext = function(chanId) {
+    for (let i =0, nbCtx = this.contexts.length; i < nbCtx; i++)
+        if (this.contexts[i].chanExists(chanId))
+            return this.contexts[i];
+    return null;
+};
+
+/**
+ * @param {string} userId
+ * @return {Chatter|null}
+**/
+MultiChatManager.prototype.getUser = function(userId) {
+    for (let i =0, nbCtx = this.contexts.length; i < nbCtx; i++) {
+        let chatter = this.contexts[i].getUser(userId);
+        if (chatter)
+            return chatter;
+    }
+    return null;
+};
+
+MultiChatManager.prototype.poll = function(knownVersion, callback) {
+    this.contexts.forEach((ctx) => {
+        ctx.onRequest(knownVersion);
+    });
+    setTimeout((function() {
+        var liveFeed = {}
+            ,staticFeed = {}
+            ,v = 0
+            ,updated = false;
+
+        this.contexts.forEach((ctx) => {
+            let id = ctx.getId();
+            if (id) {
+                let res = ctx.poll(knownVersion);
+
+                if (res) {
+                    if (res["static"])
+                        staticFeed[ctx.getId()] = res["static"];
+                    if (res["live"])
+                        for (var i in res["live"])
+                            liveFeed[i] = res["live"][i];
+                    v = Math.max(v, (res["v"] || 0));
+                    updated = true;
+                }
+            }
+        });
+        if (updated)
+            callback({
+                "live": liveFeed.length ? liveFeed : undefined,
+                "static": staticFeed,
+                "v": Math.max(v, knownVersion)
+            });
+        else
+            callback({
+                "v": knownVersion
+            });
+    }).bind(this), 2000);
+};
+
+module.exports.MultiChatManager = MultiChatManager;
+

+ 37 - 42
srv/src/slack.js

@@ -62,12 +62,13 @@ function Slack(sess, manager) {
     this.closing = false;
 }
 
-Slack.prototype.onRequest = function(knownVersion, cb) {
-    this.lastCb = cb;
+Slack.prototype.getId = function() {
+    return this.data.team ? this.data.team.id : null;
+};
+
+Slack.prototype.onRequest = function(knownVersion) {
     if (this.connected === false) {
         this.connect(knownVersion);
-    } else {
-        this.waitForEvent(knownVersion);
     }
 };
 
@@ -96,7 +97,7 @@ function httpsRequest(url, cb) {
     }
 }
 
-Slack.prototype.connect = function(knownVersion) {
+Slack.prototype.connect = function(knownVersion, cb) {
     var _this = this;
 
     this.connected = undefined;
@@ -105,20 +106,20 @@ Slack.prototype.connect = function(knownVersion) {
             _this.error = body.error;
             _this.connected = false;
             console.error("Slack api responded " +status);
-            _this.lastCb(_this);
+            cb && cb(_this);
             return;
         }
         if (!body) {
             _this.error = "Slack API error";
             _this.connected = false;
-            _this.lastCb(_this);
+            cb && cb(_this);
             return;
         }
         if (!body.ok) {
             _this.error = body.error;
             _this.connected = false;
             console.error("Slack api responded !ok with ", body);
-            _this.lastCb(_this);
+            cb && cb(_this);
             return;
         }
         _this.getEmojis((emojis) => {
@@ -127,7 +128,6 @@ Slack.prototype.connect = function(knownVersion) {
                 body.commands = commands;
                 _this.data.updateStatic(body, Date.now());
                 _this.connectRtm(body.url);
-                _this.waitForEvent(knownVersion);
             });
         });
     });
@@ -166,40 +166,20 @@ Slack.prototype.getEmojis = function(cb) {
     });
 };
 
-Slack.prototype.waitForEvent = function(knownVersion) {
-    var tick = 0
-        ,_this = this
-        ,interval;
-
-    interval = setInterval(() => {
-        tick++;
-        if (!_this.lastCb) {
-            clearInterval(interval);
-            return;
-        }
-        if (_this.connected) {
-            var updatedCtx = _this.data.getUpdates(knownVersion, Date.now())
-                ,updatedLive = _this.getLiveUpdates(knownVersion)
-                ,updated;
-
-            if (updatedCtx || updatedLive) {
-                updated = {};
-                updated["static"] = updatedCtx;
-                updated["live"] = updatedLive;
-                updated["v"] = Math.max(_this.data.liveV, _this.data.staticV);
-            }
-            if (updated) {
-                clearInterval(interval);
-                _this.lastCb(_this, updated);
-                return;
-            }
-        }
-        if (tick >= 55) { // < 1 minute timeout
-            clearInterval(interval);
-            _this.lastCb(_this, { v: knownVersion });
-            return;
+Slack.prototype.poll = function(knownVersion) {
+    if (this.connected) {
+        var updatedCtx = this.data.getUpdates(knownVersion, Date.now())
+            ,updatedLive = this.getLiveUpdates(knownVersion)
+            ,updated;
+
+        if (updatedCtx || updatedLive) {
+            updated = {};
+            updated["static"] = updatedCtx;
+            updated["live"] = updatedLive;
+            updated["v"] = Math.max(this.data.liveV, this.data.staticV);
+            return updated;
         }
-    }, 1000);
+    }
 };
 
 /** @return {Object|undefined} */
@@ -237,6 +217,7 @@ Slack.prototype.onMessage = function(msg, t) {
         var channelId = this.data.team.id +'|' +(msg["channel"] || msg["channel_id"] || msg["item"]["channel"])
             ,channel = this.data.channels[channelId]
             ,histo = this.history[channelId];
+        // FIXME remove typing for user
         if (histo) {
             var lastMsg = histo.push(msg, t);
             if (lastMsg)
@@ -520,6 +501,20 @@ Slack.prototype.editMsg = function(channel, msgId, text) {
         +"&as_user=true");
 };
 
+/**
+ * @return {SlackChan|SlackGroup|SlackIms}
+**/
+Slack.prototype.getChannel = function(chanId) {
+    return this.data.channels[chanId] || null;
+};
+
+/**
+ * @return {boolean}
+**/
+Slack.prototype.chanExists = function(chanId) {
+    return !!this.data.channels[chanId];
+};
+
 /**
  * @param {SlackChan|SlackGroup|SlackIms} target
 **/

+ 8 - 0
srv/src/slackData.js

@@ -140,6 +140,14 @@ SlackChatter.prototype.update = function(userData, t) {
     }
 };
 
+SlackChatter.prototype.getSmallIcon = function() {
+    return this.icons.small;
+};
+
+SlackChatter.prototype.getLargeIcon = function() {
+    return this.icons.large;
+};
+
 /**
  * @constructor
  * @extends {SlackChatter}

+ 2 - 2
srv/src/slackHistory.js

@@ -73,9 +73,9 @@ SlackHistory.prototype.push = function(ev, t) {
             this.messages.push(msg);
         }
     } else if (ev["type"] === "reaction_added") {
-        msg = this.addReaction(ev["reaction"], ev["user"], ev["item"]["ts"], t);
+        msg = this.addReaction(ev["reaction"], this.idPrefix +ev["user"], ev["item"]["ts"], t);
     } else if (ev["type"] === "reaction_removed") {
-        msg = this.removeReaction(ev["reaction"], ev["user"], ev["item"]["ts"], t);
+        msg = this.removeReaction(ev["reaction"], this.idPrefix +ev["user"], ev["item"]["ts"], t);
     } else {
         return 0;
     }