@Override public synchronized boolean removeMessage(String messageId) { for (int i = 0; i < messages.size(); i++) { if (messages.get(i).getId().compareTo(Long.parseLong(messageId)) == 0) { Message newMessage = messages.get(i); newMessage.setText(""); newMessage.setDeleted(true); newMessage.setEdited(false); newMessage.setWasEdited(false); messages.set(i, newMessage); rewriteHistory(); return true; } } return false; }
@Override public boolean updateMessage(Message message) { for (int i = 0; i < messages.size(); i++) { if (messages.get(i).getId().compareTo(message.getId()) == 0) { Message newMessage = messages.get(i); if (newMessage.isDeleted()) return false; if (newMessage.isEdited()) { newMessage.setWasEdited(true); } newMessage.setText(message.getText()); newMessage.setEdited(true); messages.set(i, newMessage); rewriteHistory(); return true; } } return false; }