/** * Forwards a message to another XMPP entity. * * @param message The original message. * @param to The receiver. */ public void forwardMessage(Message message, Jid to) { Message outerMessage = new Message(to, message.getType()); outerMessage.putExtension(new Forwarded(message, new DelayedDelivery(Instant.now()))); xmppSession.send(outerMessage); } }
/** * Extracts the idle time from a presence. * <p> * This methods first checks for a <a href="https://xmpp.org/extensions/xep-0319.html">XEP-0319: Last User Interaction in Presence</a> extension and uses <a href="https://xmpp.org/extensions/xep-0256.html">XEP-0256: Last Activity in Presence</a> semantics as fallback to determine the idle time. * <p> * Delayed delivery information is respected. * * @param presence The presence. * @return The idle time or null if the presence contains no idle information. */ public static Instant timeFromPresence(Presence presence) { // Check XEP-0319: Last User Interaction in Presence Idle idle = presence.getExtension(Idle.class); if (idle != null) { return idle.getSince().toInstant(); } LastActivity lastActivity = presence.getExtension(LastActivity.class); // Check XEP-0256: Last Activity in Presence // When a client automatically sets the user's <show/> value to "away" or "xa" (extended away), it can indicate when that particular was last active during the current presence session. if (lastActivity != null && EnumSet.of(Presence.Show.AWAY, Presence.Show.XA).contains(presence.getShow())) { return DelayedDelivery.sendDate(presence).minusSeconds(lastActivity.getSeconds()); } return null; }
private ContactExchangeManager(final XmppSession xmppSession) { super(xmppSession); this.inboundMessageListener = e -> { Message message = e.getMessage(); ContactExchange contactExchange = message.getExtension(ContactExchange.class); if (contactExchange != null) { List<ContactExchange.Item> items = getItemsToProcess(contactExchange.getItems()); if (!items.isEmpty()) { processItems(items, message.getFrom(), message.getBody(), DelayedDelivery.sendDate(message)); } } }; this.iqHandler = new AbstractIQHandler(IQ.Type.SET) { @Override protected IQ processRequest(IQ iq) { ContactExchange contactExchange = iq.getExtension(ContactExchange.class); if (xmppSession.getManager(RosterManager.class).getContact(iq.getFrom().asBareJid()) == null) { // If the receiving entity will not process the suggested action(s) because the sending entity is not in the receiving entity's roster, the receiving entity MUST return an error to the sending entity, which error SHOULD be <not-authorized/>. return iq.createError(Condition.NOT_AUTHORIZED); } else { List<ContactExchange.Item> items = getItemsToProcess(contactExchange.getItems()); if (!items.isEmpty()) { processItems(items, iq.getFrom(), null, Instant.now()); } return iq.createResult(); } } }; }
/** * Called after successful login. */ protected final void afterLogin() { if (wasLoggedIn) { XmppUtils.notifyEventListeners(connectionListeners, new ConnectionEvent(this, ConnectionEvent.Type.RECONNECTION_SUCCEEDED, null, Duration.ZERO)); } wasLoggedIn = true; // Copy the unacknowledged stanzas. Queue<Stanza> toBeResent = new ArrayDeque<>(unacknowledgedStanzas); // Then clear the queue. unacknowledgedStanzas.clear(); // Then resend everything, which the server didn't acknowledge. toBeResent.forEach(stanza -> { Instant originalSendDate = stanzaSendDate.remove(stanza); if (originalSendDate != null) { DelayedDelivery delayedDelivery = new DelayedDelivery(originalSendDate); if (stanza instanceof ExtensibleStanza && !stanza.hasExtension(DelayedDelivery.class)) { ((ExtensibleStanza) stanza).addExtension(delayedDelivery); } } this.sendInternal(stanza, true); }); }
if (received != null) { XmppUtils.notifyEventListeners(messageDeliveredListeners, new MessageDeliveredEvent(MessageDeliveryReceiptsManager.this, received.getId(), DelayedDelivery.sendDate(message), message.getFrom()));
XmppUtils.notifyEventListeners(subjectChangeListeners, new SubjectChangeEvent(ChatRoom.this, message.getSubject(), message.getFrom().getResource(), message.hasExtension(DelayedDelivery.class), DelayedDelivery.sendDate(message))); } else { XmppUtils.notifyEventListeners(inboundMessageListeners, new MessageEvent(ChatRoom.this, message, true));