// If a client requests a receipt, send an ack message.
if (message.getExtension(Request.class) != null && message.getId() != null) {
// Add an empty body. Otherwise some servers, won't store it in offline storage.
Message receiptMessage = new Message(message.getFrom(), Message.Type.NORMAL, " ");
receiptMessage.getExtensions().add(new Received(message.getId()));
xmppSession.send(receiptMessage);
}
// If the message is a receipt.
Received received = message.getExtension(Received.class);
if (received != null) {
DelayedDelivery delayedDelivery = message.getExtension(DelayedDelivery.class);
Date deliveryDate;
if (delayedDelivery != null) {
deliveryDate = delayedDelivery.getTimeStamp();
} else {
deliveryDate = new Date();
}
// Notify the listeners about the reception.
for (MessageDeliveredListener messageDeliveredListener : messageDeliveredListeners) {
try {
messageDeliveredListener.messageDelivered(new MessageDeliveredEvent(MessageDeliveryReceiptsManager.this, received.getId(), deliveryDate));
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage(), ex);
}
}
}