Simplify handling of ContactsSync settings

This commit is contained in:
the-djmaze 2022-11-18 09:54:53 +01:00
parent 4a2dcbc1f7
commit 867b7081f6
3 changed files with 18 additions and 26 deletions

View file

@ -1,6 +1,5 @@
import ko from 'ko';
import { SettingsGet } from 'Common/Globals';
import { pInt } from 'Common/Utils';
import { koComputable, addObservablesTo, koArrayWithDestroy } from 'External/ko';
import Remote from 'Remote/User/Fetch';
@ -51,16 +50,14 @@ ContactUserStore.sync = fResultFunc => {
};
ContactUserStore.init = () => {
let value = !!SettingsGet('ContactsSyncIsAllowed');
ContactUserStore.allowSync(value);
if (value) {
ContactUserStore.syncMode(SettingsGet('ContactsSyncMode'));
ContactUserStore.syncUrl(SettingsGet('ContactsSyncUrl'));
ContactUserStore.syncUser(SettingsGet('ContactsSyncUser'));
ContactUserStore.syncPass(SettingsGet('ContactsSyncPassword'));
let config = SettingsGet('ContactsSync');
ContactUserStore.allowSync(!!config);
if (config) {
ContactUserStore.syncMode(config.Mode);
ContactUserStore.syncUrl(config.Url);
ContactUserStore.syncUser(config.User);
ContactUserStore.syncPass(config.Password);
setTimeout(ContactUserStore.sync, 10000);
value = pInt(SettingsGet('ContactsSyncInterval'));
value = 5 <= value ? (320 >= value ? value : 320) : 20;
setInterval(ContactUserStore.sync, value * 60000 + 5000);
setInterval(ContactUserStore.sync, config.Interval * 60000 + 5000);
}
};