3 Jappix - An open social platform
4 These are the Out of Band Data JS scripts for Jappix
6 -------------------------------------------------
10 Last revision: 27/08/11
14 // Sends an OOB request to someone
15 function sendOOB(to, type, url, desc) {
19 var id = hex_md5(genID() + to + url + desc);
20 to = getHighestResource(to);
22 // IQs cannot be sent to offline users
27 setDB('send/url', id, url);
28 setDB('send/desc', id, desc);
30 var aIQ = new JSJaCIQ();
31 aIQ.setTo(fullXID(to));
35 // Append the query content
36 var aQuery = aIQ.setQuery(NS_IQOOB);
37 aQuery.appendChild(aIQ.buildNode('url', {'xmlns': NS_IQOOB}, url));
38 aQuery.appendChild(aIQ.buildNode('desc', {'xmlns': NS_IQOOB}, desc));
45 var aMsg = new JSJaCMessage();
46 aMsg.setTo(bareXID(to));
50 var aX = aMsg.appendNode('x', {'xmlns': NS_XOOB});
51 aX.appendChild(aMsg.buildNode('url', {'xmlns': NS_XOOB}, url));
56 logThis('Sent OOB request to: ' + to + ' (' + desc + ')');
59 // Handles an OOB request
60 function handleOOB(from, id, type, node) {
61 var xid = url = desc = '';
66 url = $(node).find('url').text();
67 desc = $(node).find('desc').text();
73 url = $(node).find('url').text();
74 desc = $(node).find('body').text();
81 // Open a new notification
82 if(type && xid && url && desc)
83 newNotification('send', xid, [xid, url, type, id, node], desc, hex_md5(xid + url + desc + id));
86 // Replies to an OOB request
87 function replyOOB(to, id, choice, type, node) {
93 var aIQ = new JSJaCIQ();
97 // OOB request accepted
98 if(choice == 'accept') {
99 aIQ.setType('result');
101 logThis('Accepted file request from: ' + to, 3);
104 // OOB request rejected
106 aIQ.setType('error');
108 // Append stanza content
109 for(var i = 0; i < node.childNodes.length; i++)
110 aIQ.getNode().appendChild(node.childNodes.item(i).cloneNode(true));
112 // Append error content
113 var aError = aIQ.appendNode('error', {'xmlns': NS_CLIENT, 'code': '406', 'type': 'modify'});
114 aError.appendChild(aIQ.buildNode('not-acceptable', {'xmlns': NS_STANZAS}));
116 logThis('Rejected file request from: ' + to, 3);
122 // Wait event for OOB upload
123 function waitUploadOOB() {
124 // Append the wait icon
125 $('#page-engine .chat-tools-file:not(.mini) .tooltip-subitem *').hide();
126 $('#page-engine .chat-tools-file:not(.mini) .tooltip-subitem').append('<div class="wait wait-medium"></div>');
129 $('#page-engine .chat-tools-file:not(.mini)').addClass('mini');
132 // Success event for OOB upload
133 function handleUploadOOB(responseXML) {
135 var dData = $(responseXML).find('jappix');
138 var fID = dData.find('id').text();
139 var fURL = dData.find('url').text();
140 var fDesc = dData.find('desc').text();
142 // Get the OOB values
147 oob_has = ':has(.wait)';
149 oob_has = ':has(#oob-upload input[value=' + fID + '])';
151 var xid = $('#page-engine .page-engine-chan' + oob_has).attr('data-xid');
152 var oob_type = $('#page-engine .chat-tools-file' + oob_has).attr('data-oob');
154 // Reset the file send tool
155 $('#page-engine .chat-tools-file' + oob_has).removeClass('mini');
156 $('#page-engine .bubble-file' + oob_has).remove();
159 if($('#page-engine .chat-tools-file' + oob_has).is(':hidden') && (oob_type == 'iq')) {
162 // Remove the file we sent
164 $.get(fURL + '&action=remove');
168 else if(fURL && fDesc && !dData.find('error').size()) {
169 // Send the OOB request
170 sendOOB(xid, oob_type, fURL, fDesc);
173 newNotification('send_pending', xid, [xid, fURL, oob_type, '', ''], fDesc, hex_md5(fURL + fDesc + fID));
175 logThis('File request sent.', 3);
182 logThis('Error while sending the file: ' + dData.find('error').text(), 1);