kill pending queries when archiving conversation

This commit is contained in:
Daniel Gultsch 2021-03-16 10:22:52 +01:00
parent 3c60de54cb
commit 8764d11cce

View file

@ -45,7 +45,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
public static Version get(Account account) { public static Version get(Account account) {
return get(account,null); return get(account, null);
} }
public static Version get(Account account, Conversation conversation) { public static Version get(Account account, Conversation conversation) {
@ -58,8 +58,8 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
private static Version get(List<String> features) { private static Version get(List<String> features) {
final Version[] values = values(); final Version[] values = values();
for(int i = values.length -1; i >= 0; --i) { for (int i = values.length - 1; i >= 0; --i) {
for(String feature : features) { for (String feature : features) {
if (values[i].namespace.equals(feature)) { if (values[i].namespace.equals(feature)) {
return values[i]; return values[i];
} }
@ -69,8 +69,8 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
public static boolean has(List<String> features) { public static boolean has(List<String> features) {
for(String feature : features) { for (String feature : features) {
for(Version version : values()) { for (Version version : values()) {
if (version.namespace.equals(feature)) { if (version.namespace.equals(feature)) {
return true; return true;
} }
@ -80,7 +80,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
public static Element findResult(MessagePacket packet) { public static Element findResult(MessagePacket packet) {
for(Version version : values()) { for (Version version : values()) {
Element result = packet.findChild("result", version.namespace); Element result = packet.findChild("result", version.namespace);
if (result != null) { if (result != null) {
return result; return result;
@ -209,7 +209,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
void executePendingQueries(final Account account) { void executePendingQueries(final Account account) {
List<Query> pending = new ArrayList<>(); final List<Query> pending = new ArrayList<>();
synchronized (this.pendingQueries) { synchronized (this.pendingQueries) {
for (Iterator<Query> iterator = this.pendingQueries.iterator(); iterator.hasNext(); ) { for (Iterator<Query> iterator = this.pendingQueries.iterator(); iterator.hasNext(); ) {
Query query = iterator.next(); Query query = iterator.next();
@ -250,7 +250,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
if (running) { if (running) {
processFin(query, fin); processFin(query, fin);
} else { } else {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ignoring MAM iq result because query had been killed"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": ignoring MAM iq result because query had been killed");
} }
} else if (p.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) { } else if (p.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) {
//do nothing //do nothing
@ -303,7 +303,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
public boolean isCatchupInProgress(Conversation conversation) { public boolean isCatchupInProgress(Conversation conversation) {
synchronized (this.queries) { synchronized (this.queries) {
for(Query query : queries) { for (Query query : queries) {
if (query.account == conversation.getAccount() && query.isCatchup()) { if (query.account == conversation.getAccount() && query.isCatchup()) {
final Jid with = query.getWith() == null ? null : query.getWith().asBareJid(); final Jid with = query.getWith() == null ? null : query.getWith().asBareJid();
if ((conversation.getMode() == Conversational.MODE_SINGLE && with == null) || (conversation.getJid().asBareJid().equals(with))) { if ((conversation.getMode() == Conversational.MODE_SINGLE && with == null) || (conversation.getJid().asBareJid().equals(with))) {
@ -390,8 +390,17 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
} }
void kill(Conversation conversation) { void kill(final Conversation conversation) {
final ArrayList<Query> toBeKilled = new ArrayList<>(); final ArrayList<Query> toBeKilled = new ArrayList<>();
synchronized (this.pendingQueries) {
for (final Iterator<Query> iterator = this.pendingQueries.iterator(); iterator.hasNext(); ) {
final Query query = iterator.next();
if (query.getConversation() == conversation) {
iterator.remove();
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": killed pending MAM query for archived conversation");
}
}
}
synchronized (this.queries) { synchronized (this.queries) {
for (final Query q : queries) { for (final Query q : queries) {
if (q.conversation == conversation) { if (q.conversation == conversation) {
@ -399,7 +408,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
} }
} }
for (Query q : toBeKilled) { for (final Query q : toBeKilled) {
kill(q); kill(q);
} }
} }