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

View file

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