Skip to content

Commit

Permalink
track stage speakers only
Browse files Browse the repository at this point in the history
  • Loading branch information
ouwou committed Mar 14, 2024
1 parent 533157e commit eca1a9f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/discord/discord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/discord/discord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ class DiscordClient {
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();
Expand Down Expand Up @@ -551,6 +552,7 @@ class DiscordClient {
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:
Expand Down Expand Up @@ -623,5 +625,6 @@ class DiscordClient {
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
};
15 changes: 15 additions & 0 deletions src/windows/voice/voicewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/windows/voice/voicewindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class VoiceWindow : public Gtk::Window {

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();
Expand Down

0 comments on commit eca1a9f

Please sign in to comment.