track stage speakers only

This commit is contained in:
ouwou 2024-03-14 01:38:36 -04:00
parent 533157ece2
commit eca1a9f0e0
4 changed files with 31 additions and 3 deletions

View File

@ -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

View File

@ -480,6 +480,7 @@ public:
using type_signal_voice_client_state_update = sigc::signal<void(DiscordVoiceClient::State)>;
using type_signal_voice_channel_changed = sigc::signal<void(Snowflake)>;
using type_signal_voice_state_set = sigc::signal<void(Snowflake, Snowflake, VoiceStateFlags)>;
using type_signal_voice_speaker_state_changed = sigc::signal<void(Snowflake /* channel_id */, Snowflake /* user_id */, bool /* is_speaker */)>;
#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
};

View File

@ -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;
}

View File

@ -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();