Search in sources :

Example 1 with DeliveryReceipt

use of org.jivesoftware.smackx.receipts.DeliveryReceipt in project xabber-android by redsolution.

the class ReceiptManager method onReceiptReceived.

@Override
public void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza stanza) {
    DeliveryReceipt receipt = stanza.getExtension(DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE);
    if (receipt == null) {
        return;
    }
    final MessageItem messageItem = sent.remove(toJid, receipt.getId());
    if (messageItem != null && !messageItem.isDelivered()) {
        messageItem.markAsDelivered();
        MessageManager.getInstance().onChatChanged(messageItem.getChat().getAccount(), messageItem.getChat().getUser(), false);
    }
}
Also used : DeliveryReceipt(org.jivesoftware.smackx.receipts.DeliveryReceipt)

Example 2 with DeliveryReceipt

use of org.jivesoftware.smackx.receipts.DeliveryReceipt 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 3 with DeliveryReceipt

use of org.jivesoftware.smackx.receipts.DeliveryReceipt in project xabber-android by redsolution.

the class ReceiptManager method onReceiptReceived.

@Override
public void onReceiptReceived(Jid fromJid, final Jid toJid, final String receiptId, Stanza stanza) {
    DeliveryReceipt receipt = DeliveryReceipt.from((Message) stanza);
    if (receipt == null) {
        return;
    }
    markAsDelivered(toJid, receiptId);
}
Also used : DeliveryReceipt(org.jivesoftware.smackx.receipts.DeliveryReceipt)

Example 4 with DeliveryReceipt

use of org.jivesoftware.smackx.receipts.DeliveryReceipt 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

DeliveryReceipt (org.jivesoftware.smackx.receipts.DeliveryReceipt)4 NetworkException (com.xabber.android.data.NetworkException)2 AccountItem (com.xabber.android.data.account.AccountItem)2 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)2 Message (org.jivesoftware.smack.packet.Message)2 DeliveryReceiptRequest (org.jivesoftware.smackx.receipts.DeliveryReceiptRequest)2 AccountJid (com.xabber.android.data.entity.AccountJid)1 Jid (org.jxmpp.jid.Jid)1