1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-12-26 01:18:59 -05:00

Add support for displaying legacy vcard avatars

This commit is contained in:
Lance Stout 2014-01-01 20:39:06 -08:00
parent c5e09cda61
commit fb2428940a
6 changed files with 54 additions and 23 deletions

View File

@ -11,7 +11,7 @@ function fallback(jid) {
}
module.exports = function (jid, id, type, cb) {
module.exports = function (jid, id, type, source, cb) {
if (!id) {
return cb(fallback(jid));
}
@ -26,24 +26,48 @@ module.exports = function (jid, id, type, cb) {
}
app.whenConnected(function () {
app.api.getAvatar(jid, id, function (err, resp) {
if (err) {
return cb(fallback(jid));
}
if (source == 'vcard') {
app.api.getVCard(jid, function (err, resp) {
if (err) {
return cb(fallback(jid));
}
resp = resp.toJSON();
var data = resp.pubsub.retrieve.item.avatarData;
var uri = 'data:' + type + ';base64,' + data;
resp = resp.toJSON();
console.log(JSON.stringify(resp));
type = resp.vCardTemp.photo.type || type;
avatar = {
id: id,
type: type,
uri: uri
};
var data = resp.vCardTemp.photo.data;
var uri = 'data:' + type + ';base64,' + data;
app.storage.avatars.add(avatar);
return cb(avatar);
});
avatar = {
id: id,
type: type,
uri: uri
};
app.storage.avatars.add(avatar);
return cb(avatar);
});
} else {
app.api.getAvatar(jid, id, function (err, resp) {
if (err) {
return cb(fallback(jid));
}
resp = resp.toJSON();
var data = resp.pubsub.retrieve.item.avatarData;
var uri = 'data:' + type + ';base64,' + data;
avatar = {
id: id,
type: type,
uri: uri
};
app.storage.avatars.add(avatar);
return cb(avatar);
});
}
});
});
};

View File

@ -228,7 +228,10 @@ module.exports = function (client, app) {
id = info.avatars[0].id;
type = info.avatars[0].type || 'image/png';
}
contact.setAvatar(id, type);
if (contact.setAvatar) {
contact.setAvatar(id, type, info.source);
}
});
client.on('chatState', function (info) {

View File

@ -40,6 +40,7 @@ module.exports = HumanModel.define({
session: {
activeContact: ['bool', true, false],
avatar: 'string',
avatarSource: 'string',
lastInteraction: 'date',
lastSentMessage: 'object',
lockedResource: 'string',
@ -203,11 +204,14 @@ module.exports = HumanModel.define({
logger.error('no jingle resources for this user');
}
},
setAvatar: function (id, type) {
setAvatar: function (id, type, source) {
var self = this;
fetchAvatar(this.jid, id, type, function (avatar) {
console.log('setAvatar', this.jid, id, type, source);
fetchAvatar(this.jid, id, type, source, function (avatar) {
if (source == 'vcard' && self.avatarSource == 'pubsub') return;
self.avatarID = avatar.id;
self.avatar = avatar.uri;
self.avaarSource = source;
self.save();
});
},

View File

@ -77,9 +77,9 @@ module.exports = HumanModel.define({
}
this._activeContact = jid;
},
setAvatar: function (id, type) {
setAvatar: function (id, type, source) {
var self = this;
fetchAvatar('', id, type, function (avatar) {
fetchAvatar('', id, type, source, function (avatar) {
self.avatarID = avatar.id;
self.avatar = avatar.uri;
});

View File

@ -26,7 +26,7 @@
"oembed": "0.1.0",
"semi-static": "0.0.4",
"sound-effect-manager": "0.0.5",
"stanza.io": "2.10.0",
"stanza.io": "2.11.0",
"staydown": "legastero/staydown",
"templatizer": "0.1.2",
"underscore": "1.5.1",

View File

@ -1,5 +1,5 @@
CACHE MANIFEST
# 0.0.1 1388626859519
# 0.0.1 1388637293749
CACHE:
/app.js