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);
}
};

View file

@ -686,12 +686,6 @@ class Actions
'MailToEmail' => '',
'ContactsIsAllowed' => $this->AddressBookProvider($oAccount)->IsActive(),
'ContactsSyncIsAllowed' => (bool)$oConfig->Get('contacts', 'allow_sync', false),
'ContactsSyncInterval' => (int)$oConfig->Get('contacts', 'sync_interval', 20),
'ContactsSyncMode' => 0,
'ContactsSyncUrl' => '',
'ContactsSyncUser' => '',
'ContactsSyncPassword' => '',
'ViewHTML' => (bool) $oConfig->Get('defaults', 'view_html', true),
'ShowImages' => (bool) $oConfig->Get('defaults', 'show_images', false),
@ -739,14 +733,15 @@ class Actions
)
);
if ($aResult['ContactsIsAllowed'] && $aResult['ContactsSyncIsAllowed']) {
$mData = $this->getContactsSyncData($oAccount);
if (\is_array($mData)) {
$aResult['ContactsSyncMode'] = isset($mData['Mode']) ? $mData['Mode'] : 0;
$aResult['ContactsSyncUrl'] = isset($mData['Url']) ? \trim($mData['Url']) : '';
$aResult['ContactsSyncUser'] = isset($mData['User']) ? \trim($mData['User']) : '';
$aResult['ContactsSyncPassword'] = static::APP_DUMMY;
}
if ($aResult['ContactsIsAllowed'] && $oConfig->Get('contacts', 'allow_sync', false)) {
$aData = $this->getContactsSyncData($oAccount) ?: [
'Mode' => 0,
'Url' => '',
'User' => ''
];
$aData['Password'] = $aData['Password'] ? static::APP_DUMMY : '';
$aData['Interval'] = \max(20, \min(320, (int) $oConfig->Get('contacts', 'sync_interval', 20)));
$aResult['ContactsSync'] = $aData;
}
$sToken = Utils::GetCookie(self::AUTH_MAILTO_TOKEN_KEY);

View file

@ -132,7 +132,7 @@ abstract class Upgrade
if ($aData) {
$oActions->setContactsSyncData($oAccount, $aData);
return array(
'Enable' => isset($aData['Enable']) ? !!$aData['Enable'] : false,
'Mode' => empty($aData['Enable']) ? 0 : 1,
'Url' => isset($aData['Url']) ? \trim($aData['Url']) : '',
'User' => isset($aData['User']) ? \trim($aData['User']) : '',
'Password' => isset($aData['Password']) ? $aData['Password'] : ''