Search in sources :

Example 16 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.

the class CapabilitiesManager method onPresenceChanged.

public void onPresenceChanged(final String account, final Presence presence) {
    final String user = Jid.getStringPrep(presence.getFrom());
    if (user == null)
        return;
    if (presence.getType() == Presence.Type.error)
        return;
    if (presence.getType() == Presence.Type.unavailable) {
        userCapabilities.remove(account, user);
        return;
    }
    LogManager.i(this, "onPresenceChanged " + user);
    for (ExtensionElement packetExtension : presence.getExtensions()) {
        if (packetExtension instanceof CapsExtension) {
            CapsExtension capsExtension = (CapsExtension) packetExtension;
            if (capsExtension.getNode() == null || capsExtension.getVer() == null) {
                continue;
            }
            Capability capability = new Capability(account, user, capsExtension.getHash(), capsExtension.getNode(), capsExtension.getVer());
            if (capability.equals(userCapabilities.get(account, user))) {
                continue;
            }
            userCapabilities.put(account, user, capability);
            ClientInfo clientInfo = clientInformations.get(capability);
            if (clientInfo == null || clientInfo == INVALID_CLIENT_INFO) {
                request(account, presence.getFrom(), capability);
            }
        }
    }
}
Also used : ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) CapsExtension(org.jivesoftware.smackx.caps.packet.CapsExtension)

Example 17 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.

the class CapabilitiesManager method calculateString.

private String calculateString(DiscoverInfo discoverInfo) {
    StringBuilder s = new StringBuilder();
    SortedSet<String> identities = new TreeSet<>();
    for (DiscoverInfo.Identity identity : discoverInfo.getIdentities()) {
        StringBuilder builder = new StringBuilder();
        builder.append(identity.getCategory());
        builder.append("/");
        String type = identity.getType();
        if (type != null) {
            builder.append(type);
        }
        builder.append("/");
        String lang = identity.getLanguage();
        if (lang != null) {
            builder.append(lang);
        }
        builder.append("/");
        String name = identity.getName();
        if (name != null) {
            builder.append(name);
        }
        identities.add(builder.toString());
    }
    for (String identity : identities) {
        s.append(identity);
        s.append("<");
    }
    SortedSet<String> features = new TreeSet<>();
    for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
        features.add(feature.getVar());
    }
    for (String feature : features) {
        s.append(feature);
        s.append("<");
    }
    // Maps prepared value to FORM_TYPE key.
    // Extensions with equal FORM_TYPEs are not allowed.
    SortedMap<String, String> extendeds = new TreeMap<>();
    for (ExtensionElement packetExtension : discoverInfo.getExtensions()) {
        if (packetExtension instanceof DataForm) {
            DataForm dataForm = (DataForm) packetExtension;
            // Fields with equal var are allowed for fixed type.
            SortedSet<FormField> formFields = new TreeSet<>(new Comparator<FormField>() {

                @Override
                public int compare(FormField f1, FormField f2) {
                    // Var may not exists for fixed type.
                    String s1 = f1.getVariable();
                    String s2 = f2.getVariable();
                    return (s1 == null ? "" : s1).compareTo(s2 == null ? "" : s2);
                }
            });
            String formType = null;
            for (FormField formField : dataForm.getFields()) {
                if (FORM_TYPE.equals(formField.getVariable())) {
                    if (formField.getType() != FormField.Type.hidden) {
                        continue;
                    }
                    for (String value : formField.getValues()) {
                        formType = value;
                    }
                } else {
                    formFields.add(formField);
                }
            }
            if (formType == null) {
                continue;
            }
            StringBuilder builder = new StringBuilder();
            builder.append(formType);
            builder.append("<");
            for (FormField formField : formFields) {
                builder.append(formField.getVariable());
                builder.append("<");
                SortedSet<String> values = new TreeSet<>();
                for (String value : formField.getValues()) {
                    values.add(value);
                }
                for (String value : values) {
                    builder.append(value);
                    builder.append("<");
                }
            }
            extendeds.put(formType, builder.toString());
        }
    }
    for (Entry<String, String> extended : extendeds.entrySet()) {
        s.append(extended.getValue());
    }
    return s.toString();
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) TreeMap(java.util.TreeMap) TreeSet(java.util.TreeSet) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 18 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.

