Skip to content

Commit

Permalink
Remove google event bus
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Nov 18, 2023
1 parent 0e84328 commit 9c9a89f
Show file tree
Hide file tree
Showing 135 changed files with 785 additions and 1,158 deletions.
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/lombok.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ lombok.accessors.chain=true
config.stopBubbling=true
lombok.anyConstructor.addConstructorProperties=true
lombok.copyableAnnotations+=org.springframework.beans.factory.annotation.Qualifier
lombok.copyableannotations+=org.springframework.context.annotation.Lazy
15 changes: 4 additions & 11 deletions src/main/java/com/faforever/client/avatar/AvatarService.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.faforever.client.avatar;

import com.faforever.client.avatar.event.AvatarChangedEvent;
import com.faforever.client.domain.AvatarBean;
import com.faforever.client.mapstruct.AvatarMapper;
import com.faforever.client.mapstruct.CycleAvoidingMappingContext;
import com.faforever.client.player.PlayerService;
import com.faforever.client.remote.AssetService;
import com.faforever.client.remote.FafServerAccessor;
import com.google.common.eventbus.EventBus;
import javafx.scene.image.Image;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
Expand All @@ -23,11 +21,11 @@
@Lazy
@Service
@RequiredArgsConstructor
public class AvatarService implements InitializingBean {
public class AvatarService {

private final FafServerAccessor fafServerAccessor;
private final AssetService assetService;
private final EventBus eventBus;
private final PlayerService playerService;
private final AvatarMapper avatarMapper;

@Cacheable(value = AVATARS, sync = true)
Expand All @@ -45,11 +43,6 @@ public CompletableFuture<List<AvatarBean>> getAvailableAvatars() {

public void changeAvatar(AvatarBean avatar) {
fafServerAccessor.selectAvatar(avatar.getUrl());
eventBus.post(new AvatarChangedEvent(avatar));
}

@Override
public void afterPropertiesSet() throws Exception {
eventBus.register(this);
playerService.getCurrentPlayer().setAvatar(avatar);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.faforever.client.i18n.I18n;
import com.faforever.client.main.event.NavigateEvent;
import com.faforever.client.main.event.NavigationItem;
import com.faforever.client.navigation.NavigationHandler;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.notification.TransientNotification;
import com.faforever.client.player.CountryFlagService;
Expand All @@ -29,7 +30,6 @@
import com.faforever.client.util.TimeService;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.eventbus.EventBus;
import com.google.common.io.CharStreams;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
Expand Down Expand Up @@ -131,13 +131,13 @@ public abstract class AbstractChatTabController implements Controller<Tab> {
protected final I18n i18n;
protected final NotificationService notificationService;
protected final UiService uiService;
protected final EventBus eventBus;
protected final WebViewConfigurer webViewConfigurer;
protected final EmoticonService emoticonService;
protected final CountryFlagService countryFlagService;
protected final ChatPrefs chatPrefs;
protected final NotificationPrefs notificationPrefs;
protected final FxApplicationThreadExecutor fxApplicationThreadExecutor;
protected final NavigationHandler navigationHandler;

/**
* Messages that arrived before the web view was ready. Those are appended as soon as it is ready.
Expand Down Expand Up @@ -615,7 +615,7 @@ protected void showNotificationIfNecessary(ChatMessage chatMessage) {

if (notificationPrefs.isPrivateMessageToastEnabled()) {
notificationService.addNotification(new TransientNotification(chatMessage.username(), chatMessage.message(), IdenticonUtil.createIdenticon(identIconSource), event -> {
eventBus.post(new NavigateEvent(NavigationItem.CHAT));
navigationHandler.navigateTo(new NavigateEvent(NavigationItem.CHAT));
stage.toFront();
getRoot().getTabPane().getSelectionModel().select(getRoot());
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.faforever.client.fx.SimpleInvalidationListener;
import com.faforever.client.fx.WebViewConfigurer;
import com.faforever.client.i18n.I18n;
import com.faforever.client.navigation.NavigationHandler;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.player.CountryFlagService;
import com.faforever.client.player.PlayerService;
Expand All @@ -18,7 +19,6 @@
import com.faforever.client.theme.UiService;
import com.faforever.client.user.LoginService;
import com.faforever.client.util.TimeService;
import com.google.common.eventbus.EventBus;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -94,12 +94,15 @@ public class ChannelTabController extends AbstractChatTabController {
public ChannelTabController(WebViewConfigurer webViewConfigurer, LoginService loginService, ChatService chatService,
PlayerService playerService,
AudioService audioService, TimeService timeService, I18n i18n,
NotificationService notificationService, UiService uiService, EventBus eventBus,
NotificationService notificationService, UiService uiService,
NavigationHandler navigationHandler,
CountryFlagService countryFlagService, EmoticonService emoticonService,
PlatformService platformService, ChatPrefs chatPrefs,
NotificationPrefs notificationPrefs,
FxApplicationThreadExecutor fxApplicationThreadExecutor) {
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService, eventBus, webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs, fxApplicationThreadExecutor);
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService,
webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs,
fxApplicationThreadExecutor, navigationHandler);
this.platformService = platformService;
this.audioService = audioService;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/faforever/client/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public interface ChatService {
*/
void incrementUnreadMessagesCount(int delta);

void onInitiatePrivateChat(InitiatePrivateChatEvent event);
void onInitiatePrivateChat(String username);

Set<ChatChannel> getChannels();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.theme.UiService;
import com.faforever.commons.lobby.GameStatus;
import com.google.common.eventbus.EventBus;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.ObjectProperty;
Expand Down Expand Up @@ -71,10 +70,10 @@ public class ChatUserItemController implements Controller<Node> {
private final I18n i18n;
private final UiService uiService;
private final MapService mapService;
private final ChatService chatService;
private final MapGeneratorService mapGeneratorService;
private final CountryFlagService countryFlagService;
private final AvatarService avatarService;
private final EventBus eventBus;
private final ContextMenuBuilder contextMenuBuilder;
private final ChatPrefs chatPrefs;
private final ImageViewHelper imageViewHelper;
Expand Down Expand Up @@ -186,7 +185,7 @@ public void onContextMenuRequested(ContextMenuEvent event) {
public void onItemClicked(MouseEvent mouseEvent) {
ChatChannelUser chatChannelUser = chatUser.get();
if (chatChannelUser != null && mouseEvent.getButton() == MouseButton.PRIMARY && mouseEvent.getClickCount() == 2) {
eventBus.post(new InitiatePrivateChatEvent(chatChannelUser.getUsername()));
chatService.onInitiatePrivateChat(chatChannelUser.getUsername());
}
}

Expand Down

This file was deleted.

22 changes: 8 additions & 14 deletions src/main/java/com/faforever/client/chat/KittehChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.fx.SimpleChangeListener;
import com.faforever.client.net.ConnectionState;
import com.faforever.client.player.PlayerOnlineEvent;
import com.faforever.client.player.PlayerService;
import com.faforever.client.player.SocialStatus;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.remote.FafServerAccessor;
import com.faforever.client.ui.tray.TrayIconManager;
import com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent;
import com.faforever.client.user.LoginService;
import com.faforever.commons.lobby.Player.LeaderboardStats;
import com.faforever.commons.lobby.SocialInfo;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import javafx.beans.InvalidationListener;
import javafx.beans.WeakInvalidationListener;
import javafx.beans.property.ObjectProperty;
Expand Down Expand Up @@ -94,11 +92,11 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa
private static final Set<Character> MODERATOR_PREFIXES = Set.of('~', '&', '@', '%');
private final LoginService loginService;
private final FafServerAccessor fafServerAccessor;
private final EventBus eventBus;
private final ClientProperties clientProperties;
private final PlayerService playerService;
private final ChatPrefs chatPrefs;
private final FxApplicationThreadExecutor fxApplicationThreadExecutor;
private final TrayIconManager trayIconManager;
@Qualifier("userWebClient")
private final ObjectFactory<WebClient> userWebClientFactory;

Expand All @@ -124,8 +122,6 @@ public class KittehChatService implements ChatService, InitializingBean, Disposa

@Override
public void afterPropertiesSet() {
eventBus.register(this);

loginService.loggedInProperty().addListener((SimpleChangeListener<Boolean>) loggedIn -> {
if (loggedIn) {
connect();
Expand All @@ -141,6 +137,7 @@ public void afterPropertiesSet() {
}
});

playerService.addPlayerOnlineListener(this::onPlayerOnline);
JavaFxUtil.addListener(chatPrefs.groupToColorProperty(), new WeakInvalidationListener(userColorsListener));
JavaFxUtil.addListener(chatPrefs.chatColorModeProperty(), new WeakInvalidationListener(userColorsListener));
}
Expand Down Expand Up @@ -191,10 +188,8 @@ private ChatChannelUser initializeUserForChannel(String username, ChatChannel ch
return chatChannelUser;
}

@Subscribe
public void onPlayerOnline(PlayerOnlineEvent event) {
PlayerBean player = event.player();

@VisibleForTesting
void onPlayerOnline(PlayerBean player) {
channels.values()
.stream()
.map(channel -> channel.getUser(player.getUsername()))
Expand Down Expand Up @@ -546,13 +541,12 @@ public void whois(String username) {

@Override
public void incrementUnreadMessagesCount(int delta) {
eventBus.post(UpdateApplicationBadgeEvent.ofDelta(delta));
trayIconManager.onSetApplicationBadgeEvent(UpdateApplicationBadgeEvent.ofDelta(delta));
}

@Override
@Subscribe
public void onInitiatePrivateChat(InitiatePrivateChatEvent event) {
getOrCreateChannel(event.username());
public void onInitiatePrivateChat(String username) {
getOrCreateChannel(username);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.faforever.client.chat;

import com.faforever.client.chat.emoticons.EmoticonService;
import com.faforever.client.chat.event.UnreadPartyMessageEvent;
import com.faforever.client.discord.JoinDiscordEvent;
import com.faforever.client.discord.JoinDiscordEventHandler;
import com.faforever.client.fx.FxApplicationThreadExecutor;
import com.faforever.client.fx.WebViewConfigurer;
import com.faforever.client.i18n.I18n;
import com.faforever.client.navigation.NavigationHandler;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.player.CountryFlagService;
import com.faforever.client.player.PlayerService;
Expand All @@ -15,7 +15,6 @@
import com.faforever.client.user.LoginService;
import com.faforever.client.util.TimeService;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.eventbus.EventBus;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.value.ObservableValue;
import javafx.collections.ListChangeListener;
Expand All @@ -30,6 +29,7 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.net.URISyntaxException;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
Expand All @@ -38,6 +38,8 @@
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MatchmakingChatController extends AbstractChatTabController {

private final JoinDiscordEventHandler joinDiscordEventHandler;

public Tab matchmakingChatTabRoot;
public WebView messagesWebView;
public TextField messageTextField;
Expand All @@ -57,13 +59,18 @@ public class MatchmakingChatController extends AbstractChatTabController {
// TODO cut dependencies
public MatchmakingChatController(LoginService loginService,
PlayerService playerService, TimeService timeService, I18n i18n,
NotificationService notificationService, UiService uiService, EventBus eventBus,
NotificationService notificationService, UiService uiService,
NavigationHandler navigationHandler,
ChatService chatService,
WebViewConfigurer webViewConfigurer, CountryFlagService countryFlagService,
EmoticonService emoticonService, ChatPrefs chatPrefs,
NotificationPrefs notificationPrefs,
FxApplicationThreadExecutor fxApplicationThreadExecutor) {
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService, eventBus, webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs, fxApplicationThreadExecutor);
FxApplicationThreadExecutor fxApplicationThreadExecutor,
JoinDiscordEventHandler joinDiscordEventHandler) {
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService,
webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs,
fxApplicationThreadExecutor, navigationHandler);
this.joinDiscordEventHandler = joinDiscordEventHandler;
}

@Override
Expand Down Expand Up @@ -117,17 +124,8 @@ protected WebView getMessagesWebView() {
return messagesWebView;
}

@Override
protected void onChatMessage(ChatMessage chatMessage) {
super.onChatMessage(chatMessage);

if (!hasFocus()) {
eventBus.post(new UnreadPartyMessageEvent(chatMessage));
}
}

public void onDiscordButtonClicked() {
eventBus.post(new JoinDiscordEvent(discordLink.getText()));
public void onDiscordButtonClicked() throws URISyntaxException {
joinDiscordEventHandler.onJoin(discordLink.getText());
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.faforever.client.audio.AudioService;
import com.faforever.client.avatar.AvatarService;
import com.faforever.client.chat.emoticons.EmoticonService;
import com.faforever.client.chat.event.UnreadPrivateMessageEvent;
import com.faforever.client.domain.PlayerBean;
import com.faforever.client.fx.FxApplicationThreadExecutor;
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.fx.WebViewConfigurer;
import com.faforever.client.i18n.I18n;
import com.faforever.client.navigation.NavigationHandler;
import com.faforever.client.notification.NotificationService;
import com.faforever.client.player.CountryFlagService;
import com.faforever.client.player.PlayerService;
Expand All @@ -19,7 +19,6 @@
import com.faforever.client.user.LoginService;
import com.faforever.client.util.TimeService;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.eventbus.EventBus;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.value.ObservableValue;
import javafx.collections.ListChangeListener;
Expand Down Expand Up @@ -65,13 +64,16 @@ public class PrivateChatTabController extends AbstractChatTabController {
// TODO cut dependencies
public PrivateChatTabController(LoginService loginService,
PlayerService playerService, TimeService timeService, I18n i18n,
NotificationService notificationService, UiService uiService, EventBus eventBus,
NotificationService notificationService, UiService uiService,
NavigationHandler navigationHandler,
AudioService audioService, ChatService chatService,
WebViewConfigurer webViewConfigurer, CountryFlagService countryFlagService,
EmoticonService emoticonService, AvatarService avatarService, ChatPrefs chatPrefs,
NotificationPrefs notificationPrefs,
FxApplicationThreadExecutor fxApplicationThreadExecutor) {
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService, eventBus, webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs, fxApplicationThreadExecutor);
super(loginService, chatService, playerService, timeService, i18n, notificationService, uiService,
webViewConfigurer, emoticonService, countryFlagService, chatPrefs, notificationPrefs,
fxApplicationThreadExecutor, navigationHandler);
this.avatarService = avatarService;
this.audioService = audioService;
}
Expand Down Expand Up @@ -154,7 +156,6 @@ public void onChatMessage(ChatMessage chatMessage) {
showNotificationIfNecessary(chatMessage);
setUnread(true);
incrementUnreadMessagesCount();
eventBus.post(new UnreadPrivateMessageEvent(chatMessage));
}
}

Expand Down
Loading

0 comments on commit 9c9a89f

Please sign in to comment.