diff --git a/README.md b/README.md index 6ef9afb..e7b2b43 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ There's a few bugs with avatars, however it works. ### State change It's on it's way. +### Contact's status +A status indicator is available next to the contact's avatar. + ### File transfer Maybe later. diff --git a/chromesoul.css b/chromesoul.css index f70758b..e9c9c66 100644 --- a/chromesoul.css +++ b/chromesoul.css @@ -87,6 +87,10 @@ body { font-family: monospace; } +#contact-lst > li > span { + padding-left: 5px; +} + .remove { float: right; font-family: sans-serif; diff --git a/img/status/contact-away.png b/img/status/contact-away.png new file mode 100644 index 0000000..bb151e4 Binary files /dev/null and b/img/status/contact-away.png differ diff --git a/img/status/contact-connected.png b/img/status/contact-connected.png new file mode 100644 index 0000000..a592743 Binary files /dev/null and b/img/status/contact-connected.png differ diff --git a/img/status/contact-disconnected.png b/img/status/contact-disconnected.png new file mode 100644 index 0000000..b34f45b Binary files /dev/null and b/img/status/contact-disconnected.png differ diff --git a/img/status/contact-dnd.png b/img/status/contact-dnd.png new file mode 100644 index 0000000..16f9380 Binary files /dev/null and b/img/status/contact-dnd.png differ diff --git a/img/status/me-away.png b/img/status/me-away.png new file mode 100644 index 0000000..291e349 Binary files /dev/null and b/img/status/me-away.png differ diff --git a/img/status/me-disconnected.png b/img/status/me-disconnected.png index 47ecb3c..73043b6 100644 Binary files a/img/status/me-disconnected.png and b/img/status/me-disconnected.png differ diff --git a/img/status/me-dnd.png b/img/status/me-dnd.png new file mode 100644 index 0000000..3fb0633 Binary files /dev/null and b/img/status/me-dnd.png differ diff --git a/lib/client.js b/lib/client.js index c88102f..1065dca 100644 --- a/lib/client.js +++ b/lib/client.js @@ -21,6 +21,7 @@ var Client = function() { this.ui = null; this.status = null; this.contacts = []; + this.waiting_contacts = []; }; Client.prototype.createSocket = function() { @@ -44,6 +45,7 @@ Client.prototype.connect = function() { if (elem.is_connected) { elem.daemonize(); elem.changeStatus(); + elem.addContact(); } else { elem.disconnect(); } @@ -94,8 +96,13 @@ Client.prototype.updateStatus = function() { }; Client.prototype.addContact = function(name) { + if (typeof name !== 'undefined') { + this.waiting_contacts.push(name); + } if (this.is_connected) { - this.client.addContact(this, name); + var tmp = this.waiting_contacts; + this.waiting_contacts = []; + this.client.addContact(this, tmp); } }; diff --git a/lib/contacts.nsui.js b/lib/contacts.nsui.js index ee09a53..5e16a47 100644 --- a/lib/contacts.nsui.js +++ b/lib/contacts.nsui.js @@ -16,7 +16,7 @@ var ContactList = function() { this.storage = chrome.storage.sync; - this.contacts = {}; // {: {name: , li: , avatar: }} + this.contacts = {}; // {: {name: , li: , img: , avatar: }} this.lst = document.getElementById("contact-lst"); }; @@ -52,11 +52,14 @@ ContactList.prototype.addContact = function(name) { $cs.avatars.get(infos.name, function(url) { li.style.backgroundImage = "url('" + url + "')"; }); + img = document.createElement("img"); + this.setImageStatus(img, "offline"); login = document.createElement("span"); close = document.createElement("span"); close.classList.add("remove"); login.innerHTML = name; close.innerHTML = 'x'; + li.appendChild(img); li.appendChild(login); li.appendChild(close); li.addEventListener("dblclick", function() { @@ -72,6 +75,7 @@ ContactList.prototype.addContact = function(name) { })(this)); infos.li = li; + infos.img = img; this.contacts[name] = infos; this.save(); this.insertContact(infos); @@ -87,8 +91,41 @@ ContactList.prototype.rmContact = function(name) { } }; +ContactList.prototype.setImageStatus = function(img, status) { + var status_list = {'default' : 'img/status/contact-connected.png', + + 'offline': 'img/status/contact-disconnected.png', + 'disconnected': 'img/status/contact-disconnected.png', + 'deconnecte': 'img/status/contact-disconnected.png', + 'deco': 'img/status/contact-disconnected.png', + 'hidden': 'img/status/contact-disconnected.png', + 'cache': 'img/status/contact-disconnected.png', + + 'away': 'img/status/contact-away.png', + 'inactif': 'img/status/contact-away.png', + 'absent': 'img/status/contact-away.png', + 'idle': 'img/status/contact-away.png', + + 'dnd': 'img/status/contact-dnd.png', + 'occuped': 'img/status/contact-dnd.png', + 'npd': 'img/status/contact-dnd.png', + 'occupe': 'img/status/contact-dnd.png' + }; + + if (status_list.hasOwnProperty(status)) { + img.src = status_list[status]; + } else { + img.src = status_list.default; + } + img.alt = status; + img.title = status; +}; + ContactList.prototype.changeContactStatus = function(name, status) { - console.log(name + ' changed his status to ' + status); + if (typeof this.contacts[name] !== "undefined") { + this.setImageStatus(this.contacts[name].img, status); + console.log(name + ' changed his status to ' + status); + } }; ContactList.prototype.save = function() { diff --git a/lib/ns_client.js b/lib/ns_client.js index 5fd13b9..48b8d0a 100644 --- a/lib/ns_client.js +++ b/lib/ns_client.js @@ -60,7 +60,7 @@ var NsClient = function() { return false; } - $cs.contacts.changeContactStatus(mch[2], this.msgDecode(mch[6])); // TODO: FIX ME! + $cs.contacts.changeContactStatus(mch[2], elem.msgDecode(mch[6])); // TODO: FIX ME! return true; }; @@ -90,7 +90,7 @@ var NsClient = function() { return false; } - $cs.contacts.changeContactStatus(mch[7], this.msgDecode(mch[16])); // TODO: FIX ME! + $cs.contacts.changeContactStatus(mch[7], elem.msgDecode(mch[16])); // TODO: FIX ME! return true; }; @@ -157,7 +157,6 @@ NsClient.prototype.changeStatus = function(client) { }; NsClient.prototype.recv = function(client, data) { - console.log('Debug: ' + data); // TODO: REMOVE ME! for (var i = this.actions_enabled.length - 1; i >= 0; --i) { if (this.action[this.actions_enabled[i]](client, data)) { break; @@ -165,30 +164,22 @@ NsClient.prototype.recv = function(client, data) { } }; -NsClient.prototype.addContact = function(client, name) { - // TODO -}; - -NsClient.prototype.rmContact = function(client, name) { - // TODO -}; - NsClient.prototype.speak = function(client, to, msg) { msg = 'user_cmd msg_user ' + to + ' msg ' + this.msgEncode(msg) + '\n'; client.socket.write(msg, function(inf) {}); }; -NsClient.prototype.addContact = function(client, name) { - var msg = 'user_cmd watch_log_user {' + name + '}\n'; +NsClient.prototype.addContact = function(client, lst) { + var msg = 'user_cmd watch_log_user {' + lst.join(',') + '}\n'; client.socket.write(msg, function(inf) { - var msg = 'user_cmd who {' + name + '}\n'; - console.log('stalking ' + name + ': ' + msg); + var msg = 'user_cmd who {' + lst.join(',') + '}\n'; client.socket.write(msg, function(inf) {}); }); }; NsClient.prototype.rmContact = function(client, name) { + // TODO }; NsClient.prototype.replacePairs = function(str, pairs) {