Browse Source

[add] Do group first unread message
[bugfix] resolve bots" icons

B Thibault 8 years ago
parent
commit
d97ab3d441
5 changed files with 10 additions and 6 deletions
  1. 1 3
      cli/ui.js
  2. 2 2
      srv/public/slack.min.js
  3. 1 1
      srv/src/message.js
  4. 4 0
      srv/src/slackData.js
  5. 2 0
      srv/src/slackHistory.js

+ 1 - 3
cli/ui.js

@@ -531,10 +531,8 @@ function onRoomUpdated() {
                     firstTsCombo = msg.ts;
                     newGroupDom = true;
                 }
-                if ((!prevMsg || prevMsg.ts <= SELECTED_ROOM.lastRead) && msg.ts > SELECTED_ROOM.lastRead) {
+                if ((!prevMsg || prevMsg.ts <= SELECTED_ROOM.lastRead) && msg.ts > SELECTED_ROOM.lastRead)
                     dom.classList.add(R.klass.msg.firstUnread);
-                    newGroupDom = true;
-                }
                 if (msg instanceof MeMessage) {
                     prevMsg = null;
                     prevMsgDom = null;

+ 2 - 2
srv/public/slack.min.js

@@ -1,7 +1,7 @@
 function n(a){this.id=a;this.version=0}n.prototype.update=function(a,b){void 0!==a.name&&(this.name=a.name);this.version=Math.max(this.version,b)};function ba(a){this.a=a.desc;this.name=a.name;this.type=a.type;this.usage=a.usage;this.A=a.category}function ca(){this.b={};this.a=[]}
 ca.prototype.update=function(a,b){this.b=JSON.parse(a.emoji_use);a.highlight_words?this.a=(a.highlight_words||"").split(",").filter(function(a){return""!==a.trim()}):a.highlights&&(this.a=a.highlights);this.version=Math.max(this.version,b)};function da(){this.j=null;this.f={};this.a={};this.b=null;this.i={version:0,data:{}};this.g={version:0,data:{}};this.c={};this.B=0}"undefined"!==typeof module&&(module.u.O=da,module.u.P=n,module.u.S=ba);function r(a){this.id=a;this.m=!1;this.a=this.b=0;this.g={};this.version=0}
 r.prototype.update=function(a,b,c){void 0!==a.name&&(this.name=a.name);void 0!==a.is_archived&&(this.i=a.is_archived);void 0!==a.last_read&&(this.b=Math.max(parseFloat(a.last_read),this.b));void 0!==a.last_msg&&(this.a=parseFloat(a.last_msg));void 0!==a.is_private&&(this.j=a.is_private);a.latest&&(this.a=parseFloat(a.latest.ts));void 0!==a.is_starred&&(this.m=a.is_starred);if(a.members&&(this.g={},a.members))for(var d=0,f=a.members.length;d<f;d++){var e=b.a[a.members[d]];this.g[e.id]=e;e.f[this.id]=
-this}this.version=Math.max(this.version,c)};function x(a,b){r.call(this,a);this.c=b;this.name=this.c.name;this.j=!0;b.g=this}x.prototype=Object.create(r.prototype);x.prototype.constructor=x;"undefined"!==typeof module&&(module.u.X=r,module.u.W=x);function y(a,b){this.o=a.user;this.c=a.userName;this.id=a.id||a.ts;this.h=parseFloat(a.ts);this.text="";this.g=[];this.b=this.s=this.m=!1;this.a={};this.version=b;this.update(a,b)}function z(a,b){y.call(this,a,b)}function A(a,b){y.call(this,a,b)}
+this}this.version=Math.max(this.version,c)};function x(a,b){r.call(this,a);this.c=b;this.name=this.c.name;this.j=!0;b.g=this}x.prototype=Object.create(r.prototype);x.prototype.constructor=x;"undefined"!==typeof module&&(module.u.X=r,module.u.W=x);function y(a,b){this.o=a.user;this.c=a.username;this.id=a.id||a.ts;this.h=parseFloat(a.ts);this.text="";this.g=[];this.b=this.s=this.m=!1;this.a={};this.version=b;this.update(a,b)}function z(a,b){y.call(this,a,b)}function A(a,b){y.call(this,a,b)}
 y.prototype.update=function(a,b){if(a){this.text=a.text||"";a.attachments&&(this.g=a.attachments);this.m=!!a.is_starred;this.s=!!a.edited;this.b=!!a.removed;var c=this;this.a={};(a.reactions||[]).forEach(function(a){c.a[a.name]=[];a.users.forEach(function(b){c.a[a.name].push(b)})})}else this.b=!0;this.version=b};function ea(a,b,c,d){this.id="string"===typeof a?a:a.id;this.a=[];this.b=b;c&&fa(this,c,d)}function fa(a,b,c){var d=0;b.forEach(function(a){d=Math.max(ga(this,a,c),d)}.bind(a));ha(a)}
 function ga(a,b,c){for(var d=!1,f,e=0,k=a.a.length;e<k;e++){var g=a.a[e];if(g.id===b.id){f=g.update(b,c);d=!0;break}}d||(g=!0===b.isMeMessage?new z(b,c):!0===b.isNotice?new A(b,c):new y(b,c),a.a.push(g),f=g.h);for(;a.a.length>a.b;)a.a.shift();return f||0}function ia(a){for(var b=D.b[F.id],c=0,d=b.a.length;c<d&&a>=b.a[c].h;c++)if(b.a[c].h===a)return b.a[c];return null}function ha(a){a.a.sort(function(a,c){return a.h-c.h})}z.prototype=Object.create(y.prototype);z.prototype.constructor=z;
 A.prototype=Object.create(y.prototype);A.prototype.constructor=A;"undefined"!==typeof module&&(module.u={U:y,T:z,V:A,Y:ea});function G(a){this.id=a;this.b={small:"",N:""};this.f={};this.g=this.a=null;this.version=0}G.prototype.update=function(a,b){void 0!==a.name&&(this.name=a.name);void 0!==a.deleted&&(this.i=a.deleted);void 0!==a.status&&(this.status=a.status);void 0!==a.presence&&(this.c="away"!==a.presence);void 0!==a.isPresent&&(this.c=a.isPresent);a.isBot&&(this.B=a.isBot);a.profile&&(this.b.small=a.profile.icon_small,this.b.N=a.profile.icon_large);this.version=Math.max(this.version,b)};
