Skip to content

[AND-188] Fix user blocking operations.#5532

Merged
JcMinarro merged 2 commits intodevelopfrom
bug/fix-user-blocking-operations
Dec 20, 2024
Merged

[AND-188] Fix user blocking operations.#5532
JcMinarro merged 2 commits intodevelopfrom
bug/fix-user-blocking-operations

Conversation

@VelikovPetar
Copy link
Copy Markdown
Contributor

🎯 Goal

Linear: https://linear.app/stream/issue/AND-188/user-blocking-feature-issue-with-android-sdk-version-680
The queryBlockedUsers operation had its API endpoint wrongly defined. This PR fixes that issue, and additionally ensures that the blockUser and unblockUser operation responses are correctly parsed.

  • 🚨 Breaking change: The ChatClient.unblockUser(userId: String) operation returns Call<Unit> instead of Call<UserBlock>. this is changed because the API no longer gives us return information about the unblocked user as it can be deducted from the argument that was initially passed to the unblockUser method.

🛠 Implementation details

  • Add the missing GET path to the UserApi.queryBlockedUsers
  • Adjust the BlockUserResponse and UnblockUserResponse models to ensure they are properly parsed

🎨 UI Changes

NA

🧪 Testing

  1. Apply the provided patch
  2. Uncomment the relevant operation in the ChannelsActivity
  3. Open the Compose Sample app
  4. Check the ChannelActivity logs to ensure the blockUser/unblockUser/queryBlockedUsers operations are successful.
Patch
Index: stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/ChannelsActivity.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/ChannelsActivity.kt b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/ChannelsActivity.kt
--- a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/ChannelsActivity.kt	(revision f23d2e75daea39b61fc7dab68331072906f1585e)
+++ b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/ChannelsActivity.kt	(date 1734692303819)
@@ -19,6 +19,7 @@
 import android.content.Context
 import android.content.Intent
 import android.os.Bundle
+import android.util.Log
 import androidx.activity.compose.setContent
 import androidx.activity.viewModels
 import androidx.compose.foundation.background
@@ -35,6 +36,7 @@
 import androidx.compose.material.Scaffold
 import androidx.compose.material.Text
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
 import androidx.compose.runtime.collectAsState
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
@@ -74,6 +76,7 @@
 import io.getstream.chat.android.models.User
 import io.getstream.chat.android.models.querysort.QuerySortByField
 import io.getstream.chat.android.state.extensions.globalState
+import io.getstream.result.call.enqueue
 import kotlinx.coroutines.launch
 
 class ChannelsActivity : BaseConnectedActivity() {
@@ -151,6 +154,32 @@
                 listViewModel.refresh()
             },
         )
+        LaunchedEffect(Unit) {
+            // ChatClient.instance().unblockUser("dmitrii").enqueue(
+            //     onSuccess = { response ->
+            //         Log.d("ChannelsActivity", "Unblocked user: dmitrii")
+            //     },
+            //     onError = { error ->
+            //         Log.d("ChannelsActivity", "Error: $error")
+            //     },
+            // )
+            // ChatClient.instance().blockUser("dmitrii").enqueue(
+            //     onSuccess = { response ->
+            //         Log.d("ChannelsActivity", "Blocked user: $response")
+            //     },
+            //     onError = { error ->
+            //         Log.d("ChannelsActivity", "Error: $error")
+            //     },
+            // )
+            // ChatClient.instance().queryBlockedUsers().enqueue(
+            //     onSuccess = { blockedUsers ->
+            //         Log.d("ChannelsActivity", "Blocked users: $blockedUsers")
+            //     },
+            //     onError = { error ->
+            //         Log.d("ChannelsActivity", "Error: $error")
+            //     },
+            // )
+        }
 
 //                MyCustomUiSimplified()
 //                MyCustomUi()

@VelikovPetar VelikovPetar marked this pull request as ready for review December 20, 2024 11:28
@VelikovPetar VelikovPetar requested a review from a team as a code owner December 20, 2024 11:28
@JcMinarro JcMinarro enabled auto-merge (squash) December 20, 2024 14:31
@JcMinarro JcMinarro merged commit e0611ca into develop Dec 20, 2024
@JcMinarro JcMinarro deleted the bug/fix-user-blocking-operations branch December 20, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants