From 3109089e8c557c1385d3e6a34d9a097f905cec00 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:39:11 -0400 Subject: [PATCH] accept/decline stage invite --- src/discord/discord.cpp | 17 +++++++++++++++++ src/discord/discord.hpp | 1 + src/windows/voice/voicewindow.cpp | 27 +++++++++++++++++++++++++-- src/windows/voice/voicewindow.hpp | 6 ++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index d99e57a..a7712d6 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1355,6 +1355,23 @@ void DiscordClient::SetStageSpeaking(Snowflake channel_id, bool want, const sigc }); } +void DiscordClient::DeclineInviteToSpeak(Snowflake channel_id, const sigc::slot &callback) { + const auto channel = GetChannel(channel_id); + if (!channel.has_value() || !channel->GuildID.has_value()) return; + + ModifyCurrentUserVoiceStateObject d; + d.ChannelID = channel_id; + d.Suppress = true; + d.RequestToSpeakTimestamp = ""; + m_http.MakePATCH("/guilds/" + std::to_string(*channel->GuildID) + "/voice-states/@me", nlohmann::json(d).dump(), [callback](const http::response_type &response) { + if (CheckCode(response, 204)) { + callback(DiscordError::NONE); + } else { + callback(GetCodeFromResponse(response)); + } + }); +} + DiscordVoiceClient &DiscordClient::GetVoiceClient() { return m_voice; } diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 42fa1cb..483abf0 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -209,6 +209,7 @@ public: void RequestToSpeak(Snowflake channel_id, bool want, const sigc::slot &callback); void SetStageSpeaking(Snowflake channel_id, bool want, const sigc::slot &callback); + void DeclineInviteToSpeak(Snowflake channel_id, const sigc::slot &callback); DiscordVoiceClient &GetVoiceClient(); diff --git a/src/windows/voice/voicewindow.cpp b/src/windows/voice/voicewindow.cpp index 27dd734..5930156 100644 --- a/src/windows/voice/voicewindow.cpp +++ b/src/windows/voice/voicewindow.cpp @@ -23,6 +23,9 @@ VoiceWindow::VoiceWindow(Snowflake channel_id) , m_mix_mono("Mix Mono") , m_stage_command("Request to Speak") , m_disconnect("Disconnect") + , m_stage_invite_lbl("You've been invited to speak") + , m_stage_accept("Accept") + , m_stage_decline("Decline") , m_channel_id(channel_id) , m_menu_view("View") , m_menu_view_settings("More _Settings", true) { @@ -222,14 +225,24 @@ VoiceWindow::VoiceWindow(Snowflake channel_id) if (is_speaker) { discord.SetStageSpeaking(m_channel_id, false, NOOP_CALLBACK); - } else if (is_moderator || is_invited_to_speak) { + } else if (is_moderator) { discord.SetStageSpeaking(m_channel_id, true, NOOP_CALLBACK); + } else if (is_invited_to_speak) { + discord.DeclineInviteToSpeak(m_channel_id, NOOP_CALLBACK); } else { const bool requested = discord.HasUserRequestedToSpeak(user_id); discord.RequestToSpeak(m_channel_id, !requested, NOOP_CALLBACK); } }); + m_stage_accept.signal_clicked().connect([this]() { + Abaddon::Get().GetDiscordClient().SetStageSpeaking(m_channel_id, true, NOOP_CALLBACK); + }); + + m_stage_decline.signal_clicked().connect([this]() { + Abaddon::Get().GetDiscordClient().DeclineInviteToSpeak(m_channel_id, NOOP_CALLBACK); + }); + m_TMP_speakers_label.set_markup("Speakers"); m_listing.pack_start(m_TMP_speakers_label, false, true); m_listing.pack_start(m_speakers_list, false, true); @@ -244,10 +257,16 @@ VoiceWindow::VoiceWindow(Snowflake channel_id) m_buttons.set_halign(Gtk::ALIGN_CENTER); m_buttons.pack_start(m_stage_command, false, true); m_buttons.pack_start(m_disconnect, false, true); + m_stage_invite_box.pack_start(m_stage_invite_lbl, false, true); + m_stage_invite_box.pack_start(m_stage_invite_btns); + m_stage_invite_btns.set_halign(Gtk::ALIGN_CENTER); + m_stage_invite_btns.pack_start(m_stage_accept, false, true); + m_stage_invite_btns.pack_start(m_stage_decline, false, true); m_main.pack_start(m_menu_bar, false, true); m_main.pack_start(m_TMP_stagelabel, false, true); m_main.pack_start(m_controls, false, true); m_main.pack_start(m_buttons, false, true); + m_main.pack_start(m_stage_invite_box, false, true); m_main.pack_start(m_vad_value, false, true); m_main.pack_start(*Gtk::make_managed("Input Settings"), false, true); m_main.pack_start(*sliders_container, false, true); @@ -357,12 +376,16 @@ void VoiceWindow::UpdateStageCommand() { const bool is_speaker = discord.IsUserSpeaker(user_id); const bool is_invited_to_speak = discord.IsUserInvitedToSpeak(user_id); + m_stage_invite_box.set_visible(is_invited_to_speak); + if (is_speaker) { m_stage_command.set_label("Leave the Stage"); - } else if (is_moderator || is_invited_to_speak) { + } else if (is_moderator) { m_stage_command.set_label("Speak on Stage"); } else if (m_has_requested_to_speak) { m_stage_command.set_label("Cancel Request"); + } else if (is_invited_to_speak) { + m_stage_command.set_label("Decline Invite"); } else { m_stage_command.set_label("Request to Speak"); } diff --git a/src/windows/voice/voicewindow.hpp b/src/windows/voice/voicewindow.hpp index 5005b90..7c5a137 100644 --- a/src/windows/voice/voicewindow.hpp +++ b/src/windows/voice/voicewindow.hpp @@ -66,6 +66,12 @@ private: Gtk::Button m_disconnect; Gtk::Button m_stage_command; + Gtk::VBox m_stage_invite_box; + Gtk::Label m_stage_invite_lbl; + Gtk::HBox m_stage_invite_btns; + Gtk::Button m_stage_accept; + Gtk::Button m_stage_decline; + bool m_has_requested_to_speak = false; Gtk::ComboBoxText m_vad_combo;