【问题标题】:Issue in blocking user in chatlist using smack and open fire server使用 smack 和 openfire 服务器在聊天列表中阻止用户的问题
【发布时间】:2013-09-07 18:43:47
【问题描述】:

我想通过XMPP 从我的聊天列表中屏蔽某个特定朋友。代码工作正常。没有例外,但我无法阻止用户。 我正在使用开火服务器。我应该在服务器上进行哪些更改?

你们有什么想法吗?

我的代码:

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);
    }
}

【问题讨论】:

  • 嗨,我将 PrivacyListManager.getInstanceFor(connection) 设为空。请帮助我,我无法理解为什么它会变为空。
  • 嗨,它在 java 中运行良好,但我在 asmack 中遇到异常。我知道问题出在哪里,你能给我提供隐私列表代码的providermanager吗?

标签: android xmpp smack asmack


【解决方案1】:

我认为问题应该是以下之一:

  • 用户名不正确,例如“someuser@myxmppserver.com”。
  • 我的意思是,您没有监听隐私更改,您没有实现 PrivacyListListener 接口。
  • 在 PrivacyItem 构造函数中,您是否应该使用 PrivacyRule.JID 而不是 PrivacyItem.Type.jid.toString()?。
  • 如果您想阻止朋友,您应该使用 updatePrivacyList 而不是 createPrivacyList。

我建议您仔细查看文档Smack documentation

【讨论】:

  • 嗨 astinx,请发布一个可行的代码来阻止用户。我面临阻止用户的问题。我得到 PrivacyListManager .getInstanceFor(connection) 返回 null。请帮助我
  • 对不起,我们早就埋没了 XMPP 技术。我们现在使用节点是一种更好的方法,更快更可靠,我们与近 2000 个用户聊天,XMMP 无法满足这个要求。
【解决方案2】:

试试这个……

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 for 解锁 只需将隐私项对象中的 false 替换为 true `

【讨论】:

    【解决方案3】:
        // 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;
    }
    

    【讨论】:

      【解决方案4】:

      隐私是用户阻止来自特定其他用户的通信的一种方法。在 XMPP 中,这是通过管理个人隐私列表来完成的。

      1 - 为了在服务器中添加一个新列表,客户端可以实现类似的东西:

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

      2 - 为了在服务器中添加一个新列表,客户端可以实现类似的东西:

       
      
      
      // 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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-01
        • 2011-12-31
        • 2011-11-06
        • 1970-01-01
        • 1970-01-01
        • 2015-02-05
        相关资源
        最近更新 更多