Search in sources :

Example 1 with BlockList

use of com.xabber.xmpp.blocking.BlockList in project xabber-android by redsolution.

the class BlockingManager method requestBlockList.

public void requestBlockList(String account) {
    if (!isSupported(account)) {
        return;
    }
    final BlockList blockListRequest = new BlockList();
    blockListRequest.setType(IQ.Type.get);
    try {
        ConnectionManager.getInstance().sendRequest(account, blockListRequest, new OnResponseListener() {

            @Override
            public void onReceived(String account, String packetId, IQ iq) {
                if (!blockListRequest.getStanzaId().equals(packetId) || !(iq instanceof BlockList)) {
                    return;
                }
                if (iq.getType() == IQ.Type.result) {
                    blockListsForAccounts.put(account, ((BlockList) iq).getItems());
                    for (OnBlockedListChangedListener onBlockedListChangedListener : Application.getInstance().getUIListeners(OnBlockedListChangedListener.class)) {
                        onBlockedListChangedListener.onBlockedListChanged(account);
                    }
                    for (OnContactChangedListener onContactChangedListener : Application.getInstance().getUIListeners(OnContactChangedListener.class)) {
                        onContactChangedListener.onContactsChanged(new ArrayList<BaseEntity>());
                    }
                }
            }

            @Override
            public void onError(String account, String packetId, IQ iq) {
            }

            @Override
            public void onTimeout(String account, String packetId) {
            }

            @Override
            public void onDisconnect(String account, String packetId) {
            }
        });
    } catch (NetworkException e) {
        e.printStackTrace();
    }
}
Also used : OnResponseListener(com.xabber.android.data.connection.OnResponseListener) BlockList(com.xabber.xmpp.blocking.BlockList) IQ(org.jivesoftware.smack.packet.IQ) ArrayList(java.util.ArrayList) OnContactChangedListener(com.xabber.android.data.roster.OnContactChangedListener) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

NetworkException (com.xabber.android.data.NetworkException)1 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)1 OnContactChangedListener (com.xabber.android.data.roster.OnContactChangedListener)1 BlockList (com.xabber.xmpp.blocking.BlockList)1 ArrayList (java.util.ArrayList)1 IQ (org.jivesoftware.smack.packet.IQ)1