From eca1a9f0e07b9c942502e3b4ed797d61f23ccc15 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 14 Mar 2024 01:38:36 -0400 Subject: track stage speakers only --- src/discord/discord.cpp | 15 ++++++++++++--- src/discord/discord.hpp | 3 +++ src/windows/voice/voicewindow.cpp | 15 +++++++++++++++ src/windows/voice/voicewindow.hpp | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index d997bc2..40af498 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -2426,9 +2426,14 @@ void DiscordClient::CheckVoiceState(const VoiceState &data) { if (data.ChannelID.has_value()) { const auto old_state = GetVoiceState(data.UserID); SetVoiceState(data.UserID, data); - if (old_state.has_value() && old_state->first != *data.ChannelID) { - m_signal_voice_user_disconnect.emit(data.UserID, old_state->first); - m_signal_voice_user_connect.emit(data.UserID, *data.ChannelID); + const auto new_state = GetVoiceState(data.UserID); + if (old_state.has_value()) { + if (old_state->first != *data.ChannelID) { + m_signal_voice_user_disconnect.emit(data.UserID, old_state->first); + m_signal_voice_user_connect.emit(data.UserID, *data.ChannelID); + } else if (old_state->second.IsSpeaker() != new_state.value().second.IsSpeaker()) { + m_signal_voice_speaker_state_changed.emit(*data.ChannelID, data.UserID, new_state->second.IsSpeaker()); + } } else if (!old_state.has_value()) { m_signal_voice_user_connect.emit(data.UserID, *data.ChannelID); } @@ -3308,4 +3313,8 @@ DiscordClient::type_signal_voice_channel_changed DiscordClient::signal_voice_cha DiscordClient::type_signal_voice_state_set DiscordClient::signal_voice_state_set() { return m_signal_voice_state_set; } + +DiscordClient::type_signal_voice_speaker_state_changed DiscordClient::signal_voice_speaker_state_changed() { + return m_signal_voice_speaker_state_changed; +} #endif diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 155079f..ed7245e 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -480,6 +480,7 @@ public: using type_signal_voice_client_state_update = sigc::signal; using type_signal_voice_channel_changed = sigc::signal; using type_signal_voice_state_set = sigc::signal; + using type_signal_voice_speaker_state_changed = sigc::signal; #endif type_signal_gateway_ready signal_gateway_ready(); @@ -551,6 +552,7 @@ public: type_signal_voice_client_state_update signal_voice_client_state_update(); type_signal_voice_channel_changed signal_voice_channel_changed(); type_signal_voice_state_set signal_voice_state_set(); + type_signal_voice_speaker_state_changed signal_voice_speaker_state_changed(); #endif protected: @@ -623,5 +625,6 @@ protected: type_signal_voice_client_state_update m_signal_voice_client_state_update; type_signal_voice_channel_changed m_signal_voice_channel_changed; type_signal_voice_state_set m_signal_voice_state_set; + type_signal_voice_speaker_state_changed m_signal_voice_speaker_state_changed; #endif }; diff --git a/src/windows/voice/voicewindow.cpp b/src/windows/voice/voicewindow.cpp index 1ada8ee..079d0f7 100644 --- a/src/windows/voice/voicewindow.cpp +++ b/src/windows/voice/voicewindow.cpp @@ -36,6 +36,7 @@ VoiceWindow::VoiceWindow(Snowflake channel_id) discord.signal_voice_user_disconnect().connect(sigc::mem_fun(*this, &VoiceWindow::OnUserDisconnect)); discord.signal_voice_user_connect().connect(sigc::mem_fun(*this, &VoiceWindow::OnUserConnect)); + discord.signal_voice_speaker_state_changed().connect(sigc::mem_fun(*this, &VoiceWindow::OnSpeakerStateChanged)); if (const auto self_state = discord.GetVoiceState(discord.GetUserData().ID); self_state.has_value()) { m_mute.set_active(util::FlagSet(self_state->second.Flags, VoiceStateFlags::SelfMute)); @@ -305,6 +306,20 @@ void VoiceWindow::OnUserDisconnect(Snowflake user_id, Snowflake from_channel_id) } } +void VoiceWindow::OnSpeakerStateChanged(Snowflake channel_id, Snowflake user_id, bool is_speaker) { + if (m_channel_id != channel_id) return; + if (is_speaker) { + if (auto it = m_rows.find(user_id); it == m_rows.end()) { + m_user_list.add(*CreateRow(user_id)); + } + } else { + if (auto it = m_rows.find(user_id); it != m_rows.end()) { + delete it->second; + m_rows.erase(it); + } + } +} + VoiceWindow::type_signal_mute VoiceWindow::signal_mute() { return m_signal_mute; } diff --git a/src/windows/voice/voicewindow.hpp b/src/windows/voice/voicewindow.hpp index 5d73e97..fea998c 100644 --- a/src/windows/voice/voicewindow.hpp +++ b/src/windows/voice/voicewindow.hpp @@ -29,6 +29,7 @@ private: void OnUserConnect(Snowflake user_id, Snowflake to_channel_id); void OnUserDisconnect(Snowflake user_id, Snowflake from_channel_id); + void OnSpeakerStateChanged(Snowflake channel_id, Snowflake user_id, bool is_speaker); void OnMuteChanged(); void OnDeafenChanged(); -- cgit v1.2.3