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.onload = function() { img = new Image(); // Create new Image object
var ratio = img.width/img.height; img.onload = function() {
ctx.drawImage(img,0,0, 35*ratio, 35); var ratio = img.width/img.height;
}; 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( this.addRosterItem({
item.jid, jid: item.jid,
$.proxy(function (jid, fullname, img, img_type, url) { subscription: item.subscription,
this.addRosterItem({ ask: item.ask,
jid: item.jid, fullname: item.name,
subscription: item.subscription, is_last: is_last
ask: item.ask, });
fullname: fullname,
image: img,
image_type: img_type,
url: url,
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