fix tcp message receiving
This commit is contained in:
parent
1d3e56e9b7
commit
362f5fa2f8
3 changed files with 8 additions and 5 deletions
|
@ -33,7 +33,7 @@ public class DatabaseController {
|
|||
* @param callback Function called when the request is done
|
||||
*/
|
||||
public void addMessage(Message message, MessageCallback callback) {
|
||||
|
||||
callback.onMessageSaved();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import fr.insa.clavardator.ui.LoadingScreenController;
|
|||
import fr.insa.clavardator.ui.NoSelectionModel;
|
||||
import fr.insa.clavardator.users.PeerUser;
|
||||
import fr.insa.clavardator.util.ErrorCallback;
|
||||
import fr.insa.clavardator.util.Log;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
@ -64,8 +66,9 @@ public class ChatController implements Initializable {
|
|||
}
|
||||
|
||||
private void onMessageAdded(PeerUser user, Message message) {
|
||||
Log.v(this.getClass().getSimpleName(), "Message added: " + message.getText());
|
||||
messageList.getItems().add(message);
|
||||
messageList.scrollTo(messageList.getItems().size() - 1);
|
||||
Platform.runLater(() -> messageList.scrollTo(messageList.getItems().size() - 1));
|
||||
}
|
||||
|
||||
private void setState(State state) {
|
||||
|
|
|
@ -118,11 +118,11 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
|||
connection.receive(
|
||||
msg -> {
|
||||
Log.v(this.getClass().getSimpleName(), "Received message from " + id);
|
||||
if (msg.getClass().isInstance(UserInformation.class)) {
|
||||
if (msg instanceof UserInformation) {
|
||||
assert ((UserInformation) msg).id == getId();
|
||||
Log.v(this.getClass().getSimpleName(), "Message username: " + ((UserInformation) msg).getUsername());
|
||||
setUsername(((UserInformation) msg).getUsername());
|
||||
} else if (msg.getClass().isInstance(Message.class)) {
|
||||
} else if (msg instanceof Message) {
|
||||
assert ((Message) msg).getRecipient().id != id;
|
||||
Log.v(this.getClass().getSimpleName(), "Message text: " + ((Message) msg).getText());
|
||||
history.addMessage((Message) msg);
|
||||
|
@ -130,7 +130,7 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
|||
},
|
||||
e -> {
|
||||
Log.e(this.getClass().getSimpleName(), "Error receiving message from " + id, e);
|
||||
if (e.getClass().isInstance(EOFException.class)) {
|
||||
if (e instanceof EOFException) {
|
||||
disconnect();
|
||||
} else {
|
||||
errorCallback.onError(e);
|
||||
|
|
Loading…
Reference in a new issue