Skip to content

Commit

Permalink
[AND-190] Add "Unblock user" as message options in the UI SDKs.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetarVelikov committed Dec 23, 2024
1 parent e0611ca commit a0222b4
Show file tree
Hide file tree
Showing 41 changed files with 1,022 additions and 31 deletions.
20 changes: 19 additions & 1 deletion stream-chat-android-client/api/stream-chat-android-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -2766,9 +2766,10 @@ public abstract interface class io/getstream/chat/android/client/persistance/rep
public abstract fun createRepositoryFactory (Lio/getstream/chat/android/models/User;)Lio/getstream/chat/android/client/persistance/repository/factory/RepositoryFactory;
}

public abstract interface class io/getstream/chat/android/client/plugin/Plugin : io/getstream/chat/android/client/plugin/DependencyResolver, io/getstream/chat/android/client/plugin/listeners/ChannelMarkReadListener, io/getstream/chat/android/client/plugin/listeners/CreateChannelListener, io/getstream/chat/android/client/plugin/listeners/DeleteChannelListener, io/getstream/chat/android/client/plugin/listeners/DeleteMessageListener, io/getstream/chat/android/client/plugin/listeners/DeleteReactionListener, io/getstream/chat/android/client/plugin/listeners/EditMessageListener, io/getstream/chat/android/client/plugin/listeners/FetchCurrentUserListener, io/getstream/chat/android/client/plugin/listeners/GetMessageListener, io/getstream/chat/android/client/plugin/listeners/HideChannelListener, io/getstream/chat/android/client/plugin/listeners/MarkAllReadListener, io/getstream/chat/android/client/plugin/listeners/QueryChannelListener, io/getstream/chat/android/client/plugin/listeners/QueryChannelsListener, io/getstream/chat/android/client/plugin/listeners/QueryMembersListener, io/getstream/chat/android/client/plugin/listeners/QueryThreadsListener, io/getstream/chat/android/client/plugin/listeners/SendAttachmentListener, io/getstream/chat/android/client/plugin/listeners/SendGiphyListener, io/getstream/chat/android/client/plugin/listeners/SendMessageListener, io/getstream/chat/android/client/plugin/listeners/SendReactionListener, io/getstream/chat/android/client/plugin/listeners/ShuffleGiphyListener, io/getstream/chat/android/client/plugin/listeners/ThreadQueryListener, io/getstream/chat/android/client/plugin/listeners/TypingEventListener {
public abstract interface class io/getstream/chat/android/client/plugin/Plugin : io/getstream/chat/android/client/plugin/DependencyResolver, io/getstream/chat/android/client/plugin/listeners/BlockUserListener, io/getstream/chat/android/client/plugin/listeners/ChannelMarkReadListener, io/getstream/chat/android/client/plugin/listeners/CreateChannelListener, io/getstream/chat/android/client/plugin/listeners/DeleteChannelListener, io/getstream/chat/android/client/plugin/listeners/DeleteMessageListener, io/getstream/chat/android/client/plugin/listeners/DeleteReactionListener, io/getstream/chat/android/client/plugin/listeners/EditMessageListener, io/getstream/chat/android/client/plugin/listeners/FetchCurrentUserListener, io/getstream/chat/android/client/plugin/listeners/GetMessageListener, io/getstream/chat/android/client/plugin/listeners/HideChannelListener, io/getstream/chat/android/client/plugin/listeners/MarkAllReadListener, io/getstream/chat/android/client/plugin/listeners/QueryBlockedUsersListener, io/getstream/chat/android/client/plugin/listeners/QueryChannelListener, io/getstream/chat/android/client/plugin/listeners/QueryChannelsListener, io/getstream/chat/android/client/plugin/listeners/QueryMembersListener, io/getstream/chat/android/client/plugin/listeners/QueryThreadsListener, io/getstream/chat/android/client/plugin/listeners/SendAttachmentListener, io/getstream/chat/android/client/plugin/listeners/SendGiphyListener, io/getstream/chat/android/client/plugin/listeners/SendMessageListener, io/getstream/chat/android/client/plugin/listeners/SendReactionListener, io/getstream/chat/android/client/plugin/listeners/ShuffleGiphyListener, io/getstream/chat/android/client/plugin/listeners/ThreadQueryListener, io/getstream/chat/android/client/plugin/listeners/TypingEventListener, io/getstream/chat/android/client/plugin/listeners/UnblockUserListener {
public abstract fun getErrorHandler ()Lio/getstream/chat/android/client/errorhandler/ErrorHandler;
public abstract fun onAttachmentSendRequest (Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onBlockUserResult (Lio/getstream/result/Result;)V
public abstract fun onChannelMarkReadPrecondition (Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onCreateChannelPrecondition (Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/List;)Lio/getstream/result/Result;
public abstract fun onCreateChannelRequest (Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/query/CreateChannelParams;Lio/getstream/chat/android/models/User;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down Expand Up @@ -2799,6 +2800,7 @@ public abstract interface class io/getstream/chat/android/client/plugin/Plugin :
public abstract fun onMessageEditRequest (Lio/getstream/chat/android/models/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onMessageEditResult (Lio/getstream/chat/android/models/Message;Lio/getstream/result/Result;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onMessageSendResult (Lio/getstream/result/Result;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onQueryBlockedUsersResult (Lio/getstream/result/Result;)V
public abstract fun onQueryChannelPrecondition (Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onQueryChannelRequest (Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onQueryChannelResult (Lio/getstream/result/Result;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand All @@ -2816,13 +2818,15 @@ public abstract interface class io/getstream/chat/android/client/plugin/Plugin :
public abstract fun onTypingEventPrecondition (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Date;)Lio/getstream/result/Result;
public abstract fun onTypingEventRequest (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Date;)V
public abstract fun onTypingEventResult (Lio/getstream/result/Result;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Date;)V
public abstract fun onUnblockUserResult (Ljava/lang/String;Lio/getstream/result/Result;)V
public abstract fun onUserDisconnected ()V
public abstract fun onUserSet (Lio/getstream/chat/android/models/User;)V
}

public final class io/getstream/chat/android/client/plugin/Plugin$DefaultImpls {
public static fun getErrorHandler (Lio/getstream/chat/android/client/plugin/Plugin;)Lio/getstream/chat/android/client/errorhandler/ErrorHandler;
public static fun onAttachmentSendRequest (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onBlockUserResult (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/result/Result;)V
public static fun onChannelMarkReadPrecondition (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onCreateChannelPrecondition (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/chat/android/models/User;Ljava/lang/String;Ljava/util/List;)Lio/getstream/result/Result;
public static fun onCreateChannelRequest (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/query/CreateChannelParams;Lio/getstream/chat/android/models/User;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down Expand Up @@ -2854,6 +2858,7 @@ public final class io/getstream/chat/android/client/plugin/Plugin$DefaultImpls {
public static fun onMessageEditRequest (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/chat/android/models/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onMessageEditResult (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/chat/android/models/Message;Lio/getstream/result/Result;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onMessageSendResult (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/result/Result;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/models/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onQueryBlockedUsersResult (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/result/Result;)V
public static fun onQueryChannelPrecondition (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onQueryChannelRequest (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun onQueryChannelResult (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/result/Result;Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand All @@ -2871,12 +2876,17 @@ public final class io/getstream/chat/android/client/plugin/Plugin$DefaultImpls {
public static fun onTypingEventPrecondition (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Date;)Lio/getstream/result/Result;
public static fun onTypingEventRequest (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Date;)V
public static fun onTypingEventResult (Lio/getstream/chat/android/client/plugin/Plugin;Lio/getstream/result/Result;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Date;)V
public static fun onUnblockUserResult (Lio/getstream/chat/android/client/plugin/Plugin;Ljava/lang/String;Lio/getstream/result/Result;)V
}

public abstract interface class io/getstream/chat/android/client/plugin/factory/PluginFactory : io/getstream/chat/android/client/plugin/DependencyResolver {
public abstract fun get (Lio/getstream/chat/android/models/User;)Lio/getstream/chat/android/client/plugin/Plugin;
}

public abstract interface class io/getstream/chat/android/client/plugin/listeners/BlockUserListener {
public abstract fun onBlockUserResult (Lio/getstream/result/Result;)V
}

public abstract interface class io/getstream/chat/android/client/plugin/listeners/ChannelMarkReadListener {
public abstract fun onChannelMarkReadPrecondition (Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down Expand Up @@ -2929,6 +2939,10 @@ public abstract interface class io/getstream/chat/android/client/plugin/listener
public abstract fun onMarkAllReadRequest (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract interface class io/getstream/chat/android/client/plugin/listeners/QueryBlockedUsersListener {
public abstract fun onQueryBlockedUsersResult (Lio/getstream/result/Result;)V
}

public abstract interface class io/getstream/chat/android/client/plugin/listeners/QueryChannelListener {
public abstract fun onQueryChannelPrecondition (Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun onQueryChannelRequest (Ljava/lang/String;Ljava/lang/String;Lio/getstream/chat/android/client/api/models/QueryChannelRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down Expand Up @@ -2993,6 +3007,10 @@ public abstract interface class io/getstream/chat/android/client/plugin/listener
public abstract fun onTypingEventResult (Lio/getstream/result/Result;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Date;)V
}

public abstract interface class io/getstream/chat/android/client/plugin/listeners/UnblockUserListener {
public abstract fun onUnblockUserResult (Ljava/lang/String;Lio/getstream/result/Result;)V
}

public abstract interface class io/getstream/chat/android/client/plugins/requests/ApiRequestsAnalyser {
public static final field Companion Lio/getstream/chat/android/client/plugins/requests/ApiRequestsAnalyser$Companion;
public abstract fun clearAll ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,18 @@ internal constructor(
*/
@CheckResult
public fun blockUser(userId: String): Call<UserBlock> {
return api.blockUser(userId)
return api.blockUser(userId).doOnResult(userScope) { result ->
plugins.forEach { it.onBlockUserResult(result) }
if (result is Result.Success) {
// Note: Update local user state manually as we don't get WS events for blocked users updates
val currentUser = mutableClientState.user.value ?: return@doOnResult
if (!currentUser.blockedUserIds.contains(userId)) {
val updatedCurrentUser = currentUser.copy(blockedUserIds = currentUser.blockedUserIds + userId)
userStateService.onUserUpdated(updatedCurrentUser)
mutableClientState.setUser(updatedCurrentUser)
}
}
}
}

/**
Expand All @@ -2671,15 +2682,28 @@ internal constructor(
*/
@CheckResult
public fun unblockUser(userId: String): Call<Unit> {
return api.unblockUser(userId)
return api.unblockUser(userId).doOnResult(userScope) { result ->
plugins.forEach { it.onUnblockUserResult(userId, result) }
if (result is Result.Success) {
// Note: Update local user state manually as we don't get WS events for blocked users updates
val currentUser = mutableClientState.user.value ?: return@doOnResult
if (currentUser.blockedUserIds.contains(userId)) {
val updatedCurrentUser = currentUser.copy(blockedUserIds = currentUser.blockedUserIds - userId)
userStateService.onUserUpdated(updatedCurrentUser)
mutableClientState.setUser(updatedCurrentUser)
}
}
}
}

/**
* Return na list of blocked users.
*/
@CheckResult
public fun queryBlockedUsers(): Call<List<UserBlock>> {
return api.queryBlockedUsers()
return api.queryBlockedUsers().doOnResult(userScope) { result ->
plugins.forEach { it.onQueryBlockedUsersResult(result) }
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal fun DownstreamUserDto.toDomain(currentUserId: UserId?): User =
mutes = mutes.orEmpty().map { it.toDomain(currentUserId) },
teams = teams,
channelMutes = channel_mutes.orEmpty().map { it.toDomain(currentUserId) },
blockedUserIds = blocked_user_ids.orEmpty(),
extraData = extraData.toMutableMap(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ internal data class DownstreamUserDto(
val mutes: List<DownstreamMuteDto>?,
val teams: List<String> = emptyList(),
val channel_mutes: List<DownstreamChannelMuteDto>?,
val blocked_user_ids: List<String>?,

val extraData: Map<String, Any>,
) : ExtraDataDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.getstream.chat.android.client.api.models.QueryChannelsRequest
import io.getstream.chat.android.client.api.models.QueryThreadsRequest
import io.getstream.chat.android.client.errorhandler.ErrorHandler
import io.getstream.chat.android.client.events.ChatEvent
import io.getstream.chat.android.client.plugin.listeners.BlockUserListener
import io.getstream.chat.android.client.plugin.listeners.ChannelMarkReadListener
import io.getstream.chat.android.client.plugin.listeners.CreateChannelListener
import io.getstream.chat.android.client.plugin.listeners.DeleteChannelListener
Expand All @@ -32,6 +33,7 @@ import io.getstream.chat.android.client.plugin.listeners.FetchCurrentUserListene
import io.getstream.chat.android.client.plugin.listeners.GetMessageListener
import io.getstream.chat.android.client.plugin.listeners.HideChannelListener
import io.getstream.chat.android.client.plugin.listeners.MarkAllReadListener
import io.getstream.chat.android.client.plugin.listeners.QueryBlockedUsersListener
import io.getstream.chat.android.client.plugin.listeners.QueryChannelListener
import io.getstream.chat.android.client.plugin.listeners.QueryChannelsListener
import io.getstream.chat.android.client.plugin.listeners.QueryMembersListener
Expand All @@ -43,6 +45,7 @@ import io.getstream.chat.android.client.plugin.listeners.SendReactionListener
import io.getstream.chat.android.client.plugin.listeners.ShuffleGiphyListener
import io.getstream.chat.android.client.plugin.listeners.ThreadQueryListener
import io.getstream.chat.android.client.plugin.listeners.TypingEventListener
import io.getstream.chat.android.client.plugin.listeners.UnblockUserListener
import io.getstream.chat.android.client.query.CreateChannelParams
import io.getstream.chat.android.models.Channel
import io.getstream.chat.android.models.FilterObject
Expand All @@ -51,6 +54,7 @@ import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.QueryThreadsResult
import io.getstream.chat.android.models.Reaction
import io.getstream.chat.android.models.User
import io.getstream.chat.android.models.UserBlock
import io.getstream.chat.android.models.querysort.QuerySorter
import io.getstream.result.Result
import java.util.Date
Expand Down Expand Up @@ -81,7 +85,10 @@ public interface Plugin :
DeleteChannelListener,
GetMessageListener,
FetchCurrentUserListener,
QueryThreadsListener {
QueryThreadsListener,
BlockUserListener,
UnblockUserListener,
QueryBlockedUsersListener {

public fun getErrorHandler(): ErrorHandler? = null

Expand Down Expand Up @@ -422,4 +429,16 @@ public interface Plugin :
override suspend fun onQueryThreadsResult(result: Result<QueryThreadsResult>, request: QueryThreadsRequest) {
/* No-Op */
}

override fun onBlockUserResult(result: Result<UserBlock>) {
/* No-Op */
}

override fun onUnblockUserResult(userId: String, result: Result<Unit>) {
/* No-Op */
}

override fun onQueryBlockedUsersResult(result: Result<List<UserBlock>>) {
/* No-Op */
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.chat.android.client.plugin.listeners

import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.models.UserBlock
import io.getstream.result.Result

/**
* Listener for [ChatClient.blockUser] requests.
*/
public interface BlockUserListener {

/**
* Runs side effect after the request was completed.
*
* @param result The [Result] containing the successfully retrieved [UserBlock] or the error.
*/
public fun onBlockUserResult(result: Result<UserBlock>)
}
Loading

0 comments on commit a0222b4

Please sign in to comment.