]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/storage.js
Merge pull request #520 from rabuzarus/20180206_-_membersince_frio_support
[friendica-addons.git] / jappixmini / jappix / js / storage.js
1 /*
2
3 Jappix - An open social platform
4 These are the storage JS scripts for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Author: Vanaryon
10 Last revision: 26/08/11
11
12 */
13
14 // Gets the storage items of the user
15 function getStorage(type) {
16         /* REF: http://xmpp.org/extensions/xep-0049.html */
17         
18         var iq = new JSJaCIQ();
19         iq.setType('get');
20         
21         var iqQuery = iq.setQuery(NS_PRIVATE);
22         iqQuery.appendChild(iq.buildNode('storage', {'xmlns': type}));
23         
24         con.send(iq, handleStorage);
25 }
26
27 // Handles the storage items
28 function handleStorage(iq) {
29         var handleXML = iq.getQuery();
30         var handleFrom = fullXID(getStanzaFrom(iq));
31         
32         // Define some vars
33         var options = $(handleXML).find('storage[xmlns=' + NS_OPTIONS + ']');
34         var inbox = $(handleXML).find('storage[xmlns=' + NS_INBOX + ']');
35         var bookmarks = $(handleXML).find('storage[xmlns=' + NS_BOOKMARKS + ']');
36         var rosternotes = $(handleXML).find('storage[xmlns=' + NS_ROSTERNOTES + ']');
37         
38         // No options and node not yet configured
39         if(options.size() && !options.find('option').size() && (iq.getType() != 'error'))
40                 openWelcome();
41         
42         // Parse the options xml
43         options.find('option').each(function() {
44                 // We retrieve the informations
45                 var type = $(this).attr('type');
46                 var value = $(this).text();
47                 
48                 // We display the storage
49                 setDB('options', type, value);
50                 
51                 // If this is the buddy list show status
52                 if((type == 'roster-showall') && (value == '1'))
53                         showAllBuddies('storage');
54         });
55         
56         // Parse the inbox xml
57         inbox.find('message').each(function() {
58                 storeInboxMessage(
59                                   $(this).attr('from'),
60                                   $(this).attr('subject'),
61                                   $(this).text(),
62                                   $(this).attr('status'),
63                                   $(this).attr('id'),
64                                   $(this).attr('date'),
65                                   [
66                                    $(this).attr('file_title'),
67                                    $(this).attr('file_href'),
68                                    $(this).attr('file_type'),
69                                    $(this).attr('file_length')
70                                   ]
71                                  );
72         });
73         
74         // Parse the bookmarks xml
75         bookmarks.find('conference').each(function() {
76                 // We retrieve the informations
77                 var xid = $(this).attr('jid');
78                 var name = $(this).attr('name');
79                 var autojoin = $(this).attr('autojoin');
80                 var password = $(this).find('password').text();
81                 var nick = $(this).find('nick').text();
82                 
83                 // We display the storage
84                 displayFavorites(xid, name, nick, autojoin, password);
85                 
86                 // Join the chat if autojoin is enabled
87                 if(autojoin == '1')
88                         checkChatCreate(xid, 'groupchat', nick, password, name);
89         });
90         
91         // Parse the roster notes xml
92         rosternotes.find('note').each(function() {
93                 setDB('rosternotes', $(this).attr('jid'), $(this).text());
94         });
95         
96         // Options received
97         if(options.size()) {
98                 logThis('Options received.');
99                 
100                 // Now, get the inbox
101                 getStorage(NS_INBOX);
102                 
103                 // Geolocate the user
104                 geolocate();
105                 
106                 $('.options-hidable').show();
107         }
108         
109         // Inbox received
110         else if(inbox.size()) {
111                 logThis('Inbox received.');
112                 
113                 // Send the first presence!
114                 firstPresence(getDB('checksum', 1));
115                 
116                 // Check we have new messages (play a sound if any unread messages)
117                 if(checkInboxMessages())
118                         soundPlay(2);
119                 
120                 $('.inbox-hidable').show();
121         }
122         
123         // Bookmarks received
124         else if(bookmarks.size()) {
125                 // Join the groupchats the admin defined (if any)
126                 joinConfGroupchats();
127                 
128                 logThis('Bookmarks received.');
129         }
130         
131         // Roster notes received (for logger)
132         else if(rosternotes.size())
133                 logThis('Roster notes received.');
134 }