Răsfoiți Sursa

[tmp] Backup - server architecture, network borken

B Thibault 8 ani în urmă
părinte
comite
290f027295
12 a modificat fișierele cu 645 adăugiri și 703 ștergeri
  1. 1 1
      cli/dom.js
  2. 6 7
      cli/ui.js
  3. 1 1
      cli/workflow.js
  4. 137 62
      srv/public/slack.min.js
  5. 51 1
      srv/src/chatter.js
  6. 224 17
      srv/src/context.js
  7. 11 11
      srv/src/httpServ.js
  8. 18 9
      srv/src/message.js
  9. 94 5
      srv/src/room.js
  10. 1 1
      srv/src/slack.js
  11. 97 584
      srv/src/slackData.js
  12. 4 4
      srv/src/slackHistory.js

+ 1 - 1
cli/dom.js

@@ -394,7 +394,7 @@ function createSlashAutocompleteHeader(servicename) {
 }
 
 /**
- * @param {SlackCommand} cmd
+ * @param {Command} cmd
  * @return {Element}
 **/
 function createSlashAutocompleteDom(cmd) {

+ 6 - 7
cli/ui.js

@@ -43,9 +43,8 @@ function onContextUpdated() {
     sortedUsers.forEach(function(userId) {
         var user = SLACK.context.users[userId];
 
-        if (!user.deleted) {
-            var ims = user.ims
-                ,imsListItem = createImsListItem(ims);
+        if (!user.deleted && user.privateRoom) {
+            var imsListItem = createImsListItem(user.privateRoom);
 
             if (imsListItem) {
                 chanListFram.appendChild(imsListItem);
@@ -697,7 +696,7 @@ document.addEventListener('DOMContentLoaded', function() {
                 }
             }
             commands.sort(function(a, b) {
-                return a.serviceName.localeCompare(b.serviceName) || a.name.localeCompare(b.name);
+                return a.category.localeCompare(b.category) || a.name.localeCompare(b.name);
             });
             var slashDom = document.getElementById(R.id.message.slashComplete)
                 ,slashFrag = document.createDocumentFragment()
@@ -705,9 +704,9 @@ document.addEventListener('DOMContentLoaded', function() {
             slashDom.textContent = '';
             for (var i =0, nbCmd = commands.length; i < nbCmd; i++) {
                 var command = commands[i];
-                if (prevService !== command.serviceName) {
-                    prevService = command.serviceName;
-                    slashFrag.appendChild(createSlashAutocompleteHeader(command.serviceName));
+                if (prevService !== command.category) {
+                    prevService = command.category;
+                    slashFrag.appendChild(createSlashAutocompleteHeader(command.category));
                 }
                 slashFrag.appendChild(createSlashAutocompleteDom(command));
             }

+ 1 - 1
cli/workflow.js

@@ -149,7 +149,7 @@ function uploadFile(chan, filename, file, callback) {
 
 /**
  * @param {Room} chan
- * @param {SlackCommand!} cmd
+ * @param {Command!} cmd
  * @param {string} args
 **/
 function doCommand(chan, cmd, args) {

+ 137 - 62
srv/public/slack.min.js

@@ -1,62 +1,137 @@
-function aa(a){this.id=a;this.version=0}function n(){this.b={};this.a={};this.f={version:0,data:{}};this.B={version:0,data:{}};this.H={}}"undefined"!==typeof module&&(module.o.S=n,module.o.T=aa);function p(a){this.id=a;this.i=this.h=0;this.a=[];this.version=0}function w(a,b){p.call(this,a);this.w=b}w.prototype=Object.create(p);"undefined"!==typeof module&&(module.o.Z=p,module.o.Y=w);function z(a,b){this.l=a.l;this.a=a.userName;this.id=a.id;this.c=a.c;this.version=b;B(this,a,b)}function D(a,b){z.call(this,a,b)}function F(a,b){z.call(this,a,b)}function B(a,b,c){b?(a.text=b.text||"",b.A&&(a.A=b.A),a.m=!!b.m,a.D=!!b.D,b.j&&(a.j={},b.j.forEach(function(b){a.j[b.name]=[];b.users.forEach(function(c){a.j[b.name].push(c)})}))):a.D=!0;a.version=c}function G(a,b,c,d){this.id="string"===typeof a?a:a.id;this.a=[];this.b=b;c&&H(this,c,d)}
-function H(a,b,c){var d=0;b.forEach(function(a){d=Math.max(ba(this,a,c),d)}.bind(a));ca(a)}function ba(a,b,c){for(var d=!1,g,e=0,l=a.a.length;e<l;e++){var f=a.a[e];if(f.id===b){g=B(f,c,void 0);d=!0;break}}d||(f=(void 0)(c),a.a.push(f),g=f.c);for(;a.a.length>a.b;)a.a.shift();return g||0}function da(a){for(var b=I.b[J.id],c=0,d=b.a.length;c<d&&a>=b.a[c].c;c++)if(b.a[c].c===a)return b.a[c];return null}function ca(a){a.a.sort(function(a,c){return a.c-c.c})}D.prototype=Object.create(z);F.prototype=Object.create(z);
-"undefined"!==typeof module&&(module.o={W:z,V:D,X:F,$:G});function ea(a){this.id=a;this.a={small:"",fa:""};this.F={};this.M=null;this.version=0}"undefined"!==typeof module&&(module.o.U=ea);var K={},L;function fa(){var a;if(!a){for(var b=0,c=navigator.languages.length;b<c;b++)if(K.hasOwnProperty(navigator.languages[b])){a=navigator.languages[b];break}a||(a="en")}L=K[a];console.log("Loading language pack: "+a);if(L.g)for(b in L.g)document.getElementById(b).textContent=L.g[b]};K.fr={P:"Utilisateur inconnu",O:"Channel inconnu",J:"Nouveau message",I:"Reseau",m:"edit&eacute;",K:"(visible seulement par vous)",G:function(a){return 1===a.length?a[0]+" est en train d'\u00e9crire":a.join(", ")+" sont en train d'\u00e9crire"},C: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()},g:{fileUploadCancel:"Annuler",neterror:"Impossible de se connecter au chat !"}};K.en={P:"Unknown member",O:"Unknown channel",J:"New message",I:"Network",m:"edited",K:"(only visible to you)",G:function(a){return 1===a.length?a[0]+" is typing":a.join(", ")+" are typing"},C: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()},g:{fileUploadCancel:"Cancel",neterror:"Cannot connect to chat !"}};var M=0;
-function ga(){var a=document.createDocumentFragment(),b=[];b.sort(function(a,b){return a[0]!==b[0]?a[0]-b[0]:I.a.b[a].name.localeCompare(I.a.b[b].name)});b.forEach(function(b){b=I.a.b[b];if(!b.b){var c=document.createElement("li"),g=document.createElement("a");c.id=b.id;g.href="#"+b.id;b.f?(c.className="slack-context-room slack-group",c.dataset.count=b.a.length):c.className="slack-context-room slack-channel";J===b&&c.classList.add("selected");g.textContent=b.name;c.appendChild(ha());c.appendChild(g);b.i>
-b.h&&(c.classList.add("unread"),0<=N.indexOf(b)&&c.classList.add("unreadHi"));c&&a.appendChild(c)}});b=I.a.a?Object.keys(I.a.a):[];b.sort(function(a,b){return I.a.a[a].name.localeCompare(I.a.a[b].name)});b.forEach(function(b){if(!I.a.a[b].b){b=document.createElement("li");var c=document.createElement("a");b.id=null.id;c.href="#"+null.id;b.className="slack-context-room slack-ims";c.textContent=null.w.name;b.appendChild(ha());b.appendChild(c);null.w.R||b.classList.add("away");null===J&&b.classList.add("selected");
-null.i>null.h&&(b.classList.add("unread"),0<=N.indexOf(null)&&b.classList.add("unreadHi"));b&&a.appendChild(b)}});document.getElementById("chanList").textContent="";document.getElementById("chanList").appendChild(a);ia();O();ja(function(b){document.getElementById("slackCtx").style.backgroundImage="url("+b+")"})}
-function ka(){var a=I.a.H,b;for(b in null.F)if(!null.F[b].b){var c=document.getElementById(b);a[b]?c.classList.add("slack-context-typing"):c.classList.remove("slack-context-typing")}for(var d in I.a.a);la()}function la(){var a=I.a.H;if(J&&a[J.id]){var b=[],c=!1,d;for(d in a[J.id])(a=I.a.a[d])?b.push(a.name):c=!0;c&&(I.f=0);document.getElementById("whoistyping").textContent=L.G(b)}else document.getElementById("whoistyping").textContent=""}
-function P(a){a?document.body.classList.remove("no-network"):document.body.classList.add("no-network");O()}function ma(){var a=J.name||(J.w?J.w.name:void 0);if(!a){var b=[];J.a.forEach(function(a){b.push(a.name)});a=b.join(", ")}document.getElementById("currentRoomTitle").textContent=a;na();Q();document.getElementById("fileUploadContainer").classList.add("hidden");R();S&&(S=null,T());U&&(U=null,T());la()}
-function T(){if(S){document.body.classList.add("replyingTo");var a=document.getElementById("replyToContainer"),b=document.createElement("a");b.addEventListener("click",function(){S=null;T()});b.className="replyto-close";b.textContent="x";a.textContent="";a.appendChild(b);a.appendChild(V("reply_"+J.id,S,!0))}else document.body.classList.remove("replyingTo"),document.getElementById("replyToContainer").textContent="";Q()}
-function W(){if(U){document.body.classList.add("replyingTo");var a=document.getElementById("replyToContainer"),b=document.createElement("a");b.addEventListener("click",function(){U=null;W()});b.className="replyto-close";b.textContent="x";a.textContent="";a.appendChild(b);a.appendChild(V("edit_"+J.id,U,!0));document.getElementById("msgInput").value=U.text}else document.body.classList.remove("replyingTo"),document.getElementById("replyToContainer").textContent="";Q()}
-window.toggleReaction=function(a,b,c){var d=I.b[a];if(d){a:{for(var g=0,e=d.a.length;g<e;g++)if(d.a[g].id==b){d=d.a[g];break a}d=null}d&&(g=null.id,d.j[c]&&-1!==d.j[c].indexOf(g)?(d=new XMLHttpRequest,d.open("DELETE","api/reaction?room="+a+"&msg="+b+"&reaction="+encodeURIComponent(c),!0),d.send(null)):oa(a,b,c))}};
-function pa(a){a:{for(var b=a,c={};!c[b];){if(a=I.a.f[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 qa(a){return a.replace(/:([^ \t:]+):/g,function(b,c){var d=pa(c);if(d){var g=document.createElement("span");g.className=b===a?"emoji-medium":"emoji-small";g.appendChild(d);return g.outerHTML}return b})}
-function X(a){a=a.split(/\r?\n/g);for(var b=0,c=a.length;b<c;b++){for(var d=a[b].trim(),g="",e={},l=!1,f=0,d=d.replace(RegExp("<([@#]?)([^>]*)>","g"),function(b,a,c){c=c.split("|");if("@"===a)c[1]?"@"!==c[1][0]&&(c[1]="@"+c[1]):(b=I.a.a[c[0]],c[1]=b?"@"+b.name:L.P),c[0]="#"+c[0],c[2]="slackmsg-link slackmsg-link-user";else if("#"===a)c[1]?"#"!==c[1][0]&&(c[1]="#"+c[1]):(b=I.a.b[c[0]],c[1]=b?"#"+b.name:L.O),c[0]="#"+c[0],c[2]="slackmsg-link slackmsg-link-chan";else if(-1!==c[0].indexOf("://"))c[1]||
-(c[1]=c[0]),c[2]="slackmsg-link";else return b;return'<a href="'+c[0]+'" class="'+c[2]+'"'+(a?"":' target="_blank"')+">"+c[1]+"</a>"}),d=qa(d),k=d.length,m=function(b,a,c){for(;b[a];){var d=b[a];if(("A"<=d&&"Z">=d||"a"<=d&&"z">=d||"0"<=d&&"9">=d||-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(d))&&
-b[a]!=c&&b[a+1]==c)return!0;a++}return!1},h=function(b){return Object.keys(e).length?'<span class="'+Object.keys(b).join(" ")+'">':""};f<k&&(" "===d[f]||"\t"===d[f]);)f++;"&gt;"===d.substr(f,4)&&(l=!0,f+=4);for(;f<k;f++){var q=d[f];if("<"===q){do g+=d[f++];while(">"!==d[f-1]);f--}else if(!e["slackmsg-style-bold"]&&"*"===q&&d[f+1]&&m(d,f,q))Object.keys(e).length&&(g+="</span>"),e["slackmsg-style-bold"]=!0,g+=h(e);else if(!e["slackmsg-style-strike"]&&"~"===q&&d[f+1]&&m(d,f,q))Object.keys(e).length&&
-(g+="</span>"),e["slackmsg-style-strike"]=!0,g+=h(e);else if(!e["slackmsg-style-code"]&&"`"===q&&d[f+1]&&m(d,f,q))Object.keys(e).length&&(g+="</span>"),e["slackmsg-style-code"]=!0,g+=h(e);else if(!e["slackmsg-style-italic"]&&"_"===q&&d[f+1]&&m(d,f,q))Object.keys(e).length&&(g+="</span>"),e["slackmsg-style-italic"]=!0,g+=h(e);else{var r=!1,g=g+q;do{if(e["slackmsg-style-bold"]&&"*"!==q&&"*"===d[f+1])delete e["slackmsg-style-bold"],r=!0;else if(e["slackmsg-style-strike"]&&"~"!==q&&"~"===d[f+1])delete e["slackmsg-style-strike"],
-r=!0;else if(e["slackmsg-style-code"]&&"`"!==q&&"`"===d[f+1])delete e["slackmsg-style-code"],r=!0;else if(e["slackmsg-style-italic"]&&"_"!==q&&"_"===d[f+1])delete e["slackmsg-style-italic"],r=!0;else break;q=d[++f]}while(f<k);r&&(g+="</span>"+h(e))}}e&&(g+="</span>");a[b]=l?'<span class="slackmsg-style-quote">'+g+"</span>":g}return a.join("<br/>")}
-function V(a,b,c){b.f?(a=ra(a,b,c),a.classList.add("slackmsg-me_message")):a=ra(a,b,c);b.m&&a.classList.add("slackmsg-edited");b.b&&a.classList.add("slackmsg-notice");return a}function sa(a,b){document.getElementById("linkFavicon").href=a||b?"favicon.png?h="+a+"&m="+b:"favicon_ok.png"}
-function O(){var a=N.length,b="";if(Y)b="!"+L.I+" - ",document.getElementById("linkFavicon").href="favicon_err.png";else if(a)b="(!"+a+") - ",sa(a,a);else{var a=0,c;for(c in I.a.b){var d=I.a.b[c];d.i>d.h&&a++}a&&(b="("+a+") - ");sa(0,a)}document.title=b}
-function ta(){if("Notification"in window)if("granted"===Notification.permission){var a=Date.now();if(M+3E4<a){var b=new Notification(L.J);M=a;setTimeout(function(){b.close()},5E3)}}else"denied"!==Notification.permission&&Notification.requestPermission()}
-function na(){var a=document.createDocumentFragment(),b=J.id,c=null,d=0,g=null;I.b[b]&&I.b[b].a.forEach(function(e){if(!e.D){var f=V(b,e);c&&c.l===e.l&&e.l?(f.classList.add("slackmsg-same-author"),30>Math.abs(d-e.c)?g.classList.add("slackmsg-same-ts"):d=e.c):d=e.c;(!c||c.c<=J.h)&&e.c>J.h&&f.classList.add("slackmsg-first-unread");c=e;g=f;a.appendChild(f)}});var e=document.getElementById("chatWindow");e.textContent="";e.appendChild(a);e.scrollTop=e.scrollHeight-e.clientHeight;window.hasFocus&&R()}
-function ua(a){function b(b,a){for(a=a||b.target;a!==b.currentTarget&&a;){if(a.classList.contains("slackmsg-item"))return a.id;a=a.parentElement}}for(var c=a.target;c!==a.currentTarget&&c&&!c.classList.contains("slackmsg-hover");){if(c.parentElement&&c.parentElement.classList.contains("slackmsg-hover")){if(a=b(a,c)){a=parseFloat(a.split("_")[1]);var d=da(a);d&&c.classList.contains("slackmsg-hover-reply")?(U&&(U=null,W()),S!==d&&(S=d,T())):d&&c.classList.contains("slackmsg-hover-reaction")?va.N(document.body,
-function(b){b&&oa(J.id,d.id,b)}):d&&c.classList.contains("slackmsg-hover-edit")?(S&&(S=null,T()),U!==d&&(U=d,W())):d&&c.classList.contains("slackmsg-hover-remove")&&(S&&(S=null,T()),U&&(U=null,W()),wa(d))}break}c=c.parentElement}}function Q(){document.getElementById("msgInput").focus()}
-function ia(){var a=I.a.b[document.location.hash.substr(1)];a&&a!==J&&(J&&document.getElementById(J.id).classList.remove("selected"),document.getElementById(a.id).classList.add("selected"),document.body.classList.remove("no-room-selected"),J=a,ma(),J.h&&!I.b[J.id]&&(a=new XMLHttpRequest,a.open("GET","api/hist?room="+J.id,!0),a.send(null)))}
-document.addEventListener("DOMContentLoaded",function(){fa();document.getElementById("chatWindow").addEventListener("click",ua);window.addEventListener("hashchange",function(){document.location.hash&&"#"===document.location.hash[0]&&ia()});document.getElementById("fileUploadCancel").addEventListener("click",function(b){b.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(b){b.preventDefault();b=document.getElementById("fileUploadInput");var a=b.value;a&&(a=a.substr(a.lastIndexOf("\\")+1),xa(a,b.files[0],function(b){var a=document.getElementById("fileUploadError");b?(a.textContent=b,a.classList.remove("hidden")):(a.classList.add("hidden"),document.getElementById("fileUploadInput").value="",document.getElementById("fileUploadContainer").classList.add("hidden"))}));return!1});
-document.getElementById("attachFile").addEventListener("click",function(b){b.preventDefault();J&&document.getElementById("fileUploadContainer").classList.remove("hidden");return!1});document.getElementById("msgForm").addEventListener("submit",function(b){b.preventDefault();b=document.getElementById("msgInput");J&&b.value&&ya(b.value)&&(b.value="",S&&(S=null,T()),U&&(U=null,T()),document.getElementById("slashList").textContent="");Q();return!1});window.addEventListener("blur",function(){window.hasFocus=
-!1});window.addEventListener("focus",function(){window.hasFocus=!0;M=0;J&&R();Q()});var a=0;document.getElementById("msgInput").addEventListener("input",function(){if(J){var b=Date.now();a+3E3<b&&(null.R||J instanceof w)&&(za(),a=b);var b=[],c=this.value;if("/"===this.value[0]){var d=c.indexOf(" "),g=-1!==d,d=-1===d?c.length:d,c=c.substr(0,d),e;for(e in I.a.B.data){var l=I.a.B.data[e];(!g&&l.name.substr(0,d)===c||g&&l.name===c)&&b.push(l)}}b.sort(function(b,a){return b.u.localeCompare(a.u)||b.name.localeCompare(a.name)});
-var d=document.getElementById("slashList"),g=document.createDocumentFragment(),f;d.textContent="";e=0;for(c=b.length;e<c;e++)l=b[e],f!==l.u&&(f=l.u,g.appendChild(Aa(l.u))),g.appendChild(Ba(l));d.appendChild(g)}});window.hasFocus=!0;(function(){var b=document.getElementById("emojiButton");if("makeEmoji"in window){var a=window.makeEmoji("smile");a?b.innerHTML="<span class='emoji-small'>"+a.outerHTML+"</span>":b.style.backgroundImage='url("smile.svg")';(a=window.makeEmoji("paperclip"))?document.getElementById("attachFile").innerHTML=
-"<span class='emoji-small'>"+a.outerHTML+"</span>":document.getElementById("attachFile").style.backgroundImage='url("public/paperclip.svg")';b.addEventListener("click",function(){va.N(document.body,function(a){a&&(document.getElementById("msgInput").value+=":"+a+":");Q()})})}else b.classList.add("hidden")})();Z()});function ha(){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}
-function Ca(a,b,c,d){var g=pa(c);if(g){for(var e=document.createElement("li"),l=document.createElement("a"),f=document.createElement("span"),k=document.createElement("span"),m=[],h=0,q=d.length;h<q;h++){var r=I.a.a[d[h]];r&&m.push(r.name)}m.sort();k.textContent=m.join(", ");f.appendChild(g);f.className="emoji-small";l.href="javascript:toggleReaction('"+a+"', '"+b+"', '"+c+"')";l.appendChild(f);l.appendChild(k);e.className="slackmsg-reaction-item";e.appendChild(l);return e}return null}
-function ra(a,b,c){var d=document.createElement("div"),g=document.createElement("div"),e=document.createElement("div"),l=document.createElement("div"),f=document.createElement("img"),k=document.createElement("span"),m=document.createElement("ul"),h=document.createElement("li"),q=document.createElement("ul"),r=document.createElement("ul"),t=I.a.a[b.l];d.id=a+"_"+b.c;d.className="slackmsg-item";e.className="slackmsg-ts";l.className="slackmsg-msg";f.className="slackmsg-author-img";k.className="slackmsg-author-name";
-m.className="slackmsg-hover";h.className="slackmsg-hover-reply";e.innerHTML=L.C(b.c);l.innerHTML=X(b.text);k.textContent=t?t.name:b.a||"?";f.src=t?t.a.small:"";m.appendChild(h);if("makeEmoji"in window){var u=document.createElement("li"),A=window.makeEmoji("arrow_heading_down"),E=window.makeEmoji("smile"),y=window.makeEmoji("pencil2"),t=window.makeEmoji("x");u.className="slackmsg-hover-reaction";E?(u.classList.add("emoji-small"),u.appendChild(E)):u.style.backgroundImage='url("smile.svg")';A?(h.classList.add("emoji-small"),
-h.appendChild(A)):h.style.backgroundImage='url("repl.svg")';m.appendChild(u);b.l===null.id&&(h=document.createElement("li"),h.className="slackmsg-hover-edit",y?h.classList.add("emoji-small"):h.style.backgroundImage='url("edit.svg")',h.appendChild(y),m.appendChild(h),h=document.createElement("li"),h.className="slackmsg-hover-remove",t?h.classList.add("emoji-small"):h.style.backgroundImage='url("remove.svg")',h.appendChild(t),m.appendChild(h))}else h.style.backgroundImage='url("repl.svg")',b.l===null.id&&
-(h=document.createElement("li"),h.className="slackmsg-hover-edit",h.style.backgroundImage='url("edit.svg")',m.appendChild(h),h=document.createElement("li"),h.className="slackmsg-hover-remove",h.style.backgroundImage='url("remove.svg")',m.appendChild(h));d.appendChild(f);b.b&&(f=document.createElement("span"),f.className="slackmsg-notice",f.textContent=L.K,g.appendChild(f));g.appendChild(k);g.appendChild(l);g.appendChild(e);g.appendChild(q);b.m&&(e=document.createElement("div"),e.textContent=L.m,e.className=
-"slackmsg-edited",g.appendChild(e));g.appendChild(r);g.className="slackmsg-content";q.className="slackmsg-attachments";r.className="slackmsg-reactions";if(!0!==c){if(b.j)for(var C in b.j)(c=Ca(a,b.id,C,b.j[C]))&&r.appendChild(c);b.A.forEach(function(a){var b=document.createElement("li"),c=document.createElement("div"),d=document.createElement("div"),e=document.createElement("a"),g=document.createElement("div"),f=document.createElement("img"),h=document.createElement("a"),y=document.createElement("div"),
-k=document.createElement("div"),l=document.createElement("img"),x=document.createElement("img"),m=document.createElement("div"),C=document.createElement("img"),r=document.createElement("span"),t=document.createElement("span");b.className="slackmsg-attachment";var u="#e3e4e6";a.color&&("#"===a.color[0]?u=a.color[0]:"good"===a.color?u="#2fa44f":"warning"===a.color?u="#de9e31":"danger"===a.color&&(u="#d50200"));c.style.borderColor=u;c.className="slackmsg-attachment-block";d.className="slackmsg-attachment-pretext";
-a.pretext?d.innerHTML=X(a.pretext):d.classList.add("hidden");e.target="_blank";a.title?(e.innerHTML=X(a.title),a.title_link&&(e.href=a.title_link),e.className="slackmsg-attachment-title"):e.className="hidden slackmsg-attachment-title";h.target="_blank";g.className="slackmsg-author";a.author_name?(h.innerHTML=X(a.author_name),h.href=a.author_link||"",h.className="slackmsg-author-name",f.className="slackmsg-author-img",a.author_icon?f.src=a.author_icon:f.classList.add("hidden")):g.classList.add("hidden");
-k.innerHTML=X(a.text||"");k.a="slackmsg-attachment-text";l.className="slackmsg-attachment-thumb";a.thumb_url?l.src=a.thumb_url:l.classList.add("hidden");x.className="slackmsg-attachment-img";a.image_url?x.src=a.image_url:x.classList.add("hidden");m.className="slackmsg-attachment-footer";r.className="slackmsg-attachment-footer-text";C.className="slackmsg-attachment-footer-icon";a.footer?(r.innerHTML=X(a.footer),a.footer_icon?C.src=a.footer_icon:C.classList.add("hidden")):(C.classList.add("hidden"),
-r.classList.add("hidden"));t.className="slackmsg-ts";a.ts?t.innerHTML=L.C(a.ts):t.classList.add("hidden");g.appendChild(f);g.appendChild(h);y.appendChild(k);y.appendChild(l);m.appendChild(C);m.appendChild(r);m.appendChild(t);c.appendChild(e);c.appendChild(g);c.appendChild(y);c.appendChild(x);c.appendChild(m);b.appendChild(d);b.appendChild(c);b&&q.appendChild(b)})}d.appendChild(g);d.appendChild(m);return d}
-function Aa(a){var b=document.createElement("lh");b.textContent=a;b.className="slack-command-header";return b}
-function Ba(a){var b=document.createElement("li"),c=document.createElement("span"),d=document.createElement("span"),g=document.createElement("span");c.textContent=a.name;d.textContent=a.usage;g.textContent=a.aa;b.appendChild(c);b.appendChild(d);b.appendChild(g);b.className="slack-command-item";c.className="slack-command-name";d.className="slack-command-usage";g.className="slack-command-desc";return b};var va=function(){function a(a,b){for(var c=a.target;c!==k&&c&&"LI"!==c.nodeName;)c=c.parentElement;c&&"LI"===c.nodeName&&c.id&&"emojibar-"===c.id.substr(0,9)?b(c.id.substr(9)):b(null)}function b(){if(!c())return!1;x&&x(null);return!0}function c(){return k.parentElement?(k.parentElement.removeChild(m),k.parentElement.removeChild(k),!0):!1}function d(a){var b=0,c;a=void 0===a?t.value:a;if(f()){var d=window.searchEmojis(a);c=g(d);for(var h in u)u[h].visible&&(u[h].visible=!1,q.removeChild(u[h].g));
-h=0;for(var y=c.length;h<y;h++){var v=c[h].name,k=u[v];if(!k){var k=u,l=v,x=v,v=window.makeEmoji(d[v]),m=document.createElement("span");m.appendChild(v);m.className="emoji-medium";v=e(x,m);k=k[l]=v}k.visible||(k.visible=!0,q.appendChild(k.g));b++}}for(h in A)A[h].visible&&(A[h].visible=!1,r.removeChild(A[h].g));c=g(I.a.f.data);h=0;for(y=c.length;h<y;h++)v=c[h].name,""!==a&&v.substr(0,a.length)!==a||"alias:"===I.a.f.data[v].substr(0,6)||(k=A[v],k||(d=A,l=k=v,v=I.a.f.data[v],x=document.createElement("span"),
-m=document.createElement("span"),x.className="emoji emoji-custom",x.style.backgroundImage='url("'+v+'")',m.appendChild(x),m.className="emoji-medium",v=e(l,m),k=d[k]=v),k.visible||(k.visible=!0,r.appendChild(k.g)),b++);return b}function g(a){var b=null.M.ba,c=[],d;for(d in a){var e={name:d,L:0,count:0};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.L-b.L})}function e(a,b){var c=document.createElement("li");c.appendChild(b);
-c.className="emojibar-list-item";c.id="emojibar-"+a;return{visible:!1,g:c}}function l(a){var b=document.createElement("img"),c=document.createElement("div");b.src=a;c.appendChild(b);c.className="emojibar-header";return c}function f(){return"searchEmojis"in window}var k=document.createElement("div"),m=document.createElement("div"),h=document.createElement("div"),q=document.createElement("ul"),r=document.createElement("ul"),t=document.createElement("input"),u={},A={},E=document.createElement("div"),
-y=document.createElement("span"),C=document.createElement("span"),x;m.addEventListener("click",function(a){var c=k.getBoundingClientRect();(a.screenY<c.top||a.screenY>c.bottom||a.screenX<c.left||a.screenX>c.right)&&b()});m.className="emojibar-overlay";k.className="emojibar";h.className="emojibar-emojis";E.className="emojibar-detail";y.className="emojibar-detail-img";C.className="emojibar-detail-name";q.className=r.className="emojibar-list";t.className="emojibar-search";E.appendChild(y);E.appendChild(C);
-h.appendChild(l(window.emojiProviderHeader));h.appendChild(q);h.appendChild(l("emojicustom.png"));h.appendChild(r);k.appendChild(h);k.appendChild(E);k.appendChild(t);t.addEventListener("keyup",function(){d()});k.addEventListener("mousemove",function(b){a(b,function(a){var b=a?u[a]||A[a]:null;b?(y.innerHTML=b.g.outerHTML,C.textContent=":"+a+":"):(y.textContent="",C.textContent="")})});k.addEventListener("click",function(b){a(b,function(a){a&&c()&&x&&x(a)})});return{isSupported:f,N:function(a,b){return f()?
-(x=b,a.appendChild(m),a.appendChild(k),t.value="",d(),t.focus(),!0):!1},search:d,close:b}}();var I,N=[];setInterval(function(){I.a.ca(Date.now())&&ka()},1E3);
-function Da(a,b){if(a!==J||!window.hasFocus){var c=new RegExp("<@"+null.id),d=!1,g=!1,e=!1;b.forEach(function(b){if(!(parseFloat(b.ts)<=a.h)){g=!0;var f;if(!(f=a instanceof w||b.text.match(c)))a:{f=null.M.da;for(var l=0,h=f.length;l<h;l++)if(-1!==b.text.indexOf(f[l])){f=!0;break a}f=!1}f&&(-1===N.indexOf(a)&&(e=!0,N.push(a)),d=!0)}});if(g){O();var l=document.getElementById(a.id);l&&(l.classList.add("unread"),d&&l.classList.add("unreadHi"));e&&!window.hasFocus&&ta()}}}
-function R(){var a=J,b=N.indexOf(a);if(a.i>a.h){var c=new XMLHttpRequest;c.open("POST","api/markread?room="+a.id+"&ts="+a.i,!0);c.send(null);a.h=a.i}0<=b&&(N.splice(b,1),O());a=document.getElementById(a.id);a.classList.remove("unread");a.classList.remove("unreadHi")}I=new function(){this.f=0;this.a=new n;this.b={}};var ja=function(){function a(a,b){b.sort(function(){return Math.random()-.5});for(var c=0,d=20;d<k-40;d+=h)for(var f=0;f+h<=m;f+=h)e(a,b[c],d,f),c++,c===b.length&&(b.sort(function(a,b){return a.s?b.s?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].s){c(a[e].src,function(c){a[e].s=c;b(a,d)});return}var g=[];a.forEach(function(a){a.s&&g.push(a.s)});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=t;c=c.getContext("2d");c.drawImage(a,0,0,t,t);for(var c=c.getImageData(0,0,t,t),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=f.createLinearGradient(0,0,0,m);a.addColorStop(0,"#4D394B");a.addColorStop(1,"#201820");f.fillStyle=a;f.fillRect(0,0,k,m);return f.getImageData(0,0,k,m)}function g(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 e(a,b,c,d){var e=Math.floor(d);a=[a.data[e*k*4+0],a.data[e*k*4+1],a.data[e*k*4+2]];f.fillStyle=
-"#"+(1.1*a[0]<<16|1.1*a[1]<<8|1.1*a[2]).toString(16);f.beginPath();f.moveTo(c+h/2,d+q);f.lineTo(c-q+h,d+h/2);f.lineTo(c+h/2,d-q+h);f.lineTo(c+q,d+h/2);f.closePath();f.fill();f.putImageData(g(f.getImageData(c+q,d+q,r,r),b),c+q,d+q)}var l=document.createElement("canvas"),f=l.getContext("2d"),k=l.width=250,m=l.height=290,h=(k-40)/3,q=.1*h,r=Math.floor(h-2*q),t=.5*r,u,A=[],E=!1;return function(c){if(u)c(u);else if(E)A.push(c);else{var e=d(),f=[];E=!0;A.push(c);for(var g in I.a.a)I.a.a[g].b||f.push({src:"api/avatar?user="+
-g});b(f,function(b){a(e,b);u=l.toDataURL();A.forEach(function(a){a(u)})})}}}();var Y=0,J=null,S=null,U=null;function Ea(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){Y&&(Y=0,P(!0));c=b.response;try{c=JSON.parse(c)}catch(g){c=null}}else Y?(Y+=Math.floor((Y||5)/2),Y=Math.min(60,Y)):(Y=5,P(!1));a(d,c)}else Y&&(Y=0,P(!0)),Ea(a)};b.open("GET","api?v="+I.f,!0);b.send(null)}function za(){var a=new XMLHttpRequest;a.open("POST","api/typing?room="+J.id,!0);a.send(null)}
-function Fa(a,b){if(a){if(b){var c=I,d=Date.now();b.v&&(c.f=b.v);b["static"]&&c.a.ea(b["static"],Date.now());for(var g in c.a.b){var e=c.a.b[g];if(e.i===e.h){var l=N.indexOf(e);-1!==l&&N.splice(l,1)}}if(b.live){for(e in b.live)(g=c.b[e])?H(g,b.live[e],d):c.b[e]=new G(e,250,b.live[e],d);for(var f in b.live)(d=c.a.b[f])?(c.b[f].a.length&&(e=c.b[f],d.i=Math.max(d.i,e.a[e.a.length-1].c)),d.b||(Da(d,b.live[f]),J&&b.live[J.id]&&na())):I.f=0}b["static"]&&(ga(),b["static"].typing&&ka())}Z()}else setTimeout(Z,
-1E3*Y)}function Z(){Ea(Fa)}function xa(a,b,c){var d=J;new FileReader;var g=new FormData,e=new XMLHttpRequest;g.append("file",b);g.append("filename",a);e.onreadystatechange=function(){4===e.readyState&&(204===e.status?c(null):c(e.statusText))};e.open("POST","api/file?room="+d.id);e.send(g)}
-function ya(a){if(U){var b=new XMLHttpRequest;b.open("PUT","api/msg?room="+J.id+"&ts="+U.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=I.a.B.data[a.substr(0,-1===c?void 0:c)])?(c=new XMLHttpRequest,c.open("POST","api/cmd?room="+J.id+"&cmd="+encodeURIComponent(a.name.substr(1))+"&args="+encodeURIComponent(b.trim()),!0),c.send(null),!0):!1}var b=J,c=S,d=new XMLHttpRequest;a="api/msg?room="+b.id+"&text="+encodeURIComponent(a);
-if(c){var g=I.a.a[c.l],e="Message";"C"===b.id[0]?e="Channel message":"D"===b.id[0]?e="Direct message":"G"===b.id[0]&&(e="Group message");a+="&attachments="+encodeURIComponent(JSON.stringify([{fallback:c.text,author_name:"<@"+g.id+"|"+g.name+">",author_icon:g.a.small,text:c.text,footer:e,ts:c.c}]))}d.open("POST",a,!0);d.send(null);return!0}function wa(a){var b=new XMLHttpRequest;b.open("DELETE","api/msg?room="+J.id+"&ts="+a.id,!0);b.send(null)}
-function oa(a,b,c){var d=new XMLHttpRequest;d.open("POST","api/reaction?room="+a+"&msg="+b+"&reaction="+encodeURIComponent(c),!0);d.send(null)};
+function ChatInfo(id){this.id=id;this.name;this.version=0}ChatInfo.prototype.toStatic=function(t){return t>=this.version?{}:{"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){if(data["users"])for(var i=0,nbUsers=data["users"].length;i<nbUsers;i++){var userObj=this.users[data["users"][i]["id"]];if(!userObj)userObj=this.users[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[data["channels"][i]["id"]];if(!chanObj)chanObj=this.channels[data["channels"][i]["id"]]=this.roomFactory(data["channels"][i]);
+chanObj.update(data["channels"][i],this,t)}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}if(data["team"]){if(!this.team)this.team=this.teamFactory(data["team"]["id"]);this.team.update(data["team"],t)}this.staticV=Math.max(this.staticV,t);if(data["self"]){this.self=this.users[data["self"]["id"]];if(!this.self.prefs)this.self.prefs=
+new SelfPreferences;this.self.prefs.update(data["self"]["prefs"],t)}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.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};if(this.isMember){res["members"]=this.members?Object.keys(this.members):[];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){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["latest"])this.lastMsg=parseFloat(chanData["latest"]["ts"]);if(chanData["members"]){this.members={};if(chanData["members"])for(var i=0,nbMembers=chanData["members"].length;i<nbMembers;i++){var member=ctx.users[chanData["members"][i]];this.members[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;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}};(function(){if(typeof module!=="undefined"){module.exports.Room=Room;module.exports.PrivateMessageRoom=PrivateMessageRoom}})();function Message(e,ts){this.userId=e.userId;this.username=e.userName;this.id=e.id;this.ts=e.ts;this.text;this.attachments;this.starred;this.pinned;this.edited;this.removed;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;var _this=this;if(e.reactions){this.reactions={};e.reactions.forEach(function(r){_this.reactions[r["name"]]=[];r["users"].forEach(function(userId){_this.reactions[r["name"]].push(userId)})})}}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{"user":this.userId,"username":this.username,"ts":this.id,"text":this.text,"attachments":this.attachments,"is_starred":this.is_starred||undefined,"edited":this.edited,"removed":this.removed,"reactions":reactions,"isMeMessage":this instanceof MeMessage,"isNotice":this instanceof NoticeMessage}};
+Message.prototype.addReaction=function(reaction,userId,ts){if(!this.reactions[reaction])this.reactions[reaction]=[];this.reactions[reaction].push(userId);this.version=ts};
+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 false;updated=true;return true});if(updated)this.version=ts};
+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){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.icons={small:"",large:""};this.email;this.firstName;this.lastName;this.channels={};this.ims=null;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,"icon_small":this.icons.small,"icon_large":this.icons.large}}};
+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.icons.small=userData["profile"]["image_48"];this.icons.large=userData["profile"]["image_512"];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)",areTyping:function(names){if(names.length===1)return names[0]+" est en train d'\u00e9crire";return names.join(", ")+" sont en train d'\u00e9crire"},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)",areTyping:function(names){if(names.length===1)return names[0]+" is typing";return names.join(", ")+" are typing"},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 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",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",msg:"slackmsg-msg",edited:"slackmsg-edited",same:{author:"slackmsg-same-author",ts:"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",pretext:"slackmsg-attachment-pretext",block:"slackmsg-attachment-block",title:"slackmsg-attachment-title",text:"slackmsg-attachment-text",thumbImg:"slackmsg-attachment-thumb",img:"slackmsg-attachment-img",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",italic:"slackmsg-style-italic",
+strike:"slackmsg-style-strike",quote:"slackmsg-style-quote"}}}};var NOTIFICATION_COOLDOWN=30*1E3,NOTIFICATION_DELAY=5*1E3,lastNotificationSpawn=0;
+function onContextUpdated(){var chanListFram=document.createDocumentFragment(),sortedChans=SLACK.context.self?Object.keys(SLACK.context.self.channels):[];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){var chanListItem=createChanListItem(chan);if(chanListItem)chanListFram.appendChild(chanListItem)}});var sortedUsers=
+SLACK.context.users?Object.keys(SLACK.context.users):[];sortedUsers.sort(function(a,b){return SLACK.context.users[a].name.localeCompare(SLACK.context.users[b].name)});sortedUsers.forEach(function(userId){var user=SLACK.context.users[userId];if(!user.deleted&&user.privateRoom){var imsListItem=createImsListItem(user.privateRoom);if(imsListItem)chanListFram.appendChild(imsListItem)}});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(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].ims;if(ims&&!ims.archived){var dom=document.getElementById(ims.id);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;if(SELECTED_ROOM&&typing[SELECTED_ROOM.id]){var typingUserNames=[],isOutOfSync=false;for(var i in typing[SELECTED_ROOM.id]){var member=SLACK.context.users[i];if(member)typingUserNames.push(member.name);else isOutOfSync=true}if(isOutOfSync)outOfSync();document.getElementById(R.id.typing).textContent=locale.areTyping(typingUserNames)}else document.getElementById(R.id.typing).textContent=""}
+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(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(createMessageDom("reply_"+SELECTED_ROOM.id,REPLYING_TO,true));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(createMessageDom("edit_"+SELECTED_ROOM.id,EDITING,true));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[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 formatEmojis(inputString){return inputString.replace(/:([^ \t:]+):/g,function(returnFailed,emoji){var emojiDom=makeEmojiDom(emoji);if(emojiDom){var domParent=document.createElement("span");domParent.className=returnFailed===inputString?R.klass.emoji.medium:R.klass.emoji.small;domParent.appendChild(emojiDom);return domParent.outerHTML}return returnFailed})}
+function formatText(fullText){var msgContents=fullText.split(/\r?\n/g);for(var msgContentIndex=0,nbMsgContents=msgContents.length;msgContentIndex<nbMsgContents;msgContentIndex++){var msgContent=msgContents[msgContentIndex].trim(),_msgContent="",currentMods={},quote=false,i=0;msgContent=msgContent.replace(new RegExp("<([@#]?)([^>]*)>","g"),function(matched,type,entity){var sub=entity.split("|");if(type==="@"){if(!sub[1]){var user=SLACK.context.users[sub[0]];sub[1]=user?"@"+user.name:locale.unknownMember}else if("@"!==
+sub[1][0])sub[1]="@"+sub[1];sub[0]="#"+sub[0];sub[2]=R.klass.msg.link+" "+R.klass.msg.linkuser}else if(type==="#"){if(!sub[1]){var chan=SLACK.context.channels[sub[0]];sub[1]=chan?"#"+chan.name:locale.unknownChannel}else if("#"!==sub[1][0])sub[1]="#"+sub[1];sub[0]="#"+sub[0];sub[2]=R.klass.msg.link+" "+R.klass.msg.linkchan}else if(sub[0].indexOf("://")!==-1){if(!sub[1])sub[1]=sub[0];sub[2]=R.klass.msg.link}else return matched;return'<a href="'+sub[0]+'" class="'+sub[2]+'"'+(!type?' target="_blank"':
+"")+">"+sub[1]+"</a>"});msgContent=formatEmojis(msgContent);var msgLength=msgContent.length;var isAlphadec=function(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},checkEnd=function(str,pos,c){while(str[pos]){if(isAlphadec(str[pos])&&str[pos]!=c&&str[pos+1]==c)return true;pos++}return false},appendMod=function(mods){if(!Object.keys(currentMods).length)return"";return'<span class="'+Object.keys(mods).join(" ")+'">'};while(i<msgLength&&(msgContent[i]===" "||msgContent[i]==="\t"))i++;if(msgContent.substr(i,4)==="&gt;"){quote=true;i+=4}for(;i<msgLength;i++){var c=msgContent[i];if(c==="<"){do _msgContent+=msgContent[i++];while(msgContent[i-1]!==">");i--;continue}if(!currentMods[R.klass.msg.style.bold]&&
+c==="*"&&msgContent[i+1]&&checkEnd(msgContent,i,c)){if(Object.keys(currentMods).length)_msgContent+="</span>";currentMods[R.klass.msg.style.bold]=true;_msgContent+=appendMod(currentMods)}else if(!currentMods[R.klass.msg.style.strike]&&c==="~"&&msgContent[i+1]&&checkEnd(msgContent,i,c)){if(Object.keys(currentMods).length)_msgContent+="</span>";currentMods[R.klass.msg.style.strike]=true;_msgContent+=appendMod(currentMods)}else if(!currentMods[R.klass.msg.style.code]&&c==="`"&&msgContent[i+1]&&checkEnd(msgContent,
+i,c)){if(Object.keys(currentMods).length)_msgContent+="</span>";currentMods[R.klass.msg.style.code]=true;_msgContent+=appendMod(currentMods)}else if(!currentMods[R.klass.msg.style.italic]&&c==="_"&&msgContent[i+1]&&checkEnd(msgContent,i,c)){if(Object.keys(currentMods).length)_msgContent+="</span>";currentMods[R.klass.msg.style.italic]=true;_msgContent+=appendMod(currentMods)}else{var finalFound=false;_msgContent+=c;do{if(currentMods[R.klass.msg.style.bold]&&c!=="*"&&msgContent[i+1]==="*"){delete currentMods[R.klass.msg.style.bold];
+finalFound=true}else if(currentMods[R.klass.msg.style.strike]&&c!=="~"&&msgContent[i+1]==="~"){delete currentMods[R.klass.msg.style.strike];finalFound=true}else if(currentMods[R.klass.msg.style.code]&&c!=="`"&&msgContent[i+1]==="`"){delete currentMods[R.klass.msg.style.code];finalFound=true}else if(currentMods[R.klass.msg.style.italic]&&c!=="_"&&msgContent[i+1]==="_"){delete currentMods[R.klass.msg.style.italic];finalFound=true}else break;c=msgContent[++i]}while(i<msgLength);if(finalFound)_msgContent+=
+"</span>"+appendMod(currentMods)}}if(currentMods)_msgContent+="</span>";if(quote)msgContents[msgContentIndex]='<span class="'+R.klass.msg.style.quote+'">'+_msgContent+"</span>";else msgContents[msgContentIndex]=_msgContent}return msgContents.join("<br/>")}function doCreateMeMessageDom(channelId,msg,skipAttachment){var dom=doCreateMessageDom(channelId,msg,skipAttachment);dom.classList.add(R.klass.msg.meMessage);return dom}
+function createMessageDom(channelId,msg,skipAttachment){var dom=msg.isMeMessage?doCreateMeMessageDom(channelId,msg,skipAttachment):doCreateMessageDom(channelId,msg,skipAttachment);if(msg.edited)dom.classList.add(R.klass.msg.edited);if(msg.notice)dom.classList.add(R.klass.msg.notice);return dom}
+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;if(SLACK.history[currentRoomId])SLACK.history[currentRoomId].messages.forEach(function(msg){if(!msg.removed){var dom=createMessageDom(currentRoomId,msg);if(prevMsg&&prevMsg.userId===msg.userId&&msg.userId){dom.classList.add(R.klass.msg.same.author);if(Math.abs(firstTsCombo-msg.ts)<30)prevMsgDom.classList.add(R.klass.msg.same.ts);else firstTsCombo=msg.ts}else firstTsCombo=
+msg.ts;if((!prevMsg||prevMsg.ts<=SELECTED_ROOM.lastRead)&&msg.ts>SELECTED_ROOM.lastRead)dom.classList.add(R.klass.msg.firstUnread);prevMsg=msg;prevMsgDom=dom;chatFrag.appendChild(dom)}});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.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 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)}}
+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()});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=chan.id;link.href="#"+chan.id;if(chan.isPrivate){dom.className=R.klass.chatList.entry+" "+R.klass.chatList.typePrivate;dom.dataset["count"]=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}
+function createImsListItem(ims){var dom=document.createElement("li"),link=document.createElement("a");dom.id=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}return null}
+function doCreateMessageDom(channelId,msg,skipAttachment){var dom=document.createElement("div"),msgBlock=document.createElement("div"),ts=document.createElement("div"),text=document.createElement("div"),authorImg=document.createElement("img"),authorName=document.createElement("span"),hover=document.createElement("ul"),hoverReply=document.createElement("li"),attachments=document.createElement("ul"),reactions=document.createElement("ul"),sender=SLACK.context.users[msg.userId];dom.id=channelId+"_"+msg.ts;
+dom.className=R.klass.msg.item;ts.className=R.klass.msg.ts;text.className=R.klass.msg.msg;authorImg.className=R.klass.msg.authorAvatar;authorName.className=R.klass.msg.authorname;hover.className=R.klass.msg.hover.container;hoverReply.className=R.klass.msg.hover.reply;ts.innerHTML=locale.formatDate(msg.ts);text.innerHTML=formatText(msg.text);authorName.textContent=sender?sender.name:msg.username||"?";authorImg.src=sender?sender.icons.small:"";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)}}dom.appendChild(authorImg);
+if(msg.notice){var onlyVisible=document.createElement("span");onlyVisible.className=R.klass.msg.notice;onlyVisible.textContent=locale.onlyVisible;msgBlock.appendChild(onlyVisible)}msgBlock.appendChild(authorName);msgBlock.appendChild(text);msgBlock.appendChild(ts);msgBlock.appendChild(attachments);if(msg.edited){var edited=document.createElement("div");edited.textContent=locale.edited;edited.className=R.klass.msg.edited;msgBlock.appendChild(edited)}msgBlock.appendChild(reactions);msgBlock.className=
+R.klass.msg.content;attachments.className=R.klass.msg.attachment.list;reactions.className=R.klass.msg.reactions.container;if(skipAttachment!==true){if(msg.reactions)for(var reaction in msg.reactions){var reac=createReactionDom(channelId,msg.id,reaction,msg.reactions[reaction]);reac&&reactions.appendChild(reac)}msg.attachments.forEach(function(attachment){var domAttachment=createAttachmentDom(channelId,msg,attachment);if(domAttachment)attachments.appendChild(domAttachment)})}dom.appendChild(msgBlock);
+dom.appendChild(hover);return dom}
+function createAttachmentDom(channelId,msg,attachment){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("img"),imgDom=document.createElement("img"),footerBlock=
+document.createElement("div"),footerIcon=document.createElement("img"),footerText=document.createElement("span"),footerTs=document.createElement("span");rootDom.className=R.klass.msg.attachment.container;var color="#e3e4e6";if(attachment["color"])if(attachment["color"][0]==="#")color=attachment["color"][0];else if(attachment["color"]==="good")color="#2fa44f";else if(attachment["color"]==="warning")color="#de9e31";else if(attachment["color"]==="danger")color="#d50200";attachmentBlock.style.borderColor=
+color;attachmentBlock.className=R.klass.msg.attachment.block;pretext.className=R.klass.msg.attachment.pretext;if(attachment["pretext"])pretext.innerHTML=formatText(attachment["pretext"]);else pretext.classList.add(R.klass.hidden);titleBlock.target="_blank";if(attachment["title"]){titleBlock.innerHTML=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=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"];else authorImg.classList.add(R.klass.hidden)}else authorBlock.classList.add(R.klass.hidden);textDom.innerHTML=formatText(attachment["text"]||
+"");textDom.klassName=R.klass.msg.attachment.text;thumbImgDom.className=R.klass.msg.attachment.thumbImg;if(attachment["thumb_url"])thumbImgDom.src=attachment["thumb_url"];else thumbImgDom.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;footerText.className=R.klass.msg.attachment.footerText;footerIcon.className=R.klass.msg.attachment.footerIcon;
+if(attachment["footer"]){footerText.innerHTML=formatText(attachment["footer"]);if(attachment["footer_icon"])footerIcon.src=attachment["footer_icon"];else footerIcon.classList.add(R.klass.hidden)}else{footerIcon.classList.add(R.klass.hidden);footerText.classList.add(R.klass.hidden)}footerTs.className=R.klass.msg.ts;if(attachment["ts"])footerTs.innerHTML=locale.formatDate(attachment["ts"]);else footerTs.classList.add(R.klass.hidden);authorBlock.appendChild(authorImg);authorBlock.appendChild(authorName);
+textBlock.appendChild(textDom);textBlock.appendChild(thumbImgDom);footerBlock.appendChild(footerIcon);footerBlock.appendChild(footerText);footerBlock.appendChild(footerTs);attachmentBlock.appendChild(titleBlock);attachmentBlock.appendChild(authorBlock);attachmentBlock.appendChild(textBlock);attachmentBlock.appendChild(imgDom);attachmentBlock.appendChild(footerBlock);rootDom.appendChild(pretext);rootDom.appendChild(attachmentBlock);return rootDom}
+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};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 RoomHistory(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.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(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.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)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.id).classList.add(R.klass.selected);document.body.classList.remove(R.klass.noRoomSelected);SELECTED_ROOM=room;onRoomSelected();if(SELECTED_ROOM.lastRead&&!SLACK.history[SELECTED_ROOM.id])fetchHistory(SELECTED_ROOM,function(success){})}function unselectRoom(){document.getElementById(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 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+">","author_icon":sender.icons.small,"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)};

+ 51 - 1
srv/src/chatter.js

@@ -31,9 +31,59 @@ function Chatter(id) {
     this.ims = null;
     /** @type {SelfPreferences|null} */
     this.prefs = null;
+    /** @type {boolean} */
+    this.isBot;
+    /** @type {PrivateMessageRoom|null} */
+    this.privateRoom = null;
     /** @type {number} */
     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
+            ,"icon_small": this.icons.small
+            ,"icon_large": this.icons.large
+        }
+    };
+};
+
+/**
+ * @param {*} userData
+ * @param {number} t
+**/
+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.icons.small = userData["profile"]["image_48"];
+        this.icons.large = userData["profile"]["image_512"];
+        this.email = userData["profile"]["email"];
+        this.firstName = userData["profile"]["first_name"];
+        this.lastName = userData["profile"]["last_name"];
+    }
+    this.version = Math.max(this.version, t);
+};
 
 /** @suppress {undefinedVars,checkTypes} */
 (function() {

+ 224 - 17
srv/src/context.js

@@ -7,23 +7,84 @@ function ChatInfo(id) {
     this.id = id;
     /** @type {string} */
     this.name;
-    /** @type {string} */
-    this.domain;
-    /** @type {string} */
-    this.callApp;
-    /** @type {string} */
-    this.callAppName;
-    /** @type {boolean} */
-    this.fileUploadPermission;
-    /** @type {boolean} */
-    this.fileEditPermission;
-    /** @type {boolean} */
-    this.fileDeletePermission;
-    /** @type {string} */
-    this.icons = ""
     /** @type {number} */
     this.version = 0;
-}
+};
+
+ChatInfo.prototype.toStatic = function(t) {
+    return t >= this.version ? {} : {
+        "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);
+};
+
+/**
+ * @constructor
+ * @param {*} data
+**/
+function Command(data) {
+    /** @const @type {string} */
+    this.desc = data["desc"];
+    /** @const @type {string} */
+    this.name = data["name"];
+    /** @const @type {string} */
+    this.type = data["type"];
+    /** @const @type {string} */
+    this.usage = data["usage"];
+    /** @const @type {string} */
+    this.category = data["category"];
+};
+
+/**
+ * @param {number} t
+ * @return {Object}
+**/
+Command.prototype.toStatic = function(t) {
+    return {
+        "desc": this.desc
+        ,"name": this.name
+        ,"type": this.type
+        ,"usage": this.usage
+        ,"category": this.category
+    };
+};
+
+/**
+ * @constructor
+**/
+function SelfPreferences() {
+    /** @type {Object.<string, number>} */
+    this.favoriteEmojis = {};
+
+    /** @type {Array.<string>} */
+    this.highlights = [];
+};
+
+/**
+ * @param {*} prefs
+**/
+SelfPreferences.prototype.update = function(prefs, t) {
+    this.favoriteEmojis = /** @type {Object<string,number>} */ (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
+    };
+};
 
 /**
  * @constructor
@@ -39,7 +100,7 @@ function ChatContext() {
     this.self = null;
     /** @type {{version: number, data: Object.<string, string>}} */
     this.emojis = { version: 0, data: {} };
-    /** @type {{version: number, data: Object.<string, SlackCommand>}} */
+    /** @type {{version: number, data: Object.<string, Command>}} */
     this.commands = {version: 0, data: {} };
     /** @type {Object.<string, Object.<string, number>>} */
     this.typing = {};
@@ -47,13 +108,159 @@ function ChatContext() {
     this.staticV = 0;
     /** @type {number} */
     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);
+};
+
+/**
+ * @param {*} data
+ * @param {number} t
+**/
+ChatContext.prototype.updateStatic = function(data, t) {
+    if (data["users"]) for (var i =0, nbUsers = data["users"].length; i < nbUsers; i++) {
+        var userObj = this.users[data["users"][i]["id"]];
+        if (!userObj)
+            userObj = this.users[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[data["channels"][i]["id"]];
+        if (!chanObj)
+            chanObj = this.channels[data["channels"][i]["id"]] = this.roomFactory(data["channels"][i]);
+        chanObj.update(data["channels"][i], this, t);
+    }
+    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;
+    }
+    if (data["team"]) {
+        if (!this.team) this.team = this.teamFactory(data["team"]["id"]);
+        this.team.update(data["team"], t);
+    }
+    this.staticV = Math.max(this.staticV, t);
+    if (data["self"]) {
+        this.self = this.users[data["self"]["id"]];
+        if (!this.self.prefs) this.self.prefs = new SelfPreferences();
+        this.self.prefs.update(data["self"]["prefs"], t);
+    }
+    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;
+        }
+    }
+};
+
+/**
+ * @param {number} t
+ * @param {number} now
+**/
+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] +3000 >= 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;
+};
+
+/**
+ * @param {number} now
+**/
+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] +3000 < now) {
+                delete this.typing[typingChan][typingUser];
+                updated = true;
+            } else {
+                chanEmpty = false;
+            }
+        }
+        if (chanEmpty) {
+            delete this.typing[typingChan];
+            updated = true;
+        }
+    }
+    return updated;
+};
 
 /** @suppress {undefinedVars,checkTypes} */
 (function() {
     if (typeof module !== "undefined") {
         module.exports.ChatContext = ChatContext;
         module.exports.ChatInfo = ChatInfo;
+        module.exports.Command = Command;
     }
 })();
 

