Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block a user in QuickBlox?

I am creating a chat based Application on QuickBlox Framework, I want to have a block functionality in the App. I read out some of documents like XMPP and QuickBlox. But did not got any help Out of that.

There is some logic of maintaining QBPrivacyList for not to allow other user send message and block it but I didn't got succeed with it.

This is a code snippet how I am maintaining the Privacy List.

  1. Get the privacy list with Name @"public" in method of chat did login

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

    so if there is already created privacy list named "public" will fetch it in delegate method

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

    // response is

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

  2. This is how add another member in 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 works perfectly creates and adds member in privacy list.

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

But some how the other members in my DENY privacy list can send me message. According to the documents from this http://quickblox.com/developers/SimpleSample-chat_users-ios#Contact_list it should give the error like

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

So if all privacy list works perfectly then how can my blocked users could send me messages?

I had worked with XMPP in iOS the same issue exist there also if you can give XMPP logic that will also work as QuickBlox as QuickBlox actually uses XMPP itself.

Any suggestions for this?

like image 290
haresh Avatar asked Dec 27 '14 08:12

haresh


2 Answers

Finally found its solution. The flow and logic i had written in my question was perfect. I was just remaining with the one small function to activate the privacy list. Dont know why QuickBlox has not written that function call in their demos.

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

Same in XMPP we need to maintain the Privacy list and activate single privacy at one time.

like image 158
haresh Avatar answered Sep 28 '22 05:09

haresh


Your logic is correct

Did you set the list with name "public" as the default one? http://quickblox.com/developers/SimpleSample-chat_users-ios#Activate_a_privacy_list

Without it it won't be working

like image 25
Rubycon Avatar answered Sep 28 '22 05:09

Rubycon