diff --git a/src/main/java/com/faforever/client/chat/PrivateChatTabController.java b/src/main/java/com/faforever/client/chat/PrivateChatTabController.java index a327a22601..36810418de 100644 --- a/src/main/java/com/faforever/client/chat/PrivateChatTabController.java +++ b/src/main/java/com/faforever/client/chat/PrivateChatTabController.java @@ -3,6 +3,8 @@ import com.faforever.client.avatar.AvatarService; import com.faforever.client.domain.server.PlayerInfo; import com.faforever.client.fx.JavaFxUtil; +import com.faforever.client.fx.ObservableConstant; +import com.faforever.client.player.PlayerService; import com.faforever.client.player.PrivatePlayerInfoController; import javafx.beans.value.ObservableValue; import javafx.scene.Node; @@ -15,11 +17,14 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import java.util.Optional; + @Component @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class PrivateChatTabController extends AbstractChatTabController { private final AvatarService avatarService; + private final PlayerService playerService; public Tab privateChatTabRoot; public ImageView avatarImageView; @@ -29,9 +34,10 @@ public class PrivateChatTabController extends AbstractChatTabController { public ScrollPane gameDetailScrollPane; @Autowired - public PrivateChatTabController(ChatService chatService, AvatarService avatarService) { + public PrivateChatTabController(ChatService chatService, AvatarService avatarService, PlayerService playerService) { super(chatService); this.avatarService = avatarService; + this.playerService = playerService; } @Override @@ -48,7 +54,10 @@ protected void onInitialize() { ObservableValue chatUser = chatChannel.flatMap( channel -> channelName.map(chanName -> channel.getUser(chanName).orElse(null))); - privatePlayerInfoController.chatUserProperty().bind(chatUser.when(showing)); + privatePlayerInfoController.playerInfoProperty() + .bind(channelName.map(playerName -> playerService.getPlayerByNameIfOnline(playerName).orElse(null)) + .when(showing)); + avatarImageView.imageProperty().bind(chatUser .flatMap(ChatChannelUser::playerProperty) diff --git a/src/main/java/com/faforever/client/player/PrivatePlayerInfoController.java b/src/main/java/com/faforever/client/player/PrivatePlayerInfoController.java index f819349b31..241dbdd8ea 100644 --- a/src/main/java/com/faforever/client/player/PrivatePlayerInfoController.java +++ b/src/main/java/com/faforever/client/player/PrivatePlayerInfoController.java @@ -1,7 +1,6 @@ package com.faforever.client.player; import com.faforever.client.achievements.AchievementService; -import com.faforever.client.chat.ChatChannelUser; import com.faforever.client.domain.api.Leaderboard; import com.faforever.client.domain.server.GameInfo; import com.faforever.client.domain.server.PlayerInfo; @@ -63,7 +62,7 @@ public class PrivatePlayerInfoController extends NodeController { public Label unlockedAchievementsLabel; public Separator separator; - private final ObjectProperty chatUser = new SimpleObjectProperty<>(); + private final ObjectProperty playerInfo = new SimpleObjectProperty<>(); private final ChangeListener playerChangeListener = (observable, oldValue, newValue) -> { if (newValue != null && !Objects.equals(oldValue, newValue)) { @@ -85,8 +84,7 @@ protected void onInitialize() { gameDetailController.setPlaytimeVisible(true); gameDetailWrapper.setVisible(false); - ObservableValue playerExistsProperty = chatUser.flatMap(user -> user.playerProperty().isNotNull()) - .when(showing); + ObservableValue playerExistsProperty = playerInfo.isNotNull().when(showing); userImageView.visibleProperty().bind(playerExistsProperty); country.visibleProperty().bind(playerExistsProperty); ratingsLabels.visibleProperty().bind(playerExistsProperty); @@ -96,36 +94,26 @@ protected void onInitialize() { unlockedAchievements.visibleProperty().bind(playerExistsProperty); unlockedAchievementsLabel.visibleProperty().bind(playerExistsProperty); - ObservableValue playerObservable = chatUser.flatMap(ChatChannelUser::playerProperty); - gamesPlayed.textProperty() - .bind(playerObservable.flatMap(PlayerInfo::numberOfGamesProperty).map(i18n::number).when(showing)); + .bind(playerInfo.flatMap(PlayerInfo::numberOfGamesProperty).map(i18n::number).when(showing)); - username.textProperty().bind(chatUser.map(ChatChannelUser::getUsername).when(showing)); + username.textProperty().bind(playerInfo.flatMap(PlayerInfo::usernameProperty).when(showing)); country.textProperty() - .bind( - playerObservable.flatMap(PlayerInfo::countryProperty).map(i18n::getCountryNameLocalized).when(showing)); + .bind(playerInfo.flatMap(PlayerInfo::countryProperty).map(i18n::getCountryNameLocalized).when(showing)); userImageView.imageProperty() - .bind(playerObservable.map(PlayerInfo::getId).map(IdenticonUtil::createIdenticon).when(showing)); - ObservableValue gameObservable = playerObservable.flatMap(PlayerInfo::gameProperty); - gameDetailController.gameProperty().bind(gameObservable.when(showing)); - gameDetailWrapper.visibleProperty().bind(gameObservable.flatMap(GameInfo::statusProperty) - .map(status -> status == GameStatus.OPEN || status == GameStatus.PLAYING) - .orElse(false) - .when(showing)); - chatUser.flatMap(ChatChannelUser::playerProperty).addListener(playerChangeListener); - } - - public void setChatUser(ChatChannelUser chatUser) { - this.chatUser.set(chatUser); - } - - public ChatChannelUser getChatUser() { - return chatUser.get(); + .bind(playerInfo.map(PlayerInfo::idProperty).map(IdenticonUtil::createIdenticon).when(showing)); + gameDetailController.gameProperty().bind(playerInfo.flatMap(PlayerInfo::gameProperty).when(showing)); + gameDetailWrapper.visibleProperty() + .bind(playerInfo.flatMap(PlayerInfo::gameProperty) + .flatMap(GameInfo::statusProperty) + .map(status -> status == GameStatus.OPEN || status == GameStatus.PLAYING) + .orElse(false) + .when(showing)); + playerInfo.addListener(playerChangeListener); } - public ObjectProperty chatUserProperty() { - return chatUser; + public ObjectProperty playerInfoProperty() { + return playerInfo; } private void populateUnlockedAchievementsLabel(PlayerInfo player) {