1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jappix_ynh.git synced 2024-09-03 19:26:19 +02:00
jappix_ynh/source/app/javascripts/xmpplinks.js

109 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-03-12 14:52:47 +01:00
/*
Jappix - An open social platform
These are the XMPP links handling JS scripts for Jappix
-------------------------------------------------
License: AGPL
Author: Valérian Saliou
*/
// Bundle
var XMPPLinks = (function () {
/**
* Alias of this
* @private
*/
var self = {};
2014-04-08 20:14:28 +02:00
/**
2014-03-12 14:52:47 +01:00
* Does an action with the provided XMPP link
* @public
* @param {string} link
* @return {boolean}
*/
self.go = function(link) {
/* REF: http://xmpp.org/registrar/querytypes.html */
try {
// Remove the "xmpp:" string
link = Common.explodeThis(':', link, 1);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// The XMPP URI has no "?"
2014-11-25 20:12:58 +01:00
if(link.indexOf('?') == -1) {
2014-03-12 14:52:47 +01:00
Chat.checkCreate(link, 'chat');
2014-11-25 20:12:58 +01:00
} else {
2014-03-12 14:52:47 +01:00
var xid = Common.explodeThis('?', link, 0);
var action = Common.explodeThis('?', link, 1);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
switch(action) {
// Groupchat
case 'join':
Chat.checkCreate(xid, 'groupchat');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
break;
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Profile
case 'vcard':
UserInfos.open(xid);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
break;
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Subscription
case 'subscribe':
Roster.addThisContact(xid);
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
break;
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Unsubscription
case 'unsubscribe':
Roster.send(xid, 'remove');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
break;
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
// Private chat
default:
Chat.checkCreate(xid, 'chat');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
break;
}
}
} catch(e) {
Console.error('XMPPLinks.do', e);
} finally {
return false;
}
};
/**
* Gets the links vars (get parameters in URL)
*/
self.links_var = (function() {
2014-11-25 20:12:58 +01:00
var hash;
2014-03-12 14:52:47 +01:00
var vars = [];
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
for(var i = 0; i < hashes.length; i++) {
2014-11-25 20:12:58 +01:00
hash = hashes[i].split('=');
2014-03-12 14:52:47 +01:00
vars.push(hash[0]);
vars[hash[0]] = $.trim(decodeURIComponent(hash[1]));
}
2014-11-25 23:42:38 +01:00
2014-03-12 14:52:47 +01:00
return vars;
})();
/**
* Return class scope
*/
return self;
})();