Search in sources :

Example 21 with ExtensionElement

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

the class ReceiptManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final Jid from = packet.getFrom();
    if (from == null) {
        return;
    }
    if (!(packet instanceof Message)) {
        return;
    }
    final Message message = (Message) packet;
    if (message.getType() == Message.Type.error) {
        Application.getInstance().runInBackgroundUserRequest(new Runnable() {

            @Override
            public void run() {
                markAsError(account, message);
            }
        });
    } else {
        // TODO setDefaultAutoReceiptMode should be used
        for (ExtensionElement packetExtension : message.getExtensions()) {
            if (packetExtension instanceof DeliveryReceiptRequest) {
                String id = message.getStanzaId();
                if (id == null) {
                    continue;
                }
                Message receipt = new Message(from);
                receipt.addExtension(new DeliveryReceipt(id));
                // the key problem is Thread - smack does not keep it in auto reply
                receipt.setThread(message.getThread());
                try {
                    StanzaSender.sendStanza(account, receipt);
                } catch (NetworkException e) {
                    LogManager.exception(this, e);
                }
            }
        }
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) DeliveryReceiptRequest(org.jivesoftware.smackx.receipts.DeliveryReceiptRequest) AccountJid(com.xabber.android.data.entity.AccountJid) DeliveryReceipt(org.jivesoftware.smackx.receipts.DeliveryReceipt) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) NetworkException(com.xabber.android.data.NetworkException)

Example 22 with ExtensionElement

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

the class AvatarManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(stanza instanceof Presence)) {
        return;
    }
    AccountJid account = ((AccountItem) connection).getAccount();
    Presence presence = (Presence) stanza;
    if (presence.getType() == Presence.Type.error) {
        return;
    }
    for (ExtensionElement packetExtension : presence.getExtensions()) {
        if (packetExtension instanceof VCardUpdate) {
            VCardUpdate vCardUpdate = (VCardUpdate) packetExtension;
            if (vCardUpdate.isValid() && vCardUpdate.isPhotoReady()) {
                try {
                    onPhotoReady(account, UserJid.from(stanza.getFrom()), vCardUpdate);
                } catch (UserJid.UserJidCreateException e) {
                    LogManager.exception(this, e);
                }
            }
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) UserJid(com.xabber.android.data.entity.UserJid) VCardUpdate(com.xabber.xmpp.vcardupdate.VCardUpdate)

Example 23 with ExtensionElement

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

the class ChatStateManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (stanza.getFrom() == null) {
        return;
    }
    final Resourcepart resource = stanza.getFrom().getResourceOrNull();
    if (resource == null) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final UserJid bareUserJid;
    try {
        bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
    } catch (UserJid.UserJidCreateException e) {
        return;
    }
    if (stanza instanceof Presence) {
        Presence presence = (Presence) stanza;
        if (presence.getType() != Type.unavailable) {
            return;
        }
        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
        removeCallback(account, bareUserJid.getBareJid(), resource);
        supports.remove(account.toString(), bareUserJid.toString(), resource);
    } else if (stanza instanceof Message) {
        boolean support = false;
        for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
            removeCallback(account, bareUserJid.getBareJid(), resource);
            ChatState chatState = ((ChatStateExtension) extension).getChatState();
            chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
            if (chatState != ChatState.active) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
                            return;
                        }
                        chatStates.remove(account.toString(), bareUserJid.toString(), resource);
                        removeCallback(account, bareUserJid.getBareJid(), resource);
                        RosterManager.onChatStateChanged(account, bareUserJid);
                    }
                };
                handler.postDelayed(runnable, REMOVE_STATE_DELAY);
                stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
            }
            RosterManager.onChatStateChanged(account, bareUserJid);
            support = true;
            break;
        }
        Message message = (Message) stanza;
        if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
            return;
        }
        if (support) {
            supports.put(account.toString(), bareUserJid.toString(), resource, true);
        } else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
            // Disable only if there no information about support.
            supports.put(account.toString(), bareUserJid.toString(), resource, false);
        }
    }
}
Also used : ChatState(org.jivesoftware.smackx.chatstates.ChatState) Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.chatstates.packet.ChatStateExtension) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) Presence(org.jivesoftware.smack.packet.Presence) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 24 with ExtensionElement

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

the class SSNManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    Jid from = stanza.getFrom();
    if (from == null) {
        return;
    }
    if (!(connection instanceof AccountItem) || !(stanza instanceof Message)) {
        return;
    }
    AccountJid account = ((AccountItem) connection).getAccount();
    Message message = (Message) stanza;
    String session = message.getThread();
    if (session == null) {
        return;
    }
    for (ExtensionElement packetExtension : stanza.getExtensions()) {
        if (packetExtension instanceof Feature) {
            Feature feature = (Feature) packetExtension;
            if (!feature.isValid()) {
                continue;
            }
            DataForm.Type dataFormType = feature.getDataFormType();
            if (dataFormType == DataForm.Type.form) {
                onFormReceived(account, from, session, feature);
            } else if (dataFormType == DataForm.Type.submit) {
                onSubmitReceived(account, from, session, feature);
            } else if (dataFormType == DataForm.Type.result) {
                onResultReceived(account, session, feature);
            }
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Feature(com.xabber.xmpp.ssn.Feature)

Example 25 with ExtensionElement

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

the class AttentionManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(stanza instanceof Message)) {
        return;
    }
    if (!SettingsManager.chatsAttention()) {
        return;
    }
    final AccountJid account = connection.getAccount();
    UserJid from;
    try {
        from = UserJid.from(stanza.getFrom());
    } catch (UserJid.UserJidCreateException e) {
        e.printStackTrace();
        return;
    }
    for (ExtensionElement packetExtension : stanza.getExtensions()) {
        if (packetExtension instanceof AttentionExtension) {
            MessageManager.getInstance().openChat(account, from);
            MessageManager.getInstance().getOrCreateChat(account, from).newAction(null, null, ChatAction.attention_requested);
            attentionRequestProvider.add(new AttentionRequest(account, from.getBareUserJid()), true);
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension)

Aggregations

ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)38 Message (org.jivesoftware.smack.packet.Message)12 AccountItem (com.xabber.android.data.account.AccountItem)11 Test (org.junit.Test)9 XmlPullParser (org.xmlpull.v1.XmlPullParser)9 AccountJid (com.xabber.android.data.entity.AccountJid)6 UserJid (com.xabber.android.data.entity.UserJid)4 Presence (org.jivesoftware.smack.packet.Presence)4 Stanza (org.jivesoftware.smack.packet.Stanza)4 NetworkException (com.xabber.android.data.NetworkException)3 LinkedList (java.util.LinkedList)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)3 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)3 MucPrivateChatNotification (com.xabber.android.data.message.chat.MucPrivateChatNotification)2 Feature (com.xabber.xmpp.ssn.Feature)2 TreeSet (java.util.TreeSet)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 AMPExtension (org.jivesoftware.smackx.amp.packet.AMPExtension)2 AMPExtensionProvider (org.jivesoftware.smackx.amp.provider.AMPExtensionProvider)2