Skip to content

Commit

Permalink
Merge pull request #175 from samoylenkodmitry/make_diving_in_project_…
Browse files Browse the repository at this point in the history
…more_intuitive

Make diving in project more intuitive
  • Loading branch information
skydoves authored Jun 28, 2023
2 parents 4ab59b5 + c4d710e commit bc27370
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import okhttp3.RequestBody.Companion.toRequestBody

internal class GPTMessageRepositoryImpl @Inject constructor(
@Dispatcher(ChatGPTDispatchers.IO) private val ioDispatcher: CoroutineDispatcher,
private val chatClient: ChatClient,
private val chatGptService: ChatGPTService
) : GPTMessageRepository {

Expand All @@ -57,7 +58,7 @@ internal class GPTMessageRepositoryImpl @Inject constructor(
}

override fun watchIsChannelMessageEmpty(cid: String): Flow<Boolean> = flow {
val result = ChatClient.instance().channel(cid).watch().await()
val result = chatClient.channel(cid).watch().await()
result.onSuccessSuspend { channel ->
val messages = channel.messages
emit(messages.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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.onSuccessSuspend
import io.getstream.log.streamLog
import javax.inject.Inject
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -44,7 +45,14 @@ class ChatGPTChannelsViewModel @Inject constructor(
init {
viewModelScope.launch {
gptChannelRepository.streamUserFlow().collect { user ->
user?.let { gptChannelRepository.joinTheCommonChannel(it) }
user?.let {
gptChannelRepository.joinTheCommonChannel(it)
} ?: run {
streamLog {
"User is null. Please check the app README.md and ensure " +
"**Disable Auth Checks** is ON in the Dashboard"
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import com.skydoves.chatgpt.core.preferences.Preferences
import com.skydoves.chatgpt.feature.chat.BuildConfig
import com.skydoves.chatgpt.feature.chat.di.ChatEntryPoint
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.call.Call
import io.getstream.chat.android.client.logger.ChatLogLevel
import io.getstream.chat.android.client.models.ConnectionData
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.utils.Result
import io.getstream.chat.android.offline.model.message.attachments.UploadAttachmentsNetworkType
import io.getstream.chat.android.offline.plugin.configuration.Config
import io.getstream.chat.android.offline.plugin.factory.StreamOfflinePluginFactory
Expand Down Expand Up @@ -71,7 +74,16 @@ class StreamChatInitializer : Initializer<Unit> {
)

val token = chatClient.devToken(user.id)
chatClient.connectUser(user, token).enqueue()
chatClient.connectUser(user, token).enqueue(object : Call.Callback<ConnectionData> {
override fun onResult(result: Result<ConnectionData>) {
if (result.isError) {
streamLog {
"Can't connect user. Please check the app README.md and ensure " +
"**Disable Auth Checks** is ON in the Dashboard"
}
}
}
})
}

override fun dependencies(): List<Class<out Initializer<*>>> =
Expand Down

0 comments on commit bc27370

Please sign in to comment.