1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-12-25 17:08:54 -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) { if (!id) {
return cb(fallback(jid)); return cb(fallback(jid));
} }
@ -26,24 +26,48 @@ module.exports = function (jid, id, type, cb) {
} }
app.whenConnected(function () { app.whenConnected(function () {
app.api.getAvatar(jid, id, function (err, resp) { if (source == 'vcard') {
if (err) { app.api.getVCard(jid, function (err, resp) {
return cb(fallback(jid)); if (err) {
} return cb(fallback(jid));
}
resp = resp.toJSON(); resp = resp.toJSON();
var data = resp.pubsub.retrieve.item.avatarData; console.log(JSON.stringify(resp));
var uri = 'data:' + type + ';base64,' + data; type = resp.vCardTemp.photo.type || type;
avatar = { var data = resp.vCardTemp.photo.data;
id: id, var uri = 'data:' + type + ';base64,' + data;
type: type,
uri: uri
};
app.storage.avatars.add(avatar); avatar = {
return cb(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; id = info.avatars[0].id;
type = info.avatars[0].type || 'image/png'; 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) { client.on('chatState', function (info) {

View File

@ -40,6 +40,7 @@ module.exports = HumanModel.define({
session: { session: {
activeContact: ['bool', true, false], activeContact: ['bool', true, false],
avatar: 'string', avatar: 'string',
avatarSource: 'string',
lastInteraction: 'date', lastInteraction: 'date',
lastSentMessage: 'object', lastSentMessage: 'object',
lockedResource: 'string', lockedResource: 'string',
@ -203,11 +204,14 @@ module.exports = HumanModel.define({
logger.error('no jingle resources for this user'); logger.error('no jingle resources for this user');
} }
}, },
setAvatar: function (id, type) { setAvatar: function (id, type, source) {
var self = this; 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.avatarID = avatar.id;
self.avatar = avatar.uri; self.avatar = avatar.uri;
self.avaarSource = source;
self.save(); self.save();
}); });
}, },

View File

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

View File

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

View File

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