QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms.

Privacy List

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 our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.

Before you begin

  1. 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.
  2. Configure QuickBlox SDK for your app. Check out our Setup page for more details. 3. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.
  3. Connect to the Chat server. See our Connection page to learn how to do it.

📘

The user can have multiple privacy lists, but only one can be active.

Create privacy list

A privacy list must have at least one element in order to be created. You can choose a type of blocked logic. There are 2 types:

  • Block in one way. When you blocked a user, but you can send messages to them.
  • Block in two ways. When you blocked a user, but you can't send messages to them.
var users = [
  { user_id: 34, action: "deny" },
  { user_id: 48, action: "deny", mutualBlock: true }, // it means you can't write to user
  { user_id: 18, action: "allow" }
];
var list = { name: "myList", items: users };

try {
  QB.chat.privacylist.create(list, function(error) {}); 
} catch (e) {
  if (e.name === 'ChatNotConnectedError') {
    // not connected to chat
  }
}

📘

In order to be used the privacy list should be not only set but also activated (set as default).

Activate privacy list

In order to activate rules from a privacy list you should set it as default.

try {
  QB.chat.privacylist.setAsDefault("myList", function(error) {

  });
} catch (e) {
  if (e.name === 'ChatNotConnectedError') {
    // not connected to chat
  }
}

Update privacy list

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.

try {
  QB.chat.privacylist.getNames(function(error, result) {
    if (!error) {
      var names = result.names;
    }
  });
} catch (e) {
  if (e.name === 'ChatNotConnectedError') {
    // not connected to chat
  }
}

Retrieve privacy lists

To get a list of all your privacy lists names, use the following request.

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
  }
}

Retrieve privacy list by name

To get the privacy list by name, you should use the following method.

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
  }
}

Remove privacy list

To delete a list, you can call a method below or you can edit a list and set items to nil.

try {
  QB.chat.privacylist.delete("myList", function(error) {

  });
} catch (e) {
  if (e.name === 'ChatNotConnectedError') {
    // not connected to chat
  }
}

Blocked user attempts to communicate with user

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.

QB.chat.onMessageErrorListener = function (messageId, error){
    
}

Updated 5 months ago


What's Next

Video Calling

Privacy List


Learn how to create privacy lists and implement user-to-user blocks.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.