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, delete privacy lists or define a default list.

📘

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

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.
  4. Connect to the Chat server. See our Connection page to learn how to do it.

Create privacy list

A privacy list must have at least one element in order to be created. If no elements are specified, then the list with a given name will be deleted.

QBPrivacyListsManager privacyListsManager = QBChatService.getInstance().getPrivacyListsManager();

QBPrivacyList privacyList = new QBPrivacyList();
privacyList.setName("My_Privacy_List");

ArrayList<QBPrivacyListItem> items = new ArrayList<>();

QBPrivacyListItem item = new QBPrivacyListItem();
item.setAllow(false);
item.setType(QBPrivacyListItem.Type.USER_ID);
item.setValueForType(String.valueOf(qbUser.getId()));

items.add(item);

privacyList.setItems(items);

try {
    privacyListsManager.createPrivacyList(privacyList);
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException e) {

}
val privacyListsManager = QBChatService.getInstance().privacyListsManager

val privacyList = QBPrivacyList()
privacyList.name = "My_Privacy_List"

val items = ArrayList<QBPrivacyListItem>()

val item = QBPrivacyListItem()
item.isAllow = false
item.type = QBPrivacyListItem.Type.USER_ID
item.valueForType = qbUser.id.toString()

items.add(item)

privacyList.items = items

try {
    privacyListsManager.createPrivacyList(privacyList)
} catch (e: SmackException.NotConnectedException) {

} catch (e: SmackException.NoResponseException) {
    
} catch (e: XMPPException) {
    
}

The QBPrivacyListItem class takes 4 arguments:

  • type - use USER_ID to block a user in a 1-1 chat or GROUP_USER_ID to block in a group chat.
  • valueForType - ID of a user to apply an action.
  • allow - can be true or false.
  • mutualBlock - can be true or false to block user's message in both directions or not.

📘

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 {
    privacyListsManager.applyPrivacyList("My_Privacy_List");
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException e) {

}
try {
    privacyListsManager.applyPrivacyList("My_Privacy_List")
} catch (e: SmackException.NotConnectedException) {

} catch (e: SmackException.NoResponseException) {
    
} catch (e: XMPPException) {
    
}

Update privacy list

There are some rules you should follow to update a privacy list:

  • Include all of the desired items (not a "delta").
  • If you want to update or set a new privacy list instead of the current one, you should decline the current default list first.
// deactivate active list
try {
    privacyListsManager.declinePrivacyList();
} catch (SmackException | XMPPException.XMPPErrorException e) {

}

// create new list
// ...

// activate again active list
try {
    privacyListsManager.applyPrivacyList("New_Privacy_List");
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException e) {

}
// deactivate active list
try {
    privacyListsManager.declinePrivacyList()
} catch (e: SmackException) {

} catch (e: XMPPException.XMPPErrorException) {
}

// create new list
// ...

// activate again active list
try {
    privacyListsManager.applyPrivacyList("New_Privacy_List")
} catch (e: SmackException.NotConnectedException) {

} catch (e: SmackException.NoResponseException) {
    
} catch (e: XMPPException) {
    
}

Retrieve privacy lists

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

QBPrivacyListsManager privacyListsManager = QBChatService.getInstance().getPrivacyListsManager();

// get all privacy lists
List<QBPrivacyList> lists = new ArrayList<>();

try {
    lists = privacyListsManager.getPrivacyLists();
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException e) {

}
val privacyListsManager = QBChatService.getInstance().privacyListsManager

// get all privacy lists
var lists: List<QBPrivacyList> = ArrayList()

try {
    lists = privacyListsManager.privacyLists
} catch (e: SmackException.NotConnectedException) {

} catch (e: SmackException.NoResponseException) {

} catch (e: XMPPException) {

}

Retrieve privacy list by name

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

QBPrivacyListsManager privacyListsManager = QBChatService.getInstance().getPrivacyListsManager();

// get privacy list by name
QBPrivacyList privacyList = new QBPrivacyList();
try {
    privacyList = privacyListsManager.getPrivacyList("New_Privacy_List");
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException e) {

}
val privacyListsManager = QBChatService.getInstance().privacyListsManager

// get privacy list by name
var privacyList = QBPrivacyList()
try {
    privacyList = privacyListsManager.getPrivacyList("New_Privacy_List")
} catch (e: SmackException.NotConnectedException) {

} catch (e: SmackException.NoResponseException) {

} catch (e: XMPPException) {

}

Remove privacy list

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

QBPrivacyListsManager privacyListsManager = QBChatService.getInstance().getPrivacyListsManager();

try {
    privacyListsManager.declinePrivacyList();
    privacyListsManager.deletePrivacyList("New_Privacy_List");
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException e) {

}
val privacyListsManager = QBChatService.getInstance().privacyListsManager

try {
    privacyListsManager.declinePrivacyList()
    privacyListsManager.deletePrivacyList("New_Privacy_List")
} catch (e: SmackException.NotConnectedException) {

} catch (e: SmackException.NoResponseException) {

} catch (e: XMPPException) {

}

🚧

Before deleting the privacy list, you should decline it.

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.

QBChatMessage qbChatMessage = new QBChatMessage();
qbChatMessage.setBody("I am blocked. I am trying to send message to you");

try {
    privateDialog.sendMessage(qbChatMessage);
} catch (SmackException.NotConnectedException e) {
    e.printStackTrace();
}

privateDialog.addMessageListener(new QBChatDialogMessageListener() {
    @Override
    public void processMessage(String dialogID, QBChatMessage qbChatMessage, Integer integer) {
        // When we received a message from dialog
    }

    @Override
    public void processError(String dialogID, QBChatException e, QBChatMessage qbChatMessage, Integer senderID) {
        // When we received an error from dialog
        e.printStackTrace();
    }
});
val qbChatMessage = QBChatMessage()
qbChatMessage.setBody("I am blocked. I am trying to send message to you")

try {
    privateDialog.sendMessage(qbChatMessage)
} catch (e: SmackException.NotConnectedException) {
    e.printStackTrace()
}

privateDialog.addMessageListener(object : QBChatDialogMessageListener() {
    override fun processMessage(dialogID: String?, qbChatMessage: QBChatMessage?, integer: Int?) {
    // When we received a message from dialog
    }

    override fun processError(dialogID: String?, e: QBChatException?, qbChatMessage: QBChatMessage?, senderID: Int?) {
        // When we received an error from dialog
        e?.printStackTrace()
    }
})

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.