How to block a user in QuickBlox?
Asked Answered
C

2

6

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?

Cocks answered 27/12, 2014 at 8:59 Comment(0)
C
3

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.

Cocks answered 22/1, 2015 at 12:28 Comment(3)
Thank you Haresh, I was looking for exactly this, you saved my day! :)Alderman
Hi haresh, I added multiple users in the list and updated. How to remove the single user from the list and update.Disrespect
Where did you add this code ? I tried to add it after connecting to chat. But still not working. Other user is still receiving messages. Can you please help me on this ?Ainslee
R
1

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

Roseleeroselia answered 20/1, 2015 at 16:13 Comment(1)
Yes i had set the privacy list name "public" as default. It works sometimes and some times not. Like other user still can send me message even i block it.Cocks

© 2022 - 2024 — McMap. All rights reserved.