Feature Description
To block a user's messages, add the user to the blocklist.
Blocklist
Blocking a user
Call the addToBlackList API (Details) to add a user to the blocklist, that is, block the user. By default, a blocked user does not know that he/she is "blocked". After the user sends a message, the error code indicating that he/she has been blocked will not be returned.
To have the "You have been blocked by the user" error message returned after a blocked user sends a message, you can log in to the Console > Chat > Configuration > Friends. Set Blocked User Message Sending Status. Choose Show as failed, when a blocked user sends a message, a failure message appears, and the SDK receives error code 20007. // Add a user to the blocklist
V2TimValueCallback<List<V2TimFriendOperationResult>> addBlackList = await friendshipManager.addToBlackList(userIDList: ['user1']);
Unblocking a user
Call deleteFromBlackList (Details) to remove a user from the blocklist, after which messages from the user can be received.
// Remove a user from the blocklist
V2TimValueCallback<List<V2TimFriendOperationResult>> deleteBlackList = await friendshipManager.deleteFromBlackList(userIDList: ['user1']);
Getting the blocklist
Call getBlackList (Details) to view how many users have been blocked and manage them. // Get the blocklist
V2TimValueCallback<List<V2TimFriendInfo>> blacklist = await friendshipManager.getBlackList();