mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Idea for #344
This commit is contained in:
parent
a1fd8391da
commit
a57d4dc4b1
3 changed files with 24 additions and 5 deletions
|
|
@ -28,10 +28,19 @@ ContactUserStore.sync = fResultFunc => {
|
||||||
&& !ContactUserStore.syncing()
|
&& !ContactUserStore.syncing()
|
||||||
) {
|
) {
|
||||||
ContactUserStore.syncing(true);
|
ContactUserStore.syncing(true);
|
||||||
Remote.request('ContactsSync', (iError, oData) => {
|
Remote.streamPerLine(line => {
|
||||||
|
try {
|
||||||
|
line = JSON.parse(line);
|
||||||
|
if ('ContactsSync' === line.Action) {
|
||||||
ContactUserStore.syncing(false);
|
ContactUserStore.syncing(false);
|
||||||
fResultFunc && fResultFunc(iError, oData);
|
fResultFunc && fResultFunc(line.ErrorCode, line);
|
||||||
}, null, 200000);
|
}
|
||||||
|
} catch (e) {
|
||||||
|
ContactUserStore.syncing(false);
|
||||||
|
console.error(e);
|
||||||
|
fResultFunc && fResultFunc(Notification.UnknownError);
|
||||||
|
}
|
||||||
|
}, 'ContactsSync');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,13 @@ trait Contacts
|
||||||
{
|
{
|
||||||
$oAccount = $this->getAccountFromToken();
|
$oAccount = $this->getAccountFromToken();
|
||||||
$oAddressBookProvider = $this->AddressBookProvider($oAccount);
|
$oAddressBookProvider = $this->AddressBookProvider($oAccount);
|
||||||
if (!$oAddressBookProvider || !$oAddressBookProvider->Sync()) {
|
if (!$oAddressBookProvider) {
|
||||||
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ContactsSyncError);
|
||||||
|
}
|
||||||
|
\ignore_user_abort(true);
|
||||||
|
\SnappyMail\HTTP\Stream::start(/*$binary = false*/);
|
||||||
|
\SnappyMail\HTTP\Stream::JSON(['messsage'=>'start']);
|
||||||
|
if (!$oAddressBookProvider->Sync()) {
|
||||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ContactsSyncError);
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ContactsSyncError);
|
||||||
}
|
}
|
||||||
return $this->TrueResponse(__FUNCTION__);
|
return $this->TrueResponse(__FUNCTION__);
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,7 @@ class PdoAddressBook
|
||||||
{
|
{
|
||||||
if ($aData['deleted'] && isset($aRemoteSyncData[$sKey], $aRemoteSyncData[$sKey]['vcf']))
|
if ($aData['deleted'] && isset($aRemoteSyncData[$sKey], $aRemoteSyncData[$sKey]['vcf']))
|
||||||
{
|
{
|
||||||
|
\SnappyMail\HTTP\Stream::JSON(['messsage'=>"Delete remote {$sKey}"]);
|
||||||
$this->davClientRequest($oClient, 'DELETE', $sPath.$aRemoteSyncData[$sKey]['vcf']);
|
$this->davClientRequest($oClient, 'DELETE', $sPath.$aRemoteSyncData[$sKey]['vcf']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -188,6 +189,7 @@ class PdoAddressBook
|
||||||
}
|
}
|
||||||
if (\count($aIdsForDeletedion))
|
if (\count($aIdsForDeletedion))
|
||||||
{
|
{
|
||||||
|
\SnappyMail\HTTP\Stream::JSON(['messsage'=>'Delete local ' . \implode(', ', $aIdsForDeletedion)]);
|
||||||
$this->DeleteContacts($aIdsForDeletedion, false);
|
$this->DeleteContacts($aIdsForDeletedion, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,6 +207,7 @@ class PdoAddressBook
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
\SnappyMail\HTTP\Stream::JSON(['messsage'=>"Update remote {$sKey}"]);
|
||||||
$mID = $aData['id_contact'];
|
$mID = $aData['id_contact'];
|
||||||
$oContact = $this->GetContactByID($mID);
|
$oContact = $this->GetContactByID($mID);
|
||||||
if ($oContact)
|
if ($oContact)
|
||||||
|
|
@ -254,6 +257,7 @@ class PdoAddressBook
|
||||||
$aDatabaseSyncData[$sKey]['changed'] < $aData['changed'])
|
$aDatabaseSyncData[$sKey]['changed'] < $aData['changed'])
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
\SnappyMail\HTTP\Stream::JSON(['messsage'=>"Update local {$sKey}"]);
|
||||||
$mExsistenContactID = isset($aDatabaseSyncData[$sKey]['id_contact']) ?
|
$mExsistenContactID = isset($aDatabaseSyncData[$sKey]['id_contact']) ?
|
||||||
$aDatabaseSyncData[$sKey]['id_contact'] : '';
|
$aDatabaseSyncData[$sKey]['id_contact'] : '';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue