mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-10 15:08:28 +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(true);
|
||||
Remote.request('ContactsSync', (iError, oData) => {
|
||||
ContactUserStore.syncing(false);
|
||||
fResultFunc && fResultFunc(iError, oData);
|
||||
}, null, 200000);
|
||||
Remote.streamPerLine(line => {
|
||||
try {
|
||||
line = JSON.parse(line);
|
||||
if ('ContactsSync' === line.Action) {
|
||||
ContactUserStore.syncing(false);
|
||||
fResultFunc && fResultFunc(line.ErrorCode, line);
|
||||
}
|
||||
} catch (e) {
|
||||
ContactUserStore.syncing(false);
|
||||
console.error(e);
|
||||
fResultFunc && fResultFunc(Notification.UnknownError);
|
||||
}
|
||||
}, 'ContactsSync');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,13 @@ trait Contacts
|
|||
{
|
||||
$oAccount = $this->getAccountFromToken();
|
||||
$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);
|
||||
}
|
||||
return $this->TrueResponse(__FUNCTION__);
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ class PdoAddressBook
|
|||
{
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
|
@ -188,6 +189,7 @@ class PdoAddressBook
|
|||
}
|
||||
if (\count($aIdsForDeletedion))
|
||||
{
|
||||
\SnappyMail\HTTP\Stream::JSON(['messsage'=>'Delete local ' . \implode(', ', $aIdsForDeletedion)]);
|
||||
$this->DeleteContacts($aIdsForDeletedion, false);
|
||||
}
|
||||
|
||||
|
|
@ -205,6 +207,7 @@ class PdoAddressBook
|
|||
)
|
||||
)
|
||||
{
|
||||
\SnappyMail\HTTP\Stream::JSON(['messsage'=>"Update remote {$sKey}"]);
|
||||
$mID = $aData['id_contact'];
|
||||
$oContact = $this->GetContactByID($mID);
|
||||
if ($oContact)
|
||||
|
|
@ -254,6 +257,7 @@ class PdoAddressBook
|
|||
$aDatabaseSyncData[$sKey]['changed'] < $aData['changed'])
|
||||
)
|
||||
{
|
||||
\SnappyMail\HTTP\Stream::JSON(['messsage'=>"Update local {$sKey}"]);
|
||||
$mExsistenContactID = isset($aDatabaseSyncData[$sKey]['id_contact']) ?
|
||||
$aDatabaseSyncData[$sKey]['id_contact'] : '';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue