1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 05:52:06 +01:00

Fix DeliveryReceiptsManager.autoAddDeliveryReceiptRequests

Must use interceptors instead of sending listeners, as those are
invoked *after* the stanza has been put on the wire. Also use the
correct filter, which excludes ack messages.

Fixes SMACK-656.
This commit is contained in:
Florian Schmaus 2015-04-23 21:31:09 +02:00
parent 062e9ee415
commit 475fed8c51

View file

@ -31,6 +31,7 @@ import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.MessageTypeFilter; import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.NotFilter;
import org.jivesoftware.smack.filter.StanzaFilter; import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaExtensionFilter; import org.jivesoftware.smack.filter.StanzaExtensionFilter;
import org.jivesoftware.smack.filter.StanzaTypeFilter; import org.jivesoftware.smack.filter.StanzaTypeFilter;
@ -232,6 +233,16 @@ public class DeliveryReceiptManager extends Manager {
receiptReceivedListeners.remove(listener); receiptReceivedListeners.remove(listener);
} }
/**
* A filter for stanzas to request delivery receipts for. Notably those are message stanzas of type normal, chat or
* headline, which <b>do not</b>contain a delivery receipt, i.e. are ack messages.
*
* @see <a href="http://xmpp.org/extensions/xep-0184.html#when-ack">XEP-184 § 5.4 Ack Messages</a>
*/
private static final StanzaFilter MESSAGES_TO_REQUEST_RECEIPTS_FOR = new AndFilter(
MessageTypeFilter.NORMAL_OR_CHAT_OR_HEADLINE, new NotFilter(new StanzaExtensionFilter(
DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE)));
private static final StanzaListener AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER = new StanzaListener() { private static final StanzaListener AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER = new StanzaListener() {
@Override @Override
public void processPacket(Stanza packet) throws NotConnectedException { public void processPacket(Stanza packet) throws NotConnectedException {
@ -247,8 +258,8 @@ public class DeliveryReceiptManager extends Manager {
* @see #dontAutoAddDeliveryReceiptRequests() * @see #dontAutoAddDeliveryReceiptRequests()
*/ */
public void autoAddDeliveryReceiptRequests() { public void autoAddDeliveryReceiptRequests() {
connection().addPacketSendingListener(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER, connection().addPacketInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER,
MessageTypeFilter.NORMAL_OR_CHAT_OR_HEADLINE); MESSAGES_TO_REQUEST_RECEIPTS_FOR);
} }
/** /**
@ -258,7 +269,7 @@ public class DeliveryReceiptManager extends Manager {
* @see #autoAddDeliveryReceiptRequests() * @see #autoAddDeliveryReceiptRequests()
*/ */
public void dontAutoAddDeliveryReceiptRequests() { public void dontAutoAddDeliveryReceiptRequests() {
connection().removePacketSendingListener(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER); connection().removePacketInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER);
} }
/** /**