Show our own mute, away and commander state right away

The server sends notifyclientupdated to the other clients only, so a
clientupdate of our own never came back to us and our row in the tree kept
its old icons until something else refreshed it. Apply the change to the
local model as we send it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-14 12:46:55 +00:00
parent 676e95023e
commit 25a78f52fe

View File

@@ -472,8 +472,16 @@ public final class TeamspeakConnection implements TS3Listener {
} }
private void pushSelfFlags() { private void pushSelfFlags() {
if (microphone == null || playback == null) return;
boolean micMuted = microphone.isMuted();
boolean deaf = playback.isDeafened();
updateSelf(self -> {
self.inputMuted = micMuted;
self.outputMuted = deaf;
});
// Best-effort: publish input/output muted flags to the server so others see them. // Best-effort: publish input/output muted flags to the server so others see them.
if (client == null || !connected || microphone == null || playback == null) return; if (client == null || !connected) return;
try { try {
java.util.Map<String, String> props = new java.util.HashMap<>(); java.util.Map<String, String> props = new java.util.HashMap<>();
props.put("client_input_muted", microphone.isMuted() ? "1" : "0"); props.put("client_input_muted", microphone.isMuted() ? "1" : "0");
@@ -573,6 +581,7 @@ public final class TeamspeakConnection implements TS3Listener {
public void setAway(boolean away, String message) { public void setAway(boolean away, String message) {
sound(away ? SoundEvent.STATUS_SET_AWAY : SoundEvent.STATUS_SET_PRESENT); sound(away ? SoundEvent.STATUS_SET_AWAY : SoundEvent.STATUS_SET_PRESENT);
updateSelf(self -> self.away = away);
selfUpdate(cmd -> { selfUpdate(cmd -> {
cmd.add(new CommandSingleParameter("client_away", away ? "1" : "0")); cmd.add(new CommandSingleParameter("client_away", away ? "1" : "0"));
cmd.add(new CommandSingleParameter("client_away_message", away && message != null ? message : "")); cmd.add(new CommandSingleParameter("client_away_message", away && message != null ? message : ""));
@@ -580,11 +589,24 @@ public final class TeamspeakConnection implements TS3Listener {
} }
public void setChannelCommander(boolean commander) { public void setChannelCommander(boolean commander) {
updateSelf(self -> self.channelCommander = commander);
selfUpdate(cmd -> selfUpdate(cmd ->
cmd.add(new CommandSingleParameter("client_is_channel_commander", commander ? "1" : "0")), cmd.add(new CommandSingleParameter("client_is_channel_commander", commander ? "1" : "0")),
"Channel commander update failed"); "Channel commander update failed");
} }
/**
* Applies a change of our own state to the local model. The server sends
* {@code notifyclientupdated} to the <em>other</em> clients only, so without this
* our own row would keep its old icons until something else refreshed it.
*/
private void updateSelf(java.util.function.Consumer<ClientEntry> change) {
ClientEntry self = model.getClient(selfClientId);
if (self == null) return;
change.accept(self);
ui.onModelChanged();
}
/** Sends a {@code clientupdate} for the local client on a background thread. */ /** Sends a {@code clientupdate} for the local client on a background thread. */
private void selfUpdate(java.util.function.Consumer<SingleCommand> fill, String errorLabel) { private void selfUpdate(java.util.function.Consumer<SingleCommand> fill, String errorLabel) {
new Thread(() -> { new Thread(() -> {