Skip to content

Commit

Permalink
Only notify friend joined on addition to game
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Mar 5, 2023
1 parent 31a49ad commit 1c672a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
7 changes: 0 additions & 7 deletions src/main/java/com/faforever/client/domain/GameBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ public class GameBean {

Set<ChangeListener<Set<Integer>>> playerChangeListeners = new HashSet<>();

ChangeListener<Set<PlayerBean>> playerChangeListener = (observable, oldValue, newValue) -> {
Set<PlayerBean> playersToRemove = oldValue.stream().filter(player -> !newValue.contains(player)).collect(Collectors.toSet());
Set<PlayerBean> playersToAdd = newValue.stream().filter(player -> !oldValue.contains(player)).collect(Collectors.toSet());
playersToRemove.stream().filter(player -> equals(player.getGame())).forEach(player -> player.setGame(null));
playersToAdd.forEach(player -> player.setGame(this));
};

public String getHost() {
return host.get();
}
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/com/faforever/client/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import com.faforever.client.util.MaskPatternLayout;
import com.faforever.commons.lobby.GameInfo;
import com.faforever.commons.lobby.GameStatus;
import com.faforever.commons.lobby.GameType;
import com.faforever.commons.lobby.GameVisibility;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.eventbus.EventBus;
Expand Down Expand Up @@ -228,8 +227,6 @@ public void afterPropertiesSet() {
.switchIfEmpty(initializeGameBean(gameInfo))))
.publishOn(javaFxService.getFxApplicationScheduler())
.map(TupleUtils.function(gameMapper::update))
.publishOn(javaFxService.getSingleScheduler())
.doOnNext(this::notifyIfFriendJoinedGame)
.doOnError(throwable -> log.error("Error processing game", throwable))
.retry()
.share();
Expand Down Expand Up @@ -284,21 +281,15 @@ private ChangeListener<Set<Integer>> generatePlayerChangeListener(GameBean newGa
.filter(player -> !oldValue.contains(player))
.map(playerService::getPlayerByIdIfOnline)
.flatMap(Optional::stream)
.forEach(player -> player.setGame(newGame));
.forEach(player -> {
player.setGame(newGame);
if (player.getSocialStatus() == SocialStatus.FRIEND) {
eventBus.post(new FriendJoinedGameEvent(player, newGame));
}
});
};
}

private void notifyIfFriendJoinedGame(GameBean game) {
if (game.getStatus() == GameStatus.OPEN && game.getGameType() != GameType.MATCHMAKER) {
game.getAllPlayersInGame()
.stream()
.map(playerService::getPlayerByIdIfOnline)
.flatMap(Optional::stream)
.filter(player -> player.getSocialStatus() == SocialStatus.FRIEND)
.forEach(player -> eventBus.post(new FriendJoinedGameEvent(player, game)));
}
}

private InvalidationListener generateNumberOfPlayersChangeListener(GameBean game) {
return new InvalidationListener() {
@Override
Expand Down

0 comments on commit 1c672a6

Please sign in to comment.