mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Fix OfflineMessageManager.getMessages(List<STring>)
by implementing a new logic how the messages are retrieved. Previously in case the node list has exactly one item, the method would perform an unnecessary call to nextResult() causing a delay. Fixes SMACK-785.
This commit is contained in:
parent
809ab6f42f
commit
52bd680bb5
1 changed files with 15 additions and 6 deletions
|
@ -19,6 +19,8 @@ package org.jivesoftware.smackx.offline;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
@ -58,6 +60,8 @@ import org.jivesoftware.smackx.xdata.Form;
|
||||||
*/
|
*/
|
||||||
public class OfflineMessageManager {
|
public class OfflineMessageManager {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(OfflineMessageManager.class.getName());
|
||||||
|
|
||||||
private final static String namespace = "http://jabber.org/protocol/offline";
|
private final static String namespace = "http://jabber.org/protocol/offline";
|
||||||
|
|
||||||
private final XMPPConnection connection;
|
private final XMPPConnection connection;
|
||||||
|
@ -144,7 +148,7 @@ public class OfflineMessageManager {
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public List<Message> getMessages(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public List<Message> getMessages(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
List<Message> messages = new ArrayList<Message>();
|
List<Message> messages = new ArrayList<Message>(nodes.size());
|
||||||
OfflineMessageRequest request = new OfflineMessageRequest();
|
OfflineMessageRequest request = new OfflineMessageRequest();
|
||||||
for (String node : nodes) {
|
for (String node : nodes) {
|
||||||
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
|
OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
|
||||||
|
@ -165,12 +169,17 @@ public class OfflineMessageManager {
|
||||||
try {
|
try {
|
||||||
connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
|
connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
|
||||||
// Collect the received offline messages
|
// Collect the received offline messages
|
||||||
Message message = messageCollector.nextResult();
|
Message message;
|
||||||
while (message != null && pendingNodes > 0) {
|
do {
|
||||||
pendingNodes--;
|
|
||||||
messages.add(message);
|
|
||||||
message = messageCollector.nextResult();
|
message = messageCollector.nextResult();
|
||||||
|
if (message != null) {
|
||||||
|
messages.add(message);
|
||||||
|
pendingNodes--;
|
||||||
|
} else if (message == null && pendingNodes > 0) {
|
||||||
|
LOGGER.log(Level.WARNING,
|
||||||
|
"Did not receive all expected offline messages. " + pendingNodes + " are missing.");
|
||||||
}
|
}
|
||||||
|
} while (message != null && pendingNodes > 0);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Stop queuing offline messages
|
// Stop queuing offline messages
|
||||||
|
|
Loading…
Reference in a new issue