the class MessageManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    if (bareAddress == null) {
        return;
    }
    if (packet instanceof Message && MessageArchiveManager.getInstance().isModificationsSucceed(account) && Delay.isOfflineMessage(Jid.getServer(account), packet)) {
        // archive have been received.
        return;
    }
    String contact = bareAddress;
    if (packet instanceof Message) {
        Message message = (Message) packet;
        if (MUCManager.getInstance().hasRoom(account, bareAddress) && message.getType() != Message.Type.groupchat) {
            contact = packet.getFrom();
        }
    }
    final String user = packet.getFrom();
    boolean processed = false;
    for (AbstractChat chat : chats.getNested(account).values()) {
        if (chat.onPacket(contact, packet)) {
            processed = true;
            break;
        }
    }
    final AbstractChat chat = getChat(account, user);
    if (chat != null && packet instanceof Message) {
        if (chat.isPrivateMucChat() && !chat.isPrivateMucChatAccepted()) {
            if (mucPrivateChatRequestProvider.get(chat.getAccount(), chat.getUser()) == null) {
                if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(chat.getUser())) {
                    mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
                }
            }
        }
        return;
    }
    if (!processed && packet instanceof Message) {
        final Message message = (Message) packet;
        final String body = message.getBody();
        if (body == null) {
            return;
        }
        if (message.getType() == Message.Type.chat && MUCManager.getInstance().hasRoom(account, Jid.getBareAddress(user))) {
            createPrivateMucChat(account, user).onPacket(contact, packet);
            if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(user)) {
                mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
            }
            return;
        }
        for (ExtensionElement packetExtension : message.getExtensions()) {
            if (packetExtension instanceof MUCUser) {
                return;
            }
        }
        createChat(account, user).onPacket(contact, packet);
    }
}
Also used : MucPrivateChatNotification(com.xabber.android.data.message.chat.MucPrivateChatNotification) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 19 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project xabber-android by redsolution.

the class AttentionManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    if (!(packet instanceof Message))
        return;
    if (!SettingsManager.chatsAttention())
        return;
    final String account = ((AccountItem) connection).getAccount();
    if (bareAddress == null)
        return;
    for (ExtensionElement packetExtension : packet.getExtensions()) {
        if (packetExtension instanceof Attention) {
            MessageManager.getInstance().openChat(account, bareAddress);
            MessageManager.getInstance().getOrCreateChat(account, bareAddress).newAction(null, null, ChatAction.attention_requested);
            attentionRequestProvider.add(new AttentionRequest(account, bareAddress), true);
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) Attention(com.xabber.xmpp.attention.Attention) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 20 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement 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)

Aggregations

ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)32 Test (org.junit.Test)9 XmlPullParser (org.xmlpull.v1.XmlPullParser)9 AccountItem (com.xabber.android.data.account.AccountItem)7 Message (org.jivesoftware.smack.packet.Message)7 Stanza (org.jivesoftware.smack.packet.Stanza)4 LinkedList (java.util.LinkedList)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 TreeSet (java.util.TreeSet)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 Presence (org.jivesoftware.smack.packet.Presence)2 AMPExtension (org.jivesoftware.smackx.amp.packet.AMPExtension)2 AMPExtensionProvider (org.jivesoftware.smackx.amp.provider.AMPExtensionProvider)2 Base64BinaryChunk (org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk)2 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)2 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)2 RSMSet (org.jivesoftware.smackx.rsm.packet.RSMSet)2 FormField (org.jivesoftware.smackx.xdata.FormField)2 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)2 NetworkException (com.xabber.android.data.NetworkException)1