diff --git a/src/Core/Models/View/CipherView.cs b/src/Core/Models/View/CipherView.cs index 0d0830731..2a9f20d9c 100644 --- a/src/Core/Models/View/CipherView.cs +++ b/src/Core/Models/View/CipherView.cs @@ -1,5 +1,7 @@ using Bit.Core.Enums; using Bit.Core.Models.Domain; +using Bit.Core.Resources.Localization; +using Bit.Core.Utilities; namespace Bit.Core.Models.View { @@ -119,5 +121,14 @@ namespace Bit.Core.Models.View public bool IsClonable => OrganizationId is null; public bool HasFido2Credential => Type == CipherType.Login && Login?.HasFido2Credentials == true; + + public string GetMainFido2CredentialUsername() + { + return Login?.MainFido2Credential?.UserName + .FallbackOnNullOrWhiteSpace(Login?.MainFido2Credential?.UserDisplayName) + .FallbackOnNullOrWhiteSpace(Login?.Username) + .FallbackOnNullOrWhiteSpace(Name) + .FallbackOnNullOrWhiteSpace(AppResources.UnknownAccount); + } } } diff --git a/src/Core/Models/View/LoginView.cs b/src/Core/Models/View/LoginView.cs index 9c9bafbaf..528026dc6 100644 --- a/src/Core/Models/View/LoginView.cs +++ b/src/Core/Models/View/LoginView.cs @@ -1,7 +1,5 @@ using Bit.Core.Enums; using Bit.Core.Models.Domain; -using Bit.Core.Resources.Localization; -using Bit.Core.Utilities; namespace Bit.Core.Models.View { @@ -39,15 +37,4 @@ namespace Bit.Core.Models.View }; } } - - public static class LoginViewExtensions - { - public static string GetMainFido2CredentialUsername(this LoginView loginView) - { - return loginView.MainFido2Credential.UserName - .FallbackOnNullOrWhiteSpace(loginView.MainFido2Credential.UserDisplayName) - .FallbackOnNullOrWhiteSpace(loginView.Username) - .FallbackOnNullOrWhiteSpace(AppResources.UnknownAccount); - } - } } diff --git a/src/iOS.Autofill/Utilities/BaseLoginListTableSource.cs b/src/iOS.Autofill/Utilities/BaseLoginListTableSource.cs index d997d8352..115025b5c 100644 --- a/src/iOS.Autofill/Utilities/BaseLoginListTableSource.cs +++ b/src/iOS.Autofill/Utilities/BaseLoginListTableSource.cs @@ -111,6 +111,21 @@ namespace Bit.iOS.Autofill.Utilities return IsPasskeySection(indexPath.Section) || !item.ForceSectionIcon; } + protected override string GetCipherCellSubtitle(CipherViewModel item, NSIndexPath indexPath) + { + if (!item.HasFido2Credential) + { + return base.GetCipherCellSubtitle(item, indexPath); + } + + if (Context.IsPreparingListForPasskey && !IsPasskeySection(indexPath.Section)) + { + return item.Username; + } + + return item.CipherView?.GetMainFido2CredentialUsername() ?? item.Username; + } + public override UIView GetViewForHeader(UITableView tableView, nint section) { try diff --git a/src/iOS.Core/Utilities/ASHelpers.cs b/src/iOS.Core/Utilities/ASHelpers.cs index e9607c75b..9dbc78fa9 100644 --- a/src/iOS.Core/Utilities/ASHelpers.cs +++ b/src/iOS.Core/Utilities/ASHelpers.cs @@ -145,7 +145,7 @@ namespace Bit.iOS.Core.Utilities } return new ASPasskeyCredentialIdentity(cipher.Login.MainFido2Credential.RpId, - cipher.Login.GetMainFido2CredentialUsername(), + cipher.GetMainFido2CredentialUsername(), NSData.FromArray(cipher.Login.MainFido2Credential.CredentialId.GuidToRawFormat()), cipher.Login.MainFido2Credential.UserHandle, cipher.Id); diff --git a/src/iOS.Core/Views/ExtensionTableSource.cs b/src/iOS.Core/Views/ExtensionTableSource.cs index 3cf336e66..af2a1fbc1 100644 --- a/src/iOS.Core/Views/ExtensionTableSource.cs +++ b/src/iOS.Core/Views/ExtensionTableSource.cs @@ -144,7 +144,7 @@ namespace Bit.iOS.Core.Views } cipherCell.SetTitle(item.Name); - cipherCell.SetSubtitle(item.Username); + cipherCell.SetSubtitle(GetCipherCellSubtitle(item, indexPath)); cipherCell.UpdateMainIcon(ShouldUseMainIconAsPasskey(item, indexPath)); if (item.IsShared) { @@ -161,6 +161,8 @@ namespace Bit.iOS.Core.Views protected virtual bool ShouldUseMainIconAsPasskey(CipherViewModel item, NSIndexPath indexPath) => item.HasFido2Credential; + protected virtual string GetCipherCellSubtitle(CipherViewModel item, NSIndexPath indexPath) => item.Username; + public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath) { return 55;