3 Jappix - An open social platform
4 These are the storage JS scripts for Jappix
6 -------------------------------------------------
10 Last revision: 26/08/11
14 // Gets the storage items of the user
15 function getStorage(type) {
16 /* REF: http://xmpp.org/extensions/xep-0049.html */
18 var iq = new JSJaCIQ();
21 var iqQuery = iq.setQuery(NS_PRIVATE);
22 iqQuery.appendChild(iq.buildNode('storage', {'xmlns': type}));
24 con.send(iq, handleStorage);
27 // Handles the storage items
28 function handleStorage(iq) {
29 var handleXML = iq.getQuery();
30 var handleFrom = fullXID(getStanzaFrom(iq));
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 + ']');
38 // No options and node not yet configured
39 if(options.size() && !options.find('option').size() && (iq.getType() != 'error'))
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();
48 // We display the storage
49 setDB('options', type, value);
51 // If this is the buddy list show status
52 if((type == 'roster-showall') && (value == '1'))
53 showAllBuddies('storage');
56 // Parse the inbox xml
57 inbox.find('message').each(function() {
60 $(this).attr('subject'),
62 $(this).attr('status'),
66 $(this).attr('file_title'),
67 $(this).attr('file_href'),
68 $(this).attr('file_type'),
69 $(this).attr('file_length')
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();
83 // We display the storage
84 displayFavorites(xid, name, nick, autojoin, password);
86 // Join the chat if autojoin is enabled
88 checkChatCreate(xid, 'groupchat', nick, password, name);
91 // Parse the roster notes xml
92 rosternotes.find('note').each(function() {
93 setDB('rosternotes', $(this).attr('jid'), $(this).text());
98 logThis('Options received.');
100 // Now, get the inbox
101 getStorage(NS_INBOX);
103 // Geolocate the user
106 $('.options-hidable').show();
110 else if(inbox.size()) {
111 logThis('Inbox received.');
113 // Send the first presence!
114 firstPresence(getDB('checksum', 1));
116 // Check we have new messages (play a sound if any unread messages)
117 if(checkInboxMessages())
120 $('.inbox-hidable').show();
123 // Bookmarks received
124 else if(bookmarks.size()) {
125 // Join the groupchats the admin defined (if any)
126 joinConfGroupchats();
128 logThis('Bookmarks received.');
131 // Roster notes received (for logger)
132 else if(rosternotes.size())
133 logThis('Roster notes received.');