~singpolyma/cheogram-android

fd28b32d5638d49eb382fdad7b39672ab6013be9 — Daniel Gultsch 5 years ago 53a9930
call onMessageFound outside sync block
M src/main/java/eu/siacs/conversations/entities/Conversation.java => src/main/java/eu/siacs/conversations/entities/Conversation.java +23 -20
@@ 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) {

M src/main/java/eu/siacs/conversations/services/XmppConnectionService.java => src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +2 -14
@@ 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));
			}
		}
	}