Add getVCard method (will be usefull for caching later)
This commit is contained in:
parent
e8e9718b01
commit
121fab13a8
53
converse.js
53
converse.js
@ -1095,16 +1095,15 @@
|
|||||||
if (this.isChatRoom(jid)) {
|
if (this.isChatRoom(jid)) {
|
||||||
this.createChatRoom(jid);
|
this.createChatRoom(jid);
|
||||||
} else {
|
} else {
|
||||||
xmppchat.connection.vcard.get($.proxy(function (iq) {
|
xmppchat.getVCard(jid, $.proxy(function (jid, fullname, img, img_type, url) {
|
||||||
var $vcard = $(iq).find('vCard');
|
|
||||||
this.createChatBox({
|
this.createChatBox({
|
||||||
'jid': jid,
|
'jid': jid,
|
||||||
'fullname': $vcard.find('FN').text(),
|
'fullname': fullname,
|
||||||
'image': $vcard.find('BINVAL').text(),
|
'image': img,
|
||||||
'image_type': $vcard.find('TYPE').text(),
|
'image_type': img_type,
|
||||||
'url': $vcard.find('URL').text(),
|
'url': url,
|
||||||
})
|
})
|
||||||
}, this), jid);
|
}, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, this));
|
}, this));
|
||||||
@ -1257,7 +1256,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
xmppchat.RosterItem = Backbone.Model.extend({
|
xmppchat.RosterItem = Backbone.Model.extend({
|
||||||
initialize: function (jid, subscription, ask, name, img, img_type) {
|
initialize: function (jid, subscription, ask, name, img, img_type, url) {
|
||||||
var user_id = Strophe.getNodeFromJid(jid);
|
var user_id = Strophe.getNodeFromJid(jid);
|
||||||
if (!name) {
|
if (!name) {
|
||||||
name = user_id;
|
name = user_id;
|
||||||
@ -1271,6 +1270,7 @@
|
|||||||
'fullname': name,
|
'fullname': name,
|
||||||
'image': img,
|
'image': img,
|
||||||
'image_type': img_type,
|
'image_type': img_type,
|
||||||
|
'url': url,
|
||||||
'resources': [],
|
'resources': [],
|
||||||
'presence_type': 'offline',
|
'presence_type': 'offline',
|
||||||
'status': 'offline'
|
'status': 'offline'
|
||||||
@ -1390,6 +1390,18 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
xmppchat.getVCard = function (jid, callback) {
|
||||||
|
// TODO: cache vcards
|
||||||
|
xmppchat.connection.vcard.get($.proxy(function (iq) {
|
||||||
|
$vcard = $(iq).find('vCard');
|
||||||
|
var fullname = $vcard.find('FN').text(),
|
||||||
|
img = $vcard.find('BINVAL').text(),
|
||||||
|
img_type = $vcard.find('TYPE').text(),
|
||||||
|
url = $vcard.find('URL').text();
|
||||||
|
callback(jid, fullname, img, img_type, url);
|
||||||
|
}, this), jid)
|
||||||
|
}
|
||||||
|
|
||||||
xmppchat.RosterItems = Backbone.Collection.extend({
|
xmppchat.RosterItems = Backbone.Collection.extend({
|
||||||
model: xmppchat.RosterItem,
|
model: xmppchat.RosterItem,
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
@ -1445,8 +1457,8 @@
|
|||||||
return Backbone.Collection.prototype.get.call(this, id);
|
return Backbone.Collection.prototype.get.call(this, id);
|
||||||
},
|
},
|
||||||
|
|
||||||
addRosterItem: function (jid, subscription, ask, name, img, img_type, options) {
|
addRosterItem: function (jid, subscription, ask, name, img, img_type, url, options) {
|
||||||
var model = new xmppchat.RosterItem(jid, subscription, ask, name, img, img_type);
|
var model = new xmppchat.RosterItem(jid, subscription, ask, name, img, img_type, url);
|
||||||
model.options = options || {};
|
model.options = options || {};
|
||||||
this.add(model);
|
this.add(model);
|
||||||
},
|
},
|
||||||
@ -1521,13 +1533,10 @@
|
|||||||
if (item === last_item) {
|
if (item === last_item) {
|
||||||
options.isLast = true;
|
options.isLast = true;
|
||||||
}
|
}
|
||||||
xmppchat.connection.vcard.get($.proxy(function (iq) {
|
xmppchat.getVCard(item.jid, $.proxy(function (jid, fullname, img, img_type, url) {
|
||||||
$vcard = $(iq).find('vCard');
|
this.addRosterItem(item.jid, item.subscription, item.ask, fullname, img, img_type, url, options);
|
||||||
var fullname = $vcard.find('FN').text();
|
}, this));
|
||||||
var img = $vcard.find('BINVAL').text();
|
|
||||||
var img_type = $vcard.find('TYPE').text();
|
|
||||||
this.addRosterItem(item.jid, item.subscription, item.ask, fullname, img, img_type, options);
|
|
||||||
}, this), item.jid)
|
|
||||||
} else {
|
} else {
|
||||||
// only modify model attributes if they are different from the
|
// only modify model attributes if they are different from the
|
||||||
// ones that were already set when the rosterItem was added
|
// ones that were already set when the rosterItem was added
|
||||||
@ -1596,13 +1605,9 @@
|
|||||||
if ((item) && (item.get('subscription') != 'none')) {
|
if ((item) && (item.get('subscription') != 'none')) {
|
||||||
xmppchat.connection.roster.authorize(bare_jid);
|
xmppchat.connection.roster.authorize(bare_jid);
|
||||||
} else {
|
} else {
|
||||||
xmppchat.connection.vcard.get($.proxy(function (iq) {
|
xmppchat.getVCard(bare_jid, $.proxy(function (jid, fullname, img, img_type, url) {
|
||||||
$vcard = $(iq).find('vCard');
|
this.addRosterItem(bare_jid, 'none', 'request', fullname, img, img_type, url, options);
|
||||||
var fullname = $vcard.find('BINVAL').text();
|
}, this));
|
||||||
var img = $vcard.find('BINVAL').text();
|
|
||||||
var img_type = $vcard.find('TYPE').text();
|
|
||||||
this.addRosterItem(bare_jid, 'none', 'request', fullname, img, img_type, options);
|
|
||||||
}, this), jid)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user