]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/iq.js
Removed the word "Settings" from the settings. This information is redundant.
[friendica-addons.git] / jappixmini / jappix / js / iq.js
1 /*
2
3 Jappix - An open social platform
4 These are the IQ JS scripts for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Author: Vanaryon
10 Last revision: 27/08/11
11
12 */
13
14 // Handles an incoming IQ packet
15 function handleIQ(iq) {
16         // Gets the IQ content
17         var iqNode = iq.getNode();
18         var iqFrom = fullXID(getStanzaFrom(iq));
19         var iqID = iq.getID();
20         var iqQueryXMLNS = iq.getQueryXMLNS();
21         var iqQuery = iq.getQuery();
22         var iqType = iq.getType();
23         
24         // Build the response
25         var iqResponse = new JSJaCIQ();
26         
27         iqResponse.setID(iqID);
28         iqResponse.setTo(iqFrom);
29         iqResponse.setType('result');
30         
31         // OOB request
32         if((iqQueryXMLNS == NS_IQOOB) && (iqType == 'set')) {
33                 /* REF: http://xmpp.org/extensions/xep-0066.html */
34                 
35                 handleOOB(iqFrom, iqID, 'iq', iqNode);
36                 
37                 logThis('Received IQ OOB request: ' + iqFrom);
38         }
39         
40         // OOB reply
41         else if(getDB('send/url', iqID)) {
42                 // Get the values
43                 var oob_url = getDB('send/url', iqID);
44                 var oob_desc = getDB('send/desc', iqID);
45                 var notif_id = hex_md5(oob_url + oob_desc + iqType + iqFrom + iqID);
46                 
47                 // Error?
48                 if($(iqNode).find('error').size()) {
49                         // Rejected?
50                         if($(iqNode).find('error not-acceptable').size())
51                                 newNotification('send_reject', iqFrom, [iqFrom, oob_url, 'iq', iqID, iqNode], oob_desc, notif_id);
52                         
53                         // Failed?
54                         else
55                                 newNotification('send_fail', iqFrom, [iqFrom, oob_url, 'iq', iqID, iqNode], oob_desc, notif_id);
56                         
57                         // Remove the file
58                         $.get(oob_url + '&action=remove');
59                 }
60                 
61                 // Success?
62                 else if(iqType == 'result')
63                         newNotification('send_accept', iqFrom, [iqFrom, oob_url, 'iq', iqID, iqNode], oob_desc, notif_id);
64         }
65         
66         // Software version query
67         else if((iqQueryXMLNS == NS_VERSION) && (iqType == 'get')) {
68                 /* REF: http://xmpp.org/extensions/xep-0092.html */
69                 
70                 var iqQuery = iqResponse.setQuery(NS_VERSION);
71                 
72                 iqQuery.appendChild(iq.buildNode('name', {'xmlns': NS_VERSION}, 'Jappix'));
73                 iqQuery.appendChild(iq.buildNode('version', {'xmlns': NS_VERSION}, JAPPIX_VERSION));
74                 iqQuery.appendChild(iq.buildNode('os', {'xmlns': NS_VERSION}, BrowserDetect.OS));
75                 
76                 con.send(iqResponse);
77                 
78                 logThis('Received software version query: ' + iqFrom);
79         }
80         
81         // Last activity query
82         else if((iqQueryXMLNS == NS_LAST) && (iqType == 'get')) {
83                 /* REF: http://xmpp.org/extensions/xep-0012.html */
84                 
85                 var iqQuery = iqResponse.setQuery(NS_LAST);
86                 iqQuery.setAttribute('seconds', getLastActivity());
87                 
88                 con.send(iqResponse);
89                 
90                 logThis('Received last activity query: ' + iqFrom);
91         }
92         
93         // Privacy lists push
94         else if((iqQueryXMLNS == NS_PRIVACY) && (iqType == 'set')) {
95                 // REF : http://xmpp.org/extensions/xep-0016.html
96                 
97                 // Roster push
98                 con.send(iqResponse);
99                 
100                 // Get the lists
101                 $(iqQuery).find('list').each(function() {
102                         getPrivacy($(this).attr('name'));
103                 });
104                 
105                 logThis('Received privacy lists push: ' + iqFrom);
106         }
107         
108         // Roster push
109         else if((iqQueryXMLNS == NS_ROSTER) && (iqType == 'set')) {
110                 // REF : http://xmpp.org/extensions/xep-0092.html
111                 
112                 // Roster push
113                 con.send(iqResponse);
114                 
115                 // Get the values
116                 $(iqQuery).find('item').each(function() {
117                         parseRoster($(this), 'presence');
118                 });
119                 
120                 logThis('Received roster push: ' + iqFrom);
121         }
122         
123         // Roster Item Exchange query
124         else if($(iqNode).find('x[xmlns=' + NS_ROSTERX + ']').size()) {
125                 // Open a new notification
126                 newNotification('rosterx', iqFrom, [iqNode], '');
127                 
128                 logThis('Roster Item Exchange from: ' + iqFrom);
129         }
130         
131         // Disco info query
132         else if((iqQueryXMLNS == NS_DISCO_INFO) && (iqType == 'get')) {
133                 /* REF: http://xmpp.org/extensions/xep-0030.html */
134                 
135                 var iqQuery = iqResponse.setQuery(NS_DISCO_INFO);
136                 
137                 // We set the name of the client
138                 iqQuery.appendChild(iq.buildNode('identity', {
139                         'category': 'client',
140                         'type': 'web',
141                         'name': 'Jappix',
142                         'xmlns': NS_DISCO_INFO
143                 }));
144                 
145                 // We set all the supported features
146                 var fArray = myDiscoInfos();
147                 
148                 for(i in fArray)
149                         iqQuery.appendChild(iq.buildNode('feature', {'var': fArray[i], 'xmlns': NS_DISCO_INFO}));
150                 
151                 con.send(iqResponse);
152                 
153                 logThis('Received disco#infos query: ' + iqFrom);
154         }
155         
156         // User time query
157         else if($(iqNode).find('time').size() && (iqType == 'get')) {
158                 /* REF: http://xmpp.org/extensions/xep-0202.html */
159                 
160                 var iqTime = iqResponse.appendNode('time', {'xmlns': NS_URN_TIME});
161                 iqTime.appendChild(iq.buildNode('tzo', {'xmlns': NS_URN_TIME}, getDateTZO()));
162                 iqTime.appendChild(iq.buildNode('utc', {'xmlns': NS_URN_TIME}, getXMPPTime('utc')));
163                 
164                 con.send(iqResponse);
165                 
166                 logThis('Received local time query: ' + iqFrom);
167         }
168         
169         // Ping
170         else if($(iqNode).find('ping').size() && (iqType == 'get')) {
171                 /* REF: http://xmpp.org/extensions/xep-0199.html */
172                 
173                 con.send(iqResponse);
174                 
175                 logThis('Received a ping: ' + iqFrom);
176         }
177         
178         // Not implemented
179         else if(!$(iqNode).find('error').size() && ((iqType == 'get') || (iqType == 'set'))) {
180                 // Append stanza content
181                 for(var i = 0; i < iqNode.childNodes.length; i++)
182                         iqResponse.getNode().appendChild(iqNode.childNodes.item(i).cloneNode(true));
183                 
184                 // Append error content
185                 var iqError = iqResponse.appendNode('error', {'xmlns': NS_CLIENT, 'code': '501', 'type': 'cancel'});
186                 iqError.appendChild(iq.buildNode('feature-not-implemented', {'xmlns': NS_STANZAS}));
187                 iqError.appendChild(iq.buildNode('text', {'xmlns': NS_STANZAS}, _e("The feature requested is not implemented by the recipient or server and therefore cannot be processed.")));
188                 
189                 con.send(iqResponse);
190                 
191                 logThis('Received an unsupported IQ query from: ' + iqFrom);
192         }
193 }