Search in sources :

Example 11 with NetworkException

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

the class AttentionManager method sendAttention.

public void sendAttention(String account, String user) throws NetworkException {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
    if (!(chat instanceof RegularChat)) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
    }
    String to = chat.getTo();
    if (Jid.getResource(to) == null || "".equals(Jid.getResource(to))) {
        final Presence presence = RosterManager.getInstance().getPresence(account, user);
        if (presence == null) {
            to = null;
        } else {
            to = presence.getFrom();
        }
    }
    if (to == null) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
    }
    ClientInfo clientInfo = CapabilitiesManager.getInstance().getClientInfo(account, to);
    if (clientInfo == null)
        throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
    if (!clientInfo.getFeatures().contains(Attention.NAMESPACE))
        throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
    Message message = new Message();
    message.setTo(to);
    message.setType(Message.Type.headline);
    message.addExtension(new Attention());
    ConnectionManager.getInstance().sendStanza(account, message);
    chat.newAction(null, null, ChatAction.attention_called);
}
Also used : Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) Attention(com.xabber.xmpp.attention.Attention) Presence(org.jivesoftware.smack.packet.Presence) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) NetworkException(com.xabber.android.data.NetworkException) RegularChat(com.xabber.android.data.message.RegularChat)

Example 12 with NetworkException

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

the class OTRManager method abortSmp.

/**
     * Abort SM negotiation.
     */
