call onMessageFound outside sync block
This commit is contained in:
parent
53a9930837
commit
fd28b32d56
|
@ -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,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) {
|
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.getType() != Message.TYPE_IMAGE
|
if (message.getType() != Message.TYPE_IMAGE && message.getStatus() == Message.STATUS_UNSEND) {
|
||||||
&& message.getStatus() == Message.STATUS_UNSEND) {
|
results.add(message);
|
||||||
onMessageFound.onMessageFound(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(Message result : results) {
|
||||||
|
onMessageFound.onMessageFound(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message findSentMessageWithUuidOrRemoteId(String id) {
|
public Message findSentMessageWithUuidOrRemoteId(String id) {
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue