call onMessageFound outside sync block

This commit is contained in:
Daniel Gultsch 2018-07-22 22:42:32 +02:00
parent 53a9930837
commit fd28b32d56
2 changed files with 25 additions and 34 deletions

View File

@ -151,34 +151,45 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
public void findWaitingMessages(OnMessageFound onMessageFound) { public void findWaitingMessages(OnMessageFound onMessageFound) {
final ArrayList<Message> results = new ArrayList<>();
synchronized (this.messages) { synchronized (this.messages) {
for (Message message : this.messages) { for (Message message : this.messages) {
if (message.getStatus() == Message.STATUS_WAITING) { if (message.getStatus() == Message.STATUS_WAITING) {
onMessageFound.onMessageFound(message); results.add(message);
} }
} }
} }
for(Message result : results) {
onMessageFound.onMessageFound(result);
}
} }
public void findUnreadMessages(OnMessageFound onMessageFound) { public void findUnreadMessages(OnMessageFound onMessageFound) {
final ArrayList<Message> results = new ArrayList<>();
synchronized (this.messages) { synchronized (this.messages) {
for (Message message : this.messages) { for (Message message : this.messages) {
if (!message.isRead()) { if (!message.isRead()) {
onMessageFound.onMessageFound(message); results.add(message);
} }
} }
} }
for(Message result : results) {
onMessageFound.onMessageFound(result);
}
} }
public void findMessagesWithFiles(final OnMessageFound onMessageFound) { public void findMessagesWithFiles(final OnMessageFound onMessageFound) {
final ArrayList<Message> results = new ArrayList<>();
synchronized (this.messages) { synchronized (this.messages) {
for (final Message message : this.messages) { for (final Message m : this.messages) {
if ((message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) if (m.isFileOrImage() && m.getEncryption() != Message.ENCRYPTION_PGP) {
&& message.getEncryption() != Message.ENCRYPTION_PGP) { results.add(m);
onMessageFound.onMessageFound(message);
} }
} }
} }
for(Message result : results) {
onMessageFound.onMessageFound(result);
}
} }
public Message findMessageWithFileAndUuid(final String uuid) { public Message findMessageWithFileAndUuid(final String uuid) {
@ -242,25 +253,17 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
} }
public void findUnsentMessagesWithEncryption(int encryptionType, OnMessageFound onMessageFound) { public void findUnsentTextMessages(OnMessageFound onMessageFound) {
final ArrayList<Message> results = new ArrayList<>();
synchronized (this.messages) { synchronized (this.messages) {
for (Message message : this.messages) { for (Message message : this.messages) {
if ((message.getStatus() == Message.STATUS_UNSEND || message.getStatus() == Message.STATUS_WAITING) if (message.getType() != Message.TYPE_IMAGE && message.getStatus() == Message.STATUS_UNSEND) {
&& (message.getEncryption() == encryptionType)) { results.add(message);
onMessageFound.onMessageFound(message);
} }
} }
} }
} for(Message result : results) {
onMessageFound.onMessageFound(result);
public void findUnsentTextMessages(OnMessageFound onMessageFound) {
synchronized (this.messages) {
for (Message message : this.messages) {
if (message.getType() != Message.TYPE_IMAGE
&& message.getStatus() == Message.STATUS_UNSEND) {
onMessageFound.onMessageFound(message);
}
}
} }
} }

View File

@ -1307,13 +1307,7 @@ public class XmppConnectionService extends Service {
} }
private void sendUnsentMessages(final Conversation conversation) { private void sendUnsentMessages(final Conversation conversation) {
conversation.findWaitingMessages(new Conversation.OnMessageFound() { conversation.findWaitingMessages(message -> resendMessage(message, true));
@Override
public void onMessageFound(Message message) {
resendMessage(message, true);
}
});
} }
public void resendMessage(final Message message, final boolean delay) { public void resendMessage(final Message message, final boolean delay) {
@ -3136,13 +3130,7 @@ public class XmppConnectionService extends Service {
public void resetSendingToWaiting(Account account) { public void resetSendingToWaiting(Account account) {
for (Conversation conversation : getConversations()) { for (Conversation conversation : getConversations()) {
if (conversation.getAccount() == account) { if (conversation.getAccount() == account) {
conversation.findUnsentTextMessages(new Conversation.OnMessageFound() { conversation.findUnsentTextMessages(message -> markMessage(message, Message.STATUS_WAITING));
@Override
public void onMessageFound(Message message) {
markMessage(message, Message.STATUS_WAITING);
}
});
} }
} }
} }