Search in sources :

Example 61 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class OfflineMessageManager method getMessageCount.

/**
 * Returns the number of offline messages for the user of the connection.
 *
 * @return the number of offline messages for the user of the connection.
 * @throws XMPPErrorException If the user is not allowed to make this request or the server does
 *                       not support offline message retrieval.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverInfo info = serviceDiscoveryManager.discoverInfo(null, NAMESPACE);
    DataForm dataForm = DataForm.from(info, NAMESPACE);
    if (dataForm == null) {
        return 0;
    }
    String numberOfMessagesString = dataForm.getField("number_of_messages").getFirstValue();
    return Integer.parseInt(numberOfMessagesString);
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Example 62 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.

the class CustomDataProvider method parse.

@Override
public DataForm parse(XmlPullParser parser, int initialDepth) throws Exception {
    DataForm.Type dataFormType = DataForm.Type.fromString(parser.getAttributeValue("", "type"));
    DataForm dataForm = new DataForm(dataFormType);
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                String name = parser.getName();
                String namespace = parser.getNamespace();
                switch(name) {
                    case "instructions":
                        dataForm.addInstruction(parser.nextText());
                        break;
                    case "title":
                        dataForm.setTitle(parser.nextText());
                        break;
                    case "field":
                        dataForm.addField(parseField(parser));
                        break;
                    case "item":
                        dataForm.addItem(parseItem(parser));
                        break;
                    case "reported":
                        dataForm.setReportedData(parseReported(parser));
                        break;
                    // See XEP-133 Example 32 for a corner case where the data form contains this extension.
                    case RosterPacket.ELEMENT:
                        if (namespace.equals(RosterPacket.NAMESPACE)) {
                            dataForm.addExtensionElement(RosterPacketProvider.INSTANCE.parse(parser));
                        }
                        break;
                    // See XEP-141 Data Forms Layout
                    case DataLayout.ELEMENT:
                        if (namespace.equals(DataLayout.NAMESPACE)) {
                            dataForm.addExtensionElement(DataLayoutProvider.parse(parser));
                        }
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return dataForm;
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Example 63 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.

the class SSNManager method onFormReceived.

private void onFormReceived(AccountJid account, Jid from, String session, Feature feature) {
    OtrMode otrMode = getOtrMode(account, 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;
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem != null && accountItem.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(DataForm.Type.submit);
        if (feature.getAcceptValue() != null) {
            Feature.addAcceptField(dataForm, false);
            sessionStates.remove(account.toString(), session);
        } else {
            Feature.addRenegotiateField(dataForm, false);
        }
        sendFeature(account, from, session, new Feature(dataForm));
        return;
    }
    DataForm dataForm = Feature.createDataForm(DataForm.Type.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) {
        Feature.addLoggingField(dataForm, null, loggingValue);
    }
    sessionStates.put(account.toString(), session, SessionState.active);
    sendFeature(account, from, session, new Feature(dataForm));
}
Also used : LoggingValue(com.xabber.xmpp.ssn.LoggingValue) AccountItem(com.xabber.android.data.account.AccountItem) 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) SecurityValue(com.xabber.xmpp.ssn.SecurityValue)

Example 64 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.

the class SSNManager method onTerminateReceived.

private void onTerminateReceived(AccountJid account, Jid from, String session) {
    if (sessionStates.get(account.toString(), session) == null) {
        return;
    }
    sessionStates.remove(account.toString(), session);
    DataForm dataForm = Feature.createDataForm(DataForm.Type.result);
    Feature.addTerminateField(dataForm);
    sendFeature(account, from, session, new Feature(dataForm));
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Feature(com.xabber.xmpp.ssn.Feature)

Example 65 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project xabber-android by redsolution.

the class Feature method createDataForm.

public static DataForm createDataForm(DataForm.Type type) {
    DataForm dataForm = new DataForm(type);
    FormField typeField = new FormField(FORM_TYPE_FIELD);
    typeField.addValue(FORM_TYPE_VALUE);
    typeField.setType(FormField.Type.hidden);
    dataForm.addField(typeField);
    return dataForm;
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField)

Aggregations

DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)65 FormField (org.jivesoftware.smackx.xdata.FormField)23 Test (org.junit.jupiter.api.Test)13 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)12 Feature (com.xabber.xmpp.ssn.Feature)7 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)7 Date (java.util.Date)5 MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)5 OtrMode (com.xabber.xmpp.archive.OtrMode)4 LoggingValue (com.xabber.xmpp.ssn.LoggingValue)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 LinkedList (java.util.LinkedList)3 IQ (org.jivesoftware.smack.packet.IQ)3 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)3 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)3 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)3 Form (org.jivesoftware.smackx.xdata.form.Form)3 DisclosureValue (com.xabber.xmpp.ssn.DisclosureValue)2