Search in sources :

Example 31 with ExtensionElement

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

the class CarbonManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    if (!SettingsManager.connectionUseCarbons()) {
        return;
    }
    final String user = packet.getFrom();
    if (user == null)
        return;
    if (!(packet instanceof Message))
        return;
    final Message message = (Message) packet;
    if (!getCarbonsEnabled()) {
        return;
    }
    ExtensionElement carbonExtension = null;
    Direction dir = null;
    for (ExtensionElement packetExtension : message.getExtensions()) {
        if (packetExtension instanceof Received) {
            carbonExtension = packetExtension;
            dir = Direction.received;
        } else if (packetExtension instanceof Sent) {
            carbonExtension = packetExtension;
            dir = Direction.sent;
        }
    }
    if (carbonExtension == null) {
        return;
    }
    Forwarded forwarded;
    if (dir == Direction.sent) {
        Sent carbon = (Sent) carbonExtension;
        forwarded = carbon.getForwarded();
    } else {
        Received carbon = (Received) carbonExtension;
        forwarded = carbon.getForwarded();
    }
    if (forwarded == null) {
        return;
    }
    Message forwardedMsg = (Message) forwarded.getForwardedPacket();
    MessageManager.getInstance().displayForwardedMessage(connection, forwardedMsg, dir);
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 32 with ExtensionElement

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

the class ReceiptManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    String account = ((AccountItem) connection).getAccount();
    final String user = packet.getFrom();
    if (user == null)
        return;
    if (!(packet instanceof Message))
        return;
    final Message message = (Message) packet;
    if (message.getType() == Message.Type.error) {
        final MessageItem messageItem = sent.remove(account, message.getPacketID());
        if (messageItem != null && !messageItem.isError()) {
            messageItem.markAsError();
            Application.getInstance().runInBackground(new Runnable() {

                @Override
                public void run() {
                    if (messageItem.getId() != null)
                        MessageTable.getInstance().markAsError(messageItem.getId());
                }
            });
            MessageManager.getInstance().onChatChanged(messageItem.getChat().getAccount(), messageItem.getChat().getUser(), false);
        }
    } else {
        // TODO setDefaultAutoReceiptMode should be used
        for (ExtensionElement packetExtension : message.getExtensions()) if (packetExtension instanceof DeliveryReceiptRequest) {
            String id = message.getPacketID();
            if (id == null)
                continue;
            Message receipt = new Message(user);
            receipt.addExtension(new DeliveryReceipt(id));
            // the key problem is Thread - smack does not keep it in auto reply
            receipt.setThread(message.getThread());
            try {
                ConnectionManager.getInstance().sendStanza(account, receipt);
            } catch (NetworkException e) {
                LogManager.exception(this, e);
            }
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) DeliveryReceiptRequest(org.jivesoftware.smackx.receipts.DeliveryReceiptRequest) DeliveryReceipt(org.jivesoftware.smackx.receipts.DeliveryReceipt) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) NetworkException(com.xabber.android.data.NetworkException)

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