Merge pull request #145 from informatik-ag-ngl/f/read_status
Reading the current chat if it changes or a message is received
This commit is contained in:
commit
db38d6f609
@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import envoy.client.net.WriteProxy;
|
import envoy.client.net.WriteProxy;
|
||||||
import envoy.data.*;
|
import envoy.data.*;
|
||||||
@ -42,6 +43,27 @@ public final class Chat implements Serializable {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); }
|
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
|
* 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
|
* {@code READ} starting from the bottom and stopping once a read message is
|
||||||
|
@ -91,9 +91,14 @@ public final class ChatScene {
|
|||||||
localDB.getChat(message.getSenderID()).ifPresent(chat -> {
|
localDB.getChat(message.getSenderID()).ifPresent(chat -> {
|
||||||
chat.getMessages().add(message);
|
chat.getMessages().add(message);
|
||||||
|
|
||||||
// Update UI if in current chat
|
if (chat.equals(currentChat)) {
|
||||||
if (chat == currentChat)
|
try {
|
||||||
|
currentChat.read(writeProxy);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
logger.log(Level.WARNING, "Could not read current chat: ", e1);
|
||||||
|
}
|
||||||
Platform.runLater(messageList::refresh);
|
Platform.runLater(messageList::refresh);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -163,7 +168,7 @@ public final class ChatScene {
|
|||||||
@FXML
|
@FXML
|
||||||
private void userListClicked() {
|
private void userListClicked() {
|
||||||
final Contact user = userList.getSelectionModel().getSelectedItem();
|
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());
|
contactLabel.setText(user.getName());
|
||||||
|
|
||||||
// LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes
|
// LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes
|
||||||
@ -175,6 +180,13 @@ public final class ChatScene {
|
|||||||
|
|
||||||
messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
|
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.setVisible(true);
|
||||||
remainingChars
|
remainingChars
|
||||||
.setText(String.format("remaining chars: %d/%d", MAX_MESSAGE_LENGTH - messageTextArea.getText().length(), MAX_MESSAGE_LENGTH));
|
.setText(String.format("remaining chars: %d/%d", MAX_MESSAGE_LENGTH - messageTextArea.getText().length(), MAX_MESSAGE_LENGTH));
|
||||||
|
Reference in New Issue
Block a user