mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 01:48:25 +03:00
replace vs created on save
This commit is contained in:
parent
045ce42168
commit
d958dc6bce
4 changed files with 22 additions and 12 deletions
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue