Learn how to create privacy lists and implement user-to-user blocks.
Privacy list API allows enabling or disabling communication with other users in a chat. You can create, modify, or delete privacy lists, define a default list.Visit Key Concepts page to learn the most important QuickBlox concepts.
Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
Configure QuickBlox SDK for your app. Check out Setup page for more details. 3. Create a user session to be able to use QuickBlox functionality. See Authentication page to learn how to do it.
Connect to the Chat server. See Connection page to learn how to do it.
The user can have multiple privacy lists, but only one can be active.
There is a rule you should follow to update a privacy list: if you want to update or set a new privacy list instead of the current one, you should decline the current default list first.
JavaScript
Copy
Ask AI
try { QB.chat.privacylist.setAsDefault(null, function(error) { if (!error) { var users = [{ user_id: 34, action: "allow" }]; var list = { name: "myList", items: users }; QB.chat.privacylist.update(list, function(error) { if (!error) { QB.chat.privacylist.setAsDefault("myList", function(error) {}); } }); } });} catch (e) { if (e.name === 'ChatNotConnectedError') { // not connected to chat }}
To get the privacy list by name, you should use the following method.
JavaScript
Copy
Ask AI
try { QB.chat.privacylist.getList("myList", function(error, result) { if (!error) { var name = result.name; var items = result.items; } });} catch (e) { if (e.name === 'ChatNotConnectedError') { // not connected to chat }}
A user can be blocked in 1-1 dialog and group dialog. In this case, the blocked user receives an error when trying to send a message in a 1-1 dialog and receives nothing when trying to send a message in group dialog.
JavaScript
Copy
Ask AI
QB.chat.onMessageErrorListener = function (messageId, error){}