}
function jid2id(jid) {
- return jid.split('@')[0] + "-" + jid.split('@')[1];
+ return jid.split('@').join('-').split('.').join('-');
}
function _cbVCard(e) {
var jid = e.getAttribute('from');
var avatar = e.getElementsByTagName('PHOTO')[0];
- var mime = Strophe.getText(avatar.getElementsByTagName('TYPE')[0]);
- var binval = Strophe.getText(avatar.getElementsByTagName('BINVAL')[0]);
+ if (avatar) {
+ var mime = Strophe.getText(avatar.getElementsByTagName('TYPE')[0]);
+ var binval = Strophe.getText(avatar.getElementsByTagName('BINVAL')[0]);
- $("#"+jid2id(jid)+" img").attr('src', 'data:'+mime+';base64,'+binval);
+ $("#"+jid2id(jid)+" img").attr('src', 'data:'+mime+';base64,'+binval);
+ }
return false;
}
function getAvatar(jid) {
- var id = 'getvCard'+jid;
- var vCardiq = $iq({'from':connection.jid+"/"+connection.resource,
- 'to':jid,
+ var id = 'getvCard'+jid2id(jid);
+ var vCardiq = $iq({'to':jid,
'id':id,
'type':'get'}
).c('vCard', {'xmlns':NS_VCARD});
}
function addFriend(jid, nick) {
- $('#friends').append('<div id="'+jid2id(jid)+'"><img src="imgs/none.png" /><br /><span class="nick">'+nick+'</span></div>');
+ $('#friends').append('<div class="friend" id="'+jid2id(jid)+'"><img src="imgs/none.png" /><br /><span class="nick">'+nick+'</span></div>');
$('#'+jid2id(jid)).click(function() {
getAvatar(jid);
});
function getRoster() {
var id = 'getRoster';
- var rosteriq = $iq({'from':connection.jid+"/"+connection.resource,
- 'id':id,
+ var rosteriq = $iq({'id':id,
'type':'get'}
).c('query', {'xmlns':Strophe.NS.ROSTER});