Problem with blocking user in chat using smack server and open fire

I want to block a specific friend from my chat list using XMPP . the code works fine. There is no exception, but I can not block the user. I use an open fire server. What changes should I make on the server?

Maybe the guys have an idea?

My code is:

 public void XMPPAddNewPrivacyList(Connection connection, String userName) { String listName = "newList"; // Create the list of PrivacyItem that will allow or // deny some privacy aspect List<PrivacyItem> privacyItems = new Vector<PrivacyItem>(); PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.toString(), false, 1); item.setValue(userName); privacyItems.add(item); // Create the new list. try { PrivacyListManager privacyManager = new PrivacyListManager(connection); privacyManager = PrivacyListManager .getInstanceFor(connection); privacyManager.createPrivacyList(listName, privacyItems); } catch (XMPPException e) { System.out.println("PRIVACY_ERROR: " + e); } } 
+7
android xmpp smack asmack
source share
4 answers

try it...

 public boolean blockFriend(String friendName) { PrivacyItem item=new PrivacyItem(PrivacyItem.Type.jid,friendName, false, 7); PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(connection); List<PrivacyItem> list=new ArrayList<PrivacyItem>(); list.add(item); try { privacyManager.updatePrivacyList(NEWLIST, list); privacyManager.setActiveListName(NEWLIST); return true; } catch (SmackException.NoResponseException |XMPPException.XMPPErrorException | SmackException.NotConnectedException e) { e.printStackTrace(); return false; } } 

and to unlock, just replace false with true in the privacyitem `

+3
source share

I think the problem should be one of the following:

  • username is invalid, for example, " someuser@myxmppserver.com ".
  • You are not listening to privacy changes, I mean that you did not implement the PrivacyListListener interface.
  • In the PrivacyItem constructor, you should not use PrivacyRule.JID instead of PrivacyItem.Type.jid.toString () ?.
  • If you want to block a friend, you should not use updatePrivacyList instead of createPrivacyList.

I recommend that you read the Smack documentation for more details.

0
source share
  // Here function for block user on xmpp public boolean blockUser(String userName) { String jid = userName@localhost String listName = "public"; // 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, jid, false, 1); // item.setValue(userName); item.setFilterIQ(false); item.setFilterMessage(false); item.setFilterPresenceIn(false); item.setFilterPresenceOut(false); privacyItems.add(item); // Get the privacy manager for the current connection. // Create the new list. PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(XMPPUtils.INSTANCE.connection); try { privacyManager.updatePrivacyList(listName, privacyItems); privacyManager.setActiveListName(listName); return true; } catch (Exception e) { Log.e("PRIVACY_ERROR: ", " " + e.toString()); e.printStackTrace(); } return false; } 
0
source share

Confidentiality is a method that allows users to block communication with other users. In XMPP, this is done by managing a single privacy list.

1 - To add a new list to the server, the client MAY implement something like:

 // Create a privacy manager for the current connection._ PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(myConnection); // Retrieve server privacy lists_ PrivacyList[] lists = privacyManager.getPrivacyLists(); 

2 - To add a new list to the server, the client MAY implement something like:

 

 // Set the name of the list_ String listName = "newList"; // Create the list of PrivacyItem that will allow or deny some privacy aspect_ String user = " tybalt@example.com "; String groupName = "enemies"; ArrayList privacyItems = new ArrayList(); PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid, user, true, 1); privacyItems.add(item); item = new PrivacyItem(PrivacyItem.Type.subscription, PrivacyItem.SUBSCRIPTION_BOTH, true, 2); privacyItems.add(item); item = new PrivacyItem(PrivacyItem.Type.group, groupName, false, 3); item.setFilterMessage(true); privacyItems.add(item); // Get the privacy manager for the current connection._ PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(myConnection); // Create the new list._ privacyManager.createPrivacyList(listName, privacyItems); 

code>
0
source share

All Articles