Search in sources :

Example 6 with ChatPrefs

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

the class PircBotXChatService method postConstruct.

@PostConstruct
void postConstruct() {
    eventBus.register(this);
    fafService.addOnMessageListener(SocialMessage.class, this::onSocialMessage);
    connectionState.addListener((observable, oldValue, newValue) -> {
        switch(newValue) {
            case DISCONNECTED:
            case CONNECTING:
                onDisconnected();
                break;
        }
    });
    addEventListener(NoticeEvent.class, this::onNotice);
    addEventListener(ConnectEvent.class, event -> connectionState.set(ConnectionState.CONNECTED));
    addEventListener(DisconnectEvent.class, event -> connectionState.set(ConnectionState.DISCONNECTED));
    addEventListener(UserListEvent.class, event -> onChatUserList(event.getChannel().getName(), chatUsers(event.getUsers())));
    addEventListener(JoinEvent.class, event -> onUserJoinedChannel(event.getChannel().getName(), getOrCreateChatUser(event.getUser())));
    addEventListener(PartEvent.class, event -> onChatUserLeftChannel(event.getChannel().getName(), event.getUser().getNick()));
    addEventListener(QuitEvent.class, event -> onChatUserQuit(event.getUser().getNick()));
    addEventListener(TopicEvent.class, event -> getOrCreateChannel(event.getChannel().getName()).setTopic(event.getTopic()));
    addEventListener(MessageEvent.class, this::onMessage);
    addEventListener(ActionEvent.class, this::onAction);
    addEventListener(PrivateMessageEvent.class, this::onPrivateMessage);
    addEventListener(MotdEvent.class, this::onMotd);
    addEventListener(OpEvent.class, event -> {
        User recipient = event.getRecipient();
        if (recipient != null) {
            onModeratorSet(event.getChannel().getName(), recipient.getNick());
        }
    });
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    chatPrefs.userToColorProperty().addListener((MapChangeListener<? super String, ? super Color>) change -> preferencesService.store());
    chatPrefs.chatColorModeProperty().addListener((observable, oldValue, newValue) -> {
        synchronized (chatUsersByName) {
            switch(newValue) {
                case CUSTOM:
                    chatUsersByName.values().stream().filter(chatUser -> chatPrefs.getUserToColor().containsKey(chatUser.getUsername().toLowerCase(US))).forEach(chatUser -> chatUser.setColor(chatPrefs.getUserToColor().get(chatUser.getUsername().toLowerCase(US))));
                    break;
                case RANDOM:
                    for (ChatUser chatUser : chatUsersByName.values()) {
                        chatUser.setColor(ColorGeneratorUtil.generateRandomColor(chatUser.getUsername().hashCode()));
                    }
                    break;
                default:
                    for (ChatUser chatUser : chatUsersByName.values()) {
                        chatUser.setColor(null);
                    }
            }
        }
    });
}
Also used : UserOfflineEvent(com.faforever.client.player.UserOfflineEvent) GenericEvent(org.pircbotx.hooks.types.GenericEvent) FXCollections.observableHashMap(javafx.collections.FXCollections.observableHashMap) StringUtils.containsIgnoreCase(org.apache.commons.lang3.StringUtils.containsIgnoreCase) TopicEvent(org.pircbotx.hooks.events.TopicEvent) LoggerFactory(org.slf4j.LoggerFactory) Irc(com.faforever.client.config.ClientProperties.Irc) ConnectionState(com.faforever.client.net.ConnectionState) HIGH(com.faforever.client.task.CompletableTask.Priority.HIGH) SocialMessage(com.faforever.client.remote.domain.SocialMessage) MotdEvent(org.pircbotx.hooks.events.MotdEvent) PreDestroy(javax.annotation.PreDestroy) Task(javafx.concurrent.Task) CUSTOM(com.faforever.client.chat.ChatColorMode.CUSTOM) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) RANDOM(com.faforever.client.chat.ChatColorMode.RANDOM) ChatPrefs(com.faforever.client.preferences.ChatPrefs) PircBotX(org.pircbotx.PircBotX) PlayerService(com.faforever.client.player.PlayerService) ClientProperties(com.faforever.client.config.ClientProperties) LoggedOutEvent(com.faforever.client.user.event.LoggedOutEvent) FafClientApplication(com.faforever.client.FafClientApplication) UserOnlineEvent(com.faforever.client.player.UserOnlineEvent) NoticeEvent(org.pircbotx.hooks.events.NoticeEvent) MapChangeListener(javafx.collections.MapChangeListener) MethodHandles(java.lang.invoke.MethodHandles) UpdateApplicationBadgeEvent(com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent) JoinEvent(org.pircbotx.hooks.events.JoinEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ObservableMap(javafx.collections.ObservableMap) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Player(com.faforever.client.player.Player) CountDownLatch(java.util.concurrent.CountDownLatch) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) DisconnectEvent(org.pircbotx.hooks.events.DisconnectEvent) ReadOnlyIntegerProperty(javafx.beans.property.ReadOnlyIntegerProperty) UserHostmask(org.pircbotx.UserHostmask) PostConstruct(javax.annotation.PostConstruct) Lazy(org.springframework.context.annotation.Lazy) NotNull(org.jetbrains.annotations.NotNull) User(org.pircbotx.User) Event(org.pircbotx.hooks.Event) ActionEvent(org.pircbotx.hooks.events.ActionEvent) TaskService(com.faforever.client.task.TaskService) PreferencesService(com.faforever.client.preferences.PreferencesService) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) IrcException(org.pircbotx.exception.IrcException) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CompletableTask(com.faforever.client.task.CompletableTask) US(java.util.Locale.US) Hashing(com.google.common.hash.Hashing) CompletableFuture(java.util.concurrent.CompletableFuture) UserService(com.faforever.client.user.UserService) MessageEvent(org.pircbotx.hooks.events.MessageEvent) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) PartEvent(org.pircbotx.hooks.events.PartEvent) Inject(javax.inject.Inject) OpEvent(org.pircbotx.hooks.events.OpEvent) Service(org.springframework.stereotype.Service) UtilSSLSocketFactory(org.pircbotx.UtilSSLSocketFactory) Subscribe(com.google.common.eventbus.Subscribe) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) ChatMessageEvent(com.faforever.client.chat.event.ChatMessageEvent) Profile(org.springframework.context.annotation.Profile) FafService(com.faforever.client.remote.FafService) QuitEvent(org.pircbotx.hooks.events.QuitEvent) Configuration(org.pircbotx.Configuration) UserListEvent(org.pircbotx.hooks.events.UserListEvent) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) ConnectEvent(org.pircbotx.hooks.events.ConnectEvent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) User(org.pircbotx.User) ChatPrefs(com.faforever.client.preferences.ChatPrefs) PostConstruct(javax.annotation.PostConstruct)

