diff --git a/connector/src/main.rs b/connector/src/main.rs index 7f5e669..cff7e8a 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -88,6 +88,12 @@ struct ClientInfo { database_id: u64, channel_group: u64, server_groups: Vec, + /// Whether this client is currently allowed to talk in their channel - + /// `false` in a moderated channel (one with a talk power requirement) + /// when the client's talk power is below that requirement and they + /// haven't been individually granted talk power. Always `true` in a + /// non-moderated channel. + has_talk_power: bool, } /// Payload for the "serveredit " stdin command - every field is optional so @@ -535,21 +541,32 @@ fn snapshot(con: &data::Connection) -> Event { let clients = con .clients .values() - .map(|c| ClientInfo { - id: c.id.0, - channel: c.channel.0, - name: c.name.clone(), - input_muted: c.input_muted, - output_muted: c.output_muted, - input_hardware_enabled: c.input_hardware_enabled, - away: c.away_message.is_some(), - away_message: c.away_message.clone().unwrap_or_default(), - is_channel_commander: c.is_channel_commander, - country: c.country_code.clone(), - uid: c.uid.as_ref().map(|u| u.to_string()).unwrap_or_default(), - database_id: c.database_id.0, - channel_group: c.channel_group.0, - server_groups: c.server_groups.iter().map(|g| g.0).collect(), + .map(|c| { + // A channel with no talk power requirement at all (the common + // case) is never moderated, so everyone can talk regardless of + // their own talk power - matches tsclientlib's own + // intern_can_send_audio logic for the moderated-channel check. + let has_talk_power = match con.channels.get(&c.channel).and_then(|ch| ch.needed_talk_power) { + Some(needed) => c.talk_power_granted || c.talk_power >= needed, + None => true, + }; + ClientInfo { + id: c.id.0, + channel: c.channel.0, + name: c.name.clone(), + input_muted: c.input_muted, + output_muted: c.output_muted, + input_hardware_enabled: c.input_hardware_enabled, + away: c.away_message.is_some(), + away_message: c.away_message.clone().unwrap_or_default(), + is_channel_commander: c.is_channel_commander, + country: c.country_code.clone(), + uid: c.uid.as_ref().map(|u| u.to_string()).unwrap_or_default(), + database_id: c.database_id.0, + channel_group: c.channel_group.0, + server_groups: c.server_groups.iter().map(|g| g.0).collect(), + has_talk_power, + } }) .collect(); Event::Channels { channels, clients } diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index 9b1c52a..55ed278 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -36,6 +36,7 @@ export interface ClientInfo { databaseId: number; channelGroup: number; serverGroups: number[]; + hasTalkPower: boolean; } export interface GroupEntry { @@ -233,6 +234,7 @@ export class Ts3Connection { database_id: number; channel_group: number; server_groups: number[]; + has_talk_power: boolean; } interface RawChannelInfo { @@ -387,6 +389,7 @@ export class Ts3Connection { databaseId: c.database_id, channelGroup: c.channel_group, serverGroups: c.server_groups, + hasTalkPower: c.has_talk_power, })), }); } else if (event.type === "privateMessage") { diff --git a/web/src/App.tsx b/web/src/App.tsx index b0f500b..7199378 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -330,6 +330,7 @@ interface ClientInfo { databaseId: number; channelGroup: number; serverGroups: number[]; + hasTalkPower: boolean; } interface GroupEntry { @@ -533,7 +534,7 @@ function ChannelTree({
  • onOpenPrivateChat(c.id, c.name)} onContextMenu={(e) => onClientContextMenu(e, c.id, c.name, c.id === ownClientId)} @@ -5839,7 +5840,9 @@ function AppInner() { const inputMuted = ownClient?.inputMuted ?? false; const outputMuted = ownClient?.outputMuted ?? false; const displayTalkers = - selfActive && !inputMuted && ownClient ? new Set(talkers).add(ownClient.id) : talkers; + selfActive && !inputMuted && ownClient?.hasTalkPower + ? new Set(talkers).add(ownClient.id) + : talkers; const t = useT(); return ( diff --git a/web/src/demoMode.ts b/web/src/demoMode.ts index 99b404d..68c1370 100644 --- a/web/src/demoMode.ts +++ b/web/src/demoMode.ts @@ -33,6 +33,7 @@ interface DemoClient { databaseId: number; channelGroup: number; serverGroups: number[]; + hasTalkPower: boolean; } const DEMO_CHANNELS: DemoChannel[] = [ @@ -56,10 +57,10 @@ const DEMO_SERVER_GROUPS = [ ]; const DEMO_NPCS: DemoClient[] = [ - { id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US", uid: "demo-uid-alex", databaseId: 2, channelGroup: 2, serverGroups: [2] }, - { id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB", uid: "demo-uid-sam", databaseId: 3, channelGroup: 4, serverGroups: [4] }, - { id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA", uid: "demo-uid-jordan", databaseId: 4, channelGroup: 4, serverGroups: [4] }, - { id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE", uid: "demo-uid-riley", databaseId: 5, channelGroup: 4, serverGroups: [3, 4] }, + { id: 102, channel: 1, name: "Alex", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: true, country: "US", uid: "demo-uid-alex", databaseId: 2, channelGroup: 2, serverGroups: [2], hasTalkPower: true }, + { id: 103, channel: 2, name: "Sam", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "GB", uid: "demo-uid-sam", databaseId: 3, channelGroup: 4, serverGroups: [4], hasTalkPower: true }, + { id: 104, channel: 2, name: "Jordan", inputMuted: true, outputMuted: false, inputHardwareEnabled: true, away: false, awayMessage: "", isChannelCommander: false, country: "CA", uid: "demo-uid-jordan", databaseId: 4, channelGroup: 4, serverGroups: [4], hasTalkPower: true }, + { id: 105, channel: 3, name: "Riley", inputMuted: false, outputMuted: false, inputHardwareEnabled: true, away: true, awayMessage: "brb, grabbing coffee", isChannelCommander: false, country: "DE", uid: "demo-uid-riley", databaseId: 5, channelGroup: 4, serverGroups: [3, 4], hasTalkPower: true }, ]; interface DemoFileEntry { @@ -617,6 +618,7 @@ export class DemoSocket { databaseId: 1, channelGroup: this.selfChannelGroup, serverGroups: [...this.selfServerGroups], + hasTalkPower: true, }; this.emit({ type: "channels", channels: DEMO_CHANNELS, clients: [self, ...DEMO_NPCS] }); }