]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/features.js
Merge pull request #520 from rabuzarus/20180206_-_membersince_frio_support
[friendica-addons.git] / jappixmini / jappix / js / features.js
1 /*
2
3 Jappix - An open social platform
4 This is the server features JS script for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Author: Vanaryon
10 Last revision: 01/06/11
11
12 */
13
14 // Gets the features of a server
15 function getFeatures() {
16         /* REF: http://xmpp.org/extensions/xep-0030.html */
17         
18         // Get the main values
19         var to = getServer();
20         var caps = con.server_caps;
21         var xml = null;
22         
23         // Try to get the stored data
24         if(caps)
25                 xml = XMLFromString(getPersistent('caps', caps));
26         
27         // Any stored data?
28         if(xml) {
29                 handleFeatures(xml);
30                 
31                 logThis('Read server CAPS from cache.');
32         }
33         
34         // Not stored (or no CAPS)!
35         else {
36                 var iq = new JSJaCIQ();
37                 
38                 iq.setTo(to);
39                 iq.setType('get');
40                 iq.setQuery(NS_DISCO_INFO);
41                 
42                 con.send(iq, handleDiscoInfos);
43                 
44                 logThis('Read server CAPS from network.');
45         }
46 }
47
48 // Handles the features of a server
49 function handleFeatures(xml) {
50         // Selector
51         var selector = $(xml);
52         
53         // Markers
54         var pep = false;
55         var pubsub = false;
56         var archive = false;
57         var archive_auto = false;
58         var archive_manual = false;
59         var archive_manage = false;
60         var archive_pref = false;
61         var commands = false;
62         
63         // Scan the features
64         if(selector.find('identity[category=pubsub][type=pep]').size())
65                 pep = true;
66         if(selector.find('feature[var=' + NS_PUBSUB + ']').size())
67                 pubsub = true;
68         if(selector.find('feature[var=' + NS_URN_ARCHIVE + ']').size())
69                 archive = true;
70         if(selector.find('feature[var=' + NS_URN_AR_AUTO + ']').size())
71                 archive_auto = true;
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())
77                 archive_pref = true;
78         if(selector.find('feature[var=' + NS_COMMANDS + ']').size())
79                 commands = true;
80         
81         // Enable the pep elements if available
82         if(pep) {
83                 // Update our database
84                 enableFeature('pep');
85                 
86                 // Get the microblog
87                 getInitMicroblog();
88                 
89                 // Get the notifications
90                 getNotifications();
91                 
92                 // Geolocate the user
93                 geolocate();
94                 
95                 // Enable microblogging send tools
96                 waitMicroblog('sync');
97                 $('.postit.attach').css('display', 'block');
98                 
99                 logThis('XMPP server supports PEP.', 3);
100         }
101         
102         // Disable microblogging send tools (no PEP!)
103         else {
104                 waitMicroblog('unsync');
105                 
106                 logThis('XMPP server does not support PEP.', 2);
107         }
108         
109         // Enable the pubsub features if available
110         if(pubsub)
111                 enableFeature(NS_PUBSUB);
112         
113         // Enable the archiving features if available
114         if(archive)
115                 enableFeature(NS_URN_ARCHIVE);
116         
117         // Enable the archiving sub-features if available
118         if(archive_pref)
119                 enableFeature(NS_URN_AR_PREF);
120         if(archive_auto)
121                 enableFeature(NS_URN_AR_AUTO);
122         if(archive_manual)
123                 enableFeature(NS_URN_AR_MANUAL);
124         if(archive_manage)
125                 enableFeature(NS_URN_AR_MANAGE);
126         
127         // Enable the commands features if available
128         if(commands)
129                 enableFeature(NS_COMMANDS);
130         
131         // Hide the private life fieldset if nothing to show
132         if(!pep && !archive_pref)
133                 $('#options fieldset.privacy').hide();
134         
135         // Apply the features
136         applyFeatures('talk');
137         
138         // Process the buddy-list height
139         if(pep)
140                 adaptRoster();
141         
142         return false;
143 }
144
145 // The function to apply the features to an element
146 function applyFeatures(id) {
147         // Path to the elements
148         var path = '#' + id + ' .';
149         
150         // PEP features
151         if(enabledPEP())
152                 $(path + 'pep-hidable').show();
153         
154         // PubSub features
155         if(enabledPubSub())
156                 $(path + 'pubsub-hidable').show();
157         
158         // Archives features
159         if(enabledArchives() || enabledArchives('auto') || enabledArchives('manual') || enabledArchives('manage')) {
160                 $(path + 'archives-hidable:not(.pref)').show();
161                 
162                 // Sub-feature: archives preferences
163                 if(enabledArchives('pref'))
164                         $(path + 'archives-hidable.pref').show();
165         }
166         
167         // Commands features
168         if(enabledCommands())
169                 $(path + 'commands-hidable').show();
170         
171         // XMPP links (browser feature)
172         if(navigator.registerProtocolHandler)
173                 $(path + 'xmpplinks-hidable').show();
174 }
175
176 // Enables a feature
177 function enableFeature(feature) {
178         setDB('feature', feature, 'true');
179 }
180
181 // Checks if a feature is enabled
182 function enabledFeature(feature) {
183         if(getDB('feature', feature) == 'true')
184                 return true;
185         else
186                 return false;
187 }
188
189 // Returns the XMPP server PEP support
190 function enabledPEP() {
191         return enabledFeature('pep');
192 }
193
194 // Returns the XMPP server PubSub support
195 function enabledPubSub() {
196         return enabledFeature(NS_PUBSUB);
197 }
198
199 // Returns the XMPP server archives support
200 function enabledArchives(sub) {
201         var xmlns = NS_URN_ARCHIVE;
202         
203         // Any sub element sent?
204         if(sub)
205                 xmlns += ':' + sub;
206         
207         return enabledFeature(xmlns);
208 }
209
210 // Returns the XMPP server commands support
211 function enabledCommands() {
212         return enabledFeature(NS_COMMANDS);
213 }