diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-08-03 22:24:16 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-08-03 22:24:16 +0200 |
commit | 316b0203f8b68242ccd19bbf4f31e776fad5875a (patch) | |
tree | 0d6571ac13ab667b599b5a2174482f966a7d7e72 /src/main/java/de/pixart/messenger/entities | |
parent | c0ed19f913d8969d5cde9afed892ff4b516ddbc8 (diff) |
call onMessageFound outside sync block
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
-rw-r--r-- | src/main/java/de/pixart/messenger/entities/Conversation.java | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index fe89009d3..cc995a30b 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -165,47 +165,61 @@ 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 void findFailedMessagesWithFiles(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) { - if (message.getStatus() == Message.STATUS_SEND_FAILED && !message.isDeleted() && message.needsUploading()) { - onMessageFound.onMessageFound(message); + for (final Message m : this.messages) { + if (m.isFileOrImage() && m.getEncryption() != Message.ENCRYPTION_PGP) { + if (m.getStatus() == Message.STATUS_SEND_FAILED && !m.isDeleted() && m.needsUploading()) { + results.add(m); } } } } + for(Message result : results) { + onMessageFound.onMessageFound(result); + } } public Message findMessageWithFileAndUuid(final String uuid) { @@ -281,14 +295,17 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } 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) { |