Search in sources :

Example 6 with NetworkException

use of com.xabber.android.data.NetworkException 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)

Example 7 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class BlockingManager method blockContact.

public void blockContact(String account, final String contactJid, final BlockContactListener listener) {
    final Block blockRequest = new Block();
    blockRequest.setType(IQ.Type.set);
    blockRequest.addItem(contactJid);
    try {
        ConnectionManager.getInstance().sendRequest(account, blockRequest, new OnResponseListener() {

            @Override
            public void onReceived(String account, String packetId, IQ iq) {
                if (!blockRequest.getStanzaId().equals(packetId)) {
                    return;
                }
                if (iq.getType() == IQ.Type.result) {
                    requestBlockList(account);
                    listener.onSuccess();
                } else {
                    listener.onError();
                }
            }

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

            @Override
            public void onTimeout(String account, String packetId) {
                listener.onError();
            }

            @Override
            public void onDisconnect(String account, String packetId) {
                listener.onError();
            }
        });
    } catch (NetworkException e) {
        e.printStackTrace();
        listener.onError();
    }
}
Also used : OnResponseListener(com.xabber.android.data.connection.OnResponseListener) IQ(org.jivesoftware.smack.packet.IQ) Block(com.xabber.xmpp.blocking.Block) NetworkException(com.xabber.android.data.NetworkException)

Example 8 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class MessageArchiveManager method requestList.

private String requestList(String account, String bareAddress, String before) {
    List packet = new List();
    packet.setType(Type.get);
    Set rsm = new Set();
    rsm.setMax(RSM_MAX);
    rsm.setBefore(before);
    packet.setRsm(rsm);
    packet.setWith(bareAddress);
    packet.setEnd(connected.get(account));
    String packetId = packet.getPacketID();
    try {
        ConnectionManager.getInstance().sendStanza(account, packet);
    } catch (NetworkException e) {
    }
    return packetId;
}
Also used : Set(com.xabber.xmpp.rsm.Set) List(com.xabber.xmpp.archive.List) NetworkException(com.xabber.android.data.NetworkException)

Example 9 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class MessageArchiveManager method requestModified.

private void requestModified(String account, String before) {
    Modified packet = new Modified();
    packet.setType(Type.get);
    Set rsm = new Set();
    rsm.setMax(RSM_MAX);
    rsm.setBefore(before);
    packet.setRsm(rsm);
    packet.setStart(modificationStorages.get(account).getLastRequest());
    try {
        ConnectionManager.getInstance().sendRequest(account, packet, new OnResponseListener() {

            @Override
            public void onReceived(String account, String packetId, IQ iq) {
                if (iq instanceof Modified && ((Modified) iq).isValid())
                    onModifiedReceived(account, (Modified) iq);
                else
                    onError(account, packetId, iq);
            }

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

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

            @Override
            public void onDisconnect(String account, String packetId) {
            }
        });
    } catch (NetworkException e) {
    }
}
Also used : Modified(com.xabber.xmpp.archive.Modified) Set(com.xabber.xmpp.rsm.Set) OnResponseListener(com.xabber.android.data.connection.OnResponseListener) IQ(org.jivesoftware.smack.packet.IQ) NetworkException(com.xabber.android.data.NetworkException)

Example 10 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class MessageArchiveManager method requestPreferences.

private void requestPreferences(String account) {
    Pref pref = new Pref();
    pref.setType(Type.get);
    try {
        ConnectionManager.getInstance().sendRequest(account, pref, new OnResponseListener() {

            @Override
            public void onReceived(String account, String packetId, IQ iq) {
                if (iq instanceof Pref && ((Pref) iq).isValid())
                    onPreferencesResponce(account, (Pref) iq);
                onPreferenceAvailable(account);
            }

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

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

            @Override
            public void onDisconnect(String account, String packetId) {
            }
        });
    } catch (NetworkException e) {
    }
}
Also used : OnResponseListener(com.xabber.android.data.connection.OnResponseListener) Pref(com.xabber.xmpp.archive.Pref) IQ(org.jivesoftware.smack.packet.IQ) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

NetworkException (com.xabber.android.data.NetworkException)64 Message (org.jivesoftware.smack.packet.Message)13 AccountJid (com.xabber.android.data.entity.AccountJid)11 OtrException (net.java.otr4j.OtrException)11 AccountItem (com.xabber.android.data.account.AccountItem)10 AbstractChat (com.xabber.android.data.message.AbstractChat)10 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 Date (java.util.Date)6 IQ (org.jivesoftware.smack.packet.IQ)6 UserJid (com.xabber.android.data.entity.UserJid)5 ArrayList (java.util.ArrayList)4 Presence (org.jivesoftware.smack.packet.Presence)4 Intent (android.content.Intent)3 Set (com.xabber.xmpp.rsm.Set)3 File (java.io.File)3 SmackException (org.jivesoftware.smack.SmackException)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 Captcha (com.xabber.android.data.extension.captcha.Captcha)2 RoomChat (com.xabber.android.data.extension.muc.RoomChat)2