You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue with connectUser. I figured out that this line val result = client.connectUser(user, token).await() does not return anything and code do not execute after it. So i just see a progressbar and do not get Success or Failure state. Guys i realy need help i can not figure out a cause of a problem. Thanks in advance
Here is my code snippet of ViewModel
@HiltViewModel
class LoginViewModel @Inject constructor(
val client: ChatClient,
val firebaseRepository: FirebaseRepository
) : ViewModel() {
private val _authState = MutableSharedFlow<CreatingStates>()
var authState: SharedFlow<CreatingStates> = _authState
var phoneNumber = ""
//Other code ...
fun setUser(name:String, lastname:String){
viewModelScope.launch(Dispatchers.IO) {
if (isCorrectNameAndLastname(name, lastname)){
val user = User(
id = phoneNumber,
name = name + lastname,
image = userImageUri.value?.toString() ?: ""
)
val token = client.devToken(user.id)
Log.e("Checking Stream", "I am before await function")
val result = client.connectUser(user, token).await()
Log.e("Checking Stream", "After await function")
if (result.isFailure) {
Log.e("Checking Stream", result.errorOrNull().toString())
_loginEvent.emit(LogInStates.Error("An error occurred"))
return@launch
}
Log.e("Checking Stream", "Success log in to stream")
_loginEvent.emit(LogInStates.Success)
} else{
if (!correctName(name)) {
_loginEvent.emit(LogInStates.ErrorUserNameTooShort)
} else {_loginEvent.emit(LogInStates.ErrorLastNameTooShort)}
}
}
}
My UserDataFragment snippet
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
subscribeToEvents()
//Other code...
binding.fabNext.setOnClickListener {
val name = binding.etName.toString().trim()
val lastname = binding.etLastname.toString().trim()
connectingUserUiState()
viewModel.setUser(name, lastname)
}
}
private fun connectingUserUiState() {
binding.progressBar.visibility = View.VISIBLE
binding.fabNext.isEnabled = false
}
private fun notConnectionUiState() {
binding.progressBar.visibility = View.INVISIBLE
binding.fabNext.isEnabled = true
}
private fun subscribeToEvents() {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.loginEvent.collect {
withContext(Dispatchers.Main) {
when (it) {
is LogInStates.Success -> {
notConnectionUiState()
findNavController().navigate(R.id.action_userDataFragment_to_chatListFragment)
}
is LogInStates.Error -> {
notConnectionUiState()
Toast.makeText(requireContext(), it.message, Toast.LENGTH_LONG).show()
}
is LogInStates.ErrorUserNameTooShort -> {
notConnectionUiState()
binding.etName.error = "Name length should be greater then 2"
}
is LogInStates.ErrorLastNameTooShort -> {
notConnectionUiState()
binding.etLastname.error = "Last name should not be empty"
}
}
}
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have an issue with connectUser. I figured out that this line
val result = client.connectUser(user, token).await()
does not return anything and code do not execute after it. So i just see a progressbar and do not get Success or Failure state. Guys i realy need help i can not figure out a cause of a problem. Thanks in advanceHere is my code snippet of ViewModel
My UserDataFragment snippet
Beta Was this translation helpful? Give feedback.
All reactions