mirror of
https://github.com/bitwarden/mobile.git
synced 2025-01-03 18:17:47 +01:00
replace vs created on save
This commit is contained in:
parent
045ce42168
commit
d958dc6bce
@ -16,7 +16,7 @@ namespace Bit.App.Abstractions
|
|||||||
Task<IEnumerable<Cipher>> GetAllByCollectionAsync(string collectionId);
|
Task<IEnumerable<Cipher>> GetAllByCollectionAsync(string collectionId);
|
||||||
Task<Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>, IEnumerable<Cipher>>> GetAllAsync(string uriString);
|
Task<Tuple<IEnumerable<Cipher>, IEnumerable<Cipher>, IEnumerable<Cipher>>> GetAllAsync(string uriString);
|
||||||
Task<ApiResult<CipherResponse>> SaveAsync(Cipher cipher);
|
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<ApiResult> DeleteAsync(string id);
|
||||||
Task DeleteDataAsync(string id, bool sendMessage);
|
Task DeleteDataAsync(string id, bool sendMessage);
|
||||||
Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null);
|
Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null);
|
||||||
|
@ -255,7 +255,7 @@ namespace Bit.App.Services
|
|||||||
if(response.Succeeded)
|
if(response.Succeeded)
|
||||||
{
|
{
|
||||||
var data = new CipherData(response.Result, _authService.UserId);
|
var data = new CipherData(response.Result, _authService.UserId);
|
||||||
await UpsertDataAsync(data, true);
|
await UpsertDataAsync(data, true, cipher.Id == null);
|
||||||
cipher.Id = data.Id;
|
cipher.Id = data.Id;
|
||||||
}
|
}
|
||||||
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|
||||||
@ -267,14 +267,15 @@ namespace Bit.App.Services
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpsertDataAsync(CipherData cipher, bool sendMessage)
|
public async Task UpsertDataAsync(CipherData cipher, bool sendMessage, bool created)
|
||||||
{
|
{
|
||||||
await _cipherRepository.UpsertAsync(cipher);
|
await _cipherRepository.UpsertAsync(cipher);
|
||||||
CachedCiphers = null;
|
CachedCiphers = null;
|
||||||
_appSettingsService.ClearCiphersCache = true;
|
_appSettingsService.ClearCiphersCache = true;
|
||||||
if(sendMessage && Application.Current != null)
|
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
|
try
|
||||||
{
|
{
|
||||||
|
var existingCipher = await _cipherService.GetByIdAsync(cipher.Result.Id);
|
||||||
var cipherData = new CipherData(cipher.Result, _authService.UserId);
|
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)
|
var localAttachments = (await _attachmentRepository.GetAllByCipherIdAsync(cipherData.Id)
|
||||||
.ConfigureAwait(false));
|
.ConfigureAwait(false));
|
||||||
@ -444,7 +445,7 @@ namespace Bit.App.Services
|
|||||||
localCiphers[serverCipher.Value.Id] : null;
|
localCiphers[serverCipher.Value.Id] : null;
|
||||||
|
|
||||||
var data = new CipherData(serverCipher.Value, _authService.UserId);
|
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)
|
if(serverCipher.Value.Attachments != null)
|
||||||
{
|
{
|
||||||
|
@ -155,18 +155,26 @@ namespace Bit.iOS
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
MessagingCenter.Subscribe<Xamarin.Forms.Application, string>(
|
MessagingCenter.Subscribe<Xamarin.Forms.Application, Tuple<string, bool>>(
|
||||||
Xamarin.Forms.Application.Current, "UpsertedCipher", async (sender, id) =>
|
Xamarin.Forms.Application.Current, "UpsertedCipher", async (sender, data) =>
|
||||||
{
|
{
|
||||||
if(await ASHelpers.IdentitiesCanIncremental())
|
if(await ASHelpers.IdentitiesCanIncremental())
|
||||||
{
|
{
|
||||||
var identity = await ASHelpers.GetCipherIdentityAsync(id, _cipherService);
|
var identity = await ASHelpers.GetCipherIdentityAsync(data.Item1, _cipherService);
|
||||||
if(identity == null)
|
if(identity == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
|
if(data.Item2)
|
||||||
new ASPasswordCredentialIdentity[] { identity });
|
{
|
||||||
|
await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
|
||||||
|
new ASPasswordCredentialIdentity[] { identity });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await ASCredentialIdentityStore.SharedStore.ReplaceCredentialIdentitiesAsync(
|
||||||
|
new ASPasswordCredentialIdentity[] { identity });
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await ASHelpers.ReplaceAllIdentities(_cipherService);
|
await ASHelpers.ReplaceAllIdentities(_cipherService);
|
||||||
|
Loading…
Reference in New Issue
Block a user