});
// autosubscribe
- if (autosubscribe) {
- for (i=0; i<contacts.length; i++) {
- xid = contacts[i];
- sendSubscribe(xid, "subscribe");
- console.log("Subscribed to "+xid);
+ if (!autosubscribe) return;
+
+ var get_roster = new JSJaCIQ();
+ get_roster.setType('get');
+ get_roster.setQuery(NS_ROSTER);
+
+ con.send(get_roster, function(iq){
+ var handleXML = iq.getQuery();
+
+ // filter out contacts that are already in the roster
+ $(handleXML).find('item').each(function() {
+ xid = $(this).attr("jid");
+ name = $(this).attr("name");
+ subscription = $(this).attr("subscription");
+ console.log(xid+" "+subscription);
+
+ // ignore accounts not in the list
+ if (contacts[xid]===undefined) return;
+
+ // TODO: add to Friendica group
+
+ // TODO: unblock and authorize if necessary
+
+ // remove from list
+ delete contacts[xid];
+ });
+
+ // go through remaining contacts
+ for (var xid in contacts) {if(!contacts.hasOwnProperty(xid)) continue;
+ // subscribe
+ var presence = new JSJaCPresence();
+ presence.setTo(xid);
+ presence.setType("subscribe");
+ con.send(presence);
+ console.log("subscribed to "+xid);
+
+ // add to roster
+ var iq = new JSJaCIQ();
+ iq.setType('set');
+ var iqQuery = iq.setQuery(NS_ROSTER);
+ var item = iqQuery.appendChild(iq.buildNode('item', {'xmlns': NS_ROSTER, 'jid': xid}));
+ item.setAttribute('name', contacts[xid]);
+ item.appendChild(iq.buildNode('group', {'xmlns': NS_ROSTER}, "Friendica"));
+ con.send(iq);
+ console.log("added to roster "+xid);
}
- }
+ });
}
function jappixmini_addon_subscribe() {
sendSubscribe(xid, "subscribe");
}
-function jappixmini_addon_start(server, username, bosh, encrypted, password, nickname, contacts, autoapprove, autosubscribe) {
+function jappixmini_addon_start(server, username, proxy, bosh, encrypted, password, nickname, contacts, autoapprove, autosubscribe) {
handler = function(password){
// check if settings have changed, reinitialize jappix mini if this is the case
settings_identifier = str_sha1(server);
if (saved_identifier != settings_identifier) removeDB('jappix-mini', 'dom');
setDB("jappix-mini", "settings_identifier", settings_identifier);
- // set bosh host
- if (bosh)
- HOST_BOSH = HOST_BOSH+"?host_bosh="+encodeURI(bosh);
+ // set HOST_BOSH
+ if (proxy)
+ HOST_BOSH = proxy+"?host_bosh="+encodeURI(bosh);
+ else
+ HOST_BOSH = bosh;
// start jappix mini
MINI_NICKNAME = nickname;
+ LOCK_HOST = "off";
console.log("launchMini");
launchMini(true, false, server, username, password);
- jappixmini_manage_roster(contacts, autoapprove, autosubscribe)
+
+ // increase priority over other Jabber clients
+ priority = 101;
+ sendPresence(null,null,priority);
+
+ jappixmini_manage_roster(contacts, autoapprove, autosubscribe)
}
// decrypt password if necessary