Skip to content

Commit e0611ca

Browse files
VelikovPetarPetarVelikov
and
PetarVelikov
authored
[AND-188] Fix user blocking operations. (#5532)
* [AND-188] Fix user blocking operations. * [AND-188] Update CHANGELOG.md. --------- Co-authored-by: PetarVelikov <[email protected]>
1 parent edc8543 commit e0611ca

File tree

9 files changed

+30
-16
lines changed

9 files changed

+30
-16
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212

1313
## stream-chat-android-client
1414
### 🐞 Fixed
15+
- Fix `ChatClient::queryBlockedMembers` not working. [#5532](https://github.com/GetStream/stream-chat-android/pull/5532)
16+
- Fix `ChatClient::blockUser` and `ChatClient::unblockUser` response parsing. [#5532](https://github.com/GetStream/stream-chat-android/pull/5532)
1517

1618
### ⬆️ Improved
1719

1820
### ✅ Added
1921

2022
### ⚠️ Changed
23+
- 🚨 Breaking change: Change `ChatClient::unblockUser` return type from `Call<BlockUser>` to `Call<Unit>` as we no longer get information about the unblocked user. [#5532](https://github.com/GetStream/stream-chat-android/pull/5532)
2124

2225
### ❌ Removed
2326

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,7 @@ internal constructor(
26702670
* @param userId the user ID of the user that will be unblocked.
26712671
*/
26722672
@CheckResult
2673-
public fun unblockUser(userId: String): Call<UserBlock> {
2673+
public fun unblockUser(userId: String): Call<Unit> {
26742674
return api.unblockUser(userId)
26752675
}
26762676

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api/ChatApi.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ internal interface ChatApi {
223223
fun blockUser(userId: String): Call<UserBlock>
224224

225225
@CheckResult
226-
fun unblockUser(userId: String): Call<UserBlock>
226+
fun unblockUser(userId: String): Call<Unit>
227227

228228
@CheckResult
229229
fun queryBlockedUsers(): Call<List<UserBlock>>

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt

+3-7
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ constructor(
881881
return userApi.blockUser(
882882
body = BlockUserRequest(userId),
883883
).map { response ->
884-
response.block.toDomain()
884+
response.toDomain()
885885
}
886886
}
887887

@@ -891,12 +891,8 @@ constructor(
891891
}
892892
}
893893

894-
override fun unblockUser(userId: String): Call<UserBlock> {
895-
return userApi.unblockUser(
896-
body = UnblockUserRequest(userId),
897-
).map {
898-
it.block.toDomain()
899-
}
894+
override fun unblockUser(userId: String): Call<Unit> {
895+
return userApi.unblockUser(body = UnblockUserRequest(userId)).toUnitCall()
900896
}
901897

902898
override fun partialUpdateUser(id: String, set: Map<String, Any>, unset: List<String>): Call<User> {

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/UserApi.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal interface UserApi {
5151
@POST("/users/unblock")
5252
fun unblockUser(@Body body: UnblockUserRequest): RetrofitCall<UnblockUserResponse>
5353

54-
@GET
54+
@GET("/users/block")
5555
fun queryBlockedUsers(): RetrofitCall<QueryBlockedUsersResponse>
5656

5757
@PATCH("/users")

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/UserMapping.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import io.getstream.chat.android.client.api2.model.dto.DeviceDto
2020
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserBlockDto
2121
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserDto
2222
import io.getstream.chat.android.client.api2.model.dto.UpstreamUserDto
23+
import io.getstream.chat.android.client.api2.model.response.BlockUserResponse
2324
import io.getstream.chat.android.models.Device
2425
import io.getstream.chat.android.models.User
2526
import io.getstream.chat.android.models.UserBlock
@@ -65,9 +66,15 @@ internal fun DownstreamUserDto.toDomain(currentUserId: UserId?): User =
6566
)
6667

6768
internal fun DownstreamUserBlockDto.toDomain(): UserBlock = UserBlock(
68-
blockedBy = blocked_by_user_id,
69+
blockedBy = user_id,
6970
userId = blocked_user_id,
7071
blockedAt = created_at,
7172
)
7273

7374
internal fun List<DownstreamUserBlockDto>.toDomain(): List<UserBlock> = map { it.toDomain() }
75+
76+
internal fun BlockUserResponse.toDomain(): UserBlock = UserBlock(
77+
blockedBy = blocked_by_user_id,
78+
userId = blocked_user_id,
79+
blockedAt = created_at,
80+
)

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/UserDtos.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ internal data class PartialUpdateUserDto(
8888

8989
@JsonClass(generateAdapter = true)
9090
internal data class DownstreamUserBlockDto(
91-
val blocked_by_user_id: String,
91+
val user_id: String,
9292
val blocked_user_id: String,
9393
val created_at: Date,
9494
)

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/response/BlockUserResponse.kt

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717
package io.getstream.chat.android.client.api2.model.response
1818

1919
import com.squareup.moshi.JsonClass
20-
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserBlockDto
20+
import java.util.Date
2121

22+
/**
23+
* Model representing the response from blocking a user.
24+
*
25+
* @param blocked_by_user_id The ID of the user who blocked the other user.
26+
* @param blocked_user_id The ID of the user who was blocked.
27+
* @param created_at The date when the block was created.
28+
*/
2229
@JsonClass(generateAdapter = true)
2330
internal data class BlockUserResponse(
24-
val block: DownstreamUserBlockDto,
31+
val blocked_by_user_id: String,
32+
val blocked_user_id: String,
33+
val created_at: Date,
2534
)

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/response/UnblockUserResponse.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
package io.getstream.chat.android.client.api2.model.response
1818

1919
import com.squareup.moshi.JsonClass
20-
import io.getstream.chat.android.client.api2.model.dto.DownstreamUserBlockDto
2120

2221
@JsonClass(generateAdapter = true)
2322
internal data class UnblockUserResponse(
24-
val block: DownstreamUserBlockDto,
23+
val duration: String,
2524
)

0 commit comments

Comments
 (0)