diff --git a/src/Core/Services/SyncService.cs b/src/Core/Services/SyncService.cs index eb5af45f9..e20357c4d 100644 --- a/src/Core/Services/SyncService.cs +++ b/src/Core/Services/SyncService.cs @@ -277,50 +277,37 @@ namespace Bit.Core.Services public async Task SyncUpsertSendAsync(SyncSendNotification notification, bool isEdit) { SyncStarted(); - if (await _stateService.IsAuthenticatedAsync()) + if (!await _stateService.IsAuthenticatedAsync()) return SyncCompleted(false); + + try { - try + var shouldUpdate = true; + var localSend = await _sendService.GetAsync(notification.Id); + if (localSend != null && localSend.RevisionDate >= notification.RevisionDate) { - var shouldUpdate = true; - var localSend = await _sendService.GetAsync(notification.Id); - if (localSend != null && localSend.RevisionDate >= notification.RevisionDate) - { - shouldUpdate = false; - } + shouldUpdate = false; + } - if (shouldUpdate) + if (shouldUpdate) + { + if (isEdit) { - if (isEdit) - { - shouldUpdate = localSend != null; - } - else - { - shouldUpdate = localSend == null; - } + shouldUpdate = localSend != null; } - - if (shouldUpdate) + else { - var remoteSend = await _apiService.GetSendAsync(notification.Id); - if (remoteSend != null) - { - var userId = await _stateService.GetActiveUserIdAsync(); - await _sendService.UpsertAsync(new SendData(remoteSend, userId)); - _messagingService.Send("syncedUpsertedSend", new Dictionary - { - ["sendId"] = notification.Id - }); - return SyncCompleted(true); - } + shouldUpdate = localSend == null; } } - catch (ApiException e) + + if (shouldUpdate) { - if (e.Error != null && e.Error.StatusCode == System.Net.HttpStatusCode.NotFound && isEdit) + var remoteSend = await _apiService.GetSendAsync(notification.Id); + if (remoteSend != null) { - await _sendService.DeleteAsync(notification.Id); - _messagingService.Send("syncedDeletedSend", new Dictionary + var userId = await _stateService.GetActiveUserIdAsync(); + await _sendService.UpsertAsync(new SendData(remoteSend, userId)); + _messagingService.Send("syncedUpsertedSend", new Dictionary { ["sendId"] = notification.Id }); @@ -328,6 +315,19 @@ namespace Bit.Core.Services } } } + catch (ApiException e) + { + if (e.Error != null && e.Error.StatusCode == System.Net.HttpStatusCode.NotFound && isEdit) + { + await _sendService.DeleteAsync(notification.Id); + _messagingService.Send("syncedDeletedSend", new Dictionary + { + ["sendId"] = notification.Id + }); + return SyncCompleted(true); + } + } + return SyncCompleted(false); }