Fetch vCard once a roster contact is added. Updates #38
This will happen in the background and in the meantime roster contacts will appear under their JIDs.
This commit is contained in:
parent
aad8de02d0
commit
b36e6bbce1
36
converse.js
36
converse.js
@ -1896,23 +1896,18 @@
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function () {
|
|
||||||
this.options.model.on('change', function (item, changed) {
|
|
||||||
if (_.has(item.changed, 'chat_status')) {
|
|
||||||
this.$el.attr('class', item.changed.chat_status);
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.getVCard = function (jid, callback, errback) {
|
this.getVCard = function (jid, callback, errback) {
|
||||||
converse.connection.vcard.get($.proxy(function (iq) {
|
converse.connection.vcard.get(
|
||||||
|
$.proxy(function (iq) {
|
||||||
|
// Successful callback
|
||||||
$vcard = $(iq).find('vCard');
|
$vcard = $(iq).find('vCard');
|
||||||
var fullname = $vcard.find('FN').text(),
|
var fullname = $vcard.find('FN').text(),
|
||||||
img = $vcard.find('BINVAL').text(),
|
img = $vcard.find('BINVAL').text(),
|
||||||
img_type = $vcard.find('TYPE').text(),
|
img_type = $vcard.find('TYPE').text(),
|
||||||
url = $vcard.find('URL').text();
|
url = $vcard.find('URL').text();
|
||||||
|
if (jid) {
|
||||||
var rosteritem = converse.roster.get(jid);
|
var rosteritem = converse.roster.get(jid);
|
||||||
if (rosteritem) {
|
if (rosteritem) {
|
||||||
rosteritem.save({
|
rosteritem.save({
|
||||||
@ -1923,8 +1918,24 @@
|
|||||||
'vcard_updated': converse.toISOString(new Date())
|
'vcard_updated': converse.toISOString(new Date())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (callback) {
|
||||||
callback(jid, fullname, img, img_type, url);
|
callback(jid, fullname, img, img_type, url);
|
||||||
}, this), jid, errback);
|
}
|
||||||
|
}, this),
|
||||||
|
jid,
|
||||||
|
function (iq) {
|
||||||
|
// Error callback
|
||||||
|
var rosteritem = converse.roster.get(jid);
|
||||||
|
if (rosteritem) {
|
||||||
|
rosteritem.save({
|
||||||
|
'vcard_updated': converse.toISOString(new Date())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (errback) {
|
||||||
|
errback(iq);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.RosterItems = Backbone.Collection.extend({
|
this.RosterItems = Backbone.Collection.extend({
|
||||||
@ -2199,6 +2210,11 @@
|
|||||||
var view = new converse.RosterItemView({model: item});
|
var view = new converse.RosterItemView({model: item});
|
||||||
this.rosteritemviews[item.id] = view;
|
this.rosteritemviews[item.id] = view;
|
||||||
this.render(item);
|
this.render(item);
|
||||||
|
if (!item.get('vcard_updated')) {
|
||||||
|
// This will update the vcard, which triggers a change
|
||||||
|
// request which will rerender the roster item.
|
||||||
|
converse.getVCard(item.get('jid'));
|
||||||
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.model.on('change', function (item, changed) {
|
this.model.on('change', function (item, changed) {
|
||||||
|
Loading…
Reference in New Issue
Block a user