From 743bf06b24514459a236efd43fa9e297948ed8f9 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Thu, 3 Aug 2023 17:21:42 +0200 Subject: [PATCH] Simplify shouldUpdate logic in SyncUpsertSendAsync --- src/Core/Services/SyncService.cs | 33 ++++++++++---------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/Core/Services/SyncService.cs b/src/Core/Services/SyncService.cs index e20357c4d..37a9bfca7 100644 --- a/src/Core/Services/SyncService.cs +++ b/src/Core/Services/SyncService.cs @@ -281,38 +281,25 @@ namespace Bit.Core.Services try { - var shouldUpdate = true; var localSend = await _sendService.GetAsync(notification.Id); if (localSend != null && localSend.RevisionDate >= notification.RevisionDate) { - shouldUpdate = false; - } - - if (shouldUpdate) - { - if (isEdit) + if ((isEdit && localSend == null) || (!isEdit && localSend != null)) { - shouldUpdate = localSend != null; - } - else - { - shouldUpdate = localSend == null; + return SyncCompleted(false); } } - if (shouldUpdate) + var remoteSend = await _apiService.GetSendAsync(notification.Id); + if (remoteSend != null) { - 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 { - var userId = await _stateService.GetActiveUserIdAsync(); - await _sendService.UpsertAsync(new SendData(remoteSend, userId)); - _messagingService.Send("syncedUpsertedSend", new Dictionary - { - ["sendId"] = notification.Id - }); - return SyncCompleted(true); - } + ["sendId"] = notification.Id + }); + return SyncCompleted(true); } } catch (ApiException e)