@@ -27,7 +27,7 @@ p=!0;else if(e["slackmsg-style-code"]&&"`"!==m&&"`"===d[g+1])delete e["slackmsg-
 function V(a,b,c){b instanceof z?(a=va(a,b,c),a.classList.add("slackmsg-me_message")):a=va(a,b,c);b.s&&a.classList.add("slackmsg-edited");b instanceof A&&a.classList.add("slackmsg-notice");return a}function wa(a,b){document.getElementById("linkFavicon").href=a||b?"favicon.png?h="+a+"&m="+b:"favicon_ok.png"}
 function O(){var a=M.length,b="";if(Y)b="!"+I.F+" - ",document.getElementById("linkFavicon").href="favicon_err.png";else if(a)b="(!"+a+") - ",wa(a,a);else{var a=0,c;for(c in D.a.f){var d=D.a.f[c];d.a>d.b&&a++}a&&(b="("+a+") - ");wa(0,a)}D.a.j&&(b+=D.a.j.name);document.title=b}
 function xa(){if("Notification"in window)if("granted"===Notification.permission){var a=Date.now();if(K+3E4<a){var b=new Notification(I.G);K=a;setTimeout(function(){b.close()},5E3)}}else"denied"!==Notification.permission&&Notification.requestPermission()}
-function ra(){var a=document.createDocumentFragment(),b=F.id,c=null,d=0,f=null,e;J=[];D.b[b]&&D.b[b].a.forEach(function(g){if(!g.b){var l=V(b,g),h=!1;c&&c.o===g.o&&g.o?30>Math.abs(d-g.h)&&!(g instanceof z)?f.classList.add("slackmsg-same-ts"):d=g.h:(d=g.h,h=!0);(!c||c.h<=F.b)&&g.h>F.b&&(l.classList.add("slackmsg-first-unread"),h=!0);if(g instanceof z)f=c=null,d=0,a.appendChild(l),e=null;else{if(h||!e){var h=D.a.a[g.o],k=g.c,m=document.createElement("div"),p=document.createElement("div"),t=document.createElement("span");
+function ra(){var a=document.createDocumentFragment(),b=F.id,c=null,d=0,f=null,e;J=[];D.b[b]&&D.b[b].a.forEach(function(g){if(!g.b){var l=V(b,g),h=!1;c&&c.o===g.o&&g.o?30>Math.abs(d-g.h)&&!(g instanceof z)?f.classList.add("slackmsg-same-ts"):d=g.h:(d=g.h,h=!0);(!c||c.h<=F.b)&&g.h>F.b&&l.classList.add("slackmsg-first-unread");if(g instanceof z)f=c=null,d=0,a.appendChild(l),e=null;else{if(h||!e){var h=D.a.a[g.o],k=g.c,m=document.createElement("div"),p=document.createElement("div"),t=document.createElement("span");
 m.w=document.createElement("img");m.w.className="slackmsg-author-img";t.className="slackmsg-author-name";h?(t.textContent=h.name,m.w.src=h.b.small):(t.textContent=k||"?",m.w.src="");p.appendChild(m.w);p.appendChild(t);p.className="slackmsg-author";m.className="slackmsg-authorGroup";m.appendChild(p);m.content=document.createElement("div");m.content.className="slackmsg-author-messages";m.appendChild(m.content);e=m;J.push(e);a.appendChild(e)}c=g;f=l;e.content.appendChild(l)}}});var k=document.getElementById("chatWindow");
 k.textContent="";k.appendChild(a);k.scrollTop=k.scrollHeight-k.clientHeight;window.hasFocus&&R()}
 function ya(a){function b(a,b){for(b=b||a.target;b!==a.currentTarget&&b;){if(b.classList.contains("slackmsg-item"))return b.id;b=b.parentElement}}for(var c=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=ia(a);d&&c.classList.contains("slackmsg-hover-reply")?(U&&(U=null,W()),S!==d&&(S=d,T())):d&&c.classList.contains("slackmsg-hover-reaction")?za.K(document.body,

+ 1 - 1
srv/src/message.js

@@ -9,7 +9,7 @@ function Message(e, ts) {
     this.userId = e["user"];
 
     /** @type {string} */
-    this.username = e["userName"];
+    this.username = e["username"];
 
     /** @const @type {string} **/
     this.id = e["id"] || e["ts"];

+ 4 - 0
srv/src/slackData.js

@@ -154,6 +154,10 @@ SlackBot.prototype.update = function(botData, t) {
     SlackChatter.prototype.update.call(this, botData, t);
     if (botData["app_id"] !== undefined) this.appId = botData["app_id"];
     this.isBot = true;
+    if (botData["icons"]) {
+        this.icons.small = botData["icons"]["image_48"];
+        this.icons.large = botData["icons"]["image_72"];
+    }
 };
 
 /**

+ 2 - 0
srv/src/slackHistory.js

@@ -22,6 +22,8 @@ SlackHistory.prototype.messageFactory = function(ev, ts) {
         return new NoticeMessage(ev, ts);
     if (ev["subtype"] === "me_message")
         return new MeMessage(ev, ts);
+    if (!ev["user"])
+        ev["user"] = ev["bot_id"];
     return new Message(ev, ts);
 }