1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-23 11:45:38 +01:00

implement ASHelpers from messages

This commit is contained in:
Kyle Spearrin 2019-06-27 16:22:58 -04:00
parent 9c2cbc0ecb
commit be4ae605a9
5 changed files with 53 additions and 13 deletions

View File

@ -428,7 +428,7 @@ namespace Bit.App.Pages
await _deviceActionService.HideLoadingAsync();
_platformUtilsService.ShowToast("success", null,
EditMode ? AppResources.ItemUpdated : AppResources.NewItemCreated);
_messagingService.Send(EditMode ? "editedCipher" : "addedCipher");
_messagingService.Send(EditMode ? "editedCipher" : "addedCipher", Cipher.Id);
if((Page as AddEditPage).FromAutofillFramework)
{
@ -469,7 +469,7 @@ namespace Bit.App.Pages
await _cipherService.DeleteWithServerAsync(Cipher.Id);
await _deviceActionService.HideLoadingAsync();
_platformUtilsService.ShowToast("success", null, AppResources.ItemDeleted);
_messagingService.Send("deletedCipher");
_messagingService.Send("deletedCipher", Cipher);
return true;
}
catch(ApiException e)

View File

@ -275,7 +275,7 @@ namespace Bit.App.Pages
await _cipherService.DeleteWithServerAsync(Cipher.Id);
await _deviceActionService.HideLoadingAsync();
_platformUtilsService.ShowToast("success", null, AppResources.ItemDeleted);
_messagingService.Send("deletedCipher");
_messagingService.Send("deletedCipher", Cipher);
return true;
}
catch(ApiException e)

View File

@ -175,7 +175,7 @@ namespace Bit.iOS.Core.Controllers
await loadingAlert.DismissViewControllerAsync(true);
if(await ASHelpers.IdentitiesCanIncremental())
{
var identity = await ASHelpers.GetCipherIdentityAsync(cipherDomain.Id, _cipherService);
var identity = await ASHelpers.GetCipherIdentityAsync(cipherDomain.Id);
if(identity != null)
{
await ASCredentialIdentityStore.SharedStore.SaveCredentialIdentitiesAsync(
@ -184,7 +184,7 @@ namespace Bit.iOS.Core.Controllers
}
else
{
await ASHelpers.ReplaceAllIdentities(_cipherService);
await ASHelpers.ReplaceAllIdentities();
}
Success();
}

View File

@ -4,13 +4,15 @@ using System.Threading.Tasks;
using AuthenticationServices;
using Bit.Core.Abstractions;
using Bit.Core.Models.View;
using Bit.Core.Utilities;
namespace Bit.iOS.Core.Utilities
{
public static class ASHelpers
{
public static async Task ReplaceAllIdentities(ICipherService cipherService)
public static async Task ReplaceAllIdentities()
{
var cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
if(await AutofillEnabled())
{
var identities = new List<ASPasswordCredentialIdentity>();
@ -42,8 +44,9 @@ namespace Bit.iOS.Core.Utilities
return state != null && state.Enabled;
}
public static async Task<ASPasswordCredentialIdentity> GetCipherIdentityAsync(string cipherId, ICipherService cipherService)
public static async Task<ASPasswordCredentialIdentity> GetCipherIdentityAsync(string cipherId)
{
var cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
var cipher = await cipherService.GetAsync(cipherId);
if(cipher == null)
{

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using AuthenticationServices;
using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.App.Services;
@ -51,7 +52,7 @@ namespace Bit.iOS
AppearanceAdjustments();
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
_broadcasterService.Subscribe(nameof(AppDelegate), (message) =>
_broadcasterService.Subscribe(nameof(AppDelegate), async (message) =>
{
if(message.Command == "scheduleLockTimer")
{
@ -87,23 +88,59 @@ namespace Bit.iOS
if(message.Data is Dictionary<string, object> data && data.ContainsKey("successfully"))
{
var success = data["successfully"] as bool?;
if(success.GetValueOrDefault())
if(success.GetValueOrDefault() && _deviceActionService.SystemMajorVersion() >= 12)
{
await ASHelpers.ReplaceAllIdentities();
}
}
}
else if(message.Command == "addedCipher" || message.Command == "editedCipher")
{
if(_deviceActionService.SystemMajorVersion() >= 12)
{
if(await ASHelpers.IdentitiesCanIncremental())
{
var cipherId = message.Data as string;
if(message.Command == "addedCipher" && !string.IsNullOrWhiteSpace(cipherId))
{
var identity = await ASHelpers.GetCipherIdentityAsync(cipherId);
if(identity == null)
{
return;
}
await ASCredentialIdentityStore.SharedStore?.SaveCredentialIdentitiesAsync(
new ASPasswordCredentialIdentity[] { identity });
return;
}
}
await ASHelpers.ReplaceAllIdentities();
}
}
else if(message.Command == "deletedCipher")
{
if(_deviceActionService.SystemMajorVersion() >= 12)
{
if(await ASHelpers.IdentitiesCanIncremental())
{
var identity = ASHelpers.ToCredentialIdentity(
message.Data as Bit.Core.Models.View.CipherView);
if(identity == null)
{
return;
}
await ASCredentialIdentityStore.SharedStore?.RemoveCredentialIdentitiesAsync(
new ASPasswordCredentialIdentity[] { identity });
return;
}
await ASHelpers.ReplaceAllIdentities();
}
}
else if(message.Command == "loggedOut")
{
if(_deviceActionService.SystemMajorVersion() >= 12)
{
await ASCredentialIdentityStore.SharedStore?.RemoveAllCredentialIdentitiesAsync();
}
}
});