aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java45
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java16
2 files changed, 33 insertions, 28 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) {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index b5574ca2a..068384a60 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -1482,13 +1482,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));
}
private void resendFailedFileMessages(final Conversation conversation) {
@@ -3470,13 +3464,7 @@ public class XmppConnectionService extends Service {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": reset 'sending' messages to 'waiting'");
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));
}
}
}