Merge branch 'develop' into b/postbutton_bug_and_logging
This commit is contained in:
		@@ -4,6 +4,7 @@ import java.io.IOException;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
import envoy.client.net.WriteProxy;
 | 
			
		||||
import envoy.data.*;
 | 
			
		||||
@@ -42,6 +43,27 @@ public final class Chat implements Serializable {
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Generates a hash code based on the recipient.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	@Override
 | 
			
		||||
	public int hashCode() { return Objects.hash(recipient); }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Tests equality to another object based on the recipient.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean equals(Object obj) {
 | 
			
		||||
		if (this == obj) return true;
 | 
			
		||||
		if (!(obj instanceof Chat)) return false;
 | 
			
		||||
		Chat other = (Chat) obj;
 | 
			
		||||
		return Objects.equals(recipient, other.recipient);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sets the status of all chat messages received from the recipient to
 | 
			
		||||
	 * {@code READ} starting from the bottom and stopping once a read message is
 | 
			
		||||
 
 | 
			
		||||
@@ -91,8 +91,14 @@ public final class ChatScene {
 | 
			
		||||
			localDB.getChat(message.getSenderID()).ifPresent(chat -> {
 | 
			
		||||
				chat.getMessages().add(message);
 | 
			
		||||
 | 
			
		||||
				// Update UI if in current chat
 | 
			
		||||
				if (chat == currentChat) Platform.runLater(messageList::refresh);
 | 
			
		||||
				if (chat.equals(currentChat)) {
 | 
			
		||||
					try {
 | 
			
		||||
						currentChat.read(writeProxy);
 | 
			
		||||
					} catch (IOException e1) {
 | 
			
		||||
						logger.log(Level.WARNING, "Could not read current chat: ", e1);
 | 
			
		||||
					}
 | 
			
		||||
					Platform.runLater(messageList::refresh);
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
@@ -157,7 +163,7 @@ public final class ChatScene {
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void userListClicked() {
 | 
			
		||||
		final Contact user = userList.getSelectionModel().getSelectedItem();
 | 
			
		||||
		if (user != null && (currentChat == null || user.getID() != currentChat.getRecipient().getID())) {
 | 
			
		||||
		if (user != null && (currentChat == null || !user.equals(currentChat.getRecipient()))) {
 | 
			
		||||
			contactLabel.setText(user.getName());
 | 
			
		||||
 | 
			
		||||
			// LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes
 | 
			
		||||
@@ -168,6 +174,13 @@ public final class ChatScene {
 | 
			
		||||
 | 
			
		||||
			messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
 | 
			
		||||
 | 
			
		||||
			// Read the current chat
 | 
			
		||||
			try {
 | 
			
		||||
				currentChat.read(writeProxy);
 | 
			
		||||
			} catch (IOException e) {
 | 
			
		||||
				logger.log(Level.WARNING, "Could not read current chat.", e);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			remainingChars.setVisible(true);
 | 
			
		||||
			remainingChars
 | 
			
		||||
				.setText(String.format("remaining chars: %d/%d", MAX_MESSAGE_LENGTH - messageTextArea.getText().length(), MAX_MESSAGE_LENGTH));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user