Skip to content

Commit

Permalink
Maintain chat user categories when filtering
Browse files Browse the repository at this point in the history
Fixes FAForever#1618

Use a single filter function for all filters and maintain categories during filtering
  • Loading branch information
Sheikah45 committed Aug 29, 2020
1 parent 9a21426 commit 2ad66ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private void addModerator(CategoryOrChatUserListItem item) {
public void initialize() {
super.initialize();

userSearchTextField.textProperty().addListener((observable, oldValue, newValue) -> filterChatUsers(newValue));
userSearchTextField.textProperty().addListener((observable, oldValue, newValue) -> userFilterController.filterUsers());

channelTabScrollPaneVBox.setMinWidth(preferencesService.getPreferences().getChat().getChannelTabScrollPaneWidth());
channelTabScrollPaneVBox.setPrefWidth(preferencesService.getPreferences().getChat().getChannelTabScrollPaneWidth());
Expand Down Expand Up @@ -420,20 +420,6 @@ private void updateUserMessageDisplay(ChatChannelUser chatUser, String display)
Platform.runLater(() -> getJsObject().call("updateUserMessageDisplay", chatUser.getUsername(), display));
}

/** Filters by username "contains" case insensitive. */
@SuppressWarnings("unchecked")
private void filterChatUsers(String searchString) {
setUserFilter(listItem -> {
if (Strings.isNullOrEmpty(searchString)) {
return true;
}

ChatChannelUser user = listItem.getUser();

return listItem.getCategory() != null || user.getUsername().toLowerCase(US).contains(searchString.toLowerCase(US));
});
}

private void associateChatUserWithPlayer(Player player, ChatChannelUser chatUser) {
chatUser.setPlayer(player);
player.getChatChannelUsers().add(chatUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void initialize() {
maxRatingFilterField.textProperty().addListener((observable, oldValue, newValue) -> filterUsers());
}

private void filterUsers() {
public void filterUsers() {
channelTabController.setUserFilter(this::filterUser);
filterApplied.set(
!maxRatingFilterField.getText().isEmpty()
Expand All @@ -68,14 +68,12 @@ private void filterUsers() {
}

private boolean filterUser(CategoryOrChatUserListItem userListItem) {
if (userListItem.getUser() == null) {
return false;
}
ChatChannelUser user = userListItem.getUser();
return channelTabController.isUsernameMatch(user)
return userListItem.getCategory() != null
|| (channelTabController.isUsernameMatch(user)
&& isInClan(user)
&& isBoundByRating(user)
&& isGameStatusMatch(user);
&& isGameStatusMatch(user));
}

public BooleanProperty filterAppliedProperty() {
Expand Down

0 comments on commit 2ad66ae

Please sign in to comment.