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
verifyBlacklistparameter to1.
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
- Java
kotlin
NCEngine.userModule.addToBlocklist("userId") { error ->
if (error == null) {
// Successfully blocked
} else {
// Failed
}
}
Java
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
- Java
kotlin
NCEngine.userModule.removeFromBlocklist("userId") { error ->
if (error == null) {
// Successfully unblocked
} else {
// Failed
}
}
Java
NCEngine.userModule.removeFromBlocklist("userId", error -> {
if (error == null) {
// Successfully unblocked
}
});
Check blocklist status
Use NCEngine.userModule.checkBlocked() to check whether a user is on your blocklist.
- Kotlin
- Java
kotlin
NCEngine.userModule.checkBlocked("userId") { isBlocked, error ->
if (error == null) {
if (isBlocked == true) {
println("User is blocked")
} else {
println("User is not blocked")
}
}
}
Java
NCEngine.userModule.checkBlocked("userId", (isBlocked, error) -> {
if (error == null) {
if (Boolean.TRUE.equals(isBlocked)) {
System.out.println("User is blocked");
} else {
System.out.println("User is not blocked");
}
}
});
Get blocklist
Use NCEngine.userModule.getBlocklist() to retrieve your blocklist.
- Kotlin
- Java
kotlin
NCEngine.userModule.getBlocklist { userIds, error ->
if (error == null && userIds != null) {
userIds.forEach { userId ->
println("Blocked user: $userId")
}
}
}
Java
NCEngine.userModule.getBlocklist((userIds, error) -> {
if (error == null && userIds != null) {
for (String userId : userIds) {
System.out.println("Blocked user: " + userId);
}
}
});