full sync and cipher modification messages

This commit is contained in:
Kyle Spearrin 2018-09-20 23:47:19 -04:00
parent 2732fc93f9
commit b0c6c09cea
3 changed files with 21 additions and 10 deletions

View file

@ -16,9 +16,9 @@ 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); Task UpsertDataAsync(CipherData cipher, bool sendMessage);
Task<ApiResult> DeleteAsync(string id); Task<ApiResult> DeleteAsync(string id);
Task DeleteDataAsync(string id); Task DeleteDataAsync(string id, bool sendMessage);
Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null); Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null);
Task<ApiResult<CipherResponse>> EncryptAndSaveAttachmentAsync(Cipher cipher, byte[] data, string fileName); Task<ApiResult<CipherResponse>> EncryptAndSaveAttachmentAsync(Cipher cipher, byte[] data, string fileName);
Task UpsertAttachmentDataAsync(IEnumerable<AttachmentData> attachments); Task UpsertAttachmentDataAsync(IEnumerable<AttachmentData> attachments);

View file

@ -9,6 +9,7 @@ using Bit.App.Models.Data;
using System.Net.Http; using System.Net.Http;
using Bit.App.Utilities; using Bit.App.Utilities;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Xamarin.Forms;
namespace Bit.App.Services namespace Bit.App.Services
{ {
@ -254,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); await UpsertDataAsync(data, true);
cipher.Id = data.Id; cipher.Id = data.Id;
} }
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
@ -266,11 +267,15 @@ namespace Bit.App.Services
return response; return response;
} }
public async Task UpsertDataAsync(CipherData cipher) public async Task UpsertDataAsync(CipherData cipher, bool sendMessage)
{ {
await _cipherRepository.UpsertAsync(cipher); await _cipherRepository.UpsertAsync(cipher);
CachedCiphers = null; CachedCiphers = null;
_appSettingsService.ClearCiphersCache = true; _appSettingsService.ClearCiphersCache = true;
if(sendMessage)
{
MessagingCenter.Send(Application.Current, "UpsertedCipher", cipher.Id);
}
} }
public async Task<ApiResult> DeleteAsync(string id) public async Task<ApiResult> DeleteAsync(string id)
@ -278,7 +283,7 @@ namespace Bit.App.Services
var response = await _cipherApiRepository.DeleteAsync(id); var response = await _cipherApiRepository.DeleteAsync(id);
if(response.Succeeded) if(response.Succeeded)
{ {
await DeleteDataAsync(id); await DeleteDataAsync(id, true);
} }
else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden else if(response.StatusCode == System.Net.HttpStatusCode.Forbidden
|| response.StatusCode == System.Net.HttpStatusCode.Unauthorized) || response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
@ -289,11 +294,15 @@ namespace Bit.App.Services
return response; return response;
} }
public async Task DeleteDataAsync(string id) public async Task DeleteDataAsync(string id, bool sendMessage)
{ {
await _cipherRepository.DeleteAsync(id); await _cipherRepository.DeleteAsync(id);
CachedCiphers = null; CachedCiphers = null;
_appSettingsService.ClearCiphersCache = true; _appSettingsService.ClearCiphersCache = true;
if(sendMessage)
{
MessagingCenter.Send(Application.Current, "DeletedCipher", id);
}
} }
public async Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null) public async Task<byte[]> DownloadAndDecryptAttachmentAsync(string url, string orgId = null)

View file

@ -84,7 +84,7 @@ namespace Bit.App.Services
try try
{ {
var cipherData = new CipherData(cipher.Result, _authService.UserId); var cipherData = new CipherData(cipher.Result, _authService.UserId);
await _cipherService.UpsertDataAsync(cipherData).ConfigureAwait(false); await _cipherService.UpsertDataAsync(cipherData, true).ConfigureAwait(false);
var localAttachments = (await _attachmentRepository.GetAllByCipherIdAsync(cipherData.Id) var localAttachments = (await _attachmentRepository.GetAllByCipherIdAsync(cipherData.Id)
.ConfigureAwait(false)); .ConfigureAwait(false));
@ -181,7 +181,7 @@ namespace Bit.App.Services
try try
{ {
await _cipherService.DeleteDataAsync(id).ConfigureAwait(false); await _cipherService.DeleteDataAsync(id, true).ConfigureAwait(false);
SyncCompleted(true); SyncCompleted(true);
return true; return true;
} }
@ -287,11 +287,13 @@ namespace Bit.App.Services
domainsTask.Exception != null || profileTask.Exception != null) domainsTask.Exception != null || profileTask.Exception != null)
{ {
SyncCompleted(false); SyncCompleted(false);
MessagingCenter.Send(Application.Current, "FullSyncCompleted", false);
return false; return false;
} }
_settings.AddOrUpdateValue(Constants.LastSync, now); _settings.AddOrUpdateValue(Constants.LastSync, now);
SyncCompleted(true); SyncCompleted(true);
MessagingCenter.Send(Application.Current, "FullSyncCompleted", true);
return true; return true;
} }
@ -442,7 +444,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).ConfigureAwait(false); await _cipherService.UpsertDataAsync(data, false).ConfigureAwait(false);
if(serverCipher.Value.Attachments != null) if(serverCipher.Value.Attachments != null)
{ {
@ -470,7 +472,7 @@ namespace Bit.App.Services
{ {
try try
{ {
await _cipherService.DeleteDataAsync(cipher.Value.Id).ConfigureAwait(false); await _cipherService.DeleteDataAsync(cipher.Value.Id, false).ConfigureAwait(false);
} }
catch(SQLite.SQLiteException) { } catch(SQLite.SQLiteException) { }
} }