Fixed chat loading from LocalDB into messagList
This commit is contained in:
parent
bd0da338a7
commit
67433275bd
@ -40,6 +40,9 @@ public final class Chat implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public Chat(User recipient) { this.recipient = recipient; }
|
public Chat(User recipient) { this.recipient = recipient; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -73,7 +73,7 @@ public final class ChatSceneController {
|
|||||||
@FXML
|
@FXML
|
||||||
private void userListClicked() {
|
private void userListClicked() {
|
||||||
final User user = userList.getSelectionModel().getSelectedItem();
|
final User user = userList.getSelectionModel().getSelectedItem();
|
||||||
if (user != null && (currentChat == null || user != currentChat.getRecipient())) {
|
if (user != null && (currentChat == null || user.getID() != currentChat.getRecipient().getID())) {
|
||||||
contactLabel.setText(user.getName());
|
contactLabel.setText(user.getName());
|
||||||
|
|
||||||
// Swap observable list
|
// Swap observable list
|
||||||
@ -87,7 +87,8 @@ public final class ChatSceneController {
|
|||||||
// Load the chat or create a new one and add it to the LocalDB
|
// Load the chat or create a new one and add it to the LocalDB
|
||||||
currentChat = localDB.getChats()
|
currentChat = localDB.getChats()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(c -> c.getRecipient() == user)
|
.filter(c -> c.getRecipient().getID() == user
|
||||||
|
.getID())
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseGet(() -> { var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
|
.orElseGet(() -> { var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
|
||||||
messageList.setItems(FXCollections.observableArrayList(currentChat.getMessages()));
|
messageList.setItems(FXCollections.observableArrayList(currentChat.getMessages()));
|
||||||
@ -125,7 +126,8 @@ public final class ChatSceneController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to the server.
|
* Sends a message to the server and appends it to the current chat. If all
|
||||||
|
* message IDs have been used, a new ID generator is requested.
|
||||||
*
|
*
|
||||||
* @param message the message to send
|
* @param message the message to send
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
@ -140,7 +142,7 @@ public final class ChatSceneController {
|
|||||||
messageList.getItems().add(message);
|
messageList.getItems().add(message);
|
||||||
|
|
||||||
// Request a new ID generator if all IDs were used
|
// Request a new ID generator if all IDs were used
|
||||||
if (!localDB.getIDGenerator().hasNext()) client.requestIdGenerator();
|
if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.log(Level.SEVERE, "Error sending message", e);
|
logger.log(Level.SEVERE, "Error sending message", e);
|
||||||
|
Reference in New Issue
Block a user