fix: Username field autosuggests account name instead of an email

This commit is contained in:
Artem Chepurnoy 2024-03-31 08:40:15 +03:00
parent 21eeb3559b
commit 5c394f6b26
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E

View File

@ -33,6 +33,7 @@ import com.artemchep.keyguard.common.io.effectTap
import com.artemchep.keyguard.common.io.ioEffect import com.artemchep.keyguard.common.io.ioEffect
import com.artemchep.keyguard.common.io.launchIn import com.artemchep.keyguard.common.io.launchIn
import com.artemchep.keyguard.common.io.toIO import com.artemchep.keyguard.common.io.toIO
import com.artemchep.keyguard.common.model.DProfile
import com.artemchep.keyguard.common.model.DSecret import com.artemchep.keyguard.common.model.DSecret
import com.artemchep.keyguard.common.model.Loadable import com.artemchep.keyguard.common.model.Loadable
import com.artemchep.keyguard.common.model.ToastMessage import com.artemchep.keyguard.common.model.ToastMessage
@ -73,6 +74,7 @@ import com.artemchep.keyguard.common.model.creditCards
import com.artemchep.keyguard.common.model.displayName import com.artemchep.keyguard.common.model.displayName
import com.artemchep.keyguard.common.model.fileName import com.artemchep.keyguard.common.model.fileName
import com.artemchep.keyguard.common.model.fileSize import com.artemchep.keyguard.common.model.fileSize
import com.artemchep.keyguard.common.model.firstOrNull
import com.artemchep.keyguard.common.model.title import com.artemchep.keyguard.common.model.title
import com.artemchep.keyguard.common.model.titleH import com.artemchep.keyguard.common.model.titleH
import com.artemchep.keyguard.common.service.clipboard.ClipboardService import com.artemchep.keyguard.common.service.clipboard.ClipboardService
@ -243,6 +245,12 @@ fun produceAddScreenState(
getFolders = getFolders, getFolders = getFolders,
getCiphers = getCiphers, getCiphers = getCiphers,
) )
val profileFlow = getProfiles()
.combine(ownershipFlow) { profiles, ownership ->
profiles
.firstOrNull { it.accountId == ownership.data.accountId }
}
.distinctUntilChanged()
val mergeFlow = if (args.merge != null) { val mergeFlow = if (args.merge != null) {
val ciphersHaveAttachments = args.merge.ciphers.any { it.attachments.isNotEmpty() } val ciphersHaveAttachments = args.merge.ciphers.any { it.attachments.isNotEmpty() }
@ -279,7 +287,7 @@ fun produceAddScreenState(
val loginHolder = produceLoginState( val loginHolder = produceLoginState(
args = args, args = args,
ownershipFlow = ownershipFlow, profileFlow = profileFlow,
copyText = copyText, copyText = copyText,
getTotpCode = getTotpCode, getTotpCode = getTotpCode,
getGravatarUrl = getGravatarUrl, getGravatarUrl = getGravatarUrl,
@ -2221,7 +2229,7 @@ data class TmpNote(
private suspend fun RememberStateFlowScope.produceLoginState( private suspend fun RememberStateFlowScope.produceLoginState(
args: AddRoute.Args, args: AddRoute.Args,
ownershipFlow: Flow<AddState.Ownership>, profileFlow: Flow<DProfile?>,
copyText: CopyText, copyText: CopyText,
getTotpCode: GetTotpCode, getTotpCode: GetTotpCode,
getGravatarUrl: GetGravatarUrl, getGravatarUrl: GetGravatarUrl,
@ -2241,15 +2249,11 @@ private suspend fun RememberStateFlowScope.produceLoginState(
factory( factory(
id, id,
LocalStateItem( LocalStateItem(
flow = ownershipFlow flow = profileFlow
.map { .map { profile ->
it.ui.account val email = profile?.email
?.items ?: return@map persistentListOf<String>()
?.asSequence() persistentListOf(email)
?.filter { !it.stub }
?.map { it.title }
?.toPersistentList()
?: persistentListOf()
} }
.combine(sink) { autocompleteOptions, value -> .combine(sink) { autocompleteOptions, value ->
val model = TextFieldModel2( val model = TextFieldModel2(