Skip to content

Commit

Permalink
Check if result is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Dec 15, 2022
1 parent f8cbaa1 commit 5beda6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.models.Channel
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.utils.Result
import io.getstream.chat.android.client.utils.onSuccessSuspend
import java.util.Random
import java.util.UUID
import javax.inject.Inject
Expand All @@ -44,8 +45,8 @@ internal class GPTChannelRepositoryImpl @Inject constructor(
override suspend fun joinTheCommonChannel(user: User) {
val channelClient = chatClient.channel(commonChannelId)
val result = channelClient.watch().await()
if (result.isSuccess) {
val members = result.data().members
result.onSuccessSuspend { channel ->
val members = channel.members
val isExist = members.firstOrNull { it.user.id == user.id }
if (isExist == null) {
channelClient.addMembers(listOf(user.id)).await()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.skydoves.sandwich.ApiResponse
import com.skydoves.sandwich.mapSuccess
import com.squareup.moshi.Moshi
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.utils.onSuccessSuspend
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -57,8 +58,10 @@ internal class GPTMessageRepositoryImpl @Inject constructor(
}.flowOn(ioDispatcher)

override fun watchIsChannelMessageEmpty(cid: String): Flow<Boolean> = flow {
val channel = ChatClient.instance().channel(cid).watch().await()
val messages = channel.data().messages
emit(messages.isEmpty())
val result = ChatClient.instance().channel(cid).watch().await()
result.onSuccessSuspend { channel ->
val messages = channel.messages
emit(messages.isEmpty())
}
}.flowOn(ioDispatcher)
}

0 comments on commit 5beda6f

Please sign in to comment.