如何在iOS的openfire的apns插件中获取阻止用​​户?

时间:2016-04-29 05:28:43

标签: java ios apple-push-notifications openfire

我想从iOS的openfire的apns插件中获取块用户。因为如果用户已经阻止,openfire将发送通知。但是不要发送推送通知。

谢谢!

1 个答案:

答案 0 :(得分:0)

我找到了答案。我可以从ApnsDBHandler.java类中获取块用户。

查询

private static final String LOAD_BLOCKED_USER = "SELECT list FROM ofPrivacyList WHERE username=?";

方法

    public boolean getBlockUser(JID fromJID, JID targetJID) {
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        boolean isBlocked = false;
        String list = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(LOAD_BLOCKED_USER);
//            list.repl
           String fullJID =  targetJID.toBareJID();
           String jid = fullJID.split("@")[0];

            pstmt.setString(1, jid);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                list = rs.getString(1);
//                System.out.println("Found Blocked user list: "+list);
                isBlocked =  isBlockedUser(list, fromJID.toBareJID());
            }else{
//                System.out.println("Not Found Blocked user list");
            }
            rs.close();
            pstmt.close();
        } catch (SQLException sqle) {
            System.out.println("SQL Exception Blocked user list");

            Log.error(sqle.getMessage(), sqle);
            list = sqle.getMessage();
        }
        catch (Exception e){
            System.out.println("Exception Blocked user list");

            Log.error(e.getMessage(), e);
        }
        finally {
            DbConnectionManager.closeConnection(rs, pstmt, con);
        }
        return isBlocked;
    }

    private boolean isBlockedUser(String xmlRecords, String fromJID) throws  Exception {
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xmlRecords));

        Document doc = db.parse(is);
        NodeList nodes = doc.getElementsByTagName("item");

        boolean flag = false;
        for(int x=0, size= nodes.getLength(); x<size; x++) {
            String blockedJID = nodes.item(x).getAttributes().getNamedItem("value").getNodeValue();
            String action = nodes.item(x).getAttributes().getNamedItem("action").getNodeValue();
            if (blockedJID.equals(fromJID)){
                 if(action.equals("deny")){
                     flag  =  true;
                 }else{
                     flag =  false;
                 }
                break;
            }
        }

        return flag;

    }

我希望这会对别人有所帮助。 :)