public void abortSmp(String account, String user) throws NetworkException {
    LogManager.i(this, "aborting smp... " + user);
    removeSMRequest(account, user);
    removeSMProgress(account, user);
    try {
        getOrCreateSession(account, user).abortSmp();
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
}
Also used : OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Example 13 with NetworkException

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

the class PingManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    final String account = ((AccountItem) connection).getAccount();
    if (!(packet instanceof Ping))
        return;
    final Ping ping = (Ping) packet;
    if (ping.getType() != IQ.Type.get)
        return;
    try {
        ConnectionManager.getInstance().sendStanza(account, IQ.createResultIQ(ping));
    } catch (NetworkException e) {
        LogManager.exception(this, e);
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Ping(org.jivesoftware.smackx.ping.packet.Ping) NetworkException(com.xabber.android.data.NetworkException)

Example 14 with NetworkException

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

the class TimeManager method onServerInfoReceived.

@Override
public void onServerInfoReceived(ConnectionItem connection) {
    if (!(connection instanceof AccountItem)) {
        onAvailable(connection);
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE) && offsets.get(account) == null) {
        sents.put(account, new Date());
        Time packet = new Time();
        packet.setTo(Jid.getServer(account));
        packet.setType(Type.get);
        try {
            ConnectionManager.getInstance().sendRequest(account, packet, this);
        } catch (NetworkException e) {
        }
        return;
    }
    onAvailable(connection);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Time(com.xabber.xmpp.time.Time) NetworkException(com.xabber.android.data.NetworkException) Date(java.util.Date)

Example 15 with NetworkException

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

the class AccountManager method updateAccount.

/**
     * Update user`s account.
     * <p/>
     * It will reconnect to the server if changes was made.
     * <p/>
     * It will remove old account and create new one if full jid was changed.
     *
     * @param account       full source jid
     * @param host
     * @param port
     * @param serverName
     * @param userName
     * @param storePassword
     * @param password
     * @param resource
     * @param priority
     * @param enabled
     * @param saslEnabled
     * @param tlsMode
     * @param compression
     * @param syncable
     * @param archiveMode
     */
public void updateAccount(String account, boolean custom, String host, int port, String serverName, String userName, boolean storePassword, String password, String resource, int priority, boolean enabled, boolean saslEnabled, TLSMode tlsMode, boolean compression, ProxyType proxyType, String proxyHost, int proxyPort, String proxyUser, String proxyPassword, boolean syncable, ArchiveMode archiveMode, int colorIndex) {
    AccountItem result;
    AccountItem accountItem = getAccount(account);
    if (accountItem == null) {
        return;
    }
    if (accountItem.getConnectionSettings().getServerName().equals(serverName) && accountItem.getConnectionSettings().getUserName().equals(userName) && accountItem.getConnectionSettings().getResource().equals(resource)) {
        result = accountItem;
        result.setColorIndex(colorIndex);
        boolean reconnect = false;
        if (accountItem.getConnectionSettings().isCustomHostAndPort() != custom || !accountItem.getConnectionSettings().getHost().equals(host) || accountItem.getConnectionSettings().getPort() != port || !accountItem.getConnectionSettings().getPassword().equals(password) || accountItem.getConnectionSettings().getTlsMode() != tlsMode || accountItem.getConnectionSettings().isSaslEnabled() != saslEnabled || accountItem.getConnectionSettings().useCompression() != compression || accountItem.getConnectionSettings().getProxyType() != proxyType || !accountItem.getConnectionSettings().getProxyHost().equals(proxyHost) || accountItem.getConnectionSettings().getProxyPort() != proxyPort || !accountItem.getConnectionSettings().getProxyUser().equals(proxyUser) || !accountItem.getConnectionSettings().getProxyPassword().equals(proxyPassword)) {
            result.updateConnectionSettings(custom, host, port, password, saslEnabled, tlsMode, compression, proxyType, proxyHost, proxyPort, proxyUser, proxyPassword);
            reconnect = true;
        }
        if (result.isSyncable() != syncable) {
            result.setSyncable(syncable);
            for (OnAccountSyncableChangedListener listener : application.getManagers(OnAccountSyncableChangedListener.class)) {
                listener.onAccountSyncableChanged(result);
            }
        }
        result.setStorePassword(storePassword);
        boolean changed = result.isEnabled() != enabled;
        result.setEnabled(enabled);
        if (result.getPriority() != priority) {
            result.setPriority(priority);
            try {
                PresenceManager.getInstance().resendPresence(account);
            } catch (NetworkException e) {
            }
        }
        if (result.getArchiveMode() != archiveMode) {
            reconnect = (result.getArchiveMode() == ArchiveMode.server) != (archiveMode == ArchiveMode.server);
            result.setArchiveMode(archiveMode);
            for (OnAccountArchiveModeChangedListener listener : application.getManagers(OnAccountArchiveModeChangedListener.class)) {
                listener.onAccountArchiveModeChanged(result);
            }
        }
        if (changed && enabled) {
            enabledAccounts.add(account);
            onAccountEnabled(result);
            if (result.getRawStatusMode().isOnline()) {
                onAccountOnline(result);
            }
        }
        if (changed || reconnect) {
            result.updateConnection(true);
            result.forceReconnect();
        }
        if (changed && !enabled) {
            enabledAccounts.remove(account);
            if (result.getRawStatusMode().isOnline()) {
                onAccountOffline(result);
            }
            onAccountDisabled(result);
        }
        requestToWriteAccount(result);
    } else {
        StatusMode statusMode = accountItem.getRawStatusMode();
        String statusText = accountItem.getStatusText();
        AccountProtocol protocol = accountItem.getConnectionSettings().getProtocol();
        KeyPair keyPair = accountItem.getKeyPair();
        Date lastSync = accountItem.getLastSync();
        removeAccountWithoutCallback(account);
        result = addAccount(protocol, custom, host, port, serverName, userName, storePassword, password, resource, colorIndex, priority, statusMode, statusText, enabled, saslEnabled, tlsMode, compression, proxyType, proxyHost, proxyPort, proxyUser, proxyPassword, syncable, keyPair, lastSync, archiveMode, false);
    }
    onAccountChanged(result.getAccount());
}
Also used : KeyPair(java.security.KeyPair) NetworkException(com.xabber.android.data.NetworkException) Date(java.util.Date)

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