Search in sources :

Example 1 with ChatPrefs

use of com.faforever.client.preferences.ChatPrefs in project downlords-faf-client by FAForever.

the class PrivateChatTabController method onChatMessage.

@Override
public void onChatMessage(ChatMessage chatMessage) {
    Player player = playerService.getPlayerForUsername(chatMessage.getUsername());
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    if (player != null && player.getSocialStatus() == FOE && chatPrefs.getHideFoeMessages()) {
        return;
    }
    super.onChatMessage(chatMessage);
    if (!hasFocus()) {
        audioService.playPrivateMessageSound();
        showNotificationIfNecessary(chatMessage);
        setUnread(true);
        incrementUnreadMessagesCount(1);
        eventBus.post(new UnreadPrivateMessageEvent(chatMessage));
    }
}
Also used : Player(com.faforever.client.player.Player) UnreadPrivateMessageEvent(com.faforever.client.chat.event.UnreadPrivateMessageEvent) ChatPrefs(com.faforever.client.preferences.ChatPrefs)

Example 2 with ChatPrefs

use of com.faforever.client.preferences.ChatPrefs in project downlords-faf-client by FAForever.

the class PircBotXChatService method getOrCreateChatUser.

@Override
public ChatUser getOrCreateChatUser(User user) {
    synchronized (chatUsersByName) {
        String username = user.getNick();
        String lowerUsername = username.toLowerCase(US);
        if (!chatUsersByName.containsKey(lowerUsername)) {
            ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
            Color color = null;
            if (chatPrefs.getChatColorMode() == CUSTOM && chatPrefs.getUserToColor().containsKey(lowerUsername)) {
                color = chatPrefs.getUserToColor().get(lowerUsername);
            } else if (chatPrefs.getChatColorMode() == RANDOM) {
                color = ColorGeneratorUtil.generateRandomColor(lowerUsername.hashCode());
            }
            chatUsersByName.put(lowerUsername, ChatUser.fromIrcUser(user, color));
        }
        return chatUsersByName.get(lowerUsername);
    }
}
Also used : ChatPrefs(com.faforever.client.preferences.ChatPrefs) Color(javafx.scene.paint.Color)

Example 3 with ChatPrefs

use of com.faforever.client.preferences.ChatPrefs in project downlords-faf-client by FAForever.

the class ChatUserContextMenuController method setPlayer.

public void setPlayer(Player player) {
    this.player = player;
    showUserInfo.visibleProperty().bind(Bindings.createBooleanBinding(() -> player.getId() > 0, player.idProperty()));
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    String lowerCaseUsername = player.getUsername().toLowerCase(US);
    if (chatPrefs.getUserToColor().containsKey(lowerCaseUsername)) {
        colorPicker.setValue(chatPrefs.getUserToColor().get(lowerCaseUsername));
    } else {
        colorPicker.setValue(null);
    }
    colorPicker.valueProperty().addListener((observable, oldValue, newValue) -> {
        String lowerUsername = player.getUsername().toLowerCase(US);
        if (newValue == null) {
            chatPrefs.getUserToColor().remove(lowerUsername);
        } else {
            chatPrefs.getUserToColor().put(lowerUsername, newValue);
        }
        ChatUser chatUser = chatService.getOrCreateChatUser(lowerUsername);
        chatUser.setColor(newValue);
        chatUserContextMenuRoot.hide();
    });
    removeCustomColorItem.visibleProperty().bind(chatPrefs.chatColorModeProperty().isEqualTo(CUSTOM).and(colorPicker.valueProperty().isNotNull()).and(player.socialStatusProperty().isNotEqualTo(SELF)));
    colorPickerMenuItem.visibleProperty().bind(chatPrefs.chatColorModeProperty().isEqualTo(CUSTOM).and(player.socialStatusProperty().isNotEqualTo(SELF)));
    if (player.getSocialStatus() != SocialStatus.SELF) {
        avatarPickerMenuItem.setVisible(false);
    } else {
        loadAvailableAvatars();
    }
    kickItem.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(SELF));
    banItem.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(SELF));
    moderatorActionSeparator.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(SELF));
    sendPrivateMessageItem.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(SELF));
    addFriendItem.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(FRIEND).and(player.socialStatusProperty().isNotEqualTo(SELF)));
    removeFriendItem.visibleProperty().bind(player.socialStatusProperty().isEqualTo(FRIEND));
    addFoeItem.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(FOE).and(player.socialStatusProperty().isNotEqualTo(SELF)));
    removeFoeItem.visibleProperty().bind(player.socialStatusProperty().isEqualTo(FOE));
    joinGameItem.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(SELF).and(player.statusProperty().isEqualTo(PlayerStatus.LOBBYING).or(player.statusProperty().isEqualTo(PlayerStatus.HOSTING))));
    watchGameItem.visibleProperty().bind(player.statusProperty().isEqualTo(PlayerStatus.PLAYING));
    inviteItem.visibleProperty().bind(player.socialStatusProperty().isNotEqualTo(SELF).and(player.statusProperty().isNotEqualTo(PlayerStatus.PLAYING)));
    socialSeparator.visibleProperty().bind(addFriendItem.visibleProperty().or(removeFriendItem.visibleProperty().or(addFoeItem.visibleProperty().or(removeFoeItem.visibleProperty()))));
}
Also used : ChatPrefs(com.faforever.client.preferences.ChatPrefs)

