How to block a user in QuickBlox?

I am creating a chat based QuickBlox on the QuickBlox Framework, I want to have block functionality in the application. I read some docs like XMPP and QuickBlox . But that didn’t work out.

There is some logic to maintaining the QBPrivacyList in order to prevent other users from sending messages and blocking them, but I did not succeed.

This is a piece of code, as I maintain a privacy list.

  • Get a privacy list named @"public" in chat mode logged in

     [[QBChat instance] retrievePrivacyListWithName:@"public"]; 

    so if an already created privacy list named "public" will be retrieved in the delegate method

      - (void)chatDidReceivePrivacyList:(QBPrivacyList *)privacyList{ NSLog(@"chatDidReceivePrivacyList: %@", privacyList); _blockPrivacyList = privacyList; // Save its instance for further add more users in list } 

    //answer

    [PrivacyList name: public]items:("type: USER_ID valueForType: 2075213 action: deny" )

  • Here's how to add another member to your privacy list.

     - (void)blockUserWithQBId:(NSUInteger)qbID { QBPrivacyItem *item = [[QBPrivacyItem alloc] initWithType:USER_ID valueForType:qbID action:DENY]; if (_blockPrivacyList) { [_blockPrivacyList addObject:item]; // add new user if already privacy list is there }else _blockPrivacyList = [[QBPrivacyList alloc] initWithName:@"public" items:@[item]]; // create new privacy list if not before created [[QBChat instance] setPrivacyList:_blockPrivacyList]; } 

    And all the delegate methods work fine and add the member to the privacy list.

     - (void)chatDidSetPrivacyListWithName:(NSString *)name{ NSLog(@"chatDidSetPrivacyListWithName %@", name); [[QBChat instance] setDefaultPrivacyListWithName:name]; // set it as default privacy list } 
  • I get this privacy list perfectly, even kill the application or reinstall it for the same user. so my privacy list code works fine

But some, like other members on my DENY personal list, may send me a message. According to the docs from this http://quickblox.com/developers/SimpleSample-chat_users-ios#Contact_list it should give an error like

  "error:Error Domain=com.quickblox.chat Code=503 "Service not available." 

So, if the entire privacy list works fine, then how can my blocked users send me messages?

I worked with XMPP on iOS , there is the same problem there if you can give the XMPP logic, which will also work like QuickBlox , since QuickBlox actually uses XMPP .

Any suggestions for this?

+6
source share
2 answers

Finally found my solution. The flow and logic that I wrote in my question were perfect. I just stayed with one small feature to activate a privacy list. I don’t know why QuickBlox did not write this function call in its demo versions.

  [[QBChat instance] setActivePrivacyListWithName:@"public"]; 

The same thing in XMPP we need to maintain a privacy list and activate a single privacy at a time.

+3
source

Your logic is correct

Have you set the list named "public" as the default value? http://quickblox.com/developers/SimpleSample-chat_users-ios#Activate_a_privacy_list

Without him, he will not work

+1
source

Source: https://habr.com/ru/post/980198/


All Articles