run mam queries only when online
This commit is contained in:
parent
5cbae25808
commit
f8a496a5f1
|
@ -3,7 +3,9 @@ package eu.siacs.conversations.services;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
|
@ -22,6 +24,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
private final XmppConnectionService mXmppConnectionService;
|
private final XmppConnectionService mXmppConnectionService;
|
||||||
|
|
||||||
private final HashSet<Query> queries = new HashSet<Query>();
|
private final HashSet<Query> queries = new HashSet<Query>();
|
||||||
|
private ArrayList<Query> pendingQueries = new ArrayList<Query>();
|
||||||
|
|
||||||
public enum PagingOrder {
|
public enum PagingOrder {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
|
@ -83,18 +86,41 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void executePendingQueries(final Account account) {
|
||||||
|
List<Query> pending = new ArrayList<>();
|
||||||
|
synchronized(this.pendingQueries) {
|
||||||
|
for(Iterator<Query> iterator = this.pendingQueries.iterator(); iterator.hasNext();) {
|
||||||
|
Query query = iterator.next();
|
||||||
|
if (query.getAccount() == account) {
|
||||||
|
pending.add(query);
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Query query : pending) {
|
||||||
|
this.execute(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void execute(final Query query) {
|
private void execute(final Query query) {
|
||||||
Log.d(Config.LOGTAG,query.getAccount().getJid().toBareJid().toString()+": running mam query "+query.toString());
|
final Account account= query.getAccount();
|
||||||
|
if (account.getStatus() == Account.State.ONLINE) {
|
||||||
|
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": running mam query " + query.toString());
|
||||||
IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query);
|
IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query);
|
||||||
this.mXmppConnectionService.sendIqPacket(query.getAccount(), packet, new OnIqPacketReceived() {
|
this.mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
if (packet.getType() == IqPacket.TYPE_ERROR) {
|
if (packet.getType() == IqPacket.TYPE_ERROR) {
|
||||||
Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": error executing mam: "+packet.toString());
|
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": error executing mam: " + packet.toString());
|
||||||
finalizeQuery(query);
|
finalizeQuery(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
synchronized (this.pendingQueries) {
|
||||||
|
this.pendingQueries.add(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finalizeQuery(Query query) {
|
private void finalizeQuery(Query query) {
|
||||||
|
|
|
@ -160,6 +160,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
||||||
for (Conversation conversation : account.pendingConferenceJoins) {
|
for (Conversation conversation : account.pendingConferenceJoins) {
|
||||||
joinMuc(conversation);
|
joinMuc(conversation);
|
||||||
}
|
}
|
||||||
|
mMessageArchiveService.executePendingQueries(account);
|
||||||
mJingleConnectionManager.cancelInTransmission();
|
mJingleConnectionManager.cancelInTransmission();
|
||||||
List<Conversation> conversations = getConversations();
|
List<Conversation> conversations = getConversations();
|
||||||
for (Conversation conversation : conversations) {
|
for (Conversation conversation : conversations) {
|
||||||
|
|
Loading…
Reference in New Issue