3 Jappix - An open social platform
4 This is the server features JS script for Jappix
6 -------------------------------------------------
10 Last revision: 01/06/11
14 // Gets the features of a server
15 function getFeatures() {
16 /* REF: http://xmpp.org/extensions/xep-0030.html */
18 // Get the main values
20 var caps = con.server_caps;
23 // Try to get the stored data
25 xml = XMLFromString(getPersistent('caps', caps));
31 logThis('Read server CAPS from cache.');
34 // Not stored (or no CAPS)!
36 var iq = new JSJaCIQ();
40 iq.setQuery(NS_DISCO_INFO);
42 con.send(iq, handleDiscoInfos);
44 logThis('Read server CAPS from network.');
48 // Handles the features of a server
49 function handleFeatures(xml) {
51 var selector = $(xml);
57 var archive_auto = false;
58 var archive_manual = false;
59 var archive_manage = false;
60 var archive_pref = false;
64 if(selector.find('identity[category=pubsub][type=pep]').size())
66 if(selector.find('feature[var=' + NS_PUBSUB + ']').size())
68 if(selector.find('feature[var=' + NS_URN_ARCHIVE + ']').size())
70 if(selector.find('feature[var=' + NS_URN_AR_AUTO + ']').size())
72 if(selector.find('feature[var=' + NS_URN_AR_MANUAL + ']').size())
73 archive_manual = true;
74 if(selector.find('feature[var=' + NS_URN_AR_MANAGE + ']').size())
75 archive_manage = true;
76 if(selector.find('feature[var=' + NS_URN_AR_PREF + ']').size())
78 if(selector.find('feature[var=' + NS_COMMANDS + ']').size())
81 // Enable the pep elements if available
83 // Update our database
89 // Get the notifications
95 // Enable microblogging send tools
96 waitMicroblog('sync');
97 $('.postit.attach').css('display', 'block');
99 logThis('XMPP server supports PEP.', 3);
102 // Disable microblogging send tools (no PEP!)
104 waitMicroblog('unsync');
106 logThis('XMPP server does not support PEP.', 2);
109 // Enable the pubsub features if available
111 enableFeature(NS_PUBSUB);
113 // Enable the archiving features if available
115 enableFeature(NS_URN_ARCHIVE);
117 // Enable the archiving sub-features if available
119 enableFeature(NS_URN_AR_PREF);
121 enableFeature(NS_URN_AR_AUTO);
123 enableFeature(NS_URN_AR_MANUAL);
125 enableFeature(NS_URN_AR_MANAGE);
127 // Enable the commands features if available
129 enableFeature(NS_COMMANDS);
131 // Hide the private life fieldset if nothing to show
132 if(!pep && !archive_pref)
133 $('#options fieldset.privacy').hide();
135 // Apply the features
136 applyFeatures('talk');
138 // Process the buddy-list height
145 // The function to apply the features to an element
146 function applyFeatures(id) {
147 // Path to the elements
148 var path = '#' + id + ' .';
152 $(path + 'pep-hidable').show();
156 $(path + 'pubsub-hidable').show();
159 if(enabledArchives() || enabledArchives('auto') || enabledArchives('manual') || enabledArchives('manage')) {
160 $(path + 'archives-hidable:not(.pref)').show();
162 // Sub-feature: archives preferences
163 if(enabledArchives('pref'))
164 $(path + 'archives-hidable.pref').show();
168 if(enabledCommands())
169 $(path + 'commands-hidable').show();
171 // XMPP links (browser feature)
172 if(navigator.registerProtocolHandler)
173 $(path + 'xmpplinks-hidable').show();
177 function enableFeature(feature) {
178 setDB('feature', feature, 'true');
181 // Checks if a feature is enabled
182 function enabledFeature(feature) {
183 if(getDB('feature', feature) == 'true')
189 // Returns the XMPP server PEP support
190 function enabledPEP() {
191 return enabledFeature('pep');
194 // Returns the XMPP server PubSub support
195 function enabledPubSub() {
196 return enabledFeature(NS_PUBSUB);
199 // Returns the XMPP server archives support
200 function enabledArchives(sub) {
201 var xmlns = NS_URN_ARCHIVE;
203 // Any sub element sent?
207 return enabledFeature(xmlns);
210 // Returns the XMPP server commands support
211 function enabledCommands() {
212 return enabledFeature(NS_COMMANDS);