Skip to main content

Blocklist

The blocklist feature lets you block another user by their userId. Once blocked, you will no longer receive any direct messages from that user. Keep the following in mind:

  • Blocking is a one-way operation. For example, if you block user A, user A cannot send you direct messages and receives error code 405. However, you can still send messages to user A, and user A can receive them normally.
  • Each user's blocklist has a maximum capacity that depends on your pricing plan.
  • If you send a direct message through the server-side API, the blocklist does not apply by default. To enforce blocklist restrictions for server-side API messages, set the verifyBlacklist parameter to 1.

Add to blocklist

Use NCEngine.userModule.addToBlocklist() to add a user to your blocklist. After adding, you can still send messages to the blocked user, but the blocked user cannot send you direct messages.

kotlin
NCEngine.userModule.addToBlocklist("userId") { error ->
if (error == null) {
// Successfully blocked
} else {
// Failed
}
}

Remove from blocklist

Use NCEngine.userModule.removeFromBlocklist() to remove a user from your blocklist.

kotlin
NCEngine.userModule.removeFromBlocklist("userId") { error ->
if (error == null) {
// Successfully unblocked
} else {
// Failed
}
}

Check blocklist status

Use NCEngine.userModule.checkBlocked() to check whether a user is on your blocklist.

kotlin
NCEngine.userModule.checkBlocked("userId") { isBlocked, error ->
if (error == null) {
if (isBlocked == true) {
println("User is blocked")
} else {
println("User is not blocked")
}
}
}

Get blocklist

Use NCEngine.userModule.getBlocklist() to retrieve your blocklist.

kotlin
NCEngine.userModule.getBlocklist { userIds, error ->
if (error == null && userIds != null) {
userIds.forEach { userId ->
println("Blocked user: $userId")
}
}
}