accept/decline stage invite

This commit is contained in:
ouwou 2024-06-30 20:39:11 -04:00
parent 7f709ce89c
commit 3109089e8c
4 changed files with 49 additions and 2 deletions

View File

@ -1355,6 +1355,23 @@ void DiscordClient::SetStageSpeaking(Snowflake channel_id, bool want, const sigc
}); });
} }
void DiscordClient::DeclineInviteToSpeak(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &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() { DiscordVoiceClient &DiscordClient::GetVoiceClient() {
return m_voice; return m_voice;
} }

View File

@ -209,6 +209,7 @@ public:
void RequestToSpeak(Snowflake channel_id, bool want, const sigc::slot<void(DiscordError code)> &callback); void RequestToSpeak(Snowflake channel_id, bool want, const sigc::slot<void(DiscordError code)> &callback);
void SetStageSpeaking(Snowflake channel_id, bool want, const sigc::slot<void(DiscordError code)> &callback); void SetStageSpeaking(Snowflake channel_id, bool want, const sigc::slot<void(DiscordError code)> &callback);
void DeclineInviteToSpeak(Snowflake channel_id, const sigc::slot<void(DiscordError code)> &callback);
DiscordVoiceClient &GetVoiceClient(); DiscordVoiceClient &GetVoiceClient();

View File

@ -23,6 +23,9 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
, m_mix_mono("Mix Mono") , m_mix_mono("Mix Mono")
, m_stage_command("Request to Speak") , m_stage_command("Request to Speak")
, m_disconnect("Disconnect") , 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_channel_id(channel_id)
, m_menu_view("View") , m_menu_view("View")
, m_menu_view_settings("More _Settings", true) { , m_menu_view_settings("More _Settings", true) {
@ -222,14 +225,24 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
if (is_speaker) { if (is_speaker) {
discord.SetStageSpeaking(m_channel_id, false, NOOP_CALLBACK); 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); discord.SetStageSpeaking(m_channel_id, true, NOOP_CALLBACK);
} else if (is_invited_to_speak) {
discord.DeclineInviteToSpeak(m_channel_id, NOOP_CALLBACK);
} else { } else {
const bool requested = discord.HasUserRequestedToSpeak(user_id); const bool requested = discord.HasUserRequestedToSpeak(user_id);
discord.RequestToSpeak(m_channel_id, !requested, NOOP_CALLBACK); 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("<b>Speakers</b>"); m_TMP_speakers_label.set_markup("<b>Speakers</b>");
m_listing.pack_start(m_TMP_speakers_label, false, true); m_listing.pack_start(m_TMP_speakers_label, false, true);
m_listing.pack_start(m_speakers_list, 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.set_halign(Gtk::ALIGN_CENTER);
m_buttons.pack_start(m_stage_command, false, true); m_buttons.pack_start(m_stage_command, false, true);
m_buttons.pack_start(m_disconnect, 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_menu_bar, false, true);
m_main.pack_start(m_TMP_stagelabel, false, true); m_main.pack_start(m_TMP_stagelabel, false, true);
m_main.pack_start(m_controls, false, true); m_main.pack_start(m_controls, false, true);
m_main.pack_start(m_buttons, 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(m_vad_value, false, true);
m_main.pack_start(*Gtk::make_managed<Gtk::Label>("Input Settings"), false, true); m_main.pack_start(*Gtk::make_managed<Gtk::Label>("Input Settings"), false, true);
m_main.pack_start(*sliders_container, 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_speaker = discord.IsUserSpeaker(user_id);
const bool is_invited_to_speak = discord.IsUserInvitedToSpeak(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) { if (is_speaker) {
m_stage_command.set_label("Leave the Stage"); 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"); m_stage_command.set_label("Speak on Stage");
} else if (m_has_requested_to_speak) { } else if (m_has_requested_to_speak) {
m_stage_command.set_label("Cancel Request"); m_stage_command.set_label("Cancel Request");
} else if (is_invited_to_speak) {
m_stage_command.set_label("Decline Invite");
} else { } else {
m_stage_command.set_label("Request to Speak"); m_stage_command.set_label("Request to Speak");
} }

View File

@ -66,6 +66,12 @@ private:
Gtk::Button m_disconnect; Gtk::Button m_disconnect;
Gtk::Button m_stage_command; 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; bool m_has_requested_to_speak = false;
Gtk::ComboBoxText m_vad_combo; Gtk::ComboBoxText m_vad_combo;