How to block a user / group?

Hi,

I am trying to implement a function which will block a perticular user / group from his rosters. I am following the code from the smack documentation and from a post in this forum.

Unfortunately my code never worked and getting some errors mention below in red color.

Below is the code snippet.

public void XMPPAddNewPrivacyList(XMPPConnection connection, String userName)
{
// Set the name of the list
String listName = “newList”;

        // Create the list of PrivacyItem that will allow or
        // deny some privacy aspect
                               
        //ArrayList privacyItems = new ArrayList();
       
        List<PrivacyItem> privacyItems = new Vector();
        PrivacyItem item = new PrivacyItem(PrivacyItem.PrivacyRule.SUBSCRIPTION_NONE, true, 2);
        item.setValue(userName);   
       
        privacyItems.add(item);   
        // Get the privacy manager for the current connection.
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(connection);
        // Create the new list.
       
        try
        {
            privacyManager.createPrivacyList(listName,privacyItems);
        }
        catch(XMPPException e)
        {
            System.out.println("PRIVACY_ERROR: " + e);
        }
    }
 I am calling this function with the valid connection and roster as mentioned below.
 XMPPAddNewPrivacyList(conn,"testuesr1@yahoo.Xemon");

Exception in thread “main”
java.lang.IllegalArgumentException: No enum const class
org.jivesoftware.smack.packet.PrivacyItem$Type.none

at java.lang.Enum.valueOf(Unknown Source)

at org.jivesoftware.smack.packet.PrivacyItem$Type.valueOf(PrivacyItem.java:430)

at org.jivesoftware.smack.packet.PrivacyItem$PrivacyRule.fromString(PrivacyItem.ja va:329)

at org.jivesoftware.smack.packet.PrivacyItem.<init>(PrivacyItem.java:45)
  1. Can anhybody please correct the below code so that i can use it to block a perticular user / group?
  2. Also how can i unblock the blocked user / group?
  3. Is there any other way

Regards,

Samba

got the fix

use org.jivesoftware.smack.packet.PrivacyItem.Type.jid.toString() instead of

PrivacyItem.PrivacyRule.SUBSCRIPTION_BOTH

The code is looking for a PrivacyItem,Type, not a PrivacyItem.PrivacyRule

this is not going to be supported by Kraken, I think
if that’s your goal

I mean that I think Kraken does not support privacy lists
I can’t be sure
but I believe it is not
the exception is a problem in your code
the string that you use, is not valid in this context
at least, that’s what the code says

Hi,

** String listName = “newList”;

      // Create the list of PrivacyItem that will allow or
      // deny some privacy aspect

      //ArrayList privacyItems = new ArrayList();

      List<PrivacyItem> privacyItems = new Vector<PrivacyItem>();

  
      PrivacyItem item=new PrivacyItem(PrivacyItem.Type.jid.toString(), false, 2);   
      item.setValue(userName);    
      privacyItems.add(item);   
     
      // Get the privacy manager for the current connection.
      PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(connection);
      // Create the new list.

      try
      {
      privacyManager.createPrivacyList(listName,privacyItems);
      }
      catch(XMPPException e)
      {
      System.out.println("PRIVACY_ERROR: " + e);
      }**

In the Above code i am getting the exception XMPPException like Feature in not implemented server.please resolve the issue.

Thanks & Regards,

madhusudhan D