Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/defualt-theme-needs-restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Nov 5, 2020
2 parents fc69e0f + 3a29953 commit 8ca82e7
Show file tree
Hide file tree
Showing 31 changed files with 1,161 additions and 568 deletions.
26 changes: 18 additions & 8 deletions src/main/java/com/faforever/client/chat/ChannelTabController.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import javafx.scene.web.WebView;
import javafx.stage.Popup;
import javafx.stage.PopupWindow;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
Expand All @@ -78,6 +79,7 @@
import static com.faforever.client.player.SocialStatus.FOE;
import static java.util.Locale.US;

@Slf4j
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ChannelTabController extends AbstractChatTabController {
Expand Down Expand Up @@ -296,8 +298,8 @@ public void initialize() {
JavaFxUtil.addListener(preferencesService.getPreferences().getChat().chatColorModeProperty(), chatColorModeChangeListener);
addUserFilterPopup();

chatUserListView.setItems(filteredChatUserList);
chatUserListView.setCellFactory(param -> new ChatUserListCell(uiService));
chatUserListView.setItems(filteredChatUserList);

autoCompletionHelper.bindTo(messageTextField());

Expand Down Expand Up @@ -330,8 +332,8 @@ private List<CategoryOrChatUserListItem> createCategoryTreeObjects() {

private void setAllMessageColors() {
Map<String, String> userToColor = new HashMap<>();
channel.getUsers().stream().filter(chatUser -> chatUser.getColor() != null).forEach(chatUser
-> userToColor.put(chatUser.getUsername(), JavaFxUtil.toRgbCode(chatUser.getColor())));
channel.getUsers().stream().filter(chatUser -> chatUser.getColor().isPresent()).forEach(chatUser
-> userToColor.put(chatUser.getUsername(), JavaFxUtil.toRgbCode(chatUser.getColor().get())));
getJsObject().call("setAllMessageColors", new Gson().toJson(userToColor));
}

Expand Down Expand Up @@ -366,6 +368,14 @@ protected void onMention(ChatMessage chatMessage) {
&& !chatMessage.getMessage().contains("@" + userService.getUsername())) {
return;
}

if (playerService.getPlayerForUsername(chatMessage.getUsername())
.filter(player -> player.getSocialStatus() == FOE)
.isPresent()) {
log.debug("Ignored ping from {}", chatMessage.getUsername());
return;
}

if (!hasFocus()) {
audioService.playChatMentionSound();
showNotificationIfNecessary(chatMessage);
Expand Down Expand Up @@ -404,8 +414,8 @@ private void addUserFilterPopup() {

private void updateUserMessageColor(ChatChannelUser chatUser) {
String color = "";
if (chatUser.getColor() != null) {
color = JavaFxUtil.toRgbCode(chatUser.getColor());
if (chatUser.getColor().isPresent()) {
color = JavaFxUtil.toRgbCode(chatUser.getColor().get());
}
getJsObject().call("updateUserMessageColor", chatUser.getUsername(), color);
}
Expand Down Expand Up @@ -461,7 +471,7 @@ private void onUserJoinedChannel(ChatChannelUser chatUser) {
JavaFxUtil.addListener(chatPrefs.hideFoeMessagesProperty(), weakHideFoeMessagesListener);

Platform.runLater(() -> {
weakColorPropertyListener.changed(chatUser.colorProperty(), null, chatUser.getColor());
weakColorPropertyListener.changed(chatUser.colorProperty(), null, chatUser.getColor().orElse(null));
weakHideFoeMessagesListener.changed(chatPrefs.hideFoeMessagesProperty(), null, chatPrefs.getHideFoeMessages());
});
}
Expand Down Expand Up @@ -641,8 +651,8 @@ protected String getInlineStyle(String username) {
} else {
ChatColorMode chatColorMode = chatPrefs.getChatColorMode();
if ((chatColorMode == ChatColorMode.CUSTOM || chatColorMode == ChatColorMode.RANDOM)
&& chatUser.getColor() != null) {
color = createInlineStyleFromColor(chatUser.getColor());
&& chatUser.getColor().isPresent()) {
color = createInlineStyleFromColor(chatUser.getColor().get());
}
}

Expand Down
134 changes: 131 additions & 3 deletions src/main/java/com/faforever/client/chat/ChatChannelUser.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.faforever.client.chat;

import com.faforever.client.clan.Clan;
import com.faforever.client.game.PlayerStatus;
import com.faforever.client.player.Player;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import lombok.ToString;

import java.time.Instant;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

/**
* Represents a chat user within a channel. If a user is in multiple channels, one instance per channel needs to be
* created since e.g. the {@code isModerator} flag is specific to the channel.
Expand All @@ -27,6 +29,15 @@ public class ChatChannelUser {
private final ObjectProperty<Color> color;
private final ObjectProperty<Player> player;
private final ObjectProperty<Instant> lastActive;
private final ObjectProperty<PlayerStatus> status;
private final ObjectProperty<Image> avatar;
private final ObjectProperty<Clan> clan;
private final StringProperty clanTag;
private final ObjectProperty<Image> countryFlag;
private final StringProperty countryName;
private final ObjectProperty<Image> mapImage;
private final ObjectProperty<Image> statusImage;
private final BooleanProperty displayed;

ChatChannelUser(String username, Color color, boolean moderator) {
this(username, color, moderator, null);
Expand All @@ -38,6 +49,15 @@ public class ChatChannelUser {
this.color = new SimpleObjectProperty<>(color);
this.player = new SimpleObjectProperty<>(player);
this.lastActive = new SimpleObjectProperty<>();
this.status = new SimpleObjectProperty<>();
this.avatar = new SimpleObjectProperty<>();
this.clan = new SimpleObjectProperty<>();
this.clanTag = new SimpleStringProperty();
this.countryFlag = new SimpleObjectProperty<>();
this.countryName = new SimpleStringProperty();
this.mapImage = new SimpleObjectProperty<>();
this.statusImage = new SimpleObjectProperty<>();
this.displayed = new SimpleBooleanProperty(false);
}

public Optional<Player> getPlayer() {
Expand All @@ -52,8 +72,8 @@ public ObjectProperty<Player> playerProperty() {
return player;
}

public Color getColor() {
return color.get();
public Optional<Color> getColor() {
return Optional.ofNullable(color.get());
}

public void setColor(Color color) {
Expand Down Expand Up @@ -101,6 +121,114 @@ public ObjectProperty<Instant> lastActiveProperty() {
return lastActive;
}

public Optional<PlayerStatus> getStatus() {
return Optional.ofNullable(status.get());
}

public void setStatus(PlayerStatus status) {
this.status.set(status);
}

public ObjectProperty<PlayerStatus> statusProperty() {
return status;
}

public Optional<Image> getAvatar() {
return Optional.ofNullable(avatar.get());
}

public void setAvatar(Image avatar) {
this.avatar.set(avatar);
}

public ObjectProperty<Image> avatarProperty() {
return avatar;
}

public Optional<Clan> getClan() {
return Optional.ofNullable(clan.get());
}

public void setClan(Clan clan) {
this.clan.set(clan);
}

public ObjectProperty<Clan> clanProperty() {
return clan;
}

public Optional<String> getClanTag() {
return Optional.ofNullable(clanTag.get());
}

public void setClanTag(String clanTag) {
this.clanTag.set(clanTag);
}

public StringProperty clanTagProperty() {
return clanTag;
}

public Optional<Image> getCountryFlag() {
return Optional.ofNullable(countryFlag.get());
}

public void setCountryFlag(Image countryFlag) {
this.countryFlag.set(countryFlag);
}

public ObjectProperty<Image> countryFlagProperty() {
return countryFlag;
}

public Optional<String> getCountryName() {
return Optional.ofNullable(countryName.get());
}

public void setCountryName(String countryName) {
this.countryName.set(countryName);
}

public StringProperty countryNameProperty() {
return countryName;
}

public Optional<Image> getMapImage() {
return Optional.ofNullable(mapImage.get());
}

public void setMapImage(Image mapImage) {
this.mapImage.set(mapImage);
}

public ObjectProperty<Image> mapImageProperty() {
return mapImage;
}

public Optional<Image> getStatusImage() {
return Optional.ofNullable(statusImage.get());
}

public void setStatusImage(Image statusImage) {
this.statusImage.set(statusImage);
}

public ObjectProperty<Image> statusImageProperty() {
return statusImage;
}

public boolean isDisplayed() {
return displayed.get();
}

public void setDisplayed(boolean displayed) {
this.displayed.set(displayed);
}

public BooleanProperty displayedProperty() {
return displayed;
}

@Override
public boolean equals(Object obj) {
return obj != null
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/com/faforever/client/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void onChannelJoined(Channel channel) {
String channelName = channel.getName();
chatService.addUsersListener(channelName, change -> {
if (change.wasRemoved()) {
onChatUserLeftChannel(channelName, change.getValueRemoved().getUsername());
onChatUserLeftChannel(change.getValueRemoved(), channelName);
}
if (change.wasAdded()) {
onUserJoinedChannel(change.getValueAdded(), channelName);
Expand Down Expand Up @@ -228,28 +228,27 @@ private void joinChannel(String channelName) {
chatService.joinChannel(channelName);
}

private void onChatUserLeftChannel(String channelName, String username) {
if (!username.equalsIgnoreCase(userService.getUsername())) {
return;
}
AbstractChatTabController chatTab = nameToChatTabController.get(channelName);
if (chatTab != null) {
Platform.runLater(() -> tabPane.getTabs().remove(chatTab.getRoot()));
private void onChatUserLeftChannel(ChatChannelUser chatUser, String channelName) {
if (isCurrentUser(chatUser)) {
AbstractChatTabController chatTab = nameToChatTabController.get(channelName);
if (chatTab != null) {
Platform.runLater(() -> tabPane.getTabs().remove(chatTab.getRoot()));
}
}
}

private void onUserJoinedChannel(ChatChannelUser chatUser, String channelName) {
Platform.runLater(() -> {
if (isCurrentUser(chatUser)) {
if (isCurrentUser(chatUser)) {
Platform.runLater(() -> {
AbstractChatTabController tabController = getOrCreateChannelTab(channelName);
onConnected();
if (channelName.equals(chatService.getDefaultChannelName())) {
Tab tab = tabController.getRoot();
tabPane.getSelectionModel().select(tab);
nameToChatTabController.get(tab.getId()).onDisplay();
}
}
});
});
}
}

private boolean isCurrentUser(ChatChannelUser chatUser) {
Expand Down
Loading

0 comments on commit 8ca82e7

Please sign in to comment.