Improve AppUser.bootstart

This commit is contained in:
djmaze 2021-09-23 14:24:06 +02:00
parent 3c8cdcbb07
commit 9158fcd0eb
6 changed files with 81 additions and 118 deletions

View file

@ -1,5 +1,4 @@
import ko from 'ko';
import { SettingsGet } from 'Common/Globals';
import { addObservablesTo } from 'Common/Utils';
export const AccountUserStore = {
@ -18,11 +17,6 @@ export const AccountUserStore = {
// });
// return result;
// }),
populate: () => {
AccountUserStore.email(SettingsGet('Email'));
AccountUserStore.parentEmail(SettingsGet('ParentEmail'));
}
};
addObservablesTo(AccountUserStore, {

View file

@ -1,6 +1,7 @@
import ko from 'ko';
import { SettingsGet } from 'Common/Globals';
import { addObservablesTo } from 'Common/Utils';
import { pInt, addObservablesTo } from 'Common/Utils';
import Remote from 'Remote/User/Fetch';
export const ContactUserStore = ko.observableArray();
@ -9,18 +10,42 @@ ContactUserStore.importing = ko.observable(false).extend({ debounce: 200 });
ContactUserStore.syncing = ko.observable(false).extend({ debounce: 200 });
addObservablesTo(ContactUserStore, {
allowSync: false,
allowSync: false, // Admin setting
enableSync: false,
syncUrl: '',
syncUser: '',
syncPass: ''
});
ContactUserStore.populate = function() {
this.allowSync(!!SettingsGet('ContactsSyncIsAllowed'));
this.enableSync(!!SettingsGet('EnableContactsSync'));
this.syncUrl(SettingsGet('ContactsSyncUrl'));
this.syncUser(SettingsGet('ContactsSyncUser'));
this.syncPass(SettingsGet('ContactsSyncPassword'));
/**
* @param {Function} fResultFunc
* @returns {void}
*/
ContactUserStore.sync = fResultFunc => {
if (ContactUserStore.enableSync()
&& !ContactUserStore.importing()
&& !ContactUserStore.syncing()
) {
ContactUserStore.syncing(true);
Remote.contactsSync((sResult, oData) => {
ContactUserStore.syncing(false);
fResultFunc && fResultFunc(sResult, oData);
});
}
};
ContactUserStore.init = () => {
let value = !!SettingsGet('ContactsSyncIsAllowed');
ContactUserStore.allowSync(value);
if (value) {
ContactUserStore.enableSync(!!SettingsGet('EnableContactsSync'));
ContactUserStore.syncUrl(SettingsGet('ContactsSyncUrl'));
ContactUserStore.syncUser(SettingsGet('ContactsSyncUser'));
ContactUserStore.syncPass(SettingsGet('ContactsSyncPassword'));
setTimeout(ContactUserStore.sync, 10000);
value = pInt(SettingsGet('ContactsSyncInterval'));
value = 5 <= value ? value : 20;
value = 320 >= value ? value : 320;
setInterval(ContactUserStore.sync, value * 60000 + 5000);
}
};

View file

@ -1,7 +1,6 @@
import ko from 'ko';
import { SMAudio } from 'Common/Audio';
import { SettingsGet } from 'Common/Globals';
import * as Links from 'Common/Links';
/**
@ -101,9 +100,4 @@ export const NotificationUserStore = new class {
}
}
}
populate() {
this.enableSoundNotification(!!SettingsGet('SoundNotification'));
this.enableDesktopNotification(!!SettingsGet('DesktopNotifications'));
}
};