Search in sources :

Example 61 with NetworkException

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

the class SSNManager method onFormReceived.

private void onFormReceived(String account, String from, String bareAddress, String session, Feature feature) {
    OtrMode otrMode = getOtrMode(account, bareAddress, session);
    boolean cancel = false;
    Collection<DisclosureValue> disclosureValues = feature.getDisclosureOptions();
    DisclosureValue disclosureValue = DisclosureValue.never;
    if (disclosureValues == null)
        disclosureValue = null;
    else if (!disclosureValues.contains(disclosureValue))
        cancel = true;
    Collection<SecurityValue> securityValues = feature.getSecurityOptions();
    SecurityValue securityValue;
    if (AccountManager.getInstance().getAccount(account).getConnectionSettings().getTlsMode() == TLSMode.required)
        securityValue = SecurityValue.c2s;
    else
        securityValue = SecurityValue.none;
    if (securityValues == null)
        securityValue = null;
    else if (!securityValues.contains(securityValue))
        cancel = true;
    Collection<LoggingValue> loggingValues = feature.getLoggingOptions();
    LoggingValue loggingValue;
    if (loggingValues == null)
        loggingValue = null;
    else {
        loggingValue = otrMode.selectLoggingValue(loggingValues);
        if (loggingValue == null)
            cancel = true;
    }
    if (cancel) {
        DataForm dataForm = Feature.createDataForm(DataFormType.submit);
        if (feature.getAcceptValue() != null) {
            Feature.addAcceptField(dataForm, false);
            sessionStates.remove(account, session);
        } else {
            Feature.addRenegotiateField(dataForm, false);
        }
        sendFeature(account, from, session, new Feature(dataForm));
        return;
    }
    DataForm dataForm = Feature.createDataForm(DataFormType.submit);
    if (feature.getAcceptValue() != null)
        Feature.addAcceptField(dataForm, true);
    else
        Feature.addRenegotiateField(dataForm, true);
    if (disclosureValue != null)
        Feature.addDisclosureField(dataForm, null, disclosureValue);
    if (securityValue != null)
        Feature.addSecurityField(dataForm, null, securityValue);
    if (loggingValue != null) {
        try {
            if (loggingValue == LoggingValue.mustnot)
                MessageArchiveManager.getInstance().setSaveMode(account, from, session, SaveMode.fls);
            else
                MessageArchiveManager.getInstance().setSaveMode(account, from, session, SaveMode.body);
        } catch (NetworkException e) {
        }
        Feature.addLoggingField(dataForm, null, loggingValue);
    }
    sessionStates.put(account, session, SessionState.active);
    sendFeature(account, from, session, new Feature(dataForm));
}
Also used : LoggingValue(com.xabber.xmpp.ssn.LoggingValue) DisclosureValue(com.xabber.xmpp.ssn.DisclosureValue) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) OtrMode(com.xabber.xmpp.archive.OtrMode) Feature(com.xabber.xmpp.ssn.Feature) NetworkException(com.xabber.android.data.NetworkException) SecurityValue(com.xabber.xmpp.ssn.SecurityValue)

Example 62 with NetworkException

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

the class CapabilitiesManager method request.

/**
     * Requests disco info.
     *
     * @param account
     * @param user
     * @param capability
     */
private void request(String account, String user, Capability capability) {
    for (DiscoverInfoRequest check : requests) {
        if (capability.equals(check.getCapability())) {
            return;
        }
    }
    DiscoverInfo packet = new DiscoverInfo();
    packet.setTo(user);
    packet.setType(Type.get);
    if (capability.getNode() != null && capability.getVersion() != null)
        packet.setNode(capability.getNode() + "#" + capability.getVersion());
    try {
        ConnectionManager.getInstance().sendStanza(account, packet);
    } catch (NetworkException e) {
        return;
    }
    requests.add(new DiscoverInfoRequest(account, Jid.getStringPrep(user), packet.getStanzaId(), capability));
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) NetworkException(com.xabber.android.data.NetworkException)

Example 63 with NetworkException

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

the class MessageArchiveManager method onPreferencesResponce.

private void onPreferencesResponce(String account, Pref pref) {
    defaults.remove(account);
    for (Map<String, ArchivePreference> map : items.get(account).values()) map.clear();
    sessionSaves.clear(account);
    checkForDefaults(account, pref.getDefault());
    Boolean autoSave = pref.getAutoSave();
    if (autoSave != null) {
        if (autoSave) {
        // TODO: check whether record can be disabled.
        } else if (AccountManager.getInstance().getArchiveMode(account) == ArchiveMode.server) {
            Auto auto = new Auto();
            auto.setSave(true);
            auto.setType(Type.set);
            try {
                ConnectionManager.getInstance().sendStanza(account, auto);
            } catch (NetworkException e) {
            }
            // TODO: track results.
            saves.put(account, true);
        }
    }
    onPreferenceReceived(account, pref);
}
Also used : Auto(com.xabber.xmpp.archive.Auto) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

NetworkException (com.xabber.android.data.NetworkException)63 Message (org.jivesoftware.smack.packet.Message)13 OtrException (net.java.otr4j.OtrException)11 AccountItem (com.xabber.android.data.account.AccountItem)10 AbstractChat (com.xabber.android.data.message.AbstractChat)10 AccountJid (com.xabber.android.data.entity.AccountJid)9 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 Presence (org.jivesoftware.smack.packet.Presence)4 Intent (android.content.Intent)3 Set (com.xabber.xmpp.rsm.Set)3 File (java.io.File)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 NotificationState (com.xabber.android.data.message.NotificationState)2 RegularChat (com.xabber.android.data.message.RegularChat)2 OnRosterChangedListener (com.xabber.android.data.roster.OnRosterChangedListener)2