contact status

This commit is contained in:
Rodolphe Breard 2013-03-01 17:44:34 +01:00
parent 5ee9143b71
commit bba8bffa4d
12 changed files with 60 additions and 18 deletions

View file

@ -24,6 +24,9 @@ There's a few bugs with avatars, however it works.
### State change ### State change
It's on it's way. It's on it's way.
### Contact's status
A status indicator is available next to the contact's avatar.
### File transfer ### File transfer
Maybe later. Maybe later.

View file

@ -87,6 +87,10 @@ body {
font-family: monospace; font-family: monospace;
} }
#contact-lst > li > span {
padding-left: 5px;
}
.remove { .remove {
float: right; float: right;
font-family: sans-serif; font-family: sans-serif;

BIN
img/status/contact-away.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
img/status/contact-dnd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
img/status/me-away.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
img/status/me-dnd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -21,6 +21,7 @@ var Client = function() {
this.ui = null; this.ui = null;
this.status = null; this.status = null;
this.contacts = []; this.contacts = [];
this.waiting_contacts = [];
}; };
Client.prototype.createSocket = function() { Client.prototype.createSocket = function() {
@ -44,6 +45,7 @@ Client.prototype.connect = function() {
if (elem.is_connected) { if (elem.is_connected) {
elem.daemonize(); elem.daemonize();
elem.changeStatus(); elem.changeStatus();
elem.addContact();
} else { } else {
elem.disconnect(); elem.disconnect();
} }
@ -94,8 +96,13 @@ Client.prototype.updateStatus = function() {
}; };
Client.prototype.addContact = function(name) { Client.prototype.addContact = function(name) {
if (typeof name !== 'undefined') {
this.waiting_contacts.push(name);
}
if (this.is_connected) { if (this.is_connected) {
this.client.addContact(this, name); var tmp = this.waiting_contacts;
this.waiting_contacts = [];
this.client.addContact(this, tmp);
} }
}; };

View file

@ -16,7 +16,7 @@
var ContactList = function() { var ContactList = function() {
this.storage = chrome.storage.sync; this.storage = chrome.storage.sync;
this.contacts = {}; // {<name>: {name: <string>, li: <DOM element>, avatar: <url>}} this.contacts = {}; // {<name>: {name: <string>, li: <DOM element>, img: <DOM element>, avatar: <url>}}
this.lst = document.getElementById("contact-lst"); this.lst = document.getElementById("contact-lst");
}; };
@ -52,11 +52,14 @@ ContactList.prototype.addContact = function(name) {
$cs.avatars.get(infos.name, function(url) { $cs.avatars.get(infos.name, function(url) {
li.style.backgroundImage = "url('" + url + "')"; li.style.backgroundImage = "url('" + url + "')";
}); });
img = document.createElement("img");
this.setImageStatus(img, "offline");
login = document.createElement("span"); login = document.createElement("span");
close = document.createElement("span"); close = document.createElement("span");
close.classList.add("remove"); close.classList.add("remove");
login.innerHTML = name; login.innerHTML = name;
close.innerHTML = '<img src="img/delcontact.png" alt="x" title="delete contact">'; close.innerHTML = '<img src="img/delcontact.png" alt="x" title="delete contact">';
li.appendChild(img);
li.appendChild(login); li.appendChild(login);
li.appendChild(close); li.appendChild(close);
li.addEventListener("dblclick", function() { li.addEventListener("dblclick", function() {
@ -72,6 +75,7 @@ ContactList.prototype.addContact = function(name) {
})(this)); })(this));
infos.li = li; infos.li = li;
infos.img = img;
this.contacts[name] = infos; this.contacts[name] = infos;
this.save(); this.save();
this.insertContact(infos); 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) { ContactList.prototype.changeContactStatus = function(name, status) {
if (typeof this.contacts[name] !== "undefined") {
this.setImageStatus(this.contacts[name].img, status);
console.log(name + ' changed his status to ' + status); console.log(name + ' changed his status to ' + status);
}
}; };
ContactList.prototype.save = function() { ContactList.prototype.save = function() {

View file

@ -60,7 +60,7 @@ var NsClient = function() {
return false; 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; return true;
}; };
@ -90,7 +90,7 @@ var NsClient = function() {
return false; 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; return true;
}; };
@ -157,7 +157,6 @@ NsClient.prototype.changeStatus = function(client) {
}; };
NsClient.prototype.recv = function(client, data) { NsClient.prototype.recv = function(client, data) {
console.log('Debug: ' + data); // TODO: REMOVE ME!
for (var i = this.actions_enabled.length - 1; i >= 0; --i) { for (var i = this.actions_enabled.length - 1; i >= 0; --i) {
if (this.action[this.actions_enabled[i]](client, data)) { if (this.action[this.actions_enabled[i]](client, data)) {
break; 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) { NsClient.prototype.speak = function(client, to, msg) {
msg = 'user_cmd msg_user ' + to + ' msg ' + this.msgEncode(msg) + '\n'; msg = 'user_cmd msg_user ' + to + ' msg ' + this.msgEncode(msg) + '\n';
client.socket.write(msg, function(inf) {}); client.socket.write(msg, function(inf) {});
}; };
NsClient.prototype.addContact = function(client, name) { NsClient.prototype.addContact = function(client, lst) {
var msg = 'user_cmd watch_log_user {' + name + '}\n'; var msg = 'user_cmd watch_log_user {' + lst.join(',') + '}\n';
client.socket.write(msg, function(inf) { client.socket.write(msg, function(inf) {
var msg = 'user_cmd who {' + name + '}\n'; var msg = 'user_cmd who {' + lst.join(',') + '}\n';
console.log('stalking ' + name + ': ' + msg);
client.socket.write(msg, function(inf) {}); client.socket.write(msg, function(inf) {});
}); });
}; };
NsClient.prototype.rmContact = function(client, name) { NsClient.prototype.rmContact = function(client, name) {
// TODO
}; };
NsClient.prototype.replacePairs = function(str, pairs) { NsClient.prototype.replacePairs = function(str, pairs) {