> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickblox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<Note>
  The user can have multiple privacy lists, but only one can be active.
</Note>

Visit [Key Concepts](/docs/key-concepts) page to learn the most important QuickBlox concepts.

## Before you begin

1. Register a [QuickBlox account](https://admin.quickblox.com/signin). 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 [Setup](/sdks/ios-setup) page for more details.
3. Create a user session to be able to use QuickBlox functionality. See [Authentication](/sdks/ios-authentication) page to learn how to do it.
4. Connect to the Chat server. See [Connection](/sdks/ios-chat-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.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    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)
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    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];
    ```
  </Tab>
</Tabs>

If the privacy list is set successfully, the `QBChat` instance will call `chatDidSetPrivacyList(withName:)` delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidSetPrivacyList(withName name: String) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidSetPrivacyListWithName:(NSString *)name {

    }
    ```
  </Tab>
</Tabs>

In case of error the `QBChat` instance will call the `chatDidNotSetPrivacyList(withName:error:)` delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidNotSetPrivacyList(withName name: String, error: Error) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidNotSetPrivacyListWithName:(NSString *)name error:(NSError *)error {

    }
    ```
  </Tab>
</Tabs>

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

## Activate privacy list

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

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    QBChat.instance.setDefaultPrivacyListWithName("PrivacyList")
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    [QBChat.instance setDefaultPrivacyListWithName:@"PrivacyList"];
    ```
  </Tab>
</Tabs>

If the privacy list is activated, the`QBChat` instance will call the `chatDidSetDefaultPrivacyList(withName:)` method of deledate.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBQBChatDelegate
    func chatDidSetDefaultPrivacyList(withName name: String) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidSetDefaultPrivacyListWithName:(NSString *)name {

    }
    ```
  </Tab>
</Tabs>

Otherwise, the `QBChat` instance will call `chatDidNotSetDefaultPrivacyList(withName:error:)` delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidNotSetDefaultPrivacyList(withName name: String, error: Error) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidNotSetDefaultPrivacyListWithName:(NSString *)name error:(NSError *)error {

    }
    ```
  </Tab>
</Tabs>

## 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.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //Deactivating privacy list before update
    QBChat.instance.setDefaultPrivacyListWithName(nil)
    //Some updates here
    //....
    //Activating privacy list
    QBChat.instance.setDefaultPrivacyListWithName("PrivacyList")
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //Deactivating privacy list before update
    [QBChat.instance setDefaultPrivacyListWithName:nil];
    //Some updates here
    //....
    //Activating privacy list
    [QBChat.instance setDefaultPrivacyListWithName:@"PrivacyList"];
    ```
  </Tab>
</Tabs>

## Retrieve privacy lists

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

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    QBChat.instance.retrievePrivacyListNames()
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    [QBChat.instance retrievePrivacyListNames];
    ```
  </Tab>
</Tabs>

If the privacy list names are retrieved successfully, the `QBChat` instance will call `chatDidReceivePrivacyListNames()` delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidReceivePrivacyListNames(_ listNames: [String]) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidReceivePrivacyListNames:(NSArray<NSString *> *)listNames {

    }
    ```
  </Tab>
</Tabs>

Otherwise, the `QBChat` instance will call `chatDidNotReceivePrivacyListNamesDue(toError:)` delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidNotReceivePrivacyListNamesDue(toError error: Error) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidNotReceivePrivacyListNamesDueToError:(NSError *)error {

    }
    ```
  </Tab>
</Tabs>

## Retrieve privacy list by name

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

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    QBChat.instance.retrievePrivacyList(withName: "PrivacyList")
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    [QBChat.instance retrievePrivacyListWithName:@"PrivacyList"];
    ```
  </Tab>
</Tabs>

If the privacy list is retrieved successfully, the `QBChat` instance will call `chatDidReceive(_ privacyList:)` its delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidReceive(_ privacyList: QBPrivacyList) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidReceivePrivacyList:(QBPrivacyList *)privacyList {

    }
    ```
  </Tab>
</Tabs>

Otherwise, the `QBChat` instance will call `chatDidNotReceivePrivacyList(withName:error)` delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidNotReceivePrivacyList(withName name: String, error: Error) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidNotReceivePrivacyListWithName:(NSString *)name error:(NSError *)error {

    }
    ```
  </Tab>
</Tabs>

## Remove privacy list

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

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    QBChat.instance.removePrivacyList(withName: "PrivacyList")
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    [QBChat.instance removePrivacyListWithName:@"PrivacyList"];
    ```
  </Tab>
</Tabs>

If the privacy list is removed successfully, the `QBChat` instance will call `chatDidRemovedPrivacyList(withName:)` delegate method.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    //MARK: QBChatDelegate
    func chatDidRemovedPrivacyList(withName name: String) {

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    //MARK: QBChatDelegate
    - (void)chatDidRemovedPrivacyListWithName:(NSString *)name {

    }
    ```
  </Tab>
</Tabs>

<Note>
  Before deleting the privacy list, you should decline it.
</Note>

## 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**.

<Tabs>
  <Tab title="Swift">
    ```Swift theme={null}
    chatDialog.onBlockedMessage = { (error) in

    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```Objective-C theme={null}
    chatDialog.onBlockedMessage = ^(NSError * _Nullable error) {

    };
    ```
  </Tab>
</Tabs>
