Use MutableSharedFlow for errors in NewMessage

This commit is contained in:
Andrew 2024-06-18 12:20:05 +09:30
parent 4e43f6077d
commit 51b0510edc

View File

@ -34,10 +34,10 @@ internal class NewMessageViewModel @Inject constructor(
val state = _state.asStateFlow() val state = _state.asStateFlow()
private val _success = MutableSharedFlow<Success>() private val _success = MutableSharedFlow<Success>()
val success: Flow<Success> get() = _success.asSharedFlow() val success get() = _success.asSharedFlow()
private val _qrErrors = Channel<String>() private val _qrErrors = MutableSharedFlow<String>()
val qrErrors: Flow<String> = _qrErrors.receiveAsFlow() val qrErrors = _qrErrors.asSharedFlow()
private var loadOnsJob: Job? = null private var loadOnsJob: Job? = null
@ -62,7 +62,7 @@ internal class NewMessageViewModel @Inject constructor(
if (PublicKeyValidation.isValid(value, isPrefixRequired = false) && PublicKeyValidation.hasValidPrefix(value)) { if (PublicKeyValidation.isValid(value, isPrefixRequired = false) && PublicKeyValidation.hasValidPrefix(value)) {
onPublicKey(value) onPublicKey(value)
} else { } else {
_qrErrors.trySend(application.getString(R.string.this_qr_code_does_not_contain_an_account_id)) _qrErrors.tryEmit(application.getString(R.string.this_qr_code_does_not_contain_an_account_id))
} }
} }