|
@@ -6,7 +6,12 @@
|
|
|
function createChanListItem(chan) {
|
|
function createChanListItem(chan) {
|
|
|
var dom = document.createElement("li");
|
|
var dom = document.createElement("li");
|
|
|
dom.id = chan.id;
|
|
dom.id = chan.id;
|
|
|
- dom.className = R.klass.chatList.entry;
|
|
|
|
|
|
|
+ if (chan.id[0] === 'D')
|
|
|
|
|
+ dom.className = R.klass.chatList.entry + " " +R.klass.chatList.typeDirect;
|
|
|
|
|
+ else if (chan.id[0] === 'G')
|
|
|
|
|
+ dom.className = R.klass.chatList.entry + " " +R.klass.chatList.typeGroup;
|
|
|
|
|
+ else if (chan.id[0] === 'C')
|
|
|
|
|
+ dom.className = R.klass.chatList.entry + " " +R.klass.chatList.typeChannel;
|
|
|
dom.textContent = chan.name;
|
|
dom.textContent = chan.name;
|
|
|
return dom;
|
|
return dom;
|
|
|
}
|
|
}
|
|
@@ -69,44 +74,55 @@ function onRoomSelected() {
|
|
|
onRoomUpdated();
|
|
onRoomUpdated();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function createMessageDom(msg) {
|
|
|
|
|
|
|
+function createMessageDom(channelId, msg) {
|
|
|
var dom = document.createElement("div")
|
|
var dom = document.createElement("div")
|
|
|
,ts = document.createElement("div")
|
|
,ts = document.createElement("div")
|
|
|
,text = document.createElement("div")
|
|
,text = document.createElement("div")
|
|
|
,author = document.createElement("div")
|
|
,author = document.createElement("div")
|
|
|
,authorImg = document.createElement("img")
|
|
,authorImg = document.createElement("img")
|
|
|
- ,authorName = document.createElement("span");
|
|
|
|
|
|
|
+ ,authorName = document.createElement("span")
|
|
|
|
|
+ ,hover = document.createElement("ul")
|
|
|
|
|
+ ,hoverReply = document.createElement("li")
|
|
|
,sender = msg.raw["user"] ?
|
|
,sender = msg.raw["user"] ?
|
|
|
SLACK.context.users[msg.raw["user"]] :
|
|
SLACK.context.users[msg.raw["user"]] :
|
|
|
SLACK.context.bots[msg.raw["bot_id"]];
|
|
SLACK.context.bots[msg.raw["bot_id"]];
|
|
|
|
|
|
|
|
|
|
+ dom.id = channelId +"_" +msg.ts;
|
|
|
dom.className = R.klass.msg.item;
|
|
dom.className = R.klass.msg.item;
|
|
|
ts.className = R.klass.msg.ts;
|
|
ts.className = R.klass.msg.ts;
|
|
|
text.className = R.klass.msg.msg;
|
|
text.className = R.klass.msg.msg;
|
|
|
author.className = R.klass.msg.author;
|
|
author.className = R.klass.msg.author;
|
|
|
authorImg.className = R.klass.msg.authorAvatar;
|
|
authorImg.className = R.klass.msg.authorAvatar;
|
|
|
authorName.className = R.klass.msg.authorname;
|
|
authorName.className = R.klass.msg.authorname;
|
|
|
|
|
+ hover.className = R.klass.msg.hover.container;
|
|
|
|
|
+ hoverReply.className = R.klass.msg.hover.reply;
|
|
|
ts.textContent = (new Date(msg.ts * 1000)).toLocaleTimeString();
|
|
ts.textContent = (new Date(msg.ts * 1000)).toLocaleTimeString();
|
|
|
text.textContent = msg.raw["text"];
|
|
text.textContent = msg.raw["text"];
|
|
|
authorName.textContent = sender ? sender.name : (msg.raw["username"] || "?");
|
|
authorName.textContent = sender ? sender.name : (msg.raw["username"] || "?");
|
|
|
authorImg.src = sender ? sender.icons.image_48 : "";
|
|
authorImg.src = sender ? sender.icons.image_48 : "";
|
|
|
author.appendChild(authorImg);
|
|
author.appendChild(authorImg);
|
|
|
author.appendChild(authorName);
|
|
author.appendChild(authorName);
|
|
|
|
|
+ hover.appendChild(hoverReply);
|
|
|
dom.appendChild(author);
|
|
dom.appendChild(author);
|
|
|
dom.appendChild(text);
|
|
dom.appendChild(text);
|
|
|
dom.appendChild(ts);
|
|
dom.appendChild(ts);
|
|
|
|
|
+ dom.appendChild(hover);
|
|
|
return dom;
|
|
return dom;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onRoomUpdated() {
|
|
function onRoomUpdated() {
|
|
|
- var chatFrag = document.createDocumentFragment();
|
|
|
|
|
|
|
+ var chatFrag = document.createDocumentFragment()
|
|
|
|
|
+ ,currentRoomId = SELECTED_ROOM.id;
|
|
|
|
|
|
|
|
document.getElementById(R.id.currentRoom.content).textContent = "";
|
|
document.getElementById(R.id.currentRoom.content).textContent = "";
|
|
|
- if (SLACK.history[SELECTED_ROOM.id])
|
|
|
|
|
- SLACK.history[SELECTED_ROOM.id].messages.forEach(function(msg) {
|
|
|
|
|
- chatFrag.appendChild(createMessageDom(msg));
|
|
|
|
|
|
|
+ if (SLACK.history[currentRoomId])
|
|
|
|
|
+ SLACK.history[currentRoomId].messages.forEach(function(msg) {
|
|
|
|
|
+ chatFrag.appendChild(createMessageDom(currentRoomId, msg));
|
|
|
});
|
|
});
|
|
|
- document.getElementById(R.id.currentRoom.content).appendChild(chatFrag);
|
|
|
|
|
|
|
+ var content = document.getElementById(R.id.currentRoom.content);
|
|
|
|
|
+ content.appendChild(chatFrag);
|
|
|
|
|
+ //TODO scroll lock
|
|
|
|
|
+ console.log(content.scrollTop = content.scrollHeight -content.clientHeight);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onChanClick(e) {
|
|
function onChanClick(e) {
|
|
@@ -125,8 +141,46 @@ function onChanClick(e) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function replyTo(msg) {
|
|
|
|
|
+ console.log("Replying to ", msg);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+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.classList.contains(R.klass.msg.hover.reply)) {
|
|
|
|
|
+ var messageId = getMessageId(e, target);
|
|
|
|
|
+ if (messageId) {
|
|
|
|
|
+ messageId = parseFloat(messageId.split("_")[1]);
|
|
|
|
|
+ var history = SLACK.history[SELECTED_ROOM.id].messages;
|
|
|
|
|
+
|
|
|
|
|
+ for (var i =0, histLen =history.length; i < histLen && history[i].ts <= messageId; i++) {
|
|
|
|
|
+ if (history[i].ts === messageId) {
|
|
|
|
|
+ replyTo(history[i]);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ target = target.parentElement;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
document.getElementById(R.id.chatList).addEventListener("click", onChanClick);
|
|
document.getElementById(R.id.chatList).addEventListener("click", onChanClick);
|
|
|
|
|
+ document.getElementById(R.id.currentRoom.content).addEventListener("click", chatClickDelegate);
|
|
|
document.getElementById(R.id.message.form).addEventListener("submit", function(e) {
|
|
document.getElementById(R.id.message.form).addEventListener("submit", function(e) {
|
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
|
var input =document.getElementById(R.id.message.input);
|
|
var input =document.getElementById(R.id.message.input);
|