# Block User

## Overview

The user block feature allows users to control their 1-on-1 interactions within the chat application by blocking other users. When a user is blocked, several changes occur to the blocked user's experience and the blocker’s interactions within the application.

- **Direct Communication Termination**

- When a user blocks another user, **communication in all 1-on-1 channels are hidden** for the blocking user.

- **Adding to Channels**

- If a blocked user tries to add the blocking user to a channel as a member, the action is ignored. The channel will not include the blocking user but will have the remaining members.

- **Push Notifications**

- The blocking user will not receive push notifications from blocked users for 1-on-1 channels.

- **Channel Events**

- The blocking user will not receive any events from blocked users in 1-on-1 channels (e.g., message.new).

- **Group Channels**

- Group channels are unaffected by the block. Both the blocking and blocked users can participate, receive push notifications, and events in group channels.

- **Query Channels**

- When hidden channels are requested, 1-on-1 channels with blocked users will be returned with a `blocked:true` flag and all the messages.

- **Active Chats and Unread Counts**

- Blocked users will not appear in the blocking user's list of active chats. Messages from blocked users will not contribute to unread counts.

- **Unblocking Users**

- After unblocking, all previous messages in 1-on-1 channels become visible again, including those sent during the block period.

- **Hidden Channels**

- Channels with only the blocked and blocking users are marked as hidden for the blocking user by default.

- If a blocked user sends a message in a hidden channel, the channel remains hidden for the blocking user.

- **Group Channel Messages**

- Messages from blocked users will still appear when retrieving messages from a group channel.

- **WebSocket Connection**

- When connecting to the WebSocket, the blocking user receives a list of users they have blocked (user.blocked_users). This is only available for the blocking user's own account.

- **Message Actions**

- Actions such as sending, updating, reacting to, and deleting messages will still work in blocked channels. However, since the channels are hidden, these actions will not be visible to the blocking user.

## Features

1. **Block User** : Users can block others in 1-on-1 chats, preventing further direct communication.

2. **Get Blocked Users** : Users can view a list of individuals they have blocked.

3. **Unblock User** : Users can unblock previously blocked users, allowing direct communication to resume.

### Setup example

Any user is allowed to block another user. BlockedUsers are stored at the user level and returned with the rest of the user information when connectUser is called. A user will be blocked until the user is unblocked.

### Block User

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
const blockingUser = "user1";
const blockedUser = "user2";
await ctx.createUsers([blockingUser, blockedUser]);
const client = await ctx.userClient(blockingUser);
await client.blockUser(blockedUser);
```

</codetabs-item>

<codetabs-item value="kotlin" label="Kotlin">

```kotlin
client.blockUser("user-to-block-id").enqueue { /* ... */ }
```

</codetabs-item>

<codetabs-item value="swift" label="Swift">

```swift
chatClient.userController(userId: userToBlock.id).block { error in ... }
```

</codetabs-item>

</codetabs>

### Unblock user

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
await client.unBlockUser(blockedUser);
```

</codetabs-item>

<codetabs-item value="kotlin" label="Kotlin">

```kotlin
client.unblockUser("user-to-unblock-id").enqueue { /* ... */ }
```

</codetabs-item>

<codetabs-item value="swift" label="Swift">

```swift
chatClient.userController(userId: userToUnblock.id).unblock { error in ... }
```

</codetabs-item>

</codetabs>

### List of Blocked Users

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
const resp = await client.getBlockedUsers();
```

</codetabs-item>

<codetabs-item value="kotlin" label="Kotlin">

```kotlin
client.queryBlockedUsers().enqueue { result ->
    if (result is Result.Success) {
        val blockedUsers: List<UserBlock> = result.value
    } else {
        // Handle Result.Failure
    }
}
```

</codetabs-item>

<codetabs-item value="swift" label="Swift">

```swift
chatClient.currentUserController().loadBlockedUsers { result in
  switch result {
  case .success(let blockedUsers):
    // Handle success
  case .failure(let error):
    // Handle error
  }
}
```

</codetabs-item>

</codetabs>

## **Server Side**

### Block User

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
const blockingUser = "user1";
const blockedUser = "user2";
await ctx.createUsers([blockingUser, blockedUser]);
const serverClient = await ctx.serverClient();

await serverClient.blockUser(blockedUser, blockingUser);
const resp = await serverClient.getBlockedUsers(blockingUser);
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
resp, err := client.BlockUser(ctx, blockedUserID, blockingUserID)
```

</codetabs-item>

<codetabs-item value="csharp" label="C#">

```csharp
await userClient.BlockUserAsync(user2.Id, user1.Id);
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
BlockUser.BlockUserResponse blockResponse = BlockUser.blockUser()
  .blockedUserID(blockedUserId)
  .userID(blockingUserId)
  .request();
```

</codetabs-item>

</codetabs>

### Unblock user

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
await serverClient.unBlockUser(blockedUser, blockingUser);
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
resp, err := client.UnblockUser(ctx, blockedUserID, blockingUserID)
```

</codetabs-item>

<codetabs-item value="csharp" label="C#">

```csharp
await userClient.UnblockUserAsync(user2.Id, user1.Id);
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
BlockUser.UnblockUserResponse unblockResponse = BlockUser.unblockUser()
  .blockedUserID(blockedUserId)
  .userID(blockingUserId)
  .request();
```

</codetabs-item>

</codetabs>

### Get List of Blocked Users

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
const resp = await client.getBlockedUsers(blockingUser);
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
getRes, err := client.GetBlockedUser(ctx, blockingUserID)
for _, blockedUser := getRes.BlockedUsers{
	fmt.Println(blockedUser.BlockedUserID)
}
```

</codetabs-item>

<codetabs-item value="csharp" label="C#">

```csharp
await userClient.GetBlockedUsersAsync(user1.Id);
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
BlockUser.GetBlockedUsersResponse getBlockedUsersResponse = BlockUser.getBlockedUsers(blockingUserId).request();
```

</codetabs-item>

</codetabs>

---

This page was last updated at 2025-08-15T14:15:10.039Z.

For the most recent version of this documentation, visit [https://getstream.io/chat/docs/react/block_user/](https://getstream.io/chat/docs/react/block_user/).