Fixed problems with groupMemberName displaying

This commit is contained in:
DieGurke 2020-07-20 14:09:30 +02:00
parent 79a121b6b5
commit 60791f2913
3 changed files with 19 additions and 22 deletions

View File

@ -242,7 +242,7 @@ public final class ChatScene implements Restorable {
chatList.setItems(FXCollections.observableList(localDB.getChats()));
contactLabel.setText(localDB.getUser().getName());
MessageControl.setUser(localDB.getUser());
MessageControl.setLocalDB(localDB);
if (!client.isOnline()) updateInfoLabel("You are offline", "infoLabel-info");
recorder = new AudioRecorder();

View File

@ -238,5 +238,6 @@ public final class LoginScene {
sceneContext.getStage().setMinWidth(843);
sceneContext.load(SceneContext.SceneInfo.CHAT_SCENE);
sceneContext.<ChatScene>getController().initializeData(sceneContext, localDB, client, writeProxy);
sceneContext.getStage().centerOnScreen();
}
}

View File

@ -18,6 +18,7 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import envoy.client.data.LocalDB;
import envoy.client.ui.AudioControl;
import envoy.client.ui.IconUtil;
import envoy.data.GroupMessage;
@ -34,11 +35,12 @@ import envoy.util.EnvoyLog;
* Created: <strong>01.07.2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Client v0.1-beta
* @author Maximilian K&auml;fer
* @since Envoy Client v0.2-beta
*/
public class MessageControl extends Label {
private static User client;
private static LocalDB localDB;
private boolean ownMessage;
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss")
@ -54,24 +56,18 @@ public class MessageControl extends Label {
public MessageControl(Message message) {
// Creating the underlying VBox and the dateLabel
final var hbox = new HBox();
if (message.getSenderID() != client.getID() && message instanceof GroupMessage) {
client.getContacts()
if (message.getSenderID() != localDB.getUser().getID() && message instanceof GroupMessage) {
Label label = new Label();
label.getStyleClass().add("groupMemberNames");
label.setText(localDB.getUsers()
.values()
.stream()
.filter(c -> c instanceof User)
.filter(c -> c.getID() == message.getSenderID())
.findFirst()
.ifPresentOrElse(c -> {
Label label = new Label(c.getName() + " ");
label.getStyleClass().add("groupMemberNames");
hbox.getChildren().add(label);
}, () -> {
Label label = new Label("Unknown User ");
label.getStyleClass().add("groupMemberNames");
hbox.getChildren().add(label);
});
// TODO improve offline login (contacts list is empty when logging in offline)
// TODO when contact is added, unknown user has to change immediately to the
// name, not only after relogging
.map(User::getName)
.orElse("Unknown User"));
label.setPadding(new Insets(0, 5, 0, 0));
hbox.getChildren().add(label);
}
hbox.getChildren().add(new Label(dateFormat.format(message.getCreationDate())));
final var vbox = new VBox(hbox);
@ -114,7 +110,7 @@ public class MessageControl extends Label {
textLabel.setWrapText(true);
vbox.getChildren().add(textLabel);
// Setting the message status icon and background color
if (message.getSenderID() == client.getID()) {
if (message.getSenderID() == localDB.getUser().getID()) {
final var statusIcon = new ImageView(statusImages.get(message.getStatus()));
statusIcon.setPreserveRatio(true);
vbox.getChildren().add(statusIcon);
@ -147,10 +143,10 @@ public class MessageControl extends Label {
private void saveAttachment(Message message) { logger.log(Level.FINEST, "attachment saving was requested for " + message); }
/**
* @param client the user who has logged in
* @since Envoy Client v0.1-beta
* @param localDB the localDB
* @since Envoy Client v0.2-beta
*/
public static void setUser(User client) { MessageControl.client = client; }
public static void setLocalDB(LocalDB localDB) { MessageControl.localDB = localDB; }
public boolean isOwnMessage() { return ownMessage; }
}