$contacts[$address] = $name;
}
$contacts_json = json_encode($contacts);
+ $contacts_hash = sha1($contacts_json);
// get nickname
$r = q("SELECT `username` FROM `user` WHERE `uid`=$uid");
// add javascript to start Jappix Mini
$a->page['htmlhead'] .= "<script type=\"text/javascript\">
jQuery(document).ready(function() {
- jappixmini_addon_start('$server', '$username', '$proxy', '$bosh', $encrypt, '$password', $nickname, $contacts_json, $autoapprove, $autosubscribe);
+ jappixmini_addon_start('$server', '$username', '$proxy', '$bosh', $encrypt, '$password', $nickname, $contacts_json, '$contacts_hash', $autoapprove, $autosubscribe);
});
</script>";
});
}
-function jappixmini_manage_roster(contacts, autoapprove, autosubscribe) {
+function jappixmini_manage_roster(contacts, contacts_hash, autoapprove, autosubscribe) {
// listen for subscriptions
con.registerHandler('presence',function(presence){
var type = presence.getType();
// autosubscribe
if (!autosubscribe) return;
+ stored_hash = getPersistent("jappix-mini", "contacts-hash");
+ contacts_changed = (stored_hash != contacts_hash); // stored_hash gets updated later if everything was successful
+ if (!contacts_changed) return;
+
console.log("Start autosubscribe.");
var get_roster = new JSJaCIQ();
con.send(iq);
console.log("Added "+xid+" to roster.");
}
+
+ setPersistent("jappix-mini", "contacts-hash", contacts_hash);
console.log("Autosubscribe done.");
});
sendSubscribe(xid, "subscribe");
}
-function jappixmini_addon_start(server, username, proxy, bosh, encrypted, password, nickname, contacts, autoapprove, autosubscribe) {
+function jappixmini_addon_start(server, username, proxy, bosh, encrypted, password, nickname, contacts, contacts_hash, autoapprove, autosubscribe) {
handler = function(password){
// check if settings have changed, reinitialize jappix mini if this is the case
settings_identifier = str_sha1(server);
settings_identifier += str_sha1(password);
settings_identifier += str_sha1(nickname);
- saved_identifier = getDB("jappix-mini", "settings_identifier");
- if (saved_identifier != settings_identifier) removeDB('jappix-mini', 'dom');
- setDB("jappix-mini", "settings_identifier", settings_identifier);
+ saved_identifier = getDB("jappix-mini", "settings-identifier");
+ if (saved_identifier != settings_identifier) {
+ disconnectMini();
+ removeDB('jappix-mini', 'dom');
+ removePersistent("jappix-mini", "contacts-hash");
+ }
+ setDB("jappix-mini", "settings-identifier", settings_identifier);
- // set HOST_BOSH
- if (proxy)
- HOST_BOSH = proxy+"?host_bosh="+encodeURI(bosh);
- else
- HOST_BOSH = bosh;
+ // set HOST_BOSH
+ if (proxy)
+ HOST_BOSH = proxy+"?host_bosh="+encodeURI(bosh);
+ else
+ HOST_BOSH = bosh;
// start jappix mini
MINI_NICKNAME = nickname;
priority = 101;
presenceMini(null,null,priority);
- jappixmini_manage_roster(contacts, autoapprove, autosubscribe)
+ jappixmini_manage_roster(contacts, contacts_hash, autoapprove, autosubscribe)
}
// decrypt password if necessary