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
- 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 our Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.
- 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.
let userID: UInt = 34
let privateChatPrivacyItem = QBPrivacyItem.init(privacyType: .userID, userID: userID, allow: false)
privateChatPrivacyItem.mutualBlock = true
let groupChatPrivacyItem = QBPrivacyItem.init(privacyType: .groupUserID, userID: userID, allow: false)
let privacyList = QBPrivacyList.init(name: "PrivacyList", items: [privateChatPrivacyItem, groupChatPrivacyItem])
//Setting privacy list
QBChat.instance.setPrivacyList(privacyList)
NSUInteger userID = 34;
QBPrivacyItem *privateChatPrivacyItem =
[[QBPrivacyItem alloc] initWithPrivacyType:QBPrivacyTypeUserID userID:userID allow:NO];
privateChatPrivacyItem.mutualBlock = YES;
QBPrivacyItem *groupChatPrivacyItem =
[[QBPrivacyItem alloc] initWithPrivacyType:QBPrivacyTypeGroupUserID userID:userID allow:NO];
QBPrivacyList *privacyList =
[[QBPrivacyList alloc] initWithName:@"PrivacyList" items:@[privateChatPrivacyItem,groupChatPrivacyItem]];
//Setting privacy list
[QBChat.instance setPrivacyList:privacyList];
If the privacy list is set successfully, the QBChat
instance will call chatDidSetPrivacyList(withName:)
delegate method.
//MARK: QBChatDelegate
func chatDidSetPrivacyList(withName name: String) {
}
//MARK: QBChatDelegate
- (void)chatDidSetPrivacyListWithName:(NSString *)name {
}
In case of error the QBChat
instance will call the chatDidNotSetPrivacyList(withName:error:)
delegate method.
//MARK: QBChatDelegate
func chatDidNotSetPrivacyList(withName name: String, error: Error) {
}
//MARK: QBChatDelegate
- (void)chatDidNotSetPrivacyListWithName:(NSString *)name error:(NSError *)error {
}
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.
QBChat.instance.setDefaultPrivacyListWithName("PrivacyList")
[QBChat.instance setDefaultPrivacyListWithName:@"PrivacyList"];
If the privacy list is activated, theQBChat
instance will call the chatDidSetDefaultPrivacyList(withName:)
method of deledate.
//MARK: QBQBChatDelegate
func chatDidSetDefaultPrivacyList(withName name: String) {
}
//MARK: QBChatDelegate
- (void)chatDidSetDefaultPrivacyListWithName:(NSString *)name {
}
Otherwise, the QBChat
instance will call chatDidNotSetDefaultPrivacyList(withName:error:)
delegate method.
//MARK: QBChatDelegate
func chatDidNotSetDefaultPrivacyList(withName name: String, error: Error) {
}
//MARK: QBChatDelegate
- (void)chatDidNotSetDefaultPrivacyListWithName:(NSString *)name error:(NSError *)error {
}
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.
//Deactivating privacy list before update
QBChat.instance.setDefaultPrivacyListWithName(nil)
//Some updates here
//....
//Activating privacy list
QBChat.instance.setDefaultPrivacyListWithName("PrivacyList")
//Deactivating privacy list before update
[QBChat.instance setDefaultPrivacyListWithName:nil];
//Some updates here
//....
//Activating privacy list
[QBChat.instance setDefaultPrivacyListWithName:@"PrivacyList"];
Retrieve privacy lists
To get a list of all your privacy lists names, use the following request.
QBChat.instance.retrievePrivacyListNames()
[QBChat.instance retrievePrivacyListNames];
If the privacy list names are retrieved successfully, the QBChat
instance will call chatDidReceivePrivacyListNames()
delegate method.
//MARK: QBChatDelegate
func chatDidReceivePrivacyListNames(_ listNames: [String]) {
}
//MARK: QBChatDelegate
- (void)chatDidReceivePrivacyListNames:(NSArray<NSString *> *)listNames {
}
Otherwise, the QBChat
instance will call chatDidNotReceivePrivacyListNamesDue(toError:)
delegate method.
//MARK: QBChatDelegate
func chatDidNotReceivePrivacyListNamesDue(toError error: Error) {
}
//MARK: QBChatDelegate
- (void)chatDidNotReceivePrivacyListNamesDueToError:(NSError *)error {
}
Retrieve privacy list by name
To get the privacy list by name, you should use the following method.
QBChat.instance.retrievePrivacyList(withName: "PrivacyList")
[QBChat.instance retrievePrivacyListWithName:@"PrivacyList"];
If the privacy list is retrieved successfully, the QBChat
instance will call chatDidReceive(_ privacyList:)
its delegate method.
//MARK: QBChatDelegate
func chatDidReceive(_ privacyList: QBPrivacyList) {
}
//MARK: QBChatDelegate
- (void)chatDidReceivePrivacyList:(QBPrivacyList *)privacyList {
}
Otherwise, the QBChat
instance will call chatDidNotReceivePrivacyList(withName:error)
delegate method.
//MARK: QBChatDelegate
func chatDidNotReceivePrivacyList(withName name: String, error: Error) {
}
//MARK: QBChatDelegate
- (void)chatDidNotReceivePrivacyListWithName:(NSString *)name error:(NSError *)error {
}
Remove privacy list
To delete a list, you can call the method below or you can edit a list and set items to nil
.
QBChat.instance.removePrivacyList(withName: "PrivacyList")
[QBChat.instance removePrivacyListWithName:@"PrivacyList"];
If the privacy list is removed successfully, the QBChat
instance will call chatDidRemovedPrivacyList(withName:)
delegate method.
//MARK: QBChatDelegate
func chatDidRemovedPrivacyList(withName name: String) {
}
//MARK: QBChatDelegate
- (void)chatDidRemovedPrivacyListWithName:(NSString *)name {
}
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.
chatDialog.onBlockedMessage = { (error) in
}
chatDialog.onBlockedMessage = ^(NSError * _Nullable error) {
};
Updated about 3 years ago