3 Jappix - An open social platform
4 These are the buddy name related JS scripts for Jappix
6 -------------------------------------------------
10 Last revision: 29/04/11
14 // Gets an user name for buddy add tool
15 function getAddUserName(xid) {
16 var iq = new JSJaCIQ();
20 iq.appendNode('vCard', {'xmlns': NS_VCARD});
22 con.send(iq, handleAddUserName);
25 // Handles an user name for buddy add tool
26 function handleAddUserName(iq) {
27 // Was it an obsolete request?
28 if(!exists('.add-contact-name-get[data-for=' + escape(bareXID(getStanzaFrom(iq))) + ']'))
31 // Reset the waiting item
32 $('.add-contact-name-get').hide().removeAttr('data-for');
35 if(iq.getType() == 'result') {
36 var full_name = generateBuddyName(iq)[0];
39 $('.add-contact-name').val(full_name);
45 // Generates the good buddy name from a vCard IQ reply
46 function generateBuddyName(iq) {
48 var xml = $(iq.getNode()).find('vCard');
50 // Get the full name & the nickname
51 var pFull = xml.find('FN:first').text();
52 var pNick = xml.find('NICKNAME:first').text();
57 var pN = xml.find('N:first');
58 var pGiven = pN.find('GIVEN:first').text();
63 // Get the family name (optional)
64 var pFamily = pN.find('FAMILY:first').text();
67 pFull += ' ' + pFamily;
71 return [pFull, pNick];
74 // Returns the given XID buddy name
75 function getBuddyName(xid) {
79 // Cut the XID resource
83 if(isAnonymous() && !xid)
85 else if(xid == getXID())
90 cname = $('#buddy-list .buddy[data-xid=' + escape(xid) + ']:first .buddy-name').html();
92 // If the complete name exists
94 bname = cname.revertHtmlEnc();
96 // Else, we just get the nickname of the buddy
98 bname = getXIDNick(xid);
104 // Gets the nickname of the user
106 // Try to read the user nickname
107 var nick = getDB('profile', 'nick');
116 // Gets the full name of the user
118 // Try to read the user name
119 var name = getDB('profile', 'name');
121 // No name? Use the nickname instead!
128 // Gets the MUC nickname of the user
129 function getMUCNick(id) {
130 return unescape($('#' + id).attr('data-nick'));