+ 11 - 11
srv/src/httpServ.js

@@ -127,7 +127,7 @@ Server.prototype.onRequest = function(req, res) {
             } else {
                 var allFound = true;
                 req.urlObj.queryTokens.room.forEach(function(targetId) {
-                    if (!res.slack.data.getChannel(targetId)) {
+                    if (!res.slack.data.channels[targetId]) {
                         allFound = false;
                     }
                     res.slack.fetchHistory(targetId);
@@ -144,7 +144,7 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var chan = res.slack.data.getChannel(req.urlObj.queryTokens.room[0]);
+                var chan = res.slack.data.channels[req.urlObj.queryTokens.room[0]];
 
                 if (!chan) {
                     res.writeHeader("404", "Chan not found");
@@ -160,7 +160,7 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var chan = res.slack.data.getChannel(req.urlObj.queryTokens.room[0])
+                var chan = res.slack.data.channels[req.urlObj.queryTokens.room[0]]
                     ,cmd = res.slack.data.commands.data['/' +req.urlObj.queryTokens.cmd[0]];
 
                 if (!chan) {
@@ -181,7 +181,7 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var chan = res.slack.data.getChannel(req.urlObj.queryTokens.room[0])
+                var chan = res.slack.data.channels[req.urlObj.queryTokens.room[0]]
                     ,ts = parseFloat(req.urlObj.queryTokens.ts[0]);
                 if (!chan)
                     res.writeHeader("404", "Chan Not Found");
@@ -197,12 +197,12 @@ Server.prototype.onRequest = function(req, res) {
                 res.writeHeader("400", "Bad request");
                 res.end();
             } else {
-                var user = res.slack.data.getMember(req.urlObj.queryTokens.user[0]);
+                var user = res.slack.data.users[req.urlObj.queryTokens.user[0]];
                 if (!user) {
                     res.writeHeader("404", "User Not Found");
                     res.end();
                 } else {
-                    var url = user.icons.image_48;
+                    var url = user.icons.small;
                     if (url.substr(0, 7) === "http://")
                         http.get(url, (d) => {
                             d.pipe(res, { end: true });
@@ -219,7 +219,7 @@ Server.prototype.onRequest = function(req, res) {
                 if (!req.urlObj.queryTokens.room || !req.urlObj.queryTokens.text) {
                     res.writeHeader("400", "Bad request");
                 } else {
-                    var chan = res.slack.data.getChannel(req.urlObj.queryTokens.room[0]);
+                    var chan = res.slack.data.channels[req.urlObj.queryTokens.room[0]];
                     if (chan) {
                         var attachments = null;
                         if (req.urlObj.queryTokens.attachments) {
@@ -239,7 +239,7 @@ Server.prototype.onRequest = function(req, res) {
                 if (!req.urlObj.queryTokens.room || !req.urlObj.queryTokens.ts) {
                     res.writeHeader("400", "Bad request");
                 } else {
-                    var chan = res.slack.data.getChannel(req.urlObj.queryTokens.room[0]);
+                    var chan = res.slack.data.channels[req.urlObj.queryTokens.room[0]];
                     if (chan) {
                         res.slack.removeMsg(chan, req.urlObj.queryTokens.ts[0]);
                         res.writeHeader("204", "No Content");
@@ -251,7 +251,7 @@ 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.slack.data.getChannel(req.urlObj.queryTokens.room[0]);
+                    var chan = res.slack.data.channels[req.urlObj.queryTokens.room[0]];
                     if (chan) {
                         res.slack.editMsg(chan, req.urlObj.queryTokens.ts[0], req.urlObj.queryTokens.text);
                         res.writeHeader("204", "No Content");
@@ -270,7 +270,7 @@ Server.prototype.onRequest = function(req, res) {
                 ,reaction = req.urlObj.queryTokens["reaction"] ? req.urlObj.queryTokens["reaction"][0] : undefined;
 
             if (chanId && msgId && reaction) {
-                var chan = res.slack.data.getChannel(chanId);
+                var chan = res.slack.data.channels[chanId];
                 if (!chan) {
                     res.writeHeader("404", "Channel Not Found");
                 } else if (req.method === 'POST') {
@@ -290,7 +290,7 @@ 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.slack.data.getChannel(req.urlObj.queryTokens["room"][0]);
+                var chan = res.slack.data.channels[req.urlObj.queryTokens["room"][0]];
                 if (chan) {
                     var uploadRequest = res.slack.openUploadFileStream(chan, req.headers["content-type"], (errorMsg) => {
                         if (!errorMsg)

+ 18 - 9
srv/src/message.js

@@ -191,25 +191,32 @@ RoomHistory.prototype.pushAll = function(evts, t) {
 }
 
 /**
- * @param {string} msgId
- * @param {Message} msg
- * @param {function(*):Message} msgFactory
+ * @param {*} ev
+ * @param {number} ts
+ * @return {Message}
+**/
+RoomHistory.prototype.messageFactory = function(ev, ts) {
+    return new Message(ev, ts);
+}
+
+/**
+ * @param {*} e
  * @return {number} t
 **/
-RoomHistory.prototype.push = function(msgId, msg, msgFactory, t) {
+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 === msgId) {
-            ts = msgObj.update(msg, t);
+        if (msgObj.id === e["id"]) {
+            ts = msgObj.update(e, t);
             exists = true;
             break;
         }
     }
     if (!exists) {
-        var msgObj = msgFactory(msg);
+        var msgObj = this.messageFactory(e, t);
         this.messages.push(msgObj);
         ts = msgObj.ts;
     }
@@ -293,8 +300,10 @@ RoomHistory.prototype.resort = function() {
     });
 };
 
-MeMessage.prototype = Object.create(Message);
-NoticeMessage.prototype = Object.create(Message);
+MeMessage.prototype = Object.create(Message.prototype);
+MeMessage.prototype.constructor = MeMessage;
+NoticeMessage.prototype = Object.create(Message.prototype);
+NoticeMessage.prototype.constructor = NoticeMessage;
 
 /** @suppress {undefinedVars,checkTypes} */
 (function() {

+ 94 - 5
srv/src/room.js

@@ -1,3 +1,4 @@
+
 /**
  * @constructor
 **/
@@ -36,8 +37,12 @@ function Room(id) {
     this.version = 0;
     /** @type {boolean} */
     this.isPrivate;
-}
+};
 
+/**
+ * @param {number} lastMsg
+ * @param {number} t
+**/
 Room.prototype.setLastMsg = function(lastMsg, t) {
     if (this.lastMsg < lastMsg) {
         this.lastMsg = lastMsg;
@@ -45,20 +50,104 @@ Room.prototype.setLastMsg = function(lastMsg, t) {
         return true;
     }
     return false;
-}
+};
+
+/**
+ * @param {number} t
+**/
+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
+    };
+    if (this.isMember) {
+        res["members"] = this.members ? Object.keys(this.members) : [];
+        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;
+};
+
+/**
+ * @param {*} chanData
+ * @param {ChatContext} ctx
+ * @param {number} t
+**/
+Room.prototype.update = function(chanData, ctx, t) {
+    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["latest"]) this.lastMsg = parseFloat(chanData["latest"]["ts"]);
+    if (chanData["members"]) {
+        this.members = {};
+        if (chanData["members"]) for (var i =0, nbMembers = chanData["members"].length; i < nbMembers; i++) {
+            var member = ctx.users[chanData["members"][i]];
+            this.members[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);
+};
 
 /**
  * @constructor
+ * @extends {Room}
  * @param {string} id
  * @param {Chatter} user
- * @extends {Room}
 **/
 function PrivateMessageRoom(id, user) {
     Room.call(this, id);
     /** @const @type {Chatter} */
     this.user = user;
-}
-PrivateMessageRoom.prototype = Object.create(Room);
+    user.privateRoom = this;
+};
+PrivateMessageRoom.prototype = Object.create(Room.prototype);
+PrivateMessageRoom.prototype.constructor = PrivateMessageRoom;
+
+/**
+ * @param {number} t
+**/
+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
+    };
+};
 
 /** @suppress {undefinedVars,checkTypes} */
 (function() {

+ 1 - 1
srv/src/slack.js

@@ -226,7 +226,7 @@ Slack.prototype.onMessage = function(msg, t) {
     this.data.onMessage(msg, t);
     if ((msg["channel"] || msg["channel_id"] || (msg["item"] && msg["item"]["channel"])) && msg["type"] && UPDATE_LIVE.indexOf(msg["type"]) !== -1) {
         var channelId = msg["channel"] || msg["channel_id"] || msg["item"]["channel"]
-            ,channel = this.data.getChannel(msg["channel"])
+            ,channel = this.data.channels[msg["channel"]]
             ,histo = this.history[channelId];
         if (histo) {
             var lastMsg = histo.push(msg, t);

+ 97 - 584
srv/src/slackData.js

@@ -1,6 +1,10 @@
 
 const ChatContext = require('./context.js').ChatContext
-    ,ChatInfo = require('./context.js').ChatInfo;
+    ,ChatInfo = require('./context.js').ChatInfo
+    ,Command = require('./context.js').Command
+    ,Room = require('./room.js').Room
+    ,Chatter = require('./chatter.js').Chatter
+    ,PrivateMessageRoom = require('./room.js').PrivateMessageRoom;
 
 /**
  * @constructor
@@ -8,11 +12,48 @@ const ChatContext = require('./context.js').ChatContext
 **/
 function SlackTeam(teamId) {
     ChatInfo.call(this, teamId);
+    /** @type {string} */
+    this.domain;
+    /** @type {string} */
+    this.callApp;
+    /** @type {string} */
+    this.callAppName;
+    /** @type {boolean} */
+    this.fileUploadPermission;
+    /** @type {boolean} */
+    this.fileEditPermission;
+    /** @type {boolean} */
+    this.fileDeletePermission;
+    /** @type {string} */
+    this.icons = {
+        small: ""
+        ,large: ""
+    };
+}
+SlackTeam.prototype = Object.create(ChatInfo.prototype);
+SlackTeam.prototype.constructor = SlackTeam;
+
+SlackTeam.prototype.toStatic = function(t) {
+    var res = ChatInfo.prototype.toStatic.call(this, t);
+    if (res) {
+        res["domain"] = this.domain
+        res["prefs"] = {
+            "calling_app_id": this.callApp
+            ,"calling_app_name": this.callAppName
+            ,"disable_file_uploads": this.fileUploadPermission
+            ,"disable_file_editing": this.fileEditPermission
+            ,"disable_file_deleting": this.fileDeletePermission
+        }
+        res["icon"] = {
+            "small": this.icons.small
+            ,"large": this.icons.large
+        };
+    }
+    return res;
 }
-SlackTeam.prototype = Object.create(ChatInfo);
 
 SlackTeam.prototype.update = function(teamData, t) {
-    if (teamData["name"] !== undefined) this.name = teamData["name"];
+    ChatInfo.prototype.update.call(this, teamData, t);
     if (teamData["domain"] !== undefined) this.domain = teamData["domain"];
     if (teamData["prefs"]) {
         this.callApp = teamData["prefs"]["calling_app_id"];
@@ -22,197 +63,33 @@ SlackTeam.prototype.update = function(teamData, t) {
         this.fileDeletePermission = teamData["prefs"]["disable_file_deleting"];
     }
     if (teamData["icon"]) {
-        this.icons.image_34 = teamData["icon"]["image_34"];
-        this.icons.image_44 = teamData["icon"]["image_44"];
-        this.icons.image_68 = teamData["icon"]["image_68"];
-        this.icons.image_88 = teamData["icon"]["image_88"];
-        this.icons.image_102 = teamData["icon"]["image_102"];
-        this.icons.image_132 = teamData["icon"]["image_132"];
-        this.icons.image_230 = teamData["icon"]["image_230"];
-        this.icons.image_default = teamData["icon"]["image_default"];
+        this.icons.small = teamData["icon"]["image_34"];
+        this.icons.large = teamData["icon"]["image_230"];
     }
-    this.version = Math.max(this.version, t);
 }
 
 /**
  * @constructor
 **/
-function SlackChan(chanId) {
+function SlackChan(chanId, isGroup) {
     Room.call(this, chanId);
+    this.isPrivate = isGroup;
 }
 
-SlackChan.prototype = Object.create(Room);
-
-/**
- * @param {*} chanData
- * @param {SlackData} slackData
-**/
-SlackChan.prototype.update = function(chanData, slackData, t) {
-    if (chanData["name"] !== undefined) this.name = chanData["name"];
-    if (chanData["created"] !== undefined) this.created = chanData["created"];
-    if (chanData["creator"] !== undefined) this.creator = slackData.getMember(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["latest"]) this.lastMsg = parseFloat(chanData["latest"]["ts"]);
-    if (chanData["members"]) {
-        this.members = {};
-        if (chanData["members"]) for (var i =0, nbMembers = chanData["members"].length; i < nbMembers; i++) {
-            var member = slackData.getMember(chanData["members"][i]);
-            this.members[member.id] = member;
-            member.channels[this.id] = this;
-        }
-    }
-    if (chanData["topic"]) {
-        this.topic = chanData["topic"]["value"];
-        this.topicCreator = slackData.getMember(chanData["topic"]["creator"]);
-        this.topicTs = chanData["topic"]["last_set"];
-    }
-    if (chanData["purpose"]) {
-        this.purpose = chanData["purpose"]["value"];
-        this.purposeCreator = slackData.getMember(chanData["purpose"]["creator"]);
-        this.purposeTs = chanData["purpose"]["last_set"];
-    }
-    this.version = Math.max(this.version, t);
-}
+SlackChan.prototype = Object.create(Room.prototype);
+SlackChan.prototype.constructor = SlackChan;
 
 /**
  * @constructor
+ * @extends {PrivateMessageRoom}
  * @param {string} id
-**/
-function SlackGroup(id) {
-    /** @const @type {string} */
-    this.id = id;
-    /** @type {Object.<string, SlackUser|SlackBot>} */
-    this.members = {};
-    /** @type {number} */
-    this.nbMembers = 0;
-    /** @type {string} */
-    this.name;
-    /** @type {number} */
-    this.created;
-    /** @type {SlackUser|SlackBot} */
-    this.creator;
-    /** @type {boolean} */
-    this.archived;
-    /** @type {number} */
-    this.lastRead = 0;
-    /** @type {number} */
-    this.lastMsg = 0;
-    /** @type {string|undefined} */
-    this.topic;
-    /** @type {number|undefined} */
-    this.topicTs;
-    /** @type {SlackUser|SlackBot|undefined} */
-    this.topicCreator;
-    /** @type {string|undefined} */
-    this.purpose;
-    /** @type {number|undefined} */
-    this.purposeTs;
-    /** @type {SlackUser|SlackBot|undefined} */
-    this.purposeCreator;
-    /** @type {number} version */
-    this.version = 0;
-}
-
-/**
- * @param {SlackData} slack
- * @param {*} groupData
-**/
-SlackGroup.prototype.update = function(slack, groupData, t) {
-    var memberNames = [];
-    if (groupData["members"]) {
-        /** @type {Object.<string, SlackUser|SlackBot>} */
-        this.members = {};
-        this.nbMembers = 0;
-        for (var i =0, nbMembers = groupData["members"].length; i < nbMembers; i++) {
-            var member = slack.getMember(groupData["members"][i]);
-            this.members[groupData["members"][i]] = member;
-            member.channels[this.id] = this;
-            memberNames.push(member.name);
-            this.nbMembers++;
-        }
-        this.name = memberNames.join(", ");
-    }
-    if (groupData["created"] !== undefined) this.created = groupData["created"];
-    if (groupData["creator"] !== undefined) this.creator = slack.getMember(groupData["creator"]);
-    if (groupData["is_archived"] !== undefined) this.archived = groupData["is_archived"] || groupData["is_open"] === false;
-    if (groupData["last_read"] !== undefined) this.lastRead = Math.max(parseFloat(groupData["last_read"]), this.lastRead);
-    if (groupData["last_msg"] !== undefined) this.lastMsg = parseFloat(groupData["last_msg"]);
-    else if (groupData["latest"]) this.lastMsg = parseFloat(groupData["latest"]["ts"]);
-    if (groupData["topic"]) {
-        this.topic = groupData["topic"]["value"];
-        this.topicCreator = slack.getMember(groupData["topic"]["creator"]);
-        this.topicTs = groupData["topic"]["last_set"];
-    }
-    if (groupData["purpose"]) {
-        this.purpose = groupData["purpose"]["value"];
-        this.purposeCreator = slack.getMember(groupData["purpose"]["creator"]);
-        this.purposeTs = groupData["purpose"]["last_set"];
-    }
-    this.version = Math.max(this.version, t);
-}
-
-/**
- * @constructor
- * @param {string} id
- * @param {SlackUser|SlackBot} user
+ * @param {SlackChatter} user
 **/
 function SlackIms(id, user) {
-    /** @const @type {string} */
-    this.id = id;
-    /** @type {number} */
-    this.created;
-    /** @type {SlackUser|SlackBot} */
-    this.user = user;
-    /** @type {number} */
-    this.lastRead = 0;
-    /** @type {number} */
-    this.lastMsg = 0;
-    /** @type {boolean} */
-    this.archived;
-    /** @type {number} */
-    this.version = 0;
-}
-
-/**
- * @param {SlackUser|SlackBot} user
- * @param {*} imsData
-**/
-SlackIms.prototype.update = function(user, imsData, t) {
-    if (imsData["created"] !== undefined) this.created = imsData["created"];
-    if (imsData["last_read"] !== undefined) this.lastRead = Math.max(parseFloat(imsData["last_read"]), this.lastRead);
-    if (imsData["last_msg"] !== undefined) this.lastMsg = parseFloat(imsData["last_msg"]);
-    if (imsData["latest"]) this.lastMsg = parseFloat(imsData["latest"]["ts"]);
-    this.archived = user.deleted;
-    this.version = Math.max(this.version, t);
-}
-
-/**
- * @constructor
-**/
-function SelfPreferences() {
-    /** @type {Object.<string, number>} */
-    this.favoriteEmojis = {};
-
-    /** @type {Array.<string>} */
-    this.highlights = [];
-}
-
-/**
- * @param {*} prefs
-**/
-SelfPreferences.prototype.update = function(prefs, t) {
-    this.favoriteEmojis = /** @type {Object<string,number>} */ (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);
+    PrivateMessageRoom.call(this, id, user);
 }
+SlackIms.prototype = Object.create(PrivateMessageRoom.prototype);
+SlackIms.prototype.constructor = SlackIms;
 
 /**
  * @constructor
@@ -221,7 +98,8 @@ SelfPreferences.prototype.update = function(prefs, t) {
 function SlackChatter(id) {
     Chatter.call(this, id);
 }
-SlackChatter.prototype = Object.create(Chatter);
+SlackChatter.prototype = Object.create(Chatter.prototype);
+SlackChatter.prototype.constructor = SlackChatter;
 
 SlackChatter.prototype.setPresence = function(presenceStr, t) {
     this.presence = presenceStr !== 'away';
@@ -235,36 +113,8 @@ SlackChatter.prototype.setPresence = function(presenceStr, t) {
 function SlackUser(id) {
     SlackChatter.call(this, id);
 }
-SlackUser.prototype = Object.create(SlackChatter);
-
-/**
- * @param {*} userData
-**/
-SlackUser.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["profile"]) {
-        this.icons.image_24 = userData["profile"]["image_24"];
-        this.icons.image_32 = userData["profile"]["image_32"];
-        this.icons.image_48 = userData["profile"]["image_48"];
-        this.icons.image_72 = userData["profile"]["image_72"];
-        this.icons.image_192 = userData["profile"]["image_192"];
-        this.icons.image_512 = userData["profile"]["image_512"];
-        this.email = userData["profile"]["email"];
-        this.firstName = userData["profile"]["first_name"];
-        this.lastName = userData["profile"]["last_name"];
-    }
-    this.version = Math.max(this.version, t);
-}
+SlackUser.prototype = Object.create(SlackChatter.prototype);
+SlackUser.prototype.constructor = SlackUser;
 
 /**
  * @constructor
@@ -274,75 +124,16 @@ function SlackBot(id) {
     SlackChatter.call(this, id);
     /** @type {string} */
     this.appId;
+    this.isBot = true;
 }
-SlackBot.prototype = Object.create(SlackChatter);
+SlackBot.prototype = Object.create(SlackChatter.prototype);
+SlackBot.prototype.constructor = SlackBot;
 
 /** @param {*} botData */
 SlackBot.prototype.update = function(botData, t) {
-    if (botData["deleted"] !== undefined) this.deleted = botData["deleted"];
-    if (botData["name"] !== undefined) this.name = botData["name"];
+    SlackChatter.prototype.update.call(this, botData, t);
     if (botData["app_id"] !== undefined) this.appId = botData["app_id"];
-    if (botData["icons"]) {
-        this.icons.image_36 = botData["icons"]["image_36"]
-        this.icons.image_48 = botData["icons"]["image_48"]
-        this.icons.image_72 = botData["icons"]["image_72"]
-    }
-    if (botData["presence"] !== undefined)
-        this.presence = botData["presence"] !== 'away';
-    if (botData["isPresent"] !== undefined)
-        this.presence = botData["isPresent"];
-    this.version = Math.max(this.version, t);
-}
-
-/**
- * @constructor
- * @param {*} data
-**/
-function SlackCommand(slack, data) {
-    /** @const @type {string} */
-    this.desc = data["desc"];
-    /** @const @type {string} */
-    this.name = data["name"];
-    /** @const @type {string} */
-    this.type = data["type"];
-    /** @const @type {string} */
-    this.usage = data["usage"];
-    /** @const @type {string|null} */
-    this.serviceName = SlackCommand.getServiceName(slack, data);
-}
-
-/**
- * @param {SlackData} slack
- * @param {*} data
- * @return {string|null}
-**/
-SlackCommand.getServiceName = function(slack, data) {
-    if (data["service_name"])
-        return data["service_name"];
-    else if (data["app"]) {
-        var bots = slack.getBotsByAppId(data["app"]);
-        if (bots)
-            for (var i =0; i < bots.length; i++)
-                if (bots[i].name)
-                    return bots[i].name;
-        console.log("Unknown app " +data["app"]);
-        return "";
-    }
-    return "Slack";
-}
-
-/**
- * @param {number} t
- * @return {Object}
-**/
-SlackCommand.prototype.toStatic = function(t) {
-    return {
-        "desc": this.desc
-        ,"name": this.name
-        ,"type": this.type
-        ,"usage": this.usage
-        ,"service_name": this.serviceName
-    };
+    this.isBot = true;
 }
 
 /**
@@ -357,341 +148,63 @@ function SlackData(slack) {
     **/
     this.slack = slack;
 }
-SlackData.prototype = Object.create(ChatContext);
-
-/**
- * @return {Object}
-**/
-SlackTeam.prototype.toStatic = function(t) {
-    return t >= this.version ? {} : {
-        "id": this.id
-        ,"name": this.name
-        ,"domain": this.domain
-        ,"prefs": {
-            "calling_app_id": this.callApp
-            ,"calling_app_name": this.callAppName
-            ,"disable_file_uploads": this.fileUploadPermission
-            ,"disable_file_editing": this.fileEditPermission
-            ,"disable_file_deleting": this.fileDeletePermission
-        }
-        ,"icon": this.icons
-    };
-};
-
-/**
- * @return {Object}
-**/
-SlackChan.prototype.toStatic = function(t) {
-    if (t >= this.version)
-        return null;
-    var res = {
-        "id": this.id
-        ,"name": this.name
-        ,"created": this.created
-        ,"creator": this.creator.id
-        ,"is_archived": this.archived
-        ,"is_member": this.isMember
-        ,"last_read": this.lastRead
-        ,"last_msg": this.lastMsg
-    };
-    if (this.isMember) {
-        res["members"] = this.members ? Object.keys(this.members) : [];
-        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;
-};
-
-/**
- * @return {Object}
-**/
-SlackUser.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
-        ,"profile": {
-            "email": this.email
-            ,"first_name": this.firstName
-            ,"last_name": this.lastName
-
-            ,"image_24": this.icons.image_24
-            ,"image_32": this.icons.image_32
-            ,"image_48": this.icons.image_48
-            ,"image_72": this.icons.image_72
-            ,"image_192": this.icons.image_192
-            ,"image_512": this.icons.image_512
-        }
-    };
-};
-
-SlackGroup.prototype.toStatic = function(t) {
-    if (t >= this.version)
-        return null;
-    var res = {
-        "id": this.id
-        ,"members": []
-        ,"created": this.created
-        ,"creator": this.creator.id
-        ,"is_archived": this.archived
-        ,"last_read": this.lastRead
-        ,"last_msg": this.lastMsg
-    };
-    for (var mId in this.members) {
-        res["members"].push(mId);
-    }
-    if (this.topic) {
-        res["topic"] = {
-            "value": this.topic
-            ,"creator": this.topicCreator.id
-            ,"last_set": this.topicTs
-        };
-    }
-    if (this.purpose) {
-        res["purpose"] = {
-            "value": this.purpose
-            ,"creator": this.purposeCreator.id
-            ,"last_set": this.purposeTs
-        };
-    }
-    return res;
-};
-
-SlackIms.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
-    };
-}
-
-SlackBot.prototype.toStatic = function(t) {
-    return t >= this.version ? null : {
-        "id": this.id
-        ,"deleted": this.deleted
-        ,"name": this.name
-        ,"app_id": this.appId
-        ,"isPresent": this.presence
-        ,"icons": {
-            "image_36": this.icons.image_36
-            ,"image_48": this.icons.image_48
-            ,"image_72": this.icons.image_72
-        }
-    };
-}
+SlackData.prototype = Object.create(ChatContext.prototype);
+SlackData.prototype.constructor = SlackData;
 
 /**
  * @param {*} data
 **/
 SlackData.prototype.updateStatic = function(data, t) {
     if (data["bots"]) for (var i =0, nbBots = data["bots"].length; i < nbBots; i++) {
-        var botObj = this.bots[data["bots"][i]["id"]];
+        var botObj = this.users[data["bots"][i]["id"]];
         if (!botObj)
-            botObj = this.bots[data["bots"][i]["id"]] = new SlackBot(data["bots"][i]["id"]);
+            botObj = this.users[data["bots"][i]["id"]] = new SlackBot(data["bots"][i]["id"]);
         botObj.update(data["bots"][i], t);
     }
-    if (data["users"]) for (var i =0, nbUsers = data["users"].length; i < nbUsers; i++) {
-        var userObj = this.users[data["users"][i]["id"]];
-        if (!userObj)
-            userObj = this.users[data["users"][i]["id"]] = new SlackUser(data["users"][i]["id"]);
-        userObj.update(data["users"][i], t);
-    }
+    ChatContext.prototype.updateStatic.call(this, data, t);
     if (data["ims"]) for (var i =0, nbIms = data["ims"].length; i < nbIms; i++) {
-        var user = this.getMember(data["ims"][i]["user"]);
+        var user = this.users[data["ims"][i]["user"]];
         if (user) {
-            if (!user.ims)
-                this.ims[data["ims"][i]["id"]] = user.ims = new SlackIms(data["ims"][i]["id"], user);
-            user.ims.update(user, data["ims"][i], t);
+            if (!this.channels[data["ims"][i]["id"]])
+                this.channels[data["ims"][i]["id"]] = new SlackIms(data["ims"][i]["id"], user);
+            this.channels[data["ims"][i]["id"]].update(user, data["ims"][i], t);
         }
     }
-    if (data["channels"]) for (var i =0, nbChan = data["channels"].length; i < nbChan; i++) {
-        var chanObj = this.channels[data["channels"][i]["id"]];
-        if (!chanObj)
-            chanObj = this.channels[data["channels"][i]["id"]] = new SlackChan(data["channels"][i]["id"]);
-        chanObj.update(data["channels"][i], this, t);
-    }
     for (var i =0, nbGroups = data["groups"].length; i < nbGroups; i++) {
-        var groupObj = this.groups[data["groups"][i]["id"]];
+        var groupObj = this.channels[data["groups"][i]["id"]];
         if (!groupObj)
-            groupObj = this.groups[data["groups"][i]["id"]] = new SlackGroup(data["groups"][i]["id"]);
+            groupObj = this.channels[data["groups"][i]["id"]] = new SlackChan(data["groups"][i]["id"]);
         groupObj.update(this, data["groups"][i], t);
     }
-    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] = new SlackCommand(this, data["commands"][i]);
-        }
-        this.commands.version = t;
-    }
-    if (data["team"]) {
-        if (!this.team) this.team = new SlackTeam(data["team"]["id"]);
-        this.team.update(data["team"], t);
-    }
-    this.staticV = Math.max(this.staticV, t);
-    if (data["self"]) {
-        this.self = this.getMember(data["self"]["id"]);
-        if (!this.self.prefs) this.self.prefs = new SelfPreferences();
-        this.self.prefs.update(data["self"]["prefs"], t);
-    }
-    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;
-        }
-    }
 };
 
-SelfPreferences.prototype.toStatic = function(t) {
-    return this.version > t ? null : {
-        "emoji_use": JSON.stringify(this.favoriteEmojis)
-        ,"highlights": this.highlights
-    };
+SlackData.prototype.userFactory = function(userData) {
+    return new SlackUser(userData["id"]);
 }
 
-/**
- * @param {string} appId
- * @return {Array.<SlackBot>}
-**/
-SlackData.prototype.getBotsByAppId = function(appId) {
-    var bots = [];
-
-    for (var botId in this.bots) {
-        if (this.bots[botId].appId === appId) {
-            bots.push(this.bots[botId]);
-        }
-    }
-    return bots;
-};
-
-/**
- * @param {string} chanId
- * @return {SlackChan|SlackGroup|SlackIms|null}
-**/
-SlackData.prototype.getChannel = function(chanId) {
-    return this.channels[chanId] || this.ims[chanId] || this.groups[chanId] || null;
-};
-
-/**
- * @param {function(Room):(boolean|undefined)} cb should return false to stop iterating
- * @return {boolean} true if iterated through all entities
-**/
-SlackData.prototype.forEachChans = function(cb) {
-    for (var i in this.channels) {
-        if (cb(this.channels[i]) === false) return false;
-    }
-    for (var i in this.ims) {
-        if (!cb(this.ims[i]) === false) return false;
-    }
-    for (var i in this.groups) {
-        if (!cb(this.groups[i]) === false) return false;
-    }
-    return true;
+SlackData.prototype.roomFactory = function(roomData) {
+    return new SlackChan(roomData["id"]);
 }
 
-/** @return {Object} */
-SlackData.prototype.buildStatic = function(t, now) {
-    var res = {
-        "team": this.team.toStatic(t)
-        ,"channels": []
-        ,"groups": []
-        ,"ims": []
-        ,"users": []
-        ,"bots": []
-        ,"self": {
-            "id": this.self.id
-            ,"prefs": this.self.prefs.toStatic(t)
-        }
-        ,"emojis": this.emojis.version > t ? this.emojis.data : undefined
-        ,"commands": undefined
-        ,"typing": 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)
-            res["channels"].push(chan);
-    }
-    for (var userId in this.users) {
-        var user = this.users[userId].toStatic(t)
-            ,ims = this.users[userId].ims.toStatic(t);
-
-        if (user)
-            res["users"].push(user);
-        if (ims)
-            res["ims"].push(ims);
-    }
-    for (var botId in this.bots) {
-        var bot = this.bots[botId].toStatic(t);
-        if (bot)
-            res["bots"].push(bot);
-    }
-    for (var groupId in this.groups) {
-        var group = this.groups[groupId].toStatic(t);
-        if (group)
-            res["groups"].push(group);
-    }
-    for (var typingChan in this.typing) {
-        var tChan = null;
-        for (var typingUser in this.typing[typingChan]) {
-            if (this.typing[typingChan][typingUser] +3000 >= 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;
-};
+SlackData.prototype.teamFactory = function(id) {
+    return new SlackTeam(id);
+}
 
-SlackData.prototype.cleanTyping = function(t) {
-    var updated = false;
-    for (var typingChan in this.typing) {
-        var chanEmpty = true;
-        for (var typingUser in this.typing[typingChan]) {
-            if (this.typing[typingChan][typingUser] +3000 < t) {
-                delete this.typing[typingChan][typingUser];
-                updated = true;
-            } else {
-                chanEmpty = false;
-            }
+SlackData.prototype.commandFactory = function(data) {
+    var getServiceName = (function() {
+        if (data["service_name"])
+            return data["service_name"];
+        else if (data["app"]) {
+            for (var i in this.users)
+                if (this.users[i].appId === data["app"] && this.users[i].name)
+                    return this.users[i].name;
+            console.error("Unknown app " +data["app"]);
+            return "";
         }
-        if (chanEmpty) {
-            delete this.typing[typingChan];
-            updated = true;
-        }
-    }
-    return updated;
+        return "Slack";
+    }).bind(this);
+    data["category"] = data["category"] || getServiceName();
+    return new Command(data);
 }
 
 /**
@@ -724,7 +237,7 @@ SlackData.prototype.onMessage = function(msg, t) {
 **/
 SlackData.prototype.getUpdates = function(knownVersion, now) {
     if (this.staticV > knownVersion)
-        return this.buildStatic(knownVersion, now);
+        return this.toStatic(knownVersion, now);
     return undefined;
 };
 

+ 4 - 4
srv/src/slackHistory.js

@@ -1,4 +1,4 @@
-const Message = require('./message.js');
+const Message = require('./message.js').Message;
 
 /**
  * @constructor
@@ -9,10 +9,10 @@ function SlackMessage(e, ts) {
     Message.call(this, e, ts);
 }
 
-SlackMessage.prototype = Object.create(Message);
-SlackMessage.prototype.superMessageUpdate = SlackMessage.prototype.update;
+SlackMessage.prototype = Object.create(Message.prototype);
+SlackMessage.prototype.constructor = SlackMessage;
 SlackMessage.prototype.update = function(e, ts) {
-    this.superMessageUpdate(e, ts);
+    Message.prototype.update.call(this, e, ts);
 }
 
 /**