Requests return futures that fail with a typed RequestException
Server requests on TeamspeakConnection took callbacks given a value and an error string, null on success, so frontends told a permission refusal from other failures by the message's wording (ban list, server log) and core needed a sentinel message for a refused search. They now return a CompletableFuture that fails with a RequestException carrying the kind (not connected, permission, failed) and the server's reason. Replies hands the outcome to a success or a failure handler on a given executor; Swing's Edt runs them on the event thread, so call sites no longer marshal by hand. Android's ServerController, whose suspend calls answered a String? that was null once done, returns Result instead. lookupDatabaseClient answers an Optional rather than null. Starts the structural audit in AUDIT-STRUCTURE.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,12 +6,12 @@ import eu.lixko.ts3j.client.net.avatar.Avatar;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.Component;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/** Sets, takes and deletes our avatar on one server, reporting failures in a dialog. */
|
||||
final class AvatarActions {
|
||||
@@ -36,7 +36,7 @@ final class AvatarActions {
|
||||
if (chooser.showOpenDialog(owner) != JFileChooser.APPROVE_OPTION) return;
|
||||
File file = chooser.getSelectedFile();
|
||||
lastDirectory = file.getParentFile();
|
||||
conn.setAvatar(file, error -> fail("Error uploading avatar: ", error));
|
||||
Edt.onFailure(conn.setAvatar(file), failure -> show("Error uploading avatar: " + failure.getMessage()));
|
||||
}
|
||||
|
||||
/** Uploads someone else's avatar as ours. */
|
||||
@@ -47,30 +47,26 @@ final class AvatarActions {
|
||||
file = Files.createTempFile("avatar", "." + avatar.format().extension).toFile();
|
||||
Files.write(file.toPath(), avatar.data());
|
||||
} catch (IOException e) {
|
||||
fail("Error uploading avatar: ", e.getMessage());
|
||||
show("Error uploading avatar: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
conn.setAvatar(file, error -> {
|
||||
file.delete();
|
||||
fail("Error uploading avatar: ", error);
|
||||
});
|
||||
CompletableFuture<Void> upload = conn.setAvatar(file);
|
||||
upload.whenComplete((ignored, failure) -> file.delete());
|
||||
Edt.onFailure(upload, failure -> show("Error uploading avatar: " + failure.getMessage()));
|
||||
}
|
||||
|
||||
void delete() {
|
||||
if (!conn.isConnected()) return;
|
||||
conn.removeAvatar(error -> fail("Error deleting avatar: ", error));
|
||||
Edt.onFailure(conn.removeAvatar(), failure -> show("Error deleting avatar: " + failure.getMessage()));
|
||||
}
|
||||
|
||||
/** Deletes another client's avatar for everyone. */
|
||||
void deleteOf(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
conn.removeAvatarOf(client, error -> fail("Error deleting avatar: ", error));
|
||||
Edt.onFailure(conn.removeAvatarOf(client), failure -> show("Error deleting avatar: " + failure.getMessage()));
|
||||
}
|
||||
|
||||
/** Shows {@code error}, if there is one; callable from any thread. */
|
||||
private void fail(String what, String error) {
|
||||
if (error == null) return;
|
||||
SwingUtilities.invokeLater(() ->
|
||||
JOptionPane.showMessageDialog(owner, what + error, "Error", JOptionPane.ERROR_MESSAGE));
|
||||
private void show(String message) {
|
||||
JOptionPane.showMessageDialog(owner, message, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -373,26 +374,21 @@ final class BanListDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
conn.requestBanList((bans, error) -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.requestBanList(), bans -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
tableModel.setBans(List.of());
|
||||
status.setText(isPermissionError(error)
|
||||
? "You have insufficient permissions to view the ban list."
|
||||
: "Failed to request ban list: " + error);
|
||||
updateButtons();
|
||||
return;
|
||||
}
|
||||
tableModel.setBans(bans);
|
||||
status.setText(bans.size() == 1 ? "1 ban" : bans.size() + " bans");
|
||||
updateButtons();
|
||||
}));
|
||||
}
|
||||
|
||||
private static boolean isPermissionError(String message) {
|
||||
String m = message.toLowerCase(Locale.ROOT);
|
||||
return m.contains("insufficient") || m.contains("permission");
|
||||
}, failure -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
tableModel.setBans(List.of());
|
||||
status.setText(failure.permissionDenied()
|
||||
? "You have insufficient permissions to view the ban list."
|
||||
: "Failed to request ban list: " + failure.getMessage());
|
||||
updateButtons();
|
||||
});
|
||||
}
|
||||
|
||||
private void applyFilter() {
|
||||
@@ -448,9 +444,9 @@ final class BanListDialog extends JDialog {
|
||||
dialog.setVisible(true);
|
||||
BanRule rule = dialog.getRule();
|
||||
if (rule == null) return;
|
||||
conn.addBan(rule, error -> afterChange(error, "Error adding ban: ",
|
||||
afterChange(conn.addBan(rule), "Error adding ban: ",
|
||||
() -> JOptionPane.showMessageDialog(this, "Your ban was successfully added.", "Ban List",
|
||||
JOptionPane.INFORMATION_MESSAGE)));
|
||||
JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
private void editBan() {
|
||||
@@ -460,7 +456,7 @@ final class BanListDialog extends JDialog {
|
||||
dialog.setVisible(true);
|
||||
BanRule rule = dialog.getRule();
|
||||
if (rule == null) return;
|
||||
conn.replaceBan(ban.id, rule, error -> afterChange(error, "Error editing ban: ", null));
|
||||
afterChange(conn.replaceBan(ban.id, rule), "Error editing ban: ");
|
||||
}
|
||||
|
||||
private void removeBans() {
|
||||
@@ -470,18 +466,23 @@ final class BanListDialog extends JDialog {
|
||||
"Delete bans", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (answer != JOptionPane.YES_OPTION) return;
|
||||
List<Integer> ids = bans.stream().map(b -> b.id).collect(Collectors.toList());
|
||||
conn.deleteBans(ids, error -> afterChange(error, "Error deleting ban: ", null));
|
||||
afterChange(conn.deleteBans(ids), "Error deleting ban: ");
|
||||
}
|
||||
|
||||
/** Reports a failed change, or re-reads the list so the table shows what the server now holds. */
|
||||
private void afterChange(String error, String errorPrefix, Runnable onSuccess) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
private void afterChange(CompletableFuture<Void> change, String errorPrefix) {
|
||||
afterChange(change, errorPrefix, () -> {
|
||||
});
|
||||
}
|
||||
|
||||
private void afterChange(CompletableFuture<Void> change, String errorPrefix, Runnable onSuccess) {
|
||||
Edt.handle(change, () -> {
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(this, errorPrefix + error, "Ban List", JOptionPane.ERROR_MESSAGE);
|
||||
} else if (onSuccess != null) {
|
||||
onSuccess.run();
|
||||
}
|
||||
onSuccess.run();
|
||||
reload();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
JOptionPane.showMessageDialog(this, errorPrefix + failure.getMessage(), "Ban List", JOptionPane.ERROR_MESSAGE);
|
||||
reload();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
@@ -33,6 +32,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* TeamSpeak's channel editor: the channel's name, icon, password, topic and description
|
||||
@@ -286,19 +286,13 @@ final class ChannelDialog extends JDialog {
|
||||
// ---- loading ----
|
||||
|
||||
private void load() {
|
||||
conn.requestChannelSettings(channel.id, (settings, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(this, "Could not read the channel: " + error,
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
apply(settings);
|
||||
}));
|
||||
conn.requestChannelPermissions(channel.id, (permissions, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) permissionsPanel.showUnavailable("No permission to view channel permissions.");
|
||||
else permissionsPanel.read(permissions);
|
||||
}));
|
||||
Edt.handle(conn.requestChannelSettings(channel.id), this::apply, failure -> {
|
||||
JOptionPane.showMessageDialog(this, "Could not read the channel: " + failure.getMessage(),
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
dispose();
|
||||
});
|
||||
Edt.handle(conn.requestChannelPermissions(channel.id), permissionsPanel::read,
|
||||
failure -> permissionsPanel.showUnavailable("No permission to view channel permissions."));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,9 +397,8 @@ final class ChannelDialog extends JDialog {
|
||||
|
||||
if (channel == null) {
|
||||
ok.setEnabled(false);
|
||||
conn.createChannel(parentId, edited.creationParameters(), permissionsPanel.changed(),
|
||||
(channelId, error) -> SwingUtilities.invokeLater(
|
||||
() -> finish(error, "Could not create the channel: ")));
|
||||
finish(conn.createChannel(parentId, edited.creationParameters(), permissionsPanel.changed()),
|
||||
"Could not create the channel: ");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -418,17 +411,15 @@ final class ChannelDialog extends JDialog {
|
||||
}
|
||||
|
||||
ok.setEnabled(false);
|
||||
conn.applyChannelEdit(channel.id, changes, setPermissions, clearedPermissions,
|
||||
error -> SwingUtilities.invokeLater(() -> finish(error, "Could not save the channel: ")));
|
||||
finish(conn.applyChannelEdit(channel.id, changes, setPermissions, clearedPermissions),
|
||||
"Could not save the channel: ");
|
||||
}
|
||||
|
||||
/** Closes the dialog, or reports why the server would not have it and lets the user retry. */
|
||||
private void finish(String error, String errorPrefix) {
|
||||
if (error == null) {
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
ok.setEnabled(true);
|
||||
JOptionPane.showMessageDialog(this, errorPrefix + error, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
private void finish(CompletableFuture<?> request, String errorPrefix) {
|
||||
Edt.handle(request, ignored -> dispose(), failure -> {
|
||||
ok.setEnabled(true);
|
||||
JOptionPane.showMessageDialog(this, errorPrefix + failure.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,17 +256,17 @@ final class ComplaintsDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
conn.requestComplaints((complaints, error) -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.requestComplaints(), complaints -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
setTargets(List.of());
|
||||
status.setText("Failed to request complaint list: " + error);
|
||||
} else {
|
||||
setTargets(groupByTarget(complaints));
|
||||
status.setText(complaints.size() == 1 ? "1 complaint" : complaints.size() + " complaints");
|
||||
}
|
||||
}));
|
||||
setTargets(groupByTarget(complaints));
|
||||
status.setText(complaints.size() == 1 ? "1 complaint" : complaints.size() + " complaints");
|
||||
}, failure -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
setTargets(List.of());
|
||||
status.setText("Failed to request complaint list: " + failure.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
private static List<Target> groupByTarget(List<Complaint> complaints) {
|
||||
@@ -384,14 +384,14 @@ final class ComplaintsDialog extends JDialog {
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (answer != JOptionPane.YES_OPTION) return;
|
||||
List<Integer> whole = sel.whole().stream().map(Target::dbId).toList();
|
||||
conn.deleteComplaints(whole, sel.single(), error -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.deleteComplaints(whole, sel.single()), () -> {
|
||||
if (isDisplayable()) reload();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(this, "Failed to delete complaints: " + error, getTitle(),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
JOptionPane.showMessageDialog(this, "Failed to delete complaints: " + failure.getMessage(), getTitle(),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
reload();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void banSelected() {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import eu.lixko.ts3j.client.net.Replies;
|
||||
import eu.lixko.ts3j.client.net.RequestException;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/** {@link Replies} on the event dispatch thread. */
|
||||
final class Edt {
|
||||
|
||||
private Edt() {
|
||||
}
|
||||
|
||||
static <T> void handle(CompletableFuture<T> request, Consumer<T> onSuccess, Consumer<RequestException> onFailure) {
|
||||
Replies.handle(request, SwingUtilities::invokeLater, onSuccess, onFailure);
|
||||
}
|
||||
|
||||
static void handle(CompletableFuture<Void> request, Runnable onSuccess, Consumer<RequestException> onFailure) {
|
||||
Replies.handle(request, SwingUtilities::invokeLater, onSuccess, onFailure);
|
||||
}
|
||||
|
||||
static void onFailure(CompletableFuture<?> request, Consumer<RequestException> onFailure) {
|
||||
Replies.onFailure(request, SwingUtilities::invokeLater, onFailure);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.BorderLayout;
|
||||
@@ -179,15 +178,11 @@ final class IconChooserDialog extends JDialog {
|
||||
|
||||
private void loadRemoteIcons() {
|
||||
status.setText("Loading icons…");
|
||||
conn.requestServerIcons((ids, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) {
|
||||
status.setText("Could not list the server's icons: " + error);
|
||||
return;
|
||||
}
|
||||
Edt.handle(conn.requestServerIcons(), ids -> {
|
||||
status.setText(" ");
|
||||
remoteModel.clear();
|
||||
for (Long id : ids) remoteModel.addElement(id);
|
||||
}));
|
||||
}, failure -> status.setText("Could not list the server's icons: " + failure.getMessage()));
|
||||
}
|
||||
|
||||
private void uploadIcon() {
|
||||
@@ -197,16 +192,14 @@ final class IconChooserDialog extends JDialog {
|
||||
if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;
|
||||
File file = chooser.getSelectedFile();
|
||||
status.setText("Uploading " + file.getName() + "…");
|
||||
conn.uploadIcon(file, (iconId, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) {
|
||||
status.setText(" ");
|
||||
JOptionPane.showMessageDialog(this, "Error uploading icon: " + error,
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
Edt.handle(conn.uploadIcon(file), iconId -> {
|
||||
loadRemoteIcons();
|
||||
startRefreshing();
|
||||
}));
|
||||
}, failure -> {
|
||||
status.setText(" ");
|
||||
JOptionPane.showMessageDialog(this, "Error uploading icon: " + failure.getMessage(),
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteSelectedIcon() {
|
||||
@@ -216,14 +209,9 @@ final class IconChooserDialog extends JDialog {
|
||||
"Permanently delete this icon from the server?", "Confirmation",
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (answer != JOptionPane.YES_OPTION) return;
|
||||
conn.deleteIcon(id, error -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(this, "Failed to delete remote icon file: " + error,
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
remoteModel.removeElement(id);
|
||||
}));
|
||||
Edt.handle(conn.deleteIcon(id), () -> remoteModel.removeElement(id),
|
||||
failure -> JOptionPane.showMessageDialog(this, "Failed to delete remote icon file: " + failure.getMessage(),
|
||||
"Error", JOptionPane.ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+23
-24
@@ -54,6 +54,7 @@ import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -361,11 +362,10 @@ final class OfflineMessageComposeDialog extends JDialog {
|
||||
String typed = recipientField.getText().trim();
|
||||
if (typed.isEmpty()) return;
|
||||
if (UNIQUE_ID.matcher(typed).matches()) {
|
||||
conn.lookupDatabaseClient(typed, (client, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) showRecipientError(error);
|
||||
else if (client == null) showRecipientError("The unique ID is unknown on this server.");
|
||||
else accept(client);
|
||||
}));
|
||||
Edt.handle(conn.lookupDatabaseClient(typed),
|
||||
client -> client.ifPresentOrElse(this::accept,
|
||||
() -> showRecipientError("The unique ID is unknown on this server.")),
|
||||
failure -> showRecipientError(failure.getMessage()));
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < available.size(); i++) {
|
||||
@@ -374,18 +374,18 @@ final class OfflineMessageComposeDialog extends JDialog {
|
||||
return;
|
||||
}
|
||||
}
|
||||
conn.searchDatabaseClients(typed, (found, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) {
|
||||
showRecipientError(error);
|
||||
} else if (found.isEmpty()) {
|
||||
Edt.handle(conn.searchDatabaseClients(typed), found -> {
|
||||
if (found.isEmpty()) {
|
||||
showRecipientError("The nickname is unknown on this server.");
|
||||
} else {
|
||||
offer(found);
|
||||
DatabaseClient exact = found.stream().filter(c -> c.nickname().equalsIgnoreCase(typed))
|
||||
.findFirst().orElse(found.size() == 1 ? found.get(0) : null);
|
||||
if (exact != null) accept(exact);
|
||||
return;
|
||||
}
|
||||
}));
|
||||
offer(found);
|
||||
found.stream().filter(c -> c.nickname().equalsIgnoreCase(typed)).findFirst()
|
||||
.or(() -> found.size() == 1 ? Optional.of(found.get(0)) : Optional.empty())
|
||||
.ifPresent(this::accept);
|
||||
}, failure -> showRecipientError(failure.permissionDenied()
|
||||
? "You have no permission to search for users on this server, so you can only use contacts or unique IDs."
|
||||
: failure.getMessage()));
|
||||
}
|
||||
|
||||
private void accept(DatabaseClient client) {
|
||||
@@ -431,18 +431,17 @@ final class OfflineMessageComposeDialog extends JDialog {
|
||||
if (!sendButton.isEnabled()) return;
|
||||
sending = true;
|
||||
updateSendButton();
|
||||
conn.sendOfflineMessage(new ArrayList<>(recipients.keySet()), subjectField.getText(), bodyArea.getText(),
|
||||
error -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.sendOfflineMessage(new ArrayList<>(recipients.keySet()), subjectField.getText(), bodyArea.getText()),
|
||||
() -> {
|
||||
sending = false;
|
||||
if (isDisplayable()) dispose();
|
||||
}, failure -> {
|
||||
sending = false;
|
||||
if (!isDisplayable()) return;
|
||||
if (error == null) {
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
updateSendButton();
|
||||
JOptionPane.showMessageDialog(this, "Failed to send offline message: " + error, getTitle(),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}));
|
||||
JOptionPane.showMessageDialog(this, "Failed to send offline message: " + failure.getMessage(),
|
||||
getTitle(), JOptionPane.ERROR_MESSAGE);
|
||||
});
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
|
||||
@@ -27,7 +27,6 @@ import javax.swing.KeyStroke;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.RowSorter;
|
||||
import javax.swing.SortOrder;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
@@ -328,16 +327,15 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
conn.requestOfflineMessages((messages, error) -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.requestOfflineMessages(), messages -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
status.setText("Failed to list offline messages: " + error);
|
||||
return;
|
||||
}
|
||||
setMessages(messages);
|
||||
status.setText(messages.isEmpty() ? "No messages" : " ");
|
||||
}));
|
||||
}, failure -> {
|
||||
loading = false;
|
||||
if (isDisplayable()) status.setText("Failed to list offline messages: " + failure.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
private void setMessages(List<OfflineMessage> messages) {
|
||||
@@ -390,15 +388,15 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
return;
|
||||
}
|
||||
bodyPane.setText("");
|
||||
conn.requestOfflineMessageBody(message.id(), (text, error) -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.requestOfflineMessageBody(message.id()), text -> {
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
if (shownId == message.id()) status.setText("Failed to get offline message: " + error);
|
||||
return;
|
||||
}
|
||||
bodies.put(message.id(), text);
|
||||
if (shownId == message.id()) showBody(message, text);
|
||||
}));
|
||||
}, failure -> {
|
||||
if (isDisplayable() && shownId == message.id()) {
|
||||
status.setText("Failed to get offline message: " + failure.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showBody(OfflineMessage message, String body) {
|
||||
@@ -421,15 +419,13 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
composer.reply(message, body);
|
||||
return;
|
||||
}
|
||||
conn.requestOfflineMessageBody(message.id(), (text, error) -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.requestOfflineMessageBody(message.id()), text -> {
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
status.setText("Failed to get offline message: " + error);
|
||||
return;
|
||||
}
|
||||
bodies.put(message.id(), text);
|
||||
composer.reply(message, text);
|
||||
}));
|
||||
}, failure -> {
|
||||
if (isDisplayable()) status.setText("Failed to get offline message: " + failure.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
private void markSelected(boolean read) {
|
||||
@@ -440,12 +436,11 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
private void mark(List<OfflineMessage> messages, boolean read) {
|
||||
if (messages.isEmpty()) return;
|
||||
for (OfflineMessage m : messages) tableModel.replace(m.withRead(read));
|
||||
conn.markOfflineMessages(messages.stream().map(OfflineMessage::id).toList(), read,
|
||||
error -> SwingUtilities.invokeLater(() -> {
|
||||
if (error == null || !isDisplayable()) return;
|
||||
status.setText("Failed to update offline message: " + error);
|
||||
reload();
|
||||
}));
|
||||
Edt.onFailure(conn.markOfflineMessages(messages.stream().map(OfflineMessage::id).toList(), read), failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
status.setText("Failed to update offline message: " + failure.getMessage());
|
||||
reload();
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteSelected() {
|
||||
@@ -461,16 +456,18 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (answer != JOptionPane.YES_OPTION) return;
|
||||
}
|
||||
conn.deleteOfflineMessages(selected.stream().map(OfflineMessage::id).toList(),
|
||||
error -> SwingUtilities.invokeLater(() -> {
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(this, "Failed to delete offline message: " + error,
|
||||
getTitle(), JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
for (OfflineMessage m : selected) bodies.remove(m.id());
|
||||
reload();
|
||||
}));
|
||||
Runnable deleted = () -> {
|
||||
for (OfflineMessage m : selected) bodies.remove(m.id());
|
||||
reload();
|
||||
};
|
||||
Edt.handle(conn.deleteOfflineMessages(selected.stream().map(OfflineMessage::id).toList()), () -> {
|
||||
if (isDisplayable()) deleted.run();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
JOptionPane.showMessageDialog(this, "Failed to delete offline message: " + failure.getMessage(),
|
||||
getTitle(), JOptionPane.ERROR_MESSAGE);
|
||||
deleted.run();
|
||||
});
|
||||
}
|
||||
|
||||
private static String subjectOrPlaceholder(OfflineMessage m) {
|
||||
|
||||
+15
-16
@@ -19,7 +19,6 @@ import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
@@ -149,20 +148,20 @@ final class PrivilegeKeyCreateDialog extends JDialog {
|
||||
Group group = (Group) groupBox.getSelectedItem();
|
||||
ChannelNode channel = (ChannelNode) channelBox.getSelectedItem();
|
||||
create.setEnabled(false);
|
||||
conn.addPrivilegeKey(forChannelGroup(), group.id, channel == null ? 0 : channel.id,
|
||||
descriptionField.getText().trim(), (key, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (!isDisplayable()) return;
|
||||
updateCreate();
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(this, "Failed to add Privilege Key: " + error,
|
||||
getTitle(), JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
keyField.setText(key);
|
||||
keyField.selectAll();
|
||||
keyField.requestFocusInWindow();
|
||||
copy.setEnabled(true);
|
||||
onCreated.run();
|
||||
}));
|
||||
Edt.handle(conn.addPrivilegeKey(forChannelGroup(), group.id, channel == null ? 0 : channel.id,
|
||||
descriptionField.getText().trim()), key -> {
|
||||
if (!isDisplayable()) return;
|
||||
updateCreate();
|
||||
keyField.setText(key);
|
||||
keyField.selectAll();
|
||||
keyField.requestFocusInWindow();
|
||||
copy.setEnabled(true);
|
||||
onCreated.run();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
updateCreate();
|
||||
JOptionPane.showMessageDialog(this, "Failed to add Privilege Key: " + failure.getMessage(),
|
||||
getTitle(), JOptionPane.ERROR_MESSAGE);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
@@ -213,18 +212,19 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
conn.requestPrivilegeKeys((keys, error) -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.requestPrivilegeKeys(), keys -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
tableModel.setKeys(List.of());
|
||||
status.setText("Failed to request Privilege Key list: " + error);
|
||||
} else {
|
||||
tableModel.setKeys(keys);
|
||||
status.setText(keys.size() == 1 ? "1 privilege key" : keys.size() + " privilege keys");
|
||||
}
|
||||
tableModel.setKeys(keys);
|
||||
status.setText(keys.size() == 1 ? "1 privilege key" : keys.size() + " privilege keys");
|
||||
updateButtons();
|
||||
}));
|
||||
}, failure -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
tableModel.setKeys(List.of());
|
||||
status.setText("Failed to request Privilege Key list: " + failure.getMessage());
|
||||
updateButtons();
|
||||
});
|
||||
}
|
||||
|
||||
private List<PrivilegeKey> selectedKeys() {
|
||||
@@ -252,14 +252,14 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
"Delete Privilege Keys", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (answer != JOptionPane.YES_OPTION) return;
|
||||
List<String> tokens = selectedKeys().stream().map(PrivilegeKey::token).collect(Collectors.toList());
|
||||
conn.deletePrivilegeKeys(tokens, error -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.deletePrivilegeKeys(tokens), () -> {
|
||||
if (isDisplayable()) reload();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(this, "Failed to delete Privilege Key: " + error, getTitle(),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
JOptionPane.showMessageDialog(this, "Failed to delete Privilege Key: " + failure.getMessage(), getTitle(),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
reload();
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void copyKeys() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.config.ServerLogSettings;
|
||||
import eu.lixko.ts3j.client.config.ServerLogSettings.Highlight;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.net.RequestException;
|
||||
import eu.lixko.ts3j.client.net.ServerLogEntry;
|
||||
import eu.lixko.ts3j.client.net.ServerLogEntry.Level;
|
||||
import eu.lixko.ts3j.client.net.ServerLogPage;
|
||||
@@ -263,16 +264,15 @@ final class ServerLogDialog extends JDialog {
|
||||
loading = true;
|
||||
olderButton.setEnabled(false);
|
||||
showStatus("Loading…", Theme.chatEvent());
|
||||
conn.requestServerLog(from, (page, error) -> SwingUtilities.invokeLater(() -> {
|
||||
Edt.handle(conn.requestServerLog(from), page -> {
|
||||
loading = false;
|
||||
if (isDisplayable()) received(page, from > 0);
|
||||
}, failure -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
if (error != null) {
|
||||
failed(error);
|
||||
olderButton.setEnabled(olderFrom > 0);
|
||||
return;
|
||||
}
|
||||
received(page, from > 0);
|
||||
}));
|
||||
failed(failure);
|
||||
olderButton.setEnabled(olderFrom > 0);
|
||||
});
|
||||
}
|
||||
|
||||
private void received(ServerLogPage page, boolean older) {
|
||||
@@ -284,10 +284,10 @@ final class ServerLogDialog extends JDialog {
|
||||
if (older) log.setCaretPosition(0);
|
||||
}
|
||||
|
||||
private void failed(String error) {
|
||||
showStatus(error.toLowerCase(Locale.ROOT).contains("insufficient")
|
||||
private void failed(RequestException failure) {
|
||||
showStatus(failure.permissionDenied()
|
||||
? "Insufficient permissions to view Server Log"
|
||||
: "Error requesting server log: " + error,
|
||||
: "Error requesting server log: " + failure.getMessage(),
|
||||
Theme.isDark() ? new Color(0xFF6B6B) : new Color(0xC00000));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import eu.lixko.ts3j.client.text.TsLink;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.Component;
|
||||
import java.awt.Window;
|
||||
|
||||
@@ -255,11 +254,8 @@ final class ServerTab {
|
||||
String key = (String) JOptionPane.showInputDialog(host, "Privilege Key:", "Use Privilege Key",
|
||||
JOptionPane.PLAIN_MESSAGE, Icons.of("TOKEN_USE"), null, null);
|
||||
if (key == null || key.isBlank()) return;
|
||||
conn.usePrivilegeKey(key.trim(), error -> {
|
||||
if (error == null) return;
|
||||
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(host, error,
|
||||
"Error using Privilege Key", JOptionPane.ERROR_MESSAGE));
|
||||
});
|
||||
Edt.onFailure(conn.usePrivilegeKey(key.trim()), failure -> JOptionPane.showMessageDialog(host,
|
||||
failure.getMessage(), "Error using Privilege Key", JOptionPane.ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
/** Opens the server's privilege keys, or brings the already open window forward. */
|
||||
|
||||
@@ -10,7 +10,6 @@ import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.text.TsLink;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -251,23 +250,15 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
@Override
|
||||
public void changeClientDescription(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
conn.requestClientDescription(client.id, (description, error) -> SwingUtilities.invokeLater(() -> {
|
||||
if (error != null) {
|
||||
JOptionPane.showMessageDialog(host, "Could not read the description: " + error,
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
Edt.handle(conn.requestClientDescription(client.id), description -> {
|
||||
String edited = (String) JOptionPane.showInputDialog(host,
|
||||
"Description for " + client.nickname + ":", "Change Description",
|
||||
JOptionPane.PLAIN_MESSAGE, Icons.of("EDIT"), null, description);
|
||||
if (edited == null || edited.equals(description)) return;
|
||||
conn.setClientDescription(client.id, edited, failure -> SwingUtilities.invokeLater(() -> {
|
||||
if (failure != null) {
|
||||
JOptionPane.showMessageDialog(host, "Could not change the description: " + failure,
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}));
|
||||
}));
|
||||
Edt.onFailure(conn.setClientDescription(client.id, edited), failure -> JOptionPane.showMessageDialog(host,
|
||||
"Could not change the description: " + failure.getMessage(), "Error", JOptionPane.ERROR_MESSAGE));
|
||||
}, failure -> JOptionPane.showMessageDialog(host, "Could not read the description: " + failure.getMessage(),
|
||||
"Error", JOptionPane.ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -323,10 +314,8 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
|
||||
return;
|
||||
}
|
||||
conn.deleteChannel(channel.id, true, error -> {
|
||||
if (error != null) SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(host,
|
||||
"Could not delete the channel: " + error, "Error", JOptionPane.ERROR_MESSAGE));
|
||||
});
|
||||
Edt.onFailure(conn.deleteChannel(channel.id, true), failure -> JOptionPane.showMessageDialog(host,
|
||||
"Could not delete the channel: " + failure.getMessage(), "Error", JOptionPane.ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user