1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-05 23:53:33 +00:00

Simplify shouldUpdate logic in SyncUpsertSendAsync

This commit is contained in:
Bernd Schoolmann
2023-08-03 17:21:42 +02:00
parent 73f3ffceb2
commit 743bf06b24

View File

@@ -281,38 +281,25 @@ namespace Bit.Core.Services
try try
{ {
var shouldUpdate = true;
var localSend = await _sendService.GetAsync(notification.Id); var localSend = await _sendService.GetAsync(notification.Id);
if (localSend != null && localSend.RevisionDate >= notification.RevisionDate) if (localSend != null && localSend.RevisionDate >= notification.RevisionDate)
{ {
shouldUpdate = false; if ((isEdit && localSend == null) || (!isEdit && localSend != null))
}
if (shouldUpdate)
{
if (isEdit)
{ {
shouldUpdate = localSend != null; return SyncCompleted(false);
}
else
{
shouldUpdate = localSend == null;
} }
} }
if (shouldUpdate) var remoteSend = await _apiService.GetSendAsync(notification.Id);
if (remoteSend != null)
{ {
var remoteSend = await _apiService.GetSendAsync(notification.Id); var userId = await _stateService.GetActiveUserIdAsync();
if (remoteSend != null) await _sendService.UpsertAsync(new SendData(remoteSend, userId));
_messagingService.Send("syncedUpsertedSend", new Dictionary<string, string>
{ {
var userId = await _stateService.GetActiveUserIdAsync(); ["sendId"] = notification.Id
await _sendService.UpsertAsync(new SendData(remoteSend, userId)); });
_messagingService.Send("syncedUpsertedSend", new Dictionary<string, string> return SyncCompleted(true);
{
["sendId"] = notification.Id
});
return SyncCompleted(true);
}
} }
} }
catch (ApiException e) catch (ApiException e)