1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-25 12:05:59 +01:00

PM-2572 Fix pr comments

This commit is contained in:
Carlos Gonçalves 2024-05-28 21:31:28 +01:00
parent df9fcd1aca
commit c40eb9d3db

View File

@ -578,8 +578,7 @@ namespace Bit.Core.Services
//If the cipher doesn't have a key, we update it //If the cipher doesn't have a key, we update it
if(await ShouldUseCipherKeyEncryptionAsync() && cipherView.Key == null) if(await ShouldUseCipherKeyEncryptionAsync() && cipherView.Key == null)
{ {
cipher = await EncryptAsync(cipherView); await UpdateAndUpsertAsync(cipherView, cipher => _apiService.PutCipherAsync(cipherView.Id, new CipherRequest(cipher)));
await UpdateAndUpsertAsync(() => _apiService.PutCipherAsync(cipherView.Id, new CipherRequest(cipher)));
cipher = await GetAsync(cipherView.Id); cipher = await GetAsync(cipherView.Id);
cipherView = await cipher.DecryptAsync(); cipherView = await cipher.DecryptAsync();
} }
@ -596,8 +595,15 @@ namespace Bit.Core.Services
await Task.WhenAll(attachmentTasks); await Task.WhenAll(attachmentTasks);
cipherView.OrganizationId = organizationId; cipherView.OrganizationId = organizationId;
cipherView.CollectionIds = collectionIds; cipherView.CollectionIds = collectionIds;
cipher = await EncryptAsync(cipherView); await UpdateAndUpsertAsync(cipherView, cipher => _apiService.PutShareCipherAsync(cipherView.Id, new CipherShareRequest(cipher)), collectionIds);
await UpdateAndUpsertAsync(() => _apiService.PutShareCipherAsync(cipherView.Id, new CipherShareRequest(cipher)), collectionIds);
async Task UpdateAndUpsertAsync(CipherView cipherView, Func<Cipher,Task<CipherResponse>> callPutCipherApi, HashSet<string> collectionIds = null)
{
var cipher = await EncryptAsync(cipherView);
var response = await callPutCipherApi(cipher);
var data = new CipherData(response, await _stateService.GetActiveUserIdAsync(), collectionIds);
await UpsertAsync(data);
}
} }
public async Task<Cipher> SaveAttachmentRawWithServerAsync(Cipher cipher, CipherView cipherView, string filename, byte[] data) public async Task<Cipher> SaveAttachmentRawWithServerAsync(Cipher cipher, CipherView cipherView, string filename, byte[] data)
@ -1360,13 +1366,6 @@ namespace Bit.Core.Services
} }
} }
private async Task UpdateAndUpsertAsync(Func<Task<CipherResponse>> callPutCipherApi, HashSet<string> collectionIds = null)
{
var response = await callPutCipherApi();
var data = new CipherData(response, await _stateService.GetActiveUserIdAsync(), collectionIds);
await UpsertAsync(data);
}
private class CipherLocaleComparer : IComparer<CipherView> private class CipherLocaleComparer : IComparer<CipherView>
{ {
private readonly II18nService _i18nService; private readonly II18nService _i18nService;