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. This feature works only for distinct channels.

  • Direct Communication Termination

  • When a user blocks another user, all direct 1-on-1 communication in distinct 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

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

Unblock user

await client.unBlockUser(blockedUser);

List of Blocked Users

const resp = await client.getBlockedUsers();

Server Side

Block User

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);

Unblock user

await serverClient.unBlockUser(blockedUser, blockingUser);

Get List of Blocked Users

const resp = await client.getBlockedUsers(blockingUser);
© Getstream.io, Inc. All Rights Reserved.