Example 7 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(String username) {
    synchronized (chatUsersByName) {
        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, new ChatUser(username, color));
        }
        return chatUsersByName.get(lowerUsername);
    }
}
Also used : ChatPrefs(com.faforever.client.preferences.ChatPrefs) Color(javafx.scene.paint.Color)

Example 8 with ChatPrefs

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

the class ChannelTabController method onUserJoinedChannel.

private synchronized void onUserJoinedChannel(ChatUser chatUser) {
    JavaFxUtil.assertBackgroundThread();
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    String username = chatUser.getUsername();
    Player player = playerService.createAndGetPlayerForUsername(username);
    player.moderatorForChannelsProperty().bind(chatUser.moderatorInChannelsProperty());
    player.usernameProperty().addListener((observable, oldValue, newValue) -> {
        Map<Pane, ChatUserItemController> userItemControllers = userToChatUserControls.get(oldValue);
        if (userItemControllers == null) {
            return;
        }
        for (Map.Entry<Pane, ChatUserItemController> entry : userItemControllers.entrySet()) {
            Pane pane = entry.getKey();
            ChatUserItemController chatUserItemController = entry.getValue();
            pane.getChildren().remove(chatUserItemController.getRoot());
            addChatUserItemSorted(pane, chatUserItemController);
        }
    });
    player.usernameProperty().bind(chatUser.usernameProperty());
    player.socialStatusProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue == OTHER && player.isChatOnly()) {
            addToPane(player, chatOnlyPane);
            setUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
        } else {
            addToPane(player, getPaneForSocialStatus(newValue));
            setUserMessageClass(player, newValue.getCssClass());
        }
        if (chatPrefs.getHideFoeMessages() && newValue == FOE) {
            updateUserMessageDisplay(player, "none");
        }
        if (oldValue == OTHER && player.isChatOnly()) {
            removeFromPane(player, chatOnlyPane);
            removeUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
        } else {
            removeFromPane(player, getPaneForSocialStatus(oldValue));
            removeUserMessageClass(player, oldValue.getCssClass());
        }
        if (chatPrefs.getHideFoeMessages() && oldValue == FOE) {
            updateUserMessageDisplay(player, "");
        }
    });
    player.chatOnlyProperty().addListener((observable, oldValue, newValue) -> {
        if (player.getSocialStatus() == OTHER && !chatUser.getModeratorInChannels().contains(username)) {
            if (newValue) {
                removeFromPane(player, othersPane);
                addToPane(player, chatOnlyPane);
                setUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
            } else {
                removeFromPane(player, chatOnlyPane);
                addToPane(player, getPaneForSocialStatus(player.getSocialStatus()));
                removeUserMessageClass(player, CSS_CLASS_CHAT_ONLY);
            }
        }
    });
    player.getModeratorForChannels().addListener((SetChangeListener<String>) change -> {
        if (change.wasAdded()) {
            addToPane(player, moderatorsPane);
            removeFromPane(player, othersPane);
            removeFromPane(player, chatOnlyPane);
            setUserMessageClass(player, CSS_CLASS_MODERATOR);
        } else {
            removeFromPane(player, moderatorsPane);
            SocialStatus socialStatus = player.getSocialStatus();
            if (socialStatus == OTHER || socialStatus == SELF) {
                addToPane(player, othersPane);
            }
            removeUserMessageClass(player, CSS_CLASS_MODERATOR);
        }
    });
    chatPrefs.hideFoeMessagesProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue && player.getSocialStatus() == FOE) {
            updateUserMessageDisplay(player, "none");
        } else {
            updateUserMessageDisplay(player, "");
        }
    });
    chatUser.colorProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> updateUserMessageColor(chatUser)));
    Collection<Pane> targetPanesForUser = getTargetPanesForUser(player);
    for (Pane pane : targetPanesForUser) {
        ChatUserItemController chatUserItemController = createChatUserControlForPlayerIfNecessary(pane, player);
        // Apply filter if exists
        if (!userSearchTextField.textProperty().get().isEmpty()) {
            chatUserItemController.setVisible(isUsernameMatch(chatUserItemController));
        }
        if (filterUserPopup.isShowing()) {
            userFilterController.filterUser(chatUserItemController);
        }
    }
}
Also used : Button(javafx.scene.control.Button) UiService(com.faforever.client.theme.UiService) TextInputControl(javafx.scene.control.TextInputControl) Date(java.util.Date) ImageUploadService(com.faforever.client.uploader.ImageUploadService) ReportingService(com.faforever.client.reporting.ReportingService) VBox(javafx.scene.layout.VBox) AudioService(com.faforever.client.audio.AudioService) TimeService(com.faforever.client.util.TimeService) Gson(com.google.gson.Gson) Duration(java.time.Duration) Map(java.util.Map) OTHER(com.faforever.client.chat.SocialStatus.OTHER) ChatPrefs(com.faforever.client.preferences.ChatPrefs) SELF(com.faforever.client.chat.SocialStatus.SELF) PlayerService(com.faforever.client.player.PlayerService) Pane(javafx.scene.layout.Pane) ClientProperties(com.faforever.client.config.ClientProperties) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) MapChangeListener(javafx.collections.MapChangeListener) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TaskScheduler(org.springframework.scheduling.TaskScheduler) KeyEvent(javafx.scene.input.KeyEvent) Instant(java.time.Instant) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) ObservableList(javafx.collections.ObservableList) Bounds(javafx.geometry.Bounds) PreferencesService(com.faforever.client.preferences.PreferencesService) WeakChangeListener(javafx.beans.value.WeakChangeListener) DEFAULT(com.faforever.client.chat.ChatColorMode.DEFAULT) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SetChangeListener(javafx.collections.SetChangeListener) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) UserService(com.faforever.client.user.UserService) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) PlatformService(com.faforever.client.fx.PlatformService) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) KeyCode(javafx.scene.input.KeyCode) WebView(javafx.scene.web.WebView) TitledPane(javafx.scene.control.TitledPane) PopupWindow(javafx.stage.PopupWindow) ClanService(com.faforever.client.clan.ClanService) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Node(javafx.scene.Node) ReplayService(com.faforever.client.replay.ReplayService) FOE(com.faforever.client.chat.SocialStatus.FOE) WebViewConfigurer(com.faforever.client.fx.WebViewConfigurer) Popup(javafx.stage.Popup) ActionEvent(javafx.event.ActionEvent) Component(org.springframework.stereotype.Component) Tab(javafx.scene.control.Tab) ExternalReplayInfoGenerator(com.faforever.client.replay.ExternalReplayInfoGenerator) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) ChangeListener(javafx.beans.value.ChangeListener) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Player(com.faforever.client.player.Player) ChatPrefs(com.faforever.client.preferences.ChatPrefs) Pane(javafx.scene.layout.Pane) TitledPane(javafx.scene.control.TitledPane) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 9 with ChatPrefs

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

