replace vs created on save

This commit is contained in:
Kyle Spearrin 2018-09-21 21:53:04 -04:00
parent 045ce42168
commit d958dc6bce
4 changed files with 22 additions and 12 deletions

View file

@ -16,7 +16,7 @@ namespace Bit.App.Abstractions
Task<IEnumerable<Cipher>> GetAllByCollectionAsync(string collectionId);
Task<Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>, IEnumerable<Cipher>>> GetAllAsync(string uriString);
Task<ApiResult<CipherResponse>> SaveAsync(Cipher cipher);
Task UpsertDataAsync(CipherData cipher, bool sendMessage);
Task UpsertDataAsync(CipherData cipher, bool sendMessage, bool created);
Task<ApiResult> DeleteAsync(string id);
Task DeleteDataAsync(string id, bool sendMessage);
Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null);

View file

@ -255,7 +255,7 @@ namespace Bit.App.Services
if(response.Succeeded)
{
var data = new CipherData(response.Result, _authService.UserId);
await UpsertDataAsync(data, true);
await UpsertDataAsync(data, true, cipher.Id == null);
cipher.Id = data.Id;
}
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
@ -267,14 +267,15 @@ namespace Bit.App.Services
return response;
}
public async Task UpsertDataAsync(CipherData cipher, bool sendMessage)
public async Task UpsertDataAsync(CipherData cipher, bool sendMessage, bool created)
{
await _cipherRepository.UpsertAsync(cipher);
CachedCiphers = null;
CachedCiphers = null;
_appSettingsService.ClearCiphersCache = true;
if(sendMessage && Application.Current != null)
{
MessagingCenter.Send(Application.Current, "UpsertedCipher", cipher.Id);
MessagingCenter.Send(Application.Current, "UpsertedCipher",
new Tuple<string, bool>(cipher.Id, created));
}
}

View file

@ -83,8 +83,9 @@ namespace Bit.App.Services
try
{
var existingCipher = await _cipherService.GetByIdAsync(cipher.Result.Id);
var cipherData = new CipherData(cipher.Result, _authService.UserId);
await _cipherService.UpsertDataAsync(cipherData, true).ConfigureAwait(false);
await _cipherService.UpsertDataAsync(cipherData, true, existingCipher == null).ConfigureAwait(false);
var localAttachments = (await _attachmentRepository.GetAllByCipherIdAsync(cipherData.Id)
.ConfigureAwait(false));
@ -444,7 +445,7 @@ namespace Bit.App.Services
localCiphers[serverCipher.Value.Id] : null;
var data = new CipherData(serverCipher.Value, _authService.UserId);
await _cipherService.UpsertDataAsync(data, false).ConfigureAwait(false);
await _cipherService.UpsertDataAsync(data, false, false).ConfigureAwait(false);
if(serverCipher.Value.Attachments != null)
{

View file

@ -155,18 +155,26 @@ namespace Bit.iOS
}
});
MessagingCenter.Subscribe<Xamarin.Forms.Application, string>(
Xamarin.Forms.Application.Current, "UpsertedCipher", async (sender, id) =>
MessagingCenter.Subscribe<Xamarin.Forms.Application, Tuple<string, bool>>(
Xamarin.Forms.Application.Current, "UpsertedCipher", async (sender, data) =>
{
if(await ASHelpers.IdentitiesCanIncremental())
{
var identity = await ASHelpers.GetCipherIdentityAsync(id, _cipherService);
var identity = await ASHelpers.GetCipherIdentityAsync(data.Item1, _cipherService);
if(identity == null)
{
return;
}
await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
new ASPasswordCredentialIdentity[] { identity });
if(data.Item2)
{
await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
new ASPasswordCredentialIdentity[] { identity });
}
else
{
await ASCredentialIdentityStore.SharedStore.ReplaceCredentialIdentitiesAsync(
new ASPasswordCredentialIdentity[] { identity });
}
return;
}
await ASHelpers.ReplaceAllIdentities(_cipherService);