Better handling of user avatar. Don't create canvas el if there's no avatar.

Also, don't fetch vCards in rosterHandler. This could be very expensive for
large rosters, instead we'll fetch them when a user comes online.
This commit is contained in:
JC Brand 2013-03-28 07:17:05 +02:00
parent 49b4633c3f
commit fe8ed1282c

View File

@ -500,7 +500,6 @@
'<div class="chat-head chat-head-chatbox">' + '<div class="chat-head chat-head-chatbox">' +
'<a class="close-chatbox-button">X</a>' + '<a class="close-chatbox-button">X</a>' +
'<a href="{{url}}" target="_blank" class="user">' + '<a href="{{url}}" target="_blank" class="user">' +
'<canvas height="35px" width="35px" class="avatar"></canvas>' +
'<div class="chat-title"> {{ fullname }} </div>' + '<div class="chat-title"> {{ fullname }} </div>' +
'</a>' + '</a>' +
'<p class="user-custom-message"><p/>' + '<p class="user-custom-message"><p/>' +
@ -516,15 +515,18 @@
render: function () { render: function () {
this.$el.attr('id', this.model.get('box_id')) this.$el.attr('id', this.model.get('box_id'))
.html(this.template(this.model.toJSON())); .html(this.template(this.model.toJSON()));
if (this.model.get('image')) {
var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'); var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'),
var ctx = this.$el.find('canvas').get(0).getContext('2d'); canvas = $('<canvas height="35px" width="35px" class="avatar"></canvas>'),
var img = new Image(); // Create new Image object ctx = canvas.get(0).getContext('2d'),
img = new Image(); // Create new Image object
img.onload = function() { img.onload = function() {
var ratio = img.width/img.height; var ratio = img.width/img.height;
ctx.drawImage(img,0,0, 35*ratio, 35); ctx.drawImage(img,0,0, 35*ratio, 35);
}; };
img.src = img_src; img.src = img_src;
this.$el.find('.chat-title').before(canvas);
}
return this; return this;
}, },
@ -1400,30 +1402,13 @@
if (!model) { if (!model) {
is_last = false; is_last = false;
if (index === (items.length-1)) { is_last = true; } if (index === (items.length-1)) { is_last = true; }
xmppchat.getVCard(
item.jid,
$.proxy(function (jid, fullname, img, img_type, url) {
this.addRosterItem({ this.addRosterItem({
jid: item.jid, jid: item.jid,
subscription: item.subscription, subscription: item.subscription,
ask: item.ask, ask: item.ask,
fullname: fullname, fullname: item.name,
image: img,
image_type: img_type,
url: url,
is_last: is_last is_last: is_last
}); });
}, this),
$.proxy(function (stanza) {
console.log("rosterHandler: Error occured while fetching vcard");
console.log(stanza);
this.addRosterItem({
jid: item.jid,
subscription: item.subscription,
ask: item.ask,
is_last: is_last
});
}, this));
} else { } else {
if ((item.subscription === 'none') && (item.ask === null)) { if ((item.subscription === 'none') && (item.ask === null)) {
// This user is no longer in our roster // This user is no longer in our roster