Frontends call the admin helpers directly, not through the connection

The channel, ban, privilege key, complaint, server log, offline message
and avatar helpers are public, each method running in the background and
answering a future; only the connection creates them. TeamspeakConnection
and ServerSession hand them out, which drops 30 one-line forwarders from
the connection. What the forwarders added moves into the helpers: the
stop-at-the-first-refusal loops, the "sent" log lines, re-reading an
edited channel's description and showing our own new avatar. The
complaint and offline message length limits move with them.

The icon chooser and the offline message composer take only their
helper; the other dialogs still need the connection for the model.

The connection's request runner is renamed Uplink, since
session.ServerLink is the ts3server:// link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 18:45:21 +00:00
co-authored by Claude Opus 5.5
parent da908f77bd
commit 959f7ed97a
25 changed files with 546 additions and 581 deletions
@@ -36,7 +36,7 @@ final class AvatarActions {
if (chooser.showOpenDialog(owner) != JFileChooser.APPROVE_OPTION) return;
File file = chooser.getSelectedFile();
lastDirectory = file.getParentFile();
Edt.onFailure(conn.setAvatar(file), failure -> show("Error uploading avatar: " + failure.getMessage()));
Edt.onFailure(conn.avatarAdmin().set(file), failure -> show("Error uploading avatar: " + failure.getMessage()));
}
/** Uploads someone else's avatar as ours. */
@@ -50,20 +50,20 @@ final class AvatarActions {
show("Error uploading avatar: " + e.getMessage());
return;
}
CompletableFuture<Void> upload = conn.setAvatar(file);
CompletableFuture<Void> upload = conn.avatarAdmin().set(file);
upload.whenComplete((ignored, failure) -> file.delete());
Edt.onFailure(upload, failure -> show("Error uploading avatar: " + failure.getMessage()));
}
void delete() {
if (!conn.isConnected()) return;
Edt.onFailure(conn.removeAvatar(), failure -> show("Error deleting avatar: " + failure.getMessage()));
Edt.onFailure(conn.avatarAdmin().remove(), failure -> show("Error deleting avatar: " + failure.getMessage()));
}
/** Deletes another client's avatar for everyone. */
void deleteOf(ClientEntry client) {
if (!conn.isConnected()) return;
Edt.onFailure(conn.removeAvatarOf(client), failure -> show("Error deleting avatar: " + failure.getMessage()));
Edt.onFailure(conn.avatarAdmin().removeOf(client), failure -> show("Error deleting avatar: " + failure.getMessage()));
}
private void show(String message) {
@@ -375,7 +375,7 @@ final class BanListDialog extends JDialog {
if (loading) return;
loading = true;
status.setText("Loading…");
Edt.handle(conn.requestBanList(), bans -> {
Edt.handle(conn.bans().list(), bans -> {
loading = false;
if (!isDisplayable()) return;
tableModel.setBans(bans);
@@ -438,7 +438,7 @@ final class BanListDialog extends JDialog {
dialog.setVisible(true);
BanRule rule = dialog.getRule();
if (rule == null) return;
afterChange(conn.addBan(rule), "Error adding ban: ",
afterChange(conn.bans().add(rule), "Error adding ban: ",
() -> JOptionPane.showMessageDialog(this, "Your ban was successfully added.", "Ban List",
JOptionPane.INFORMATION_MESSAGE));
}
@@ -450,7 +450,7 @@ final class BanListDialog extends JDialog {
dialog.setVisible(true);
BanRule rule = dialog.getRule();
if (rule == null) return;
afterChange(conn.replaceBan(ban.id, rule), "Error editing ban: ");
afterChange(conn.bans().replace(ban.id, rule), "Error editing ban: ");
}
private void removeBans() {
@@ -460,7 +460,7 @@ 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());
afterChange(conn.deleteBans(ids), "Error deleting ban: ");
afterChange(conn.bans().delete(ids), "Error deleting ban: ");
}
/** Reports a failed change, or re-reads the list so the table shows what the server now holds. */
@@ -286,12 +286,12 @@ final class ChannelDialog extends JDialog {
// ---- loading ----
private void load() {
Edt.handle(conn.requestChannelSettings(channel.id), this::apply, failure -> {
Edt.handle(conn.channels().settings(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,
Edt.handle(conn.channels().permissions(channel.id), permissionsPanel::read,
failure -> permissionsPanel.showUnavailable("No permission to view channel permissions."));
}
@@ -352,7 +352,7 @@ final class ChannelDialog extends JDialog {
}
private void chooseIcon() {
IconChooserDialog chooser = new IconChooserDialog(this, conn, groupIcons);
IconChooserDialog chooser = new IconChooserDialog(this, conn.channels(), groupIcons);
chooser.setVisible(true);
if (chooser.isAccepted()) setIconId(chooser.getIconId());
}
@@ -397,7 +397,7 @@ final class ChannelDialog extends JDialog {
if (channel == null) {
ok.setEnabled(false);
finish(conn.createChannel(parentId, edited.creationParameters(), permissionsPanel.changed()),
finish(conn.channels().create(parentId, edited.creationParameters(), permissionsPanel.changed()),
"Could not create the channel: ");
return;
}
@@ -411,7 +411,7 @@ final class ChannelDialog extends JDialog {
}
ok.setEnabled(false);
finish(conn.applyChannelEdit(channel.id, changes, setPermissions, clearedPermissions),
finish(conn.channels().edit(channel.id, changes, setPermissions, clearedPermissions),
"Could not save the channel: ");
}
@@ -256,7 +256,7 @@ final class ComplaintsDialog extends JDialog {
if (loading) return;
loading = true;
status.setText("Loading…");
Edt.handle(conn.requestComplaints(), complaints -> {
Edt.handle(conn.complaints().list(), complaints -> {
loading = false;
if (!isDisplayable()) return;
setTargets(groupByTarget(complaints));
@@ -384,7 +384,7 @@ 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();
Edt.handle(conn.deleteComplaints(whole, sel.single()), () -> {
Edt.handle(conn.complaints().delete(whole, sel.single()), () -> {
if (isDisplayable()) reload();
}, failure -> {
if (!isDisplayable()) return;
@@ -3,7 +3,7 @@ package eu.lixko.ts3j.client.ui;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.formdev.flatlaf.util.UIScale;
import eu.lixko.ts3j.client.net.IconRepository;
import eu.lixko.ts3j.client.net.TeamspeakConnection;
import eu.lixko.ts3j.client.net.ChannelAdmin;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
@@ -42,7 +42,7 @@ final class IconChooserDialog extends JDialog {
/** Give up repainting once nothing has arrived for this long. */
private static final int REFRESH_TIMEOUT_MS = 20_000;
private final TeamspeakConnection conn;
private final ChannelAdmin channels;
private final GroupIcons groupIcons;
private final DefaultListModel<Long> remoteModel = new DefaultListModel<>();
@@ -55,9 +55,9 @@ final class IconChooserDialog extends JDialog {
private long chosenIconId;
private boolean accepted;
IconChooserDialog(Window owner, TeamspeakConnection conn, GroupIcons groupIcons) {
IconChooserDialog(Window owner, ChannelAdmin channels, GroupIcons groupIcons) {
super(owner, "Icons", ModalityType.APPLICATION_MODAL);
this.conn = conn;
this.channels = channels;
this.groupIcons = groupIcons;
configure(remoteList);
@@ -178,7 +178,7 @@ final class IconChooserDialog extends JDialog {
private void loadRemoteIcons() {
status.setText("Loading icons…");
Edt.handle(conn.requestServerIcons(), ids -> {
Edt.handle(channels.icons(), ids -> {
status.setText(" ");
remoteModel.clear();
for (Long id : ids) remoteModel.addElement(id);
@@ -192,7 +192,7 @@ final class IconChooserDialog extends JDialog {
if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;
File file = chooser.getSelectedFile();
status.setText("Uploading " + file.getName() + "…");
Edt.handle(conn.uploadIcon(file), iconId -> {
Edt.handle(channels.uploadIcon(file), iconId -> {
loadRemoteIcons();
startRefreshing();
}, failure -> {
@@ -209,7 +209,7 @@ 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;
Edt.handle(conn.deleteIcon(id), () -> remoteModel.removeElement(id),
Edt.handle(channels.deleteIcon(id), () -> remoteModel.removeElement(id),
failure -> JOptionPane.showMessageDialog(this, "Failed to delete remote icon file: " + failure.getMessage(),
"Error", JOptionPane.ERROR_MESSAGE));
}
@@ -252,8 +252,8 @@ final class IconChooserDialog extends JDialog {
}
/** Convenience for callers that only need the picked id. */
static long pick(Window owner, TeamspeakConnection conn, GroupIcons groupIcons, long current) {
IconChooserDialog dialog = new IconChooserDialog(owner, conn, groupIcons);
static long pick(Window owner, ChannelAdmin channels, GroupIcons groupIcons, long current) {
IconChooserDialog dialog = new IconChooserDialog(owner, channels, groupIcons);
dialog.setVisible(true);
return dialog.isAccepted() ? dialog.getIconId() : current;
}
@@ -8,7 +8,7 @@ import eu.lixko.ts3j.client.contacts.ContactStore;
import eu.lixko.ts3j.client.contacts.ContactType;
import eu.lixko.ts3j.client.net.DatabaseClient;
import eu.lixko.ts3j.client.net.OfflineMessage;
import eu.lixko.ts3j.client.net.TeamspeakConnection;
import eu.lixko.ts3j.client.net.OfflineMessageAdmin;
import eu.lixko.ts3j.client.text.BBCode;
import javax.swing.BorderFactory;
@@ -71,7 +71,7 @@ final class OfflineMessageComposeDialog extends JDialog {
/** The client property naming the recipient a chip stands for. */
private static final String CHIP_UID = "ts3.recipientUid";
private final TeamspeakConnection conn;
private final OfflineMessageAdmin messages;
/** Recipients by unique id, in the order they were added. */
private final Map<String, DatabaseClient> recipients = new LinkedHashMap<>();
@@ -86,19 +86,19 @@ final class OfflineMessageComposeDialog extends JDialog {
private final JButton sendButton = new JButton("Send");
private boolean sending;
static OfflineMessageComposeDialog compose(Window owner, TeamspeakConnection conn, ContactStore contacts) {
return new OfflineMessageComposeDialog(owner, "New Offline Message", conn, contacts);
static OfflineMessageComposeDialog compose(Window owner, OfflineMessageAdmin messages, ContactStore contacts) {
return new OfflineMessageComposeDialog(owner, "New Offline Message", messages, contacts);
}
/** A reply to {@code message}, quoting {@code body}. */
static OfflineMessageComposeDialog reply(Window owner, TeamspeakConnection conn, ContactStore contacts,
static OfflineMessageComposeDialog reply(Window owner, OfflineMessageAdmin messages, ContactStore contacts,
OfflineMessage message, String body) {
OfflineMessageComposeDialog d = new OfflineMessageComposeDialog(owner, "Reply Offline Message", conn, contacts);
OfflineMessageComposeDialog d = new OfflineMessageComposeDialog(owner, "Reply Offline Message", messages, contacts);
d.addRecipient(new DatabaseClient(message.senderUid(), 0, message.senderName()));
String subject = message.subject().regionMatches(true, 0, "Re:", 0, 3)
? message.subject() : "Re: " + message.subject();
d.subjectField.setText(subject.length() > TeamspeakConnection.OFFLINE_MESSAGE_SUBJECT_LIMIT
? subject.substring(0, TeamspeakConnection.OFFLINE_MESSAGE_SUBJECT_LIMIT) : subject);
d.subjectField.setText(subject.length() > OfflineMessageAdmin.SUBJECT_LIMIT
? subject.substring(0, OfflineMessageAdmin.SUBJECT_LIMIT) : subject);
d.bodyArea.setText(quote(message.senderName(), body));
d.bodyArea.setCaretPosition(d.bodyArea.getDocument().getLength());
return d;
@@ -111,12 +111,12 @@ final class OfflineMessageComposeDialog extends JDialog {
return out.toString();
}
private OfflineMessageComposeDialog(Window owner, String title, TeamspeakConnection conn, ContactStore contacts) {
private OfflineMessageComposeDialog(Window owner, String title, OfflineMessageAdmin messages, ContactStore contacts) {
super(owner, title, ModalityType.MODELESS);
this.conn = conn;
this.messages = messages;
limit(subjectField, TeamspeakConnection.OFFLINE_MESSAGE_SUBJECT_LIMIT);
limit(bodyArea, TeamspeakConnection.OFFLINE_MESSAGE_LIMIT);
limit(subjectField, OfflineMessageAdmin.SUBJECT_LIMIT);
limit(bodyArea, OfflineMessageAdmin.BODY_LIMIT);
for (Contact c : contacts.all()) {
if (c.type != ContactType.BLOCKED) {
available.addElement(new DatabaseClient(c.uniqueId, 0, c.nickname.isEmpty() ? c.uniqueId : c.nickname));
@@ -362,7 +362,7 @@ final class OfflineMessageComposeDialog extends JDialog {
String typed = recipientField.getText().trim();
if (typed.isEmpty()) return;
if (UNIQUE_ID.matcher(typed).matches()) {
Edt.handle(conn.lookupDatabaseClient(typed),
Edt.handle(messages.lookupUid(typed),
client -> client.ifPresentOrElse(this::accept,
() -> showRecipientError("The unique ID is unknown on this server.")),
failure -> showRecipientError(failure.getMessage()));
@@ -374,7 +374,7 @@ final class OfflineMessageComposeDialog extends JDialog {
return;
}
}
Edt.handle(conn.searchDatabaseClients(typed), found -> {
Edt.handle(messages.search(typed), found -> {
if (found.isEmpty()) {
showRecipientError("The nickname is unknown on this server.");
return;
@@ -431,7 +431,7 @@ final class OfflineMessageComposeDialog extends JDialog {
if (!sendButton.isEnabled()) return;
sending = true;
updateSendButton();
Edt.handle(conn.sendOfflineMessage(new ArrayList<>(recipients.keySet()), subjectField.getText(), bodyArea.getText()),
Edt.handle(messages.send(new ArrayList<>(recipients.keySet()), subjectField.getText(), bodyArea.getText()),
() -> {
sending = false;
if (isDisplayable()) dispose();
@@ -327,7 +327,7 @@ final class OfflineMessagesDialog extends JDialog {
if (loading) return;
loading = true;
status.setText("Loading…");
Edt.handle(conn.requestOfflineMessages(), messages -> {
Edt.handle(conn.offlineMessages().list(), messages -> {
loading = false;
if (!isDisplayable()) return;
setMessages(messages);
@@ -388,7 +388,7 @@ final class OfflineMessagesDialog extends JDialog {
return;
}
bodyPane.setText("");
Edt.handle(conn.requestOfflineMessageBody(message.id()), text -> {
Edt.handle(conn.offlineMessages().body(message.id()), text -> {
if (!isDisplayable()) return;
bodies.put(message.id(), text);
if (shownId == message.id()) showBody(message, text);
@@ -419,7 +419,7 @@ final class OfflineMessagesDialog extends JDialog {
composer.reply(message, body);
return;
}
Edt.handle(conn.requestOfflineMessageBody(message.id()), text -> {
Edt.handle(conn.offlineMessages().body(message.id()), text -> {
if (!isDisplayable()) return;
bodies.put(message.id(), text);
composer.reply(message, text);
@@ -436,7 +436,7 @@ 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));
Edt.onFailure(conn.markOfflineMessages(messages.stream().map(OfflineMessage::id).toList(), read), failure -> {
Edt.onFailure(conn.offlineMessages().markRead(messages.stream().map(OfflineMessage::id).toList(), read), failure -> {
if (!isDisplayable()) return;
status.setText("Failed to update offline message: " + failure.getMessage());
reload();
@@ -460,7 +460,7 @@ final class OfflineMessagesDialog extends JDialog {
for (OfflineMessage m : selected) bodies.remove(m.id());
reload();
};
Edt.handle(conn.deleteOfflineMessages(selected.stream().map(OfflineMessage::id).toList()), () -> {
Edt.handle(conn.offlineMessages().delete(selected.stream().map(OfflineMessage::id).toList()), () -> {
if (isDisplayable()) deleted.run();
}, failure -> {
if (!isDisplayable()) return;
@@ -148,7 +148,7 @@ final class PrivilegeKeyCreateDialog extends JDialog {
Group group = (Group) groupBox.getSelectedItem();
ChannelNode channel = (ChannelNode) channelBox.getSelectedItem();
create.setEnabled(false);
Edt.handle(conn.addPrivilegeKey(forChannelGroup(), group.id, channel == null ? 0 : channel.id,
Edt.handle(conn.privilegeKeys().add(forChannelGroup(), group.id, channel == null ? 0 : channel.id,
descriptionField.getText().trim()), key -> {
if (!isDisplayable()) return;
updateCreate();
@@ -212,7 +212,7 @@ final class PrivilegeKeysDialog extends JDialog {
if (loading) return;
loading = true;
status.setText("Loading…");
Edt.handle(conn.requestPrivilegeKeys(), keys -> {
Edt.handle(conn.privilegeKeys().list(), keys -> {
loading = false;
if (!isDisplayable()) return;
tableModel.setKeys(keys);
@@ -252,7 +252,7 @@ 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());
Edt.handle(conn.deletePrivilegeKeys(tokens), () -> {
Edt.handle(conn.privilegeKeys().delete(tokens), () -> {
if (isDisplayable()) reload();
}, failure -> {
if (!isDisplayable()) return;
@@ -264,7 +264,7 @@ final class ServerLogDialog extends JDialog {
loading = true;
olderButton.setEnabled(false);
showStatus("Loading…", Theme.chatEvent());
Edt.handle(conn.requestServerLog(from), page -> {
Edt.handle(conn.serverLog().read(from), page -> {
loading = false;
if (isDisplayable()) received(page, from > 0);
}, failure -> {
@@ -227,7 +227,7 @@ final class ServerTab {
@Override
public void reply(OfflineMessage message, String body) {
if (!session.isConnected()) return;
OfflineMessageComposeDialog.reply(offlineMessages, conn, contacts, message, body).setVisible(true);
OfflineMessageComposeDialog.reply(offlineMessages, conn.offlineMessages(), contacts, message, body).setVisible(true);
}
});
}
@@ -238,7 +238,7 @@ final class ServerTab {
void composeOfflineMessage() {
if (!session.permissions().canSendOfflineMessages()) return;
Window owner = offlineMessages != null && offlineMessages.isShowing() ? offlineMessages : host;
OfflineMessageComposeDialog.compose(owner, conn, contacts).setVisible(true);
OfflineMessageComposeDialog.compose(owner, conn.offlineMessages(), contacts).setVisible(true);
}
/** New mail refreshes an open inbox; a message being read does not need to. */
@@ -254,7 +254,7 @@ 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;
Edt.onFailure(conn.usePrivilegeKey(key.trim()), failure -> JOptionPane.showMessageDialog(host,
Edt.onFailure(conn.privilegeKeys().use(key.trim()), failure -> JOptionPane.showMessageDialog(host,
failure.getMessage(), "Error using Privilege Key", JOptionPane.ERROR_MESSAGE));
}
@@ -5,6 +5,7 @@ import eu.lixko.ts3j.client.net.ChannelNode;
import eu.lixko.ts3j.client.net.Spacers;
import eu.lixko.ts3j.client.net.ChannelSettings;
import eu.lixko.ts3j.client.net.ClientEntry;
import eu.lixko.ts3j.client.net.ComplaintAdmin;
import eu.lixko.ts3j.client.net.Group;
import eu.lixko.ts3j.client.net.TeamspeakConnection;
import eu.lixko.ts3j.client.text.TsLink;
@@ -140,8 +141,8 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
public void complainAboutClient(ClientEntry client) {
if (!conn.isConnected()) return;
String reason = ReasonDialog.prompt(host, "Make a Complaint", "Enter the reason for your complaint:",
TeamspeakConnection.COMPLAINT_REASON_LIMIT);
if (reason != null) conn.complain(client, reason);
ComplaintAdmin.REASON_LIMIT);
if (reason != null) conn.complaints().complain(client, reason);
}
@Override
@@ -314,7 +315,7 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
return;
}
Edt.onFailure(conn.deleteChannel(channel.id, true), failure -> JOptionPane.showMessageDialog(host,
Edt.onFailure(conn.channels().delete(channel.id, true), failure -> JOptionPane.showMessageDialog(host,
"Could not delete the channel: " + failure.getMessage(), "Error", JOptionPane.ERROR_MESSAGE));
}