the class AbstractChatTabController method getInlineStyle.

@VisibleForTesting
String getInlineStyle(String username) {
    ChatUser chatUser = chatService.getOrCreateChatUser(username);
    Player player = playerService.getPlayerForUsername(username);
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    String color = "";
    String display = "";
    if (chatPrefs.getHideFoeMessages() && player != null && player.getSocialStatus() == FOE) {
        display = "display: none;";
    } else if (player != null && (player.getSocialStatus() == SELF || player.getSocialStatus() == FRIEND)) {
        return "";
    } else {
        ChatColorMode chatColorMode = chatPrefs.getChatColorMode();
        if ((chatColorMode == ChatColorMode.CUSTOM || chatColorMode == ChatColorMode.RANDOM) && chatUser.getColor() != null) {
            color = createInlineStyleFromColor(chatUser.getColor());
        }
    }
    return String.format("%s%s", color, display);
}
Also used : Player(com.faforever.client.player.Player) ChatPrefs(com.faforever.client.preferences.ChatPrefs) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with ChatPrefs

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

the class ChatUserItemController method configureColor.

private void configureColor() {
    ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
    if (player.getSocialStatus() == SELF) {
        usernameLabel.getStyleClass().add(SELF.getCssClass());
        clanMenu.getStyleClass().add(SELF.getCssClass());
        return;
    }
    Color color = null;
    String lowerUsername = player.getUsername().toLowerCase(US);
    ChatUser chatUser = chatService.getOrCreateChatUser(lowerUsername);
    if (chatPrefs.getChatColorMode() == CUSTOM) {
        synchronized (chatPrefs.getUserToColor()) {
            if (chatPrefs.getUserToColor().containsKey(lowerUsername)) {
                color = chatPrefs.getUserToColor().get(lowerUsername);
            }
            chatPrefs.getUserToColor().addListener(new WeakMapChangeListener<>(colorPerUserMapChangeListener));
        }
    } else if (chatPrefs.getChatColorMode() == ChatColorMode.RANDOM && colorsAllowedInPane) {
        color = ColorGeneratorUtil.generateRandomColor(chatUser.getUsername().hashCode());
    }
    chatUser.setColor(color);
    assignColor(color);
}
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