1
0

slack.min.js 6.8 KB

1234567891011121314
  1. function g(a){this.id=a.id;this.name=a.name}function h(a,b){this.id=a.id;this.name=a.name;this.b=parseFloat(a.last_read);this.a={};if(a.members)for(var c=0,d=a.members.length;c<d;c++){var f=m(b,a.members[c]);this.a[f.id]=f;f.c[this.id]=this}}function q(a,b){var c=[];this.id=b.id;this.a={};for(var d=0,f=b.members.length;d<f;d++){var e=m(a,b.members[d]);this.a[b.members[d]]=e;e.c[this.id]=this;c.push(e.name)}this.name=c.join(", ");this.b=parseFloat(b.last_read)}
  2. function r(a,b){this.id=b.id;this.f=a;this.b=parseFloat(b.last_read)}function u(a){this.id=a.id;this.name=a.name;this.status=a.status;this.b={A:a.profile.image_24,B:a.profile.image_32,l:a.profile.image_48,o:a.profile.image_72,w:a.profile.image_192,D:a.profile.image_512};this.c={};this.a=null}function v(a){this.id=a.id;this.name=a.name;this.b={C:a.icons.image_36,l:a.icons.image_48,o:a.icons.image_72};this.c={};this.a=null}
  3. function w(){this.j=null;this.c={};this.b={};this.f={};this.a={};this.h=null;this.i={}}function m(a,b){return a.a[b]||a.i[b]||null}"undefined"!==typeof module&&(module.m.s=w);function x(a){this.g=parseFloat(a.ts);this.raw=a}function y(a,b,c){this.id="string"===typeof a?a:a.id;this.a=[];this.b=b;c&&z(this,c)}function z(a,b){var c=0;b.forEach(function(a){c=Math.max(this.push(a),c)}.bind(a))}y.prototype.push=function(a){for(var b=parseFloat(a.ts),c=0,d=this.a.length;c<d;c++)if(this.a[c].g===b)return b;for(this.a.push(new x(a));this.a.length>this.b;)this.a.shift();return b};"undefined"!==typeof module&&(module.m.u=y);function A(){var a=document.createDocumentFragment(),b=B.a.h?Object.keys(B.a.h.c):[];b.sort(function(a,b){return a[0]!==b[0]?a[0]-b[0]:(B.a.c[a]||B.a.b[a]).name.localeCompare((B.a.c[b]||B.a.b[b]).name)});b.forEach(function(b){b=B.a.c[b]||B.a.b[b];var c=document.createElement("li");c.id=b.id;"D"===b.id[0]?c.className="slack-context-room slack-ims":"G"===b.id[0]?c.className="slack-context-room slack-group":"C"===b.id[0]&&(c.className="slack-context-room slack-channel");c.textContent=b.name;c&&a.appendChild(c)});
  4. b=B.a.a?Object.keys(B.a.a):[];b.sort(function(a,b){return B.a.a[a].name.localeCompare(B.a.a[b].name)});b.forEach(function(b){b=B.a.a[b].a;var c=document.createElement("li");c.id=b.id;c.className="slack-context-room";c.textContent=b.f.name;c&&a.appendChild(c)});document.getElementById("chanList").textContent="";document.getElementById("chanList").appendChild(a)}function C(a){a?document.body.classList.remove("no-network"):document.body.classList.add("no-network")}
  5. function D(a,b){var c=document.createElement("div"),d=document.createElement("div"),f=document.createElement("div"),e=document.createElement("div"),l=document.createElement("img"),n=document.createElement("span"),k=document.createElement("ul"),p=document.createElement("li"),t=b.raw.user?B.a.a[b.raw.user]:B.a.i[b.raw.bot_id];c.id=a+"_"+b.g;c.className="slackmsg-item";d.className="slackmsg-ts";f.className="slackmsg-msg";e.className="slackmsg-author";l.className="slackmsg-author-img";n.className="slackmsg-author-name";
  6. k.className="slackmsg-hover";p.className="slackmsg-hover-reply";d.textContent=(new Date(1E3*b.g)).toLocaleTimeString();f.textContent=b.raw.text;n.textContent=t?t.name:b.raw.username||"?";l.src=t?t.b.l:"";e.appendChild(l);e.appendChild(n);k.appendChild(p);c.appendChild(e);c.appendChild(f);c.appendChild(d);c.appendChild(k);return c}function E(){var a=0,b;for(b in F)F.hasOwnProperty(b)&&(a+=F[b]);document.title=(a?"("+a+") - ":"")+B.a.j.name}
  7. function G(){var a=H;F[a.id]&&(F[a.id]=0,E());a=document.getElementById(a.id);a.classList.remove("unread");a.classList.remove("unreadHi")}function I(){var a=document.createDocumentFragment(),b=H.id;document.getElementById("chatWindow").textContent="";B.b[b]&&B.b[b].a.forEach(function(c){a.appendChild(D(b,c))});var c=document.getElementById("chatWindow");c.appendChild(a);c.scrollTop=c.scrollHeight-c.clientHeight}
  8. function J(a){for(;a.target!==a.currentTarget&&a.target;){if(a.target.classList.contains("slack-context-room")){if((a=B.a.c[a.target.id]||B.a.f[a.target.id]||B.a.b[a.target.id])&&a!==H){H&&document.getElementById(H.id).classList.remove("selected");document.getElementById(a.id).classList.add("selected");document.body.classList.remove("no-room-selected");H=a;a=void 0;var b=H.name||(H.f?H.f.name:void 0);if(!b){b=[];for(a in H.a)b.push(H.a[a].name);b=b.join(", ")}document.getElementById("currentRoomTitle").textContent=
  9. b;I();G();H.b&&!B.b[H.id]&&(a=new XMLHttpRequest,a.open("GET","api/hist?room="+H.id,!0),a.send(null))}break}a.target=a.target.parentElement}}
  10. function K(a){for(var b=a.target;b!==a.currentTarget&&b&&!b.classList.contains("slackmsg-hover");){if(b.classList.contains("slackmsg-hover-reply")){a:{for(b=b||a.target;b!==a.currentTarget&&b;){if(b.classList.contains("slackmsg-item")){a=b.id;break a}b=b.parentElement}a=void 0}if(a){a=parseFloat(a.split("_")[1]);for(var b=B.b[H.id].a,c=0,d=b.length;c<d&&b[c].g<=a;c++)if(b[c].g===a){console.log("Replying to ",b[c]);break}}break}b=b.parentElement}}
  11. document.addEventListener("DOMContentLoaded",function(){document.getElementById("chatList").addEventListener("click",J);document.getElementById("chatWindow").addEventListener("click",K);document.getElementById("msgForm").addEventListener("submit",function(a){a.preventDefault();a=document.getElementById("msgInput");if(H&&a.value){var b=new XMLHttpRequest;b.open("POST","api/msg?room="+H.id+"&text="+encodeURIComponent(a.value),!0);b.send(null);a.value=""}return!1});window.addEventListener("blur",function(){window.hasFocus=
  12. !1});window.addEventListener("focus",function(){window.hasFocus=!0;H&&G()});window.hasFocus=!0;L()});var B,F={};B=new function(){this.f=0;this.a=new w;this.b={}};var M=0,H=null;function N(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){M&&(M=0,C(!0));c=b.response;try{c=JSON.parse(c)}catch(f){c=null}}else M?(M+=Math.floor((M||5)/2),M=Math.min(60,M)):(M=5,C(!1));a(d,c)}else M&&(M=0,C(!0)),N(a)};b.open("GET","api?v="+B.f,!0);b.send(null)}
  13. function O(a,b){if(a){if(b){var c=B;b.v&&(c.f=b.v);if(b["static"]){for(var d=c.a,f=b["static"],e=0,l=f.bots.length;e<l;e++)d.i[f.bots[e].id]=new v(f.bots[e]);e=0;for(l=f.users.length;e<l;e++)d.a[f.users[e].id]=new u(f.users[e]);e=0;for(l=f.ims.length;e<l;e++){var n=m(d,f.ims[e].user);n&&(n.a=new r(n,f.ims[e]),d.f[n.a.id]=n.a)}e=0;for(l=f.channels.length;e<l;e++)d.c[f.channels[e].id]=new h(f.channels[e],d);e=0;for(l=f.groups.length;e<l;e++)d.b[f.groups[e].id]=new q(d,f.groups[e]);d.j=new g(f.team);
  14. d.h=m(d,f.self.id);A()}if(b.live){for(var k in b.live)(d=c.b[k])?z(d,b.live[k]):c.b[k]=new y(k,500,b.live[k]);for(var p in b.live)k=c.a,k=k.c[p]||k.f[p]||k.b[p]||null,d=b.live[p],!k||k===H&&window.hasFocus||(document.getElementById(k.id).classList.add("unread"),F[k.id]=(F[k.id]||0)+d.length,E()),H&&b.live[H.id]&&I()}}L()}else setTimeout(L,1E3*M)}function L(){N(O)};