Example 4 with ChatPrefs

use of com.faforever.client.preferences.ChatPrefs in project downlords-faf-client by FAForever.

the class ChatUserContextMenuControllerTest method setUp.

@Before
public void setUp() throws Exception {
    instance = new ChatUserContextMenuController(userService, chatService, preferencesService, playerService, gameService, replayService, notificationService, i18n, eventBus, joinGameHelper, avatarService, uiService);
    Preferences preferences = mock(Preferences.class);
    ChatPrefs chatPrefs = mock(ChatPrefs.class);
    ObjectProperty<ChatColorMode> chatColorModeObjectProperty = new SimpleObjectProperty<>();
    when(preferencesService.getPreferences()).thenReturn(preferences);
    when(preferences.getChat()).thenReturn(chatPrefs);
    when(chatPrefs.getUserToColor()).thenReturn(mock(ObservableMap.class));
    when(chatPrefs.chatColorModeProperty()).thenReturn(chatColorModeObjectProperty);
    when(avatarService.getAvailableAvatars()).thenReturn(CompletableFuture.completedFuture(Arrays.asList(new AvatarBean(new URL("http://www.example.com/avatar1.png"), "Avatar Number #1"), new AvatarBean(new URL("http://www.example.com/avatar2.png"), "Avatar Number #2"), new AvatarBean(new URL("http://www.example.com/avatar3.png"), "Avatar Number #3"))));
    loadFxml("theme/chat/chat_user_context_menu.fxml", clazz -> instance);
    player = PlayerBuilder.create(TEST_USER_NAME).socialStatus(SELF).avatar(null).game(new Game()).get();
    instance.setPlayer(player);
}
Also used : SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Game(com.faforever.client.game.Game) ChatPrefs(com.faforever.client.preferences.ChatPrefs) AvatarBean(com.faforever.client.chat.avatar.AvatarBean) ObservableMap(javafx.collections.ObservableMap) Preferences(com.faforever.client.preferences.Preferences) URL(java.net.URL) Before(org.junit.Before)

Example 5 with ChatPrefs

use of com.faforever.client.preferences.ChatPrefs in project downlords-faf-client by FAForever.

the class ChatUserItemController method initialize.

public void initialize() {
    userActivityListener = (observable) -> Platform.runLater(this::onUserActivity);
    // TODO until server side support is available, the presence status is initially set to "unknown" until the user
    // does something
    presenceStatusIndicator.setText("\uF10C");
    setIdle(false);
    chatUserItemRoot.setUserData(this);
    countryImageView.managedProperty().bind(countryImageView.visibleProperty());
    countryImageView.setVisible(false);
    statusLabel.managedProperty().bind(statusLabel.visibleProperty());
    statusLabel.visibleProperty().bind(statusLabel.textProperty().isNotEmpty());
    clanMenu.managedProperty().bind(clanMenu.visibleProperty());
    clanMenu.setVisible(false);
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    colorModeChangeListener = (observable, oldValue, newValue) -> configureColor();
    colorPerUserMapChangeListener = change -> {
        String lowerUsername = player.getUsername().toLowerCase(US);
        if (lowerUsername.equalsIgnoreCase(change.getKey())) {
            Color newColor = chatPrefs.getUserToColor().get(lowerUsername);
            assignColor(newColor);
        }
    };
    avatarChangeListener = (observable, oldValue, newValue) -> Platform.runLater(() -> setAvatarUrl(newValue));
    clanChangeListener = (observable, oldValue, newValue) -> Platform.runLater(() -> setClanTag(newValue));
    gameStatusChangeListener = (observable, oldValue, newValue) -> Platform.runLater(this::updateGameStatus);
}
Also used : ChatPrefs(com.faforever.client.preferences.ChatPrefs) Color(javafx.scene.paint.Color)

Aggregations

ChatPrefs (com.faforever.client.preferences.ChatPrefs)10 Color (javafx.scene.paint.Color)5 Player (com.faforever.client.player.Player)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ClientProperties (com.faforever.client.config.ClientProperties)2 I18n (com.faforever.client.i18n.I18n)2 PlayerService (com.faforever.client.player.PlayerService)2 PreferencesService (com.faforever.client.preferences.PreferencesService)2 UserService (com.faforever.client.user.UserService)2 EventBus (com.google.common.eventbus.EventBus)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 MapChangeListener (javafx.collections.MapChangeListener)2 ObservableMap (javafx.collections.ObservableMap)2 Inject (javax.inject.Inject)2 FafClientApplication (com.faforever.client.FafClientApplication)1