Search in sources :

Example 1 with DataFormType

use of com.xabber.xmpp.form.DataFormType in project xabber-android by redsolution.

the class SSNManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    String from = packet.getFrom();
    if (from == null)
        return;
    if (!(connection instanceof AccountItem) || !(packet instanceof Message))
        return;
    String account = ((AccountItem) connection).getAccount();
    Message message = (Message) packet;
    String session = message.getThread();
    if (session == null)
        return;
    for (ExtensionElement packetExtension : packet.getExtensions()) if (packetExtension instanceof Feature) {
        Feature feature = (Feature) packetExtension;
        if (!feature.isValid())
            continue;
        DataFormType type = feature.getDataFormType();
        if (type == DataFormType.form)
            onFormReceived(account, from, bareAddress, session, feature);
        else if (type == DataFormType.submit)
            onSubmitReceived(account, from, bareAddress, session, feature);
        else if (type == DataFormType.result)
            onResultReceived(account, from, bareAddress, session, feature);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) DataFormType(com.xabber.xmpp.form.DataFormType) Feature(com.xabber.xmpp.ssn.Feature)

Example 2 with DataFormType

use of com.xabber.xmpp.form.DataFormType in project xabber-android by redsolution.

the class Feature method isValid.

@Override
public boolean isValid() {
    if (dataForm == null)
        return false;
    DataFormType dataFormType = getDataFormType();
    if (dataFormType == null || dataFormType == DataFormType.cancel)
        return false;
    int selected = 0;
    if (getAcceptValue() != null)
        selected += 1;
    if (getRenegotiateValue() != null)
        selected += 1;
    if (getTerminateValue() != null) {
        if (!getTerminateValue() || getDataFormType() != DataFormType.submit)
            return false;
        selected += 1;
    }
    if (selected != 1)
        return false;
    return FORM_TYPE_VALUE.equals(getValue(FORM_TYPE_FIELD));
}
Also used : DataFormType(com.xabber.xmpp.form.DataFormType)

Aggregations

DataFormType (com.xabber.xmpp.form.DataFormType)2 AccountItem (com.xabber.android.data.account.AccountItem)1 Feature (com.xabber.xmpp.ssn.Feature)1 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 Message (org.jivesoftware.smack.packet.Message)1