* UI: ignore list improved:

* Added support of usernames with spaces (#6305);
 * Increased max limit from 50 to 100;
 * Added list size info on connection or command usage;
This commit is contained in:
Oleg Agafonov 2020-02-27 02:05:16 +04:00
parent 299be53e7a
commit f50bc8f36f
7 changed files with 62 additions and 47 deletions

View file

@ -1,46 +1,51 @@
package mage.client.util;
import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.Set;
import mage.client.MageFrame;
import mage.client.preference.MagePreferences;
import mage.view.ChatMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public final class IgnoreList {
private static final String USAGE = "<br/><font color=yellow>\\ignore - shows your ignore list on this server."
+ "<br/>\\ignore [username] - add username to ignore list (they won't be able to chat or join to your game)."
+ "<br/>\\unignore [username] - remove a username from your ignore list on this server.</font>";
private static final String USAGE = ""
+ "<br><font color=yellow>\\ignore - shows your ignore list on this server."
+ "<br>\\ignore username - add username to ignore list (they won't be able to chat or join to your new game)."
+ "<br>\\unignore username - remove a username from your ignore list on this server.</font>";
public static final int MAX_IGNORE_LIST_SIZE = 50;
public static final int MAX_IGNORE_LIST_SIZE = 100;
public static final Set<ChatMessage.MessageType> IGNORED_MESSAGE_TYPES
= ImmutableSet.of(ChatMessage.MessageType.TALK,
ChatMessage.MessageType.WHISPER_FROM);
ChatMessage.MessageType.WHISPER_FROM);
public static String usage() {
return USAGE;
public static String usage(String serverAddress) {
return "<br>Your ignored list on server " + serverAddress + ": " + getIgnoredUsers(serverAddress).size()
+ USAGE;
}
public static Set<String> ignoreList(String serverAddress) {
public static Set<String> getIgnoredUsers(String serverAddress) {
return MagePreferences.ignoreList(serverAddress);
}
public static String ignoreListString(String serverAddress) {
final String[] list = MagePreferences.ignoreList(serverAddress).toArray(new String[0]);
Arrays.sort(list);
return "<font color=yellow>Current ignore list on " + serverAddress + ": "
+ Arrays.toString(list)
public static String getIgnoreListInfo(String serverAddress) {
List<String> list = new ArrayList<>(getIgnoredUsers(serverAddress));
Collections.sort(list);
return "<font color=yellow>Current ignore list on " + serverAddress + " (" + list.size() + "): "
+ String.join(", ", list)
+ "</font>";
}
public static String ignore(String serverAddress, String user) {
if (user == null || user.isEmpty()) {
return ignoreListString(serverAddress);
return getIgnoreListInfo(serverAddress);
}
if (MagePreferences.ignoreList(serverAddress).size() >= MAX_IGNORE_LIST_SIZE) {
return "Your ignore list is too big, remove a user to be able to add a new one.";
return "Your ignore list is too big (max " + MAX_IGNORE_LIST_SIZE + "), remove a user to be able to add a new one.";
}
if (userIsIgnored(serverAddress, user)) {
@ -50,7 +55,7 @@ public final class IgnoreList {
MagePreferences.addIgnoredUser(serverAddress, user);
updateTablesTable();
return "Added " + user + " to your ignore list on " + serverAddress;
return "Added " + user + " to your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")";
}
private static void updateTablesTable() {
@ -62,13 +67,13 @@ public final class IgnoreList {
public static String unignore(String serverAddress, String user) {
if (user == null || user.isEmpty()) {
return usage();
return usage(serverAddress);
}
if (MagePreferences.removeIgnoredUser(serverAddress, user)) {
updateTablesTable();
return "Removed " + user + " from your ignore list on " + serverAddress;
return "Removed " + user + " from your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")";
} else {
return "No such user \"" + user + "\" on your ignore list on " + serverAddress;
return "No such user \"" + user + "\" on your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")";
}
}