Frontends reach a server only through ServerSession
session.connection() is gone: the session hands out the model, our ids, the microphone and speakers, ping and connection info, the server's unique id, icon and avatar stores, myTeamSpeak, the connect error and a blocking disconnectNow. The connection's remaining actions move into helpers the session hands out instead of forwarding each method: ClientAdmin (move, kick, ban, groups, talk power, poke, client details), ChannelFiles (listing, mkdir, rename, delete, transfers and their sounds) and ClientContacts (display names, volume, auto-mute, whisper policy, sightings); ChannelAdmin also takes join, move, subscribe and description requests. Dialogs take the session instead of the connection. Android's network handover now uses disconnectNow, which also cancels a pending auto-reconnect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import eu.lixko.ts3j.client.net.ClientEntry;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.net.avatar.Avatar;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
@@ -20,28 +20,28 @@ final class AvatarActions {
|
||||
private static File lastDirectory;
|
||||
|
||||
private final Component owner;
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
|
||||
AvatarActions(Component owner, TeamspeakConnection conn) {
|
||||
AvatarActions(Component owner, ServerSession session) {
|
||||
this.owner = owner;
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
/** Asks for an image and uploads it as our avatar. */
|
||||
void choose() {
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
JFileChooser chooser = new JFileChooser(lastDirectory);
|
||||
chooser.setDialogTitle("Select your avatar");
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("Images", "png", "jpg", "jpeg", "gif", "bmp"));
|
||||
if (chooser.showOpenDialog(owner) != JFileChooser.APPROVE_OPTION) return;
|
||||
File file = chooser.getSelectedFile();
|
||||
lastDirectory = file.getParentFile();
|
||||
Edt.onFailure(conn.avatarAdmin().set(file), failure -> show("Error uploading avatar: " + failure.getMessage()));
|
||||
Edt.onFailure(session.avatarAdmin().set(file), failure -> show("Error uploading avatar: " + failure.getMessage()));
|
||||
}
|
||||
|
||||
/** Uploads someone else's avatar as ours. */
|
||||
void steal(Avatar avatar) {
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
File file;
|
||||
try {
|
||||
file = Files.createTempFile("avatar", "." + avatar.format().extension).toFile();
|
||||
@@ -50,20 +50,20 @@ final class AvatarActions {
|
||||
show("Error uploading avatar: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
CompletableFuture<Void> upload = conn.avatarAdmin().set(file);
|
||||
CompletableFuture<Void> upload = session.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.avatarAdmin().remove(), failure -> show("Error deleting avatar: " + failure.getMessage()));
|
||||
if (!session.isConnected()) return;
|
||||
Edt.onFailure(session.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.avatarAdmin().removeOf(client), failure -> show("Error deleting avatar: " + failure.getMessage()));
|
||||
if (!session.isConnected()) return;
|
||||
Edt.onFailure(session.avatarAdmin().removeOf(client), failure -> show("Error deleting avatar: " + failure.getMessage()));
|
||||
}
|
||||
|
||||
private void show(String message) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.config.BanReasonPresets;
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.net.Permissions;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.net.ban.BanEntry;
|
||||
import eu.lixko.ts3j.client.net.ban.BanRule;
|
||||
|
||||
@@ -96,7 +96,7 @@ final class BanListDialog extends JDialog {
|
||||
}
|
||||
|
||||
private final Frame owner;
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final Settings settings;
|
||||
private final BanReasonPresets presets;
|
||||
|
||||
@@ -117,10 +117,10 @@ final class BanListDialog extends JDialog {
|
||||
|
||||
private boolean loading;
|
||||
|
||||
BanListDialog(Frame owner, TeamspeakConnection conn, Settings settings, BanReasonPresets presets) {
|
||||
BanListDialog(Frame owner, ServerSession session, Settings settings, BanReasonPresets presets) {
|
||||
super(owner, "Ban List", false);
|
||||
this.owner = owner;
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.settings = settings;
|
||||
this.presets = presets;
|
||||
|
||||
@@ -362,7 +362,7 @@ final class BanListDialog extends JDialog {
|
||||
|
||||
/** Follows the server's name, as the official window's "Ban List - <server>" title does. */
|
||||
void serverNameChanged() {
|
||||
String name = conn.getModel().getServerName();
|
||||
String name = session.model().getServerName();
|
||||
setTitle(name == null || name.isBlank() ? "Ban List" : "Ban List - " + name);
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ final class BanListDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
Edt.handle(conn.bans().list(), bans -> {
|
||||
Edt.handle(session.bans().list(), bans -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
tableModel.setBans(bans);
|
||||
@@ -395,7 +395,7 @@ final class BanListDialog extends JDialog {
|
||||
private void applyFilter() {
|
||||
String needle = searchField.getText().trim().toLowerCase(Locale.ROOT);
|
||||
boolean own = onlyOwn.isSelected();
|
||||
String self = conn.getSelfUniqueId();
|
||||
String self = session.selfUniqueId();
|
||||
sorter.setRowFilter(new RowFilter<>() {
|
||||
@Override
|
||||
public boolean include(Entry<? extends BanTableModel, ? extends Integer> entry) {
|
||||
@@ -419,17 +419,17 @@ final class BanListDialog extends JDialog {
|
||||
// ---- permissions ----
|
||||
|
||||
private void updateButtons() {
|
||||
Permissions permissions = conn.getModel().permissions();
|
||||
Permissions permissions = session.model().permissions();
|
||||
List<BanEntry> selected = selectedBans();
|
||||
addButton.setEnabled(permissions.canCreateBans());
|
||||
removeButton.setEnabled(!selected.isEmpty() && permissions.canDeleteBans(selected, conn.getSelfUniqueId()));
|
||||
editButton.setEnabled(selected.size() == 1 && permissions.canEditBan(selected.get(0), conn.getSelfUniqueId()));
|
||||
removeButton.setEnabled(!selected.isEmpty() && permissions.canDeleteBans(selected, session.selfUniqueId()));
|
||||
editButton.setEnabled(selected.size() == 1 && permissions.canEditBan(selected.get(0), session.selfUniqueId()));
|
||||
}
|
||||
|
||||
// ---- actions ----
|
||||
|
||||
private long maxBanSeconds() {
|
||||
return conn.getModel().permissions().maxBanSeconds();
|
||||
return session.model().permissions().maxBanSeconds();
|
||||
}
|
||||
|
||||
private void addBan() {
|
||||
@@ -438,7 +438,7 @@ final class BanListDialog extends JDialog {
|
||||
dialog.setVisible(true);
|
||||
BanRule rule = dialog.getRule();
|
||||
if (rule == null) return;
|
||||
afterChange(conn.bans().add(rule), "Error adding ban: ",
|
||||
afterChange(session.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.bans().replace(ban.id, rule), "Error editing ban: ");
|
||||
afterChange(session.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.bans().delete(ids), "Error deleting ban: ");
|
||||
afterChange(session.bans().delete(ids), "Error deleting ban: ");
|
||||
}
|
||||
|
||||
/** Reports a failed change, or re-reads the list so the table shows what the server now holds. */
|
||||
@@ -582,7 +582,7 @@ final class BanListDialog extends JDialog {
|
||||
BanEntry ban = tableModel.get(t.convertRowIndexToModel(row));
|
||||
Column c = Column.values()[t.convertColumnIndexToModel(column)];
|
||||
super.getTableCellRendererComponent(t, tableModel.text(ban, c), selected, focused, row, column);
|
||||
boolean bold = highlightOwn.isSelected() && ban.createdBy(conn.getSelfUniqueId());
|
||||
boolean bold = highlightOwn.isSelected() && ban.createdBy(session.selfUniqueId());
|
||||
setFont(bold ? Theme.uiBold() : Theme.uiFont());
|
||||
setHorizontalAlignment(c == Column.ENFORCED ? RIGHT : LEFT);
|
||||
return this;
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.net.ChannelNode;
|
||||
import eu.lixko.ts3j.client.net.ChannelSettings;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
@@ -79,7 +79,7 @@ final class ChannelDialog extends JDialog {
|
||||
+ " special spacer: \"---\", \"...\", \"-.-\", \"___\", \"-..\"</td></tr>"
|
||||
+ "</table></html>";
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final GroupIcons groupIcons;
|
||||
/** The channel being edited, or {@code null} when a new one is being created. */
|
||||
private final ChannelNode channel;
|
||||
@@ -107,9 +107,9 @@ final class ChannelDialog extends JDialog {
|
||||
private boolean passwordEdited;
|
||||
|
||||
/** The editor for an existing channel. */
|
||||
static ChannelDialog toEdit(Window owner, TeamspeakConnection conn, GroupIcons groupIcons,
|
||||
static ChannelDialog toEdit(Window owner, ServerSession session, GroupIcons groupIcons,
|
||||
ChannelNode channel) {
|
||||
return new ChannelDialog(owner, conn, groupIcons, "Edit Channel: " + channel.name,
|
||||
return new ChannelDialog(owner, session, groupIcons, "Edit Channel: " + channel.name,
|
||||
channel, channel.parentId, null);
|
||||
}
|
||||
|
||||
@@ -119,20 +119,20 @@ final class ChannelDialog extends JDialog {
|
||||
* @param parentId the channel it goes below, 0 being the top level
|
||||
* @param defaults what the dialog opens with, e.g. the channel type its caller prefers
|
||||
*/
|
||||
static ChannelDialog toCreate(Window owner, TeamspeakConnection conn, GroupIcons groupIcons,
|
||||
static ChannelDialog toCreate(Window owner, ServerSession session, GroupIcons groupIcons,
|
||||
String title, int parentId, ChannelSettings defaults) {
|
||||
return new ChannelDialog(owner, conn, groupIcons, title, null, parentId, defaults);
|
||||
return new ChannelDialog(owner, session, groupIcons, title, null, parentId, defaults);
|
||||
}
|
||||
|
||||
private ChannelDialog(Window owner, TeamspeakConnection conn, GroupIcons groupIcons, String title,
|
||||
private ChannelDialog(Window owner, ServerSession session, GroupIcons groupIcons, String title,
|
||||
ChannelNode channel, int parentId, ChannelSettings defaults) {
|
||||
super(owner, title, ModalityType.APPLICATION_MODAL);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.groupIcons = groupIcons;
|
||||
this.channel = channel;
|
||||
this.parentId = parentId;
|
||||
this.standardPanel = new ChannelStandardPanel(channel != null
|
||||
? conn.getModel().siblingsOf(channel.id) : conn.getModel().childrenOf(parentId));
|
||||
? session.model().siblingsOf(channel.id) : session.model().childrenOf(parentId));
|
||||
|
||||
standardPanel.onTypeChanged(advancedPanel::setChannelType);
|
||||
settingsTabs = List.of(standardPanel, audioPanel, advancedPanel);
|
||||
@@ -286,12 +286,12 @@ final class ChannelDialog extends JDialog {
|
||||
// ---- loading ----
|
||||
|
||||
private void load() {
|
||||
Edt.handle(conn.channels().settings(channel.id), this::apply, failure -> {
|
||||
Edt.handle(session.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.channels().permissions(channel.id), permissionsPanel::read,
|
||||
Edt.handle(session.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.channels(), groupIcons);
|
||||
IconChooserDialog chooser = new IconChooserDialog(this, session.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.channels().create(parentId, edited.creationParameters(), permissionsPanel.changed()),
|
||||
finish(session.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.channels().edit(channel.id, changes, setPermissions, clearedPermissions),
|
||||
finish(session.channels().edit(channel.id, changes, setPermissions, clearedPermissions),
|
||||
"Could not save the channel: ");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.net.ClientContacts;
|
||||
import eu.lixko.ts3j.client.net.ClientEntry;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
@@ -24,17 +24,17 @@ final class ClientVolumeDialog extends JDialog {
|
||||
|
||||
private static final int RANGE_DB = 40;
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ClientContacts contacts;
|
||||
private final ClientEntry client;
|
||||
private final JSlider slider = new JSlider(-RANGE_DB, RANGE_DB, 0);
|
||||
private final JLabel value = new JLabel();
|
||||
|
||||
ClientVolumeDialog(Frame owner, TeamspeakConnection conn, ClientEntry client) {
|
||||
super(owner, "Change Volume: " + conn.displayName(client), false);
|
||||
this.conn = conn;
|
||||
ClientVolumeDialog(Frame owner, ClientContacts contacts, ClientEntry client) {
|
||||
super(owner, "Change Volume: " + contacts.displayName(client), false);
|
||||
this.contacts = contacts;
|
||||
this.client = client;
|
||||
|
||||
slider.setValue((int) Math.round(conn.getClientVolumeModifier(client)));
|
||||
slider.setValue((int) Math.round(contacts.volumeModifier(client)));
|
||||
slider.setMajorTickSpacing(20);
|
||||
slider.setMinorTickSpacing(5);
|
||||
slider.setPaintTicks(true);
|
||||
@@ -75,6 +75,6 @@ final class ClientVolumeDialog extends JDialog {
|
||||
private void onChanged() {
|
||||
int db = slider.getValue();
|
||||
value.setText((db > 0 ? "+" : "") + db + " dB");
|
||||
if (!slider.getValueIsAdjusting()) conn.setClientVolumeModifier(client, db);
|
||||
if (!slider.getValueIsAdjusting()) contacts.setVolumeModifier(client, db);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.net.ClientEntry;
|
||||
import eu.lixko.ts3j.client.net.Complaint;
|
||||
import eu.lixko.ts3j.client.net.ServerModel;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Box;
|
||||
@@ -88,7 +88,7 @@ final class ComplaintsDialog extends JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final Consumer<ClientEntry> banClient;
|
||||
|
||||
private final ComplaintTableModel tableModel = new ComplaintTableModel();
|
||||
@@ -112,9 +112,9 @@ final class ComplaintsDialog extends JDialog {
|
||||
private boolean loading;
|
||||
|
||||
/** @param banClient opens the ban dialog for an online client */
|
||||
ComplaintsDialog(Frame owner, TeamspeakConnection conn, Consumer<ClientEntry> banClient) {
|
||||
ComplaintsDialog(Frame owner, ServerSession session, Consumer<ClientEntry> banClient) {
|
||||
super(owner, "Complaints List", false);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.banClient = banClient;
|
||||
|
||||
JPanel content = new JPanel(new BorderLayout(0, UIScale.scale(6)));
|
||||
@@ -244,7 +244,7 @@ final class ComplaintsDialog extends JDialog {
|
||||
|
||||
/** Follows the server's name, as the ban list's title does. */
|
||||
void serverNameChanged() {
|
||||
String name = conn.getModel().getServerName();
|
||||
String name = session.model().getServerName();
|
||||
setTitle(name == null || name.isBlank() ? "Complaints List" : "Complaints List - " + name);
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ final class ComplaintsDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
Edt.handle(conn.complaints().list(), complaints -> {
|
||||
Edt.handle(session.complaints().list(), complaints -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
setTargets(groupByTarget(complaints));
|
||||
@@ -349,13 +349,13 @@ final class ComplaintsDialog extends JDialog {
|
||||
}
|
||||
|
||||
private int selfDbId() {
|
||||
ClientEntry self = conn.getModel().getClient(conn.getSelfClientId());
|
||||
ClientEntry self = session.model().getClient(session.selfClientId());
|
||||
return self == null ? 0 : self.databaseId;
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
Selection sel = selection();
|
||||
removeButton.setEnabled(!sel.isEmpty() && conn.getModel().permissions().canDeleteComplaints(sel.affected(), selfDbId()));
|
||||
removeButton.setEnabled(!sel.isEmpty() && session.model().permissions().canDeleteComplaints(sel.affected(), selfDbId()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,11 +365,11 @@ final class ComplaintsDialog extends JDialog {
|
||||
private ClientEntry banTarget() {
|
||||
int[] rows = table.getSelectedRows();
|
||||
if (rows.length != 1) return null;
|
||||
ServerModel model = conn.getModel();
|
||||
ServerModel model = session.model();
|
||||
if (!model.permissions().canBanClients()) return null;
|
||||
Row row = tableModel.get(rows[0]);
|
||||
ClientEntry client = model.findClientByDatabaseId(row.isTarget() ? row.target().dbId() : row.complaint().fromDbId());
|
||||
return client == null || client.id == conn.getSelfClientId() ? null : client;
|
||||
return client == null || client.id == session.selfClientId() ? null : client;
|
||||
}
|
||||
|
||||
// ---- actions ----
|
||||
@@ -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.complaints().delete(whole, sel.single()), () -> {
|
||||
Edt.handle(session.complaints().delete(whole, sel.single()), () -> {
|
||||
if (isDisplayable()) reload();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
|
||||
@@ -7,7 +7,7 @@ import eu.lixko.ts3j.client.net.ConnectionStats;
|
||||
import eu.lixko.ts3j.client.net.ConnectionStatsFormat;
|
||||
import eu.lixko.ts3j.client.net.ConnectionStatsFormat.Row;
|
||||
import eu.lixko.ts3j.client.net.ConnectionStatsFormat.TrafficRow;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.net.avatar.Avatar;
|
||||
|
||||
import javax.swing.Box;
|
||||
@@ -53,7 +53,7 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
private static final String TOTAL_SAMPLE = "100.00 %";
|
||||
private static final String VALUE_SAMPLE = "1023.00 KiB/s";
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final int clientId;
|
||||
private final String nickname;
|
||||
private final javax.swing.Timer timer;
|
||||
@@ -69,9 +69,9 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
private Figures quota;
|
||||
private final Figures voice = new Figures(List.of(ConnectionStatsFormat.voiceRows(null)), false);
|
||||
|
||||
public ConnectionInfoDialog(Frame owner, TeamspeakConnection conn, int clientId, String nickname) {
|
||||
public ConnectionInfoDialog(Frame owner, ServerSession session, int clientId, String nickname) {
|
||||
super(owner, "Connection Info - " + nickname, false);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.clientId = clientId;
|
||||
this.nickname = nickname;
|
||||
this.summary = new Figures(List.of(ConnectionStatsFormat.summaryRows(null, nickname)), true);
|
||||
@@ -169,12 +169,12 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
// ---- live update ----
|
||||
|
||||
private void refresh() {
|
||||
if (!conn.isConnected()) {
|
||||
if (!session.isConnected()) {
|
||||
timer.stop();
|
||||
return;
|
||||
}
|
||||
if (!inFlight.compareAndSet(false, true)) return; // a previous poll is still running
|
||||
conn.requestConnectionInfo(clientId, stats -> SwingUtilities.invokeLater(() -> {
|
||||
session.requestConnectionInfo(clientId, stats -> SwingUtilities.invokeLater(() -> {
|
||||
inFlight.set(false);
|
||||
apply(stats);
|
||||
}));
|
||||
@@ -192,8 +192,8 @@ public final class ConnectionInfoDialog extends JDialog {
|
||||
}
|
||||
|
||||
private void showAvatar() {
|
||||
ClientEntry client = conn.getModel().getClient(clientId);
|
||||
Avatar current = conn.avatarOf(client);
|
||||
ClientEntry client = session.model().getClient(clientId);
|
||||
Avatar current = session.avatarOf(client);
|
||||
if (current == shownAvatar) return;
|
||||
shownAvatar = current;
|
||||
avatar.setIcon(current == null ? null : avatarIcon(current));
|
||||
|
||||
@@ -145,7 +145,7 @@ final class DesktopNotifier {
|
||||
frame.bringToFront();
|
||||
frame.selectTab(tab);
|
||||
if (clientId != null) {
|
||||
var client = tab.connection().getModel().getClient(clientId);
|
||||
var client = tab.session().model().getClient(clientId);
|
||||
if (client != null) tab.chat().openPrivateChat(clientId, client.uniqueId, client.nickname);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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.ChannelNode;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.net.filetransfer.FileTransfer;
|
||||
import eu.lixko.ts3j.client.net.filetransfer.RemoteFile;
|
||||
|
||||
@@ -47,7 +47,7 @@ import java.util.List;
|
||||
*/
|
||||
public final class FileBrowserDialog extends JDialog {
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final int channelId;
|
||||
private final String channelPassword;
|
||||
|
||||
@@ -61,9 +61,9 @@ public final class FileBrowserDialog extends JDialog {
|
||||
|
||||
private volatile String currentPath = "/";
|
||||
|
||||
public FileBrowserDialog(Frame owner, TeamspeakConnection conn, ChannelNode channel) {
|
||||
public FileBrowserDialog(Frame owner, ServerSession session, ChannelNode channel) {
|
||||
super(owner, "Files — " + channel.name, false);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.channelId = channel.id;
|
||||
this.channelPassword = "";
|
||||
|
||||
@@ -181,7 +181,7 @@ public final class FileBrowserDialog extends JDialog {
|
||||
final String path = currentPath;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
List<RemoteFile> files = conn.listFiles(channelId, channelPassword, path);
|
||||
List<RemoteFile> files = session.files().list(channelId, channelPassword, path);
|
||||
Collections.sort(files, DIRECTORIES_FIRST);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (path.equals(currentPath)) tableModel.setFiles(files);
|
||||
@@ -243,7 +243,7 @@ public final class FileBrowserDialog extends JDialog {
|
||||
|
||||
private void startDownload(RemoteFile file, File target) {
|
||||
TransferRow row = new TransferRow();
|
||||
FileTransfer transfer = conn.downloadFile(channelId, channelPassword, file.getFullPath(), target,
|
||||
FileTransfer transfer = session.files().download(channelId, channelPassword, file.getFullPath(), target,
|
||||
t -> SwingUtilities.invokeLater(() -> row.update(t)));
|
||||
row.attach(transfer);
|
||||
addTransferRow(row);
|
||||
@@ -258,7 +258,7 @@ public final class FileBrowserDialog extends JDialog {
|
||||
if (!source.isFile()) continue;
|
||||
String remotePath = currentPath + source.getName();
|
||||
TransferRow row = new TransferRow();
|
||||
FileTransfer transfer = conn.uploadFile(channelId, channelPassword, remotePath, source, true,
|
||||
FileTransfer transfer = session.files().upload(channelId, channelPassword, remotePath, source, true,
|
||||
t -> SwingUtilities.invokeLater(() -> {
|
||||
row.update(t);
|
||||
if (t.getState() == FileTransfer.State.COMPLETED) refresh();
|
||||
@@ -275,7 +275,7 @@ public final class FileBrowserDialog extends JDialog {
|
||||
final String dirPath = currentPath + name.trim();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
conn.createDirectory(channelId, channelPassword, dirPath);
|
||||
session.files().createDirectory(channelId, channelPassword, dirPath);
|
||||
SwingUtilities.invokeLater(this::refresh);
|
||||
} catch (Exception ex) {
|
||||
SwingUtilities.invokeLater(() -> error("Could not create folder", ex));
|
||||
@@ -295,7 +295,7 @@ public final class FileBrowserDialog extends JDialog {
|
||||
Exception failure = null;
|
||||
for (RemoteFile f : files) {
|
||||
try {
|
||||
conn.deleteFile(channelId, channelPassword, f.getFullPath());
|
||||
session.files().delete(channelId, channelPassword, f.getFullPath());
|
||||
} catch (Exception ex) {
|
||||
failure = ex;
|
||||
}
|
||||
|
||||
@@ -829,7 +829,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
settings.save();
|
||||
|
||||
ServerTab tab = (replaceCurrent && selected != null) ? selected : tabForNewConnection();
|
||||
tab.session().connection().setMyTeamSpeakFeatures(mytsFeatures);
|
||||
tab.session().setMyTeamSpeakFeatures(mytsFeatures);
|
||||
// The first connection to come up takes the microphone; later ones are muted
|
||||
// until the user activates them.
|
||||
if (sessions.microphoneOwner() == null) sessions.giveMicrophoneTo(tab.session());
|
||||
@@ -859,7 +859,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
}
|
||||
}
|
||||
ServerTab tab = tabForNewConnection();
|
||||
tab.session().connection().setMyTeamSpeakFeatures(true);
|
||||
tab.session().setMyTeamSpeakFeatures(true);
|
||||
if (sessions.microphoneOwner() == null) sessions.giveMicrophoneTo(tab.session());
|
||||
tab.session().open(link, "");
|
||||
}
|
||||
@@ -1034,8 +1034,8 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
// Device and voice-gating changes apply to the capturing connection and the
|
||||
// playback of the visible one; the rest pick the new settings up on connect.
|
||||
SettingsDialog dlg = new SettingsDialog(this, settings, audio,
|
||||
sessions.microphoneOwner() == null ? null : sessions.microphoneOwner().connection().ownClient().microphone(),
|
||||
selected == null ? null : selected.connection().ownClient().playback(),
|
||||
sessions.microphoneOwner() == null ? null : sessions.microphoneOwner().microphone(),
|
||||
selected == null ? null : selected.session().playback(),
|
||||
sounds, hotkeys,
|
||||
new MyTeamSpeakPanel(myTeamSpeak, new TeamSpeakImporter(identities, bookmarks, settings, contacts),
|
||||
menuBar::rebuildBookmarks, this::myTeamSpeakChanged),
|
||||
@@ -1051,7 +1051,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
boolean signedIn = myTeamSpeak.isSignedIn();
|
||||
for (ServerTab tab : tabs) {
|
||||
tab.chat().setSharingAvailable(signedIn);
|
||||
tab.session().connection().updateMyTeamSpeak();
|
||||
tab.session().updateMyTeamSpeak();
|
||||
}
|
||||
if (signedIn) {
|
||||
pictures.retryFailed();
|
||||
@@ -1077,7 +1077,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
private void applyOutputSettingsToAllTabs() {
|
||||
soundPlayer.setOutputDevice(settings.outputDevice);
|
||||
for (ServerTab tab : tabs) {
|
||||
VoiceOutput playback = tab.connection().ownClient().playback();
|
||||
VoiceOutput playback = tab.session().playback();
|
||||
if (playback == null) continue;
|
||||
playback.setMasterVolume(settings.effectiveOutputVolume());
|
||||
playback.setOutputDevice(settings.outputDevice);
|
||||
@@ -1139,12 +1139,12 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
toolbar.showHostButton(hostButtonOf(selected));
|
||||
menuBar.refresh(connected, anyConnected, micMuted, deaf, active, away, commander);
|
||||
statusBar.showRecording(connected && selected.session().isRecording());
|
||||
statusBar.showUnreadMessages(connected ? selected.connection().unreadOfflineMessages() : 0);
|
||||
statusBar.showUnreadMessages(connected ? selected.session().unreadOfflineMessages() : 0);
|
||||
updateTray();
|
||||
}
|
||||
|
||||
private static HostButton hostButtonOf(ServerTab tab) {
|
||||
return tab != null && tab.session().isConnected() ? tab.connection().getModel().hostButton() : null;
|
||||
return tab != null && tab.session().isConnected() ? tab.session().model().hostButton() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1181,11 +1181,11 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
|
||||
private void updateConnectionStatus() {
|
||||
ServerTab tab = selected;
|
||||
if (tab == null || !tab.session().isConnected()) return;
|
||||
int users = tab.connection().getModel().clientCount();
|
||||
int users = tab.session().model().clientCount();
|
||||
StringBuilder s = new StringBuilder("Connected to ")
|
||||
.append(tab.connection().getModel().getServerName())
|
||||
.append(tab.session().model().getServerName())
|
||||
.append(" | ").append(users).append(users == 1 ? " user" : " users");
|
||||
double ping = tab.connection().getPingMillis();
|
||||
double ping = tab.session().pingMillis();
|
||||
if (ping >= 0) s.append(" | ping ").append(Math.round(ping)).append(" ms");
|
||||
if (tab != micTab()) s.append(" | microphone on another tab");
|
||||
statusBar.setStatus(s.toString());
|
||||
|
||||
@@ -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.OfflineMessage;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.text.BBCode;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
@@ -86,7 +86,7 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final Composer composer;
|
||||
|
||||
private final MessageTableModel tableModel = new MessageTableModel();
|
||||
@@ -124,9 +124,9 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
private boolean selectingForPopup;
|
||||
private boolean loading;
|
||||
|
||||
OfflineMessagesDialog(Frame owner, TeamspeakConnection conn, Composer composer) {
|
||||
OfflineMessagesDialog(Frame owner, ServerSession session, Composer composer) {
|
||||
super(owner, "Offline Messages", false);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.composer = composer;
|
||||
|
||||
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, buildTable(), buildReader());
|
||||
@@ -314,7 +314,7 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
// ---- data ----
|
||||
|
||||
void serverNameChanged() {
|
||||
String name = conn.getModel().getServerName();
|
||||
String name = session.model().getServerName();
|
||||
setTitle(name == null || name.isBlank() ? "Offline Messages" : "Offline Messages on " + name);
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
Edt.handle(conn.offlineMessages().list(), messages -> {
|
||||
Edt.handle(session.offlineMessages().list(), messages -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
setMessages(messages);
|
||||
@@ -363,7 +363,7 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
boolean canSend = conn.getModel().permissions().canSendOfflineMessages();
|
||||
boolean canSend = session.model().permissions().canSendOfflineMessages();
|
||||
composeButton.setEnabled(canSend);
|
||||
replyButton.setEnabled(canSend && singleSelected() != null);
|
||||
deleteButton.setEnabled(table.getSelectedRowCount() > 0);
|
||||
@@ -388,7 +388,7 @@ final class OfflineMessagesDialog extends JDialog {
|
||||
return;
|
||||
}
|
||||
bodyPane.setText("");
|
||||
Edt.handle(conn.offlineMessages().body(message.id()), text -> {
|
||||
Edt.handle(session.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.offlineMessages().body(message.id()), text -> {
|
||||
Edt.handle(session.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.offlineMessages().markRead(messages.stream().map(OfflineMessage::id).toList(), read), failure -> {
|
||||
Edt.onFailure(session.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.offlineMessages().delete(selected.stream().map(OfflineMessage::id).toList()), () -> {
|
||||
Edt.handle(session.offlineMessages().delete(selected.stream().map(OfflineMessage::id).toList()), () -> {
|
||||
if (isDisplayable()) deleted.run();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
|
||||
+7
-7
@@ -5,7 +5,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.net.ChannelNode;
|
||||
import eu.lixko.ts3j.client.net.Group;
|
||||
import eu.lixko.ts3j.client.net.ServerModel;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.ButtonGroup;
|
||||
@@ -34,7 +34,7 @@ import java.awt.datatransfer.StringSelection;
|
||||
*/
|
||||
final class PrivilegeKeyCreateDialog extends JDialog {
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final Runnable onCreated;
|
||||
|
||||
private final JRadioButton serverGroup = new JRadioButton("Server Group", true);
|
||||
@@ -47,9 +47,9 @@ final class PrivilegeKeyCreateDialog extends JDialog {
|
||||
private final JButton create = new JButton("Create");
|
||||
|
||||
/** @param onCreated runs on the UI thread after each key is created */
|
||||
PrivilegeKeyCreateDialog(Window owner, TeamspeakConnection conn, GroupIcons groupIcons, Runnable onCreated) {
|
||||
PrivilegeKeyCreateDialog(Window owner, ServerSession session, GroupIcons groupIcons, Runnable onCreated) {
|
||||
super(owner, "Create Privilege Key", ModalityType.APPLICATION_MODAL);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.onCreated = onCreated;
|
||||
|
||||
ButtonGroup type = new ButtonGroup();
|
||||
@@ -75,7 +75,7 @@ final class PrivilegeKeyCreateDialog extends JDialog {
|
||||
}
|
||||
});
|
||||
groupBox.addActionListener(e -> updateCreate());
|
||||
ServerModel model = conn.getModel();
|
||||
ServerModel model = session.model();
|
||||
channelBox.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
|
||||
@@ -133,7 +133,7 @@ final class PrivilegeKeyCreateDialog extends JDialog {
|
||||
|
||||
private void typeChanged() {
|
||||
groupBox.removeAllItems();
|
||||
for (Group g : conn.getModel().privilegeKeyGroups(forChannelGroup())) groupBox.addItem(g);
|
||||
for (Group g : session.model().privilegeKeyGroups(forChannelGroup())) groupBox.addItem(g);
|
||||
channelBox.setEnabled(forChannelGroup());
|
||||
updateCreate();
|
||||
}
|
||||
@@ -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.privilegeKeys().add(forChannelGroup(), group.id, channel == null ? 0 : channel.id,
|
||||
Edt.handle(session.privilegeKeys().add(forChannelGroup(), group.id, channel == null ? 0 : channel.id,
|
||||
descriptionField.getText().trim()), key -> {
|
||||
if (!isDisplayable()) return;
|
||||
updateCreate();
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.net.Group;
|
||||
import eu.lixko.ts3j.client.net.PrivilegeKey;
|
||||
import eu.lixko.ts3j.client.net.ServerModel;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Box;
|
||||
@@ -68,7 +68,7 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final GroupIcons groupIcons;
|
||||
|
||||
private final KeyTableModel tableModel = new KeyTableModel();
|
||||
@@ -79,9 +79,9 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
|
||||
private boolean loading;
|
||||
|
||||
PrivilegeKeysDialog(Frame owner, TeamspeakConnection conn, GroupIcons groupIcons) {
|
||||
PrivilegeKeysDialog(Frame owner, ServerSession session, GroupIcons groupIcons) {
|
||||
super(owner, "Privilege Keys", false);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.groupIcons = groupIcons;
|
||||
|
||||
JPanel content = new JPanel(new BorderLayout(0, UIScale.scale(6)));
|
||||
@@ -200,7 +200,7 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
|
||||
/** Follows the server's name, as the ban list's title does. */
|
||||
void serverNameChanged() {
|
||||
String name = conn.getModel().getServerName();
|
||||
String name = session.model().getServerName();
|
||||
setTitle(name == null || name.isBlank() ? "Privilege Keys" : "Privilege Keys - " + name);
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
status.setText("Loading…");
|
||||
Edt.handle(conn.privilegeKeys().list(), keys -> {
|
||||
Edt.handle(session.privilegeKeys().list(), keys -> {
|
||||
loading = false;
|
||||
if (!isDisplayable()) return;
|
||||
tableModel.setKeys(keys);
|
||||
@@ -234,7 +234,7 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
ServerModel model = conn.getModel();
|
||||
ServerModel model = session.model();
|
||||
createButton.setEnabled(model.permissions().canAddPrivilegeKeys());
|
||||
removeButton.setEnabled(!selectedKeys().isEmpty() && model.permissions().canDeletePrivilegeKeys());
|
||||
}
|
||||
@@ -243,7 +243,7 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
|
||||
private void createKey() {
|
||||
if (!createButton.isEnabled()) return;
|
||||
new PrivilegeKeyCreateDialog(this, conn, groupIcons, this::reload).setVisible(true);
|
||||
new PrivilegeKeyCreateDialog(this, session, groupIcons, this::reload).setVisible(true);
|
||||
}
|
||||
|
||||
private void removeKeys() {
|
||||
@@ -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.privilegeKeys().delete(tokens), () -> {
|
||||
Edt.handle(session.privilegeKeys().delete(tokens), () -> {
|
||||
if (isDisplayable()) reload();
|
||||
}, failure -> {
|
||||
if (!isDisplayable()) return;
|
||||
@@ -272,7 +272,7 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
// ---- table ----
|
||||
|
||||
private Group groupOf(PrivilegeKey key) {
|
||||
ServerModel model = conn.getModel();
|
||||
ServerModel model = session.model();
|
||||
return key.channelGroup() ? model.channelGroup(key.groupId()) : model.serverGroup(key.groupId());
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ final class PrivilegeKeysDialog extends JDialog {
|
||||
return group != null ? group.name : Integer.toString(key.groupId());
|
||||
case CHANNEL:
|
||||
if (!key.channelGroup()) return "";
|
||||
String path = conn.getModel().channelPath(key.channelId());
|
||||
String path = session.model().channelPath(key.channelId());
|
||||
return path.isEmpty() ? Integer.toString(key.channelId()) : path;
|
||||
case CREATED:
|
||||
return key.createdEpochSeconds() <= 0 ? "" : DATE.format(
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
import eu.lixko.ts3j.client.net.ClientEntry;
|
||||
import eu.lixko.ts3j.client.net.Group;
|
||||
import eu.lixko.ts3j.client.net.GroupChoice;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.GrayFilter;
|
||||
@@ -29,7 +29,7 @@ import java.util.Map;
|
||||
*/
|
||||
final class ServerGroupsDialog extends JDialog {
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final GroupIcons groupIcons;
|
||||
private final int clientId;
|
||||
private final ServerTreePanel.Actions actions;
|
||||
@@ -39,10 +39,10 @@ final class ServerGroupsDialog extends JDialog {
|
||||
/** Cached grayscale icons, keyed by the source icon's identity. */
|
||||
private final Map<ImageIcon, ImageIcon> grayscale = new HashMap<>();
|
||||
|
||||
ServerGroupsDialog(MainFrame owner, TeamspeakConnection conn, GroupIcons groupIcons,
|
||||
ServerGroupsDialog(MainFrame owner, ServerSession session, GroupIcons groupIcons,
|
||||
ClientEntry client, ServerTreePanel.Actions actions) {
|
||||
super(owner, "Server Groups", true);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.groupIcons = groupIcons;
|
||||
this.clientId = client.id;
|
||||
this.actions = actions;
|
||||
@@ -75,7 +75,7 @@ final class ServerGroupsDialog extends JDialog {
|
||||
|
||||
/** Rebuilds the list from the current model state; closes the dialog if the client left. */
|
||||
void refresh() {
|
||||
ClientEntry client = conn.getModel().getClient(clientId);
|
||||
ClientEntry client = session.model().getClient(clientId);
|
||||
if (client == null) {
|
||||
dispose();
|
||||
return;
|
||||
@@ -83,7 +83,7 @@ final class ServerGroupsDialog extends JDialog {
|
||||
header.setText(client.nickname);
|
||||
|
||||
list.removeAll();
|
||||
for (GroupChoice choice : conn.getModel().serverGroupChoices(client)) {
|
||||
for (GroupChoice choice : session.model().serverGroupChoices(client)) {
|
||||
Group g = choice.group();
|
||||
ImageIcon icon = groupIcons.iconOf(g);
|
||||
JCheckBox box = new JCheckBox(g.name, choice.allowed() ? icon : grayscale(icon));
|
||||
|
||||
@@ -9,7 +9,7 @@ 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;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.text.TextQuery;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
@@ -64,7 +64,7 @@ final class ServerLogDialog extends JDialog {
|
||||
private static final String TITLE = "Server Log";
|
||||
private static final int LEVEL_WIDTH = "Critical".length();
|
||||
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final Settings settings;
|
||||
private final ServerLogSettings view;
|
||||
|
||||
@@ -100,9 +100,9 @@ final class ServerLogDialog extends JDialog {
|
||||
private TextQuery onlyMatching;
|
||||
private boolean loading;
|
||||
|
||||
ServerLogDialog(Frame owner, TeamspeakConnection conn, Settings settings) {
|
||||
ServerLogDialog(Frame owner, ServerSession session, Settings settings) {
|
||||
super(owner, TITLE, false);
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.settings = settings;
|
||||
this.view = settings.serverLog;
|
||||
|
||||
@@ -242,7 +242,7 @@ final class ServerLogDialog extends JDialog {
|
||||
// ---- data ----
|
||||
|
||||
void serverNameChanged() {
|
||||
String name = conn.getModel().getServerName();
|
||||
String name = session.model().getServerName();
|
||||
setTitle(name == null || name.isBlank() ? TITLE : TITLE + " - " + name);
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ final class ServerLogDialog extends JDialog {
|
||||
loading = true;
|
||||
olderButton.setEnabled(false);
|
||||
showStatus("Loading…", Theme.chatEvent());
|
||||
Edt.handle(conn.serverLog().read(from), page -> {
|
||||
Edt.handle(session.serverLog().read(from), page -> {
|
||||
loading = false;
|
||||
if (isDisplayable()) received(page, from > 0);
|
||||
}, failure -> {
|
||||
|
||||
@@ -10,7 +10,6 @@ import eu.lixko.ts3j.client.net.ClientEntry;
|
||||
import eu.lixko.ts3j.client.net.ConnectionListener.ChatScope;
|
||||
import eu.lixko.ts3j.client.net.OfflineMessage;
|
||||
import eu.lixko.ts3j.client.net.PictureDownloads;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.net.avatar.Avatar;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.sound.SoundNotifier;
|
||||
@@ -38,7 +37,6 @@ final class ServerTab {
|
||||
|
||||
private final ServerSession session;
|
||||
private final ContactStore contacts;
|
||||
private final TeamspeakConnection conn;
|
||||
private final GroupIcons groupIcons;
|
||||
private final ServerTabTreeActions treeActions;
|
||||
private final ServerTreePanel treePanel;
|
||||
@@ -72,13 +70,12 @@ final class ServerTab {
|
||||
// everything is built. Nothing fires callbacks before then.
|
||||
ServerTabConnectionEvents events = new ServerTabConnectionEvents(host, this, settings);
|
||||
this.session = new ServerSession(settings, identities, audio, sounds, contacts, events);
|
||||
this.conn = session.connection();
|
||||
session.setAutoReconnect(true);
|
||||
this.conn.setMyTeamSpeakLogin(host.myTeamSpeakLogin());
|
||||
this.groupIcons = new GroupIcons(conn.getIcons());
|
||||
this.chatPanel = new ChatPanel(host.chatZoom(), settings, pictures, conn::serverUniqueId);
|
||||
this.treeActions = new ServerTabTreeActions(host, this, conn, chatPanel, infoPanel, groupIcons);
|
||||
this.treePanel = new ServerTreePanel(conn.getModel(), groupIcons, contacts, settings, treeActions);
|
||||
session.setMyTeamSpeakLogin(host.myTeamSpeakLogin());
|
||||
this.groupIcons = new GroupIcons(session.icons());
|
||||
this.chatPanel = new ChatPanel(host.chatZoom(), settings, pictures, session::serverUniqueId);
|
||||
this.treeActions = new ServerTabTreeActions(host, this, session, chatPanel, infoPanel, groupIcons);
|
||||
this.treePanel = new ServerTreePanel(session.model(), groupIcons, contacts, settings, treeActions);
|
||||
treeActions.attach(treePanel);
|
||||
events.attach(session, treePanel, chatPanel, treeActions);
|
||||
|
||||
@@ -120,7 +117,7 @@ final class ServerTab {
|
||||
}
|
||||
});
|
||||
|
||||
this.avatar = new AvatarActions(host, conn);
|
||||
this.avatar = new AvatarActions(host, session);
|
||||
infoPanel.setAvatarHandler(new InfoPanel.AvatarHandler() {
|
||||
@Override
|
||||
public void steal(Avatar other) {
|
||||
@@ -176,10 +173,6 @@ final class ServerTab {
|
||||
return session;
|
||||
}
|
||||
|
||||
TeamspeakConnection connection() {
|
||||
return conn;
|
||||
}
|
||||
|
||||
ChatPanel chat() {
|
||||
return chatPanel;
|
||||
}
|
||||
@@ -188,7 +181,7 @@ final class ServerTab {
|
||||
void showBanList(BanReasonPresets presets) {
|
||||
if (!session.isConnected()) return;
|
||||
if (banList == null || !banList.isDisplayable()) {
|
||||
banList = new BanListDialog(host, conn, settings, presets);
|
||||
banList = new BanListDialog(host, session, settings, presets);
|
||||
}
|
||||
banList.setVisible(true);
|
||||
banList.toFront();
|
||||
@@ -198,7 +191,7 @@ final class ServerTab {
|
||||
void showComplaints() {
|
||||
if (!session.isConnected()) return;
|
||||
if (complaints == null || !complaints.isDisplayable()) {
|
||||
complaints = new ComplaintsDialog(host, conn, treeActions::banClient);
|
||||
complaints = new ComplaintsDialog(host, session, treeActions::banClient);
|
||||
}
|
||||
complaints.setVisible(true);
|
||||
complaints.toFront();
|
||||
@@ -208,7 +201,7 @@ final class ServerTab {
|
||||
void showServerLog() {
|
||||
if (!session.isConnected()) return;
|
||||
if (serverLog == null || !serverLog.isDisplayable()) {
|
||||
serverLog = new ServerLogDialog(host, conn, settings);
|
||||
serverLog = new ServerLogDialog(host, session, settings);
|
||||
}
|
||||
serverLog.setVisible(true);
|
||||
serverLog.toFront();
|
||||
@@ -218,7 +211,7 @@ final class ServerTab {
|
||||
void showOfflineMessages() {
|
||||
if (!session.isConnected()) return;
|
||||
if (offlineMessages == null || !offlineMessages.isDisplayable()) {
|
||||
offlineMessages = new OfflineMessagesDialog(host, conn, new OfflineMessagesDialog.Composer() {
|
||||
offlineMessages = new OfflineMessagesDialog(host, session, new OfflineMessagesDialog.Composer() {
|
||||
@Override
|
||||
public void compose() {
|
||||
composeOfflineMessage();
|
||||
@@ -227,7 +220,7 @@ final class ServerTab {
|
||||
@Override
|
||||
public void reply(OfflineMessage message, String body) {
|
||||
if (!session.isConnected()) return;
|
||||
OfflineMessageComposeDialog.reply(offlineMessages, conn.offlineMessages(), contacts, message, body).setVisible(true);
|
||||
OfflineMessageComposeDialog.reply(offlineMessages, session.offlineMessages(), contacts, message, body).setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -238,7 +231,7 @@ final class ServerTab {
|
||||
void composeOfflineMessage() {
|
||||
if (!session.permissions().canSendOfflineMessages()) return;
|
||||
Window owner = offlineMessages != null && offlineMessages.isShowing() ? offlineMessages : host;
|
||||
OfflineMessageComposeDialog.compose(owner, conn.offlineMessages(), contacts).setVisible(true);
|
||||
OfflineMessageComposeDialog.compose(owner, session.offlineMessages(), contacts).setVisible(true);
|
||||
}
|
||||
|
||||
/** New mail refreshes an open inbox; a message being read does not need to. */
|
||||
@@ -254,7 +247,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.privilegeKeys().use(key.trim()), failure -> JOptionPane.showMessageDialog(host,
|
||||
Edt.onFailure(session.privilegeKeys().use(key.trim()), failure -> JOptionPane.showMessageDialog(host,
|
||||
failure.getMessage(), "Error using Privilege Key", JOptionPane.ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
@@ -262,7 +255,7 @@ final class ServerTab {
|
||||
void showPrivilegeKeys() {
|
||||
if (!session.isConnected()) return;
|
||||
if (privilegeKeys == null || !privilegeKeys.isDisplayable()) {
|
||||
privilegeKeys = new PrivilegeKeysDialog(host, conn, groupIcons);
|
||||
privilegeKeys = new PrivilegeKeysDialog(host, session, groupIcons);
|
||||
}
|
||||
privilegeKeys.setVisible(true);
|
||||
privilegeKeys.toFront();
|
||||
@@ -295,7 +288,7 @@ final class ServerTab {
|
||||
|
||||
/** The contact list changed: names, colours and per-client playback follow. */
|
||||
void contactsChanged() {
|
||||
conn.applyContacts();
|
||||
session.contacts().applyAll();
|
||||
treePanel.refreshRowSizes();
|
||||
treeActions.renderInfo();
|
||||
}
|
||||
|
||||
+4
-7
@@ -2,7 +2,6 @@ package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import eu.lixko.ts3j.client.config.Settings;
|
||||
import eu.lixko.ts3j.client.net.ChannelNode;
|
||||
import eu.lixko.ts3j.client.net.TeamspeakConnection;
|
||||
import eu.lixko.ts3j.client.session.ServerSession;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -27,7 +26,6 @@ final class ServerTabConnectionEvents implements ServerSession.Listener {
|
||||
private final AtomicBoolean modelChangePending = new AtomicBoolean();
|
||||
|
||||
private ServerSession session;
|
||||
private TeamspeakConnection conn;
|
||||
private ServerTreePanel treePanel;
|
||||
private ChatPanel chatPanel;
|
||||
private ServerTabTreeActions treeActions;
|
||||
@@ -41,7 +39,6 @@ final class ServerTabConnectionEvents implements ServerSession.Listener {
|
||||
void attach(ServerSession session, ServerTreePanel treePanel, ChatPanel chatPanel,
|
||||
ServerTabTreeActions treeActions) {
|
||||
this.session = session;
|
||||
this.conn = session.connection();
|
||||
this.treePanel = treePanel;
|
||||
this.chatPanel = chatPanel;
|
||||
this.treeActions = treeActions;
|
||||
@@ -63,7 +60,7 @@ final class ServerTabConnectionEvents implements ServerSession.Listener {
|
||||
@Override
|
||||
public void onOwnChat(ChatScope scope, int peerClientId, String peerName, String text) {
|
||||
String me = settings.nickname + " (you)";
|
||||
int myId = conn.getSelfClientId();
|
||||
int myId = session.selfClientId();
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
switch (scope) {
|
||||
case SERVER -> chatPanel.appendServerMessage(myId, me, text);
|
||||
@@ -89,7 +86,7 @@ final class ServerTabConnectionEvents implements ServerSession.Listener {
|
||||
@Override
|
||||
public void onConnected() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
treePanel.setSelfClientId(conn.getSelfClientId());
|
||||
treePanel.setSelfClientId(session.selfClientId());
|
||||
chatPanel.setInputEnabled(true);
|
||||
host.tabConnected(tab);
|
||||
});
|
||||
@@ -122,7 +119,7 @@ final class ServerTabConnectionEvents implements ServerSession.Listener {
|
||||
host.refreshHostButton(tab);
|
||||
if (session.isConnected()) {
|
||||
ChannelNode channel = session.currentChannel();
|
||||
chatPanel.setServerName(conn.getModel().getServerName());
|
||||
chatPanel.setServerName(session.model().getServerName());
|
||||
chatPanel.setChannelName(channel == null ? null : channel.name);
|
||||
}
|
||||
});
|
||||
@@ -178,7 +175,7 @@ final class ServerTabConnectionEvents implements ServerSession.Listener {
|
||||
public void onTalkStateChanged(int clientId, boolean talking) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
treePanel.refreshVisual();
|
||||
if (clientId == conn.getSelfClientId()) host.selfStateChanged(tab);
|
||||
if (clientId == session.selfClientId()) host.selfStateChanged(tab);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@ package eu.lixko.ts3j.client.ui;
|
||||
|
||||
import eu.lixko.ts3j.client.audio.VoiceOutput;
|
||||
import eu.lixko.ts3j.client.contacts.ContactType;
|
||||
import eu.lixko.ts3j.client.net.ClientAdmin;
|
||||
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.session.ServerSession;
|
||||
import eu.lixko.ts3j.client.text.TsLink;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -29,7 +30,7 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
private final MainFrame host;
|
||||
private final ServerTab tab;
|
||||
private final TeamspeakConnection conn;
|
||||
private final ServerSession session;
|
||||
private final ChatPanel chatPanel;
|
||||
private final InfoPanel infoPanel;
|
||||
private final GroupIcons groupIcons;
|
||||
@@ -39,11 +40,11 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
/** The one open {@link ServerGroupsDialog}, if any, refreshed whenever the model changes. */
|
||||
private ServerGroupsDialog groupsDialog;
|
||||
|
||||
ServerTabTreeActions(MainFrame host, ServerTab tab, TeamspeakConnection conn,
|
||||
ServerTabTreeActions(MainFrame host, ServerTab tab, ServerSession session,
|
||||
ChatPanel chatPanel, InfoPanel infoPanel, GroupIcons groupIcons) {
|
||||
this.host = host;
|
||||
this.tab = tab;
|
||||
this.conn = conn;
|
||||
this.session = session;
|
||||
this.chatPanel = chatPanel;
|
||||
this.infoPanel = infoPanel;
|
||||
this.groupIcons = groupIcons;
|
||||
@@ -65,11 +66,11 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
infoPanel.showChannel((ChannelNode) sel);
|
||||
} else if (sel instanceof ClientEntry) {
|
||||
ClientEntry client = (ClientEntry) sel;
|
||||
infoPanel.showClient(client, conn.getModel(), conn.getIcons(),
|
||||
conn.getContacts().find(client.uniqueId), conn.avatarOf(client));
|
||||
} else if (sel instanceof String && conn.isConnected()) {
|
||||
infoPanel.showClient(client, session.model(), session.icons(),
|
||||
session.contacts().store().find(client.uniqueId), session.avatarOf(client));
|
||||
} else if (sel instanceof String && session.isConnected()) {
|
||||
// The root row is the server itself, whose user object is just its name.
|
||||
infoPanel.showServer(conn.getModel(), conn.getServerHost() + ":" + conn.getServerPort());
|
||||
infoPanel.showServer(session.model(), session.address() + ":" + session.port());
|
||||
} else {
|
||||
infoPanel.clear();
|
||||
}
|
||||
@@ -83,25 +84,25 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
/** A client link in the chat log was clicked: show the same menu as the tree does. */
|
||||
void handleClientLink(TsLink.Ref ref, Component source, int x, int y) {
|
||||
ClientEntry client = conn.getModel().getClient(ref.id);
|
||||
ClientEntry client = session.model().getClient(ref.id);
|
||||
// The id is only valid for the session the link was made in; fall back to
|
||||
// the unique id (and finally the nickname) so older links still resolve.
|
||||
if (client == null || (!ref.uniqueId.isEmpty() && !ref.uniqueId.equals(client.uniqueId))) {
|
||||
ClientEntry byUid = ref.uniqueId.isEmpty() ? null
|
||||
: conn.getModel().findClientByUniqueId(ref.uniqueId);
|
||||
if (byUid == null && !ref.name.isEmpty()) byUid = conn.getModel().findClientByName(ref.name);
|
||||
: session.model().findClientByUniqueId(ref.uniqueId);
|
||||
if (byUid == null && !ref.name.isEmpty()) byUid = session.model().findClientByName(ref.name);
|
||||
if (byUid != null) client = byUid;
|
||||
}
|
||||
if (client == null) {
|
||||
chatPanel.appendSystem("That client is no longer on the server.");
|
||||
return;
|
||||
}
|
||||
ClientMenu.build(client, client.id == conn.getSelfClientId(), false, conn.getModel(), groupIcons, this)
|
||||
ClientMenu.build(client, client.id == session.selfClientId(), false, session.model(), groupIcons, this)
|
||||
.show(source, x, y);
|
||||
}
|
||||
|
||||
void handleChannelLink(TsLink.Ref ref, Component source, int x, int y) {
|
||||
ChannelNode channel = conn.getModel().getChannel(ref.id);
|
||||
ChannelNode channel = session.model().getChannel(ref.id);
|
||||
if (channel == null) {
|
||||
chatPanel.appendSystem("That channel no longer exists.");
|
||||
return;
|
||||
@@ -113,57 +114,57 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public void joinChannel(int channelId) {
|
||||
if (conn.isConnected()) conn.joinChannel(channelId, null);
|
||||
if (session.isConnected()) session.channels().join(channelId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveClientsToChannel(List<ClientEntry> clients, ChannelNode target) {
|
||||
if (conn.isConnected()) conn.moveClients(ids(clients), target.id);
|
||||
if (session.isConnected()) session.clients().move(ids(clients), target.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveChannel(ChannelNode channel, int newParentId, int orderPredecessorId) {
|
||||
if (conn.isConnected()) conn.moveChannel(channel.id, newParentId, orderPredecessorId);
|
||||
if (session.isConnected()) session.channels().move(channel.id, newParentId, orderPredecessorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openPrivateChat(ClientEntry client) {
|
||||
chatPanel.openPrivateChat(client.id, client.uniqueId, conn.displayName(client));
|
||||
conn.loadPrivateChatHistory(client.id, client.uniqueId);
|
||||
chatPanel.openPrivateChat(client.id, client.uniqueId, session.contacts().displayName(client));
|
||||
session.loadPrivateChatHistory(client.id, client.uniqueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pokeClient(ClientEntry client) {
|
||||
String msg = JOptionPane.showInputDialog(host, "Poke message for " + client.nickname + ":", "Poke!");
|
||||
if (msg != null) conn.poke(client.id, msg);
|
||||
if (msg != null) session.clients().poke(client.id, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complainAboutClient(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
String reason = ReasonDialog.prompt(host, "Make a Complaint", "Enter the reason for your complaint:",
|
||||
ComplaintAdmin.REASON_LIMIT);
|
||||
if (reason != null) conn.complaints().complain(client, reason);
|
||||
if (reason != null) session.complaints().complain(client, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickClientsFromChannel(List<ClientEntry> clients) {
|
||||
String reason = kickReason("Channel", clients);
|
||||
if (reason != null) conn.kickFromChannel(ids(clients), reason);
|
||||
if (reason != null) session.clients().kickFromChannel(ids(clients), reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kickClientsFromServer(List<ClientEntry> clients) {
|
||||
String reason = kickReason("Server", clients);
|
||||
if (reason != null) conn.kickFromServer(ids(clients), reason);
|
||||
if (reason != null) session.clients().kickFromServer(ids(clients), reason);
|
||||
}
|
||||
|
||||
private String kickReason(String from, List<ClientEntry> clients) {
|
||||
if (!conn.isConnected()) return null;
|
||||
if (!session.isConnected()) return null;
|
||||
boolean one = clients.size() == 1;
|
||||
String whom = one ? clients.get(0).nickname : clients.size() + " clients";
|
||||
return ReasonDialog.prompt(host, "Kick " + (one ? "Client" : "Clients") + " from " + from,
|
||||
"Reason for kicking " + whom + ":", TeamspeakConnection.KICK_REASON_LIMIT);
|
||||
"Reason for kicking " + whom + ":", ClientAdmin.KICK_REASON_LIMIT);
|
||||
}
|
||||
|
||||
private static List<Integer> ids(List<ClientEntry> clients) {
|
||||
@@ -174,16 +175,16 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public void banClient(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
BanDialog dialog = new BanDialog(host, client.nickname,
|
||||
conn.getModel().permissions().maxBanSeconds());
|
||||
session.model().permissions().maxBanSeconds());
|
||||
dialog.setVisible(true);
|
||||
if (dialog.isConfirmed()) conn.banClient(client.id, dialog.getSeconds(), dialog.getReason());
|
||||
if (dialog.isConfirmed()) session.clients().ban(client.id, dialog.getSeconds(), dialog.getReason());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleClientMute(ClientEntry client) {
|
||||
VoiceOutput playback = conn.ownClient().playback();
|
||||
VoiceOutput playback = session.playback();
|
||||
if (playback != null) playback.setClientMuted(client.id, !playback.isClientMuted(client.id));
|
||||
}
|
||||
|
||||
@@ -195,31 +196,31 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public void showConnectionInfo(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
new ConnectionInfoDialog(host, conn, client.id, client.nickname).setVisible(true);
|
||||
if (!session.isConnected()) return;
|
||||
new ConnectionInfoDialog(host, session, client.id, client.nickname).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveClientsToOwnChannel(List<ClientEntry> clients) {
|
||||
if (!conn.isConnected()) return;
|
||||
ClientEntry self = conn.getModel().getClient(conn.getSelfClientId());
|
||||
if (self != null) conn.moveClients(ids(clients), self.channelId);
|
||||
if (!session.isConnected()) return;
|
||||
ClientEntry self = session.model().getClient(session.selfClientId());
|
||||
if (self != null) session.clients().move(ids(clients), self.channelId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientServerGroup(ClientEntry client, Group group, boolean assign) {
|
||||
if (conn.isConnected()) conn.setClientServerGroup(client.databaseId, group.id, assign);
|
||||
if (session.isConnected()) session.clients().setServerGroup(client.databaseId, group.id, assign);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientChannelGroup(ClientEntry client, Group group) {
|
||||
if (conn.isConnected()) conn.setClientChannelGroup(client.databaseId, client.channelId, group.id);
|
||||
if (session.isConnected()) session.clients().setChannelGroup(client.databaseId, client.channelId, group.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showServerGroupsDialog(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
groupsDialog = new ServerGroupsDialog(host, conn, groupIcons, client, this);
|
||||
if (!session.isConnected()) return;
|
||||
groupsDialog = new ServerGroupsDialog(host, session, groupIcons, client, this);
|
||||
groupsDialog.setVisible(true);
|
||||
groupsDialog = null;
|
||||
}
|
||||
@@ -230,17 +231,17 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
*/
|
||||
@Override
|
||||
public boolean canDeleteOtherAvatars() {
|
||||
return tab.session().permissions().canDeleteOtherAvatars();
|
||||
return session.permissions().canDeleteOtherAvatars();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrantTalkPower() {
|
||||
return tab.session().permissions().canGrantTalkPower();
|
||||
return session.permissions().canGrantTalkPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTalker(List<ClientEntry> clients, boolean talker) {
|
||||
conn.setTalker(ids(clients), talker);
|
||||
session.clients().setTalker(ids(clients), talker);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,13 +251,13 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public void changeClientDescription(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
Edt.handle(conn.requestClientDescription(client.id), description -> {
|
||||
if (!session.isConnected()) return;
|
||||
Edt.handle(session.clients().description(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;
|
||||
Edt.onFailure(conn.setClientDescription(client.id, edited), failure -> JOptionPane.showMessageDialog(host,
|
||||
Edt.onFailure(session.clients().setDescription(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));
|
||||
@@ -264,7 +265,7 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public void addContact(ClientEntry client, ContactType type) {
|
||||
conn.getContacts().add(client.uniqueId, client.nickname, type, host.settings().contactDefaults);
|
||||
session.contacts().store().add(client.uniqueId, client.nickname, type, host.settings().contactDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,18 +275,18 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public void removeContact(ClientEntry client) {
|
||||
conn.getContacts().remove(client.uniqueId);
|
||||
session.contacts().store().remove(client.uniqueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactType contactTypeOf(ClientEntry client) {
|
||||
return conn.getContacts().typeOf(client.uniqueId);
|
||||
return session.contacts().store().typeOf(client.uniqueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeClientVolume(ClientEntry client) {
|
||||
if (!conn.isConnected()) return;
|
||||
new ClientVolumeDialog(host, conn, client).setVisible(true);
|
||||
if (!session.isConnected()) return;
|
||||
new ClientVolumeDialog(host, session.contacts(), client).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -295,18 +296,18 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
|
||||
@Override
|
||||
public void setChannelSubscribed(ChannelNode channel, boolean family, boolean subscribed) {
|
||||
if (conn.isConnected()) conn.setChannelsSubscribed(channel.familyIds(family), subscribed);
|
||||
if (session.isConnected()) session.channels().setSubscribed(channel.familyIds(family), subscribed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editChannel(ChannelNode channel) {
|
||||
if (!conn.isConnected()) return;
|
||||
ChannelDialog.toEdit(host, conn, groupIcons, channel).setVisible(true);
|
||||
if (!session.isConnected()) return;
|
||||
ChannelDialog.toEdit(host, session, groupIcons, channel).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteChannel(ChannelNode channel) {
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
// Like TeamSpeak, a channel that is not empty takes its sub-channels along and sends its clients away.
|
||||
boolean occupied = !channel.children.isEmpty() || !channel.clients.isEmpty();
|
||||
String question = "Delete channel \"" + channel.name + "\""
|
||||
@@ -315,50 +316,50 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
|
||||
return;
|
||||
}
|
||||
Edt.onFailure(conn.channels().delete(channel.id, true), failure -> JOptionPane.showMessageDialog(host,
|
||||
Edt.onFailure(session.channels().delete(channel.id, true), failure -> JOptionPane.showMessageDialog(host,
|
||||
"Could not delete the channel: " + failure.getMessage(), "Error", JOptionPane.ERROR_MESSAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createChannel(ChannelNode parent, ChannelSettings.Type type) {
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
ChannelSettings defaults = new ChannelSettings();
|
||||
defaults.type = type;
|
||||
ChannelDialog.toCreate(host, conn, groupIcons,
|
||||
ChannelDialog.toCreate(host, session, groupIcons,
|
||||
parent == null ? "Create Channel" : "Create Sub-Channel of " + parent.name,
|
||||
parent == null ? 0 : parent.id, defaults).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSpacer() {
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
ChannelSettings defaults = new ChannelSettings();
|
||||
// Spacers are cosmetic root channels, so they outlive everyone and, being channels,
|
||||
// need a name no other channel has — which is what the tag's number is for.
|
||||
defaults.name = Spacers.freeName(conn.getModel().childrenOf(0));
|
||||
ChannelDialog.toCreate(host, conn, groupIcons, "Create Spacer", 0, defaults)
|
||||
defaults.name = Spacers.freeName(session.model().childrenOf(0));
|
||||
ChannelDialog.toCreate(host, session, groupIcons, "Create Spacer", 0, defaults)
|
||||
.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return conn.isConnected();
|
||||
return session.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBrowseFiles() {
|
||||
return tab.session().permissions().canBrowseFiles();
|
||||
return session.permissions().canBrowseFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void browseFiles(ChannelNode channel) {
|
||||
if (!conn.canTransferFiles()) return;
|
||||
new FileBrowserDialog(host, conn, channel).setVisible(true);
|
||||
if (!session.files().isAvailable()) return;
|
||||
new FileBrowserDialog(host, session, channel).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClientLocallyMuted(int clientId) {
|
||||
VoiceOutput playback = conn.ownClient().playback();
|
||||
VoiceOutput playback = session.playback();
|
||||
return playback != null && playback.isClientMuted(clientId);
|
||||
}
|
||||
|
||||
@@ -366,12 +367,12 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
public void onSelectionChanged(Object userObject) {
|
||||
currentSelection = userObject;
|
||||
renderInfo();
|
||||
if (!conn.isConnected()) return;
|
||||
if (!session.isConnected()) return;
|
||||
if (userObject instanceof ChannelNode) {
|
||||
ChannelNode ch = (ChannelNode) userObject;
|
||||
if (!ch.descriptionLoaded) conn.requestChannelInfo(ch.id);
|
||||
if (!ch.descriptionLoaded) session.channels().requestInfo(ch.id);
|
||||
} else if (userObject instanceof ClientEntry) {
|
||||
conn.requestClientInfo(((ClientEntry) userObject).id);
|
||||
session.clients().requestInfo(((ClientEntry) userObject).id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user