From 468fae012d1d0e7726e03cb628a6a1b476da0aa5 Mon Sep 17 00:00:00 2001 From: skydoves Date: Fri, 16 Dec 2022 14:36:45 +0900 Subject: [PATCH 1/2] Reset the ui state toast --- .../feature/chat/channels/ChatGPTChannelsViewModel.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/channels/ChatGPTChannelsViewModel.kt b/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/channels/ChatGPTChannelsViewModel.kt index 8ddfd849..77aadd54 100644 --- a/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/channels/ChatGPTChannelsViewModel.kt +++ b/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/channels/ChatGPTChannelsViewModel.kt @@ -21,8 +21,9 @@ import androidx.lifecycle.viewModelScope import com.skydoves.chatgpt.core.data.repository.GPTChannelRepository import dagger.hilt.android.lifecycle.HiltViewModel import io.getstream.chat.android.client.utils.onError -import io.getstream.chat.android.client.utils.onSuccess +import io.getstream.chat.android.client.utils.onSuccessSuspend import javax.inject.Inject +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch @@ -54,8 +55,10 @@ class ChatGPTChannelsViewModel @Inject constructor( viewModelScope.launch { channelsMutableUiState.value = GPTChannelUiState.Loading val result = gptChannelRepository.createRandomChannel() - result.onSuccess { + result.onSuccessSuspend { channelsMutableUiState.value = GPTChannelUiState.Success(it.id) + delay(100L) + channelsMutableUiState.value = GPTChannelUiState.Nothing }.onError { channelsMutableUiState.value = GPTChannelUiState.Error } From 01f060c8b8a29a7c8624ca31369266a979e56042 Mon Sep 17 00:00:00 2001 From: skydoves Date: Fri, 16 Dec 2022 14:42:21 +0900 Subject: [PATCH 2/2] Update the error message --- .../skydoves/chatgpt/feature/chat/messages/ChatGPTMessages.kt | 2 +- feature-chat/src/main/res/values/strings.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/messages/ChatGPTMessages.kt b/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/messages/ChatGPTMessages.kt index 52b794cf..8ce56742 100644 --- a/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/messages/ChatGPTMessages.kt +++ b/feature-chat/src/main/kotlin/com/skydoves/chatgpt/feature/chat/messages/ChatGPTMessages.kt @@ -503,7 +503,7 @@ private fun HandleToastMessages( LaunchedEffect(key1 = error) { if (error.isNotEmpty()) { - viewModel.sendStreamChatMessage(error) + viewModel.sendStreamChatMessage("$error: ${context.getString(R.string.toast_hello)}") } } } diff --git a/feature-chat/src/main/res/values/strings.xml b/feature-chat/src/main/res/values/strings.xml index ecd88a9e..89e1f511 100644 --- a/feature-chat/src/main/res/values/strings.xml +++ b/feature-chat/src/main/res/values/strings.xml @@ -18,6 +18,6 @@ Stream A random ChatGPT channel is created! Hi, I\'m OpenAI\'s ChatGPT with Stream SDK. Ask me anything! - Something went wrong + Something went wrong. Please re-install this app. Something went wrong. Please check out your session and CF_CLEARANCE is valid.