powered by Jive Software

Block all comunications from user (jid) not working for me

Dear All

I read this alot http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/ smack/packet/PrivacyItem.html but still can not make it to work please help

#1 if the blocking will be done on ther server side what the PrivaceListener for ???

#2 if i’m blocking mss, presnce here { item.setFilterMessage(true) ; } what the false in

{ new PrivacyItem(PrivacyItem.Type.jid.toString() , false , 1); } do ??

String listName = “newList12sc34”;

String user = “b@ubuntu”

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

ArrayList privacyItems = new ArrayList();

PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.toString() , false , 1);

item.setValue(user);

// I need to prevent rececving msgs from this user

item.setFilterMessage(true) ;

item.setFilterPresence_out( true ) ;

privacyItems.add(item);

// Get the privacy manager for the current connection.

PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(MyApplication.connection );

// Create the new list.

try {

privacyManager.createPrivacyList(listName, privacyItems );

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

#1 if the blocking will be done on ther server side what the PrivaceListener for ???

#2 if i’m blocking mss, presnce here { item.setFilterMessage(true) ; } what the false in

{ new PrivacyItem(PrivacyItem.Type.jid.toString() , false , 1); } do ??

#1: To listen for PrivacyList updates (aka “privacy list push”)

#2: to deny messages. (true = allow, false = deny).

Read this:

http://xmpp.org/extensions/xep-0016.html

There is everything explained.

1 Like

so what I’m missing here ?

sorry but still not clear if the blocking done on the server why clients should listen to “privacy list push” !!??

and if i did not implementit user will still receive msgs from users he blockedd ???

I check the link and the xml for blocking conunications is the same as the xml sent by my code but still not working ???

It’s just there, to inform the client about an update of a privacy list. Similar to a roster push.

thanks for ur reply

so listner doesnt efect the blocking process and the blocking should work either ways

but it doesn’t as I sad i checked the xml my code send and it is the same as the xml in the link why it is stil not working , what I’m missing plz help

Sry, I don’t know what you are missing. PrivacyLists (blocking single users, type=“jid”), work for me (using Openfire 3.8.2 and Smack 3.3.1).

thanks for reply

can u post some code ?

I can’t post the complete code here. But maybe the following help you:

  • I had to always add a “dummy” privacy item to the privacy list. Otherwise an XmppException was thrown. I don’t know why, but appearently Openfire does not like empty lists.

PrivacyItem dummyItem = new PrivacyItem(PrivacyItem.Type.subscription.name(), true, 999999);

dummyItem.setValue(“both”);

// Add a dummy item, otherwise the list won’t be stored.

if (privacyItemsWithDummy.size() == 0) {

privacyItemsWithDummy.add(dummyItem);

}

privacyManager.updatePrivacyList(DEFAULT_LIST_NAME, privacyItemsWithDummy);

I always work on a default list:

privacyManager.setDefaultListName(DEFAULT_LIST_NAME);

And needed to set this list as default in order to make it work.