rudimentary dm voice call support

This commit is contained in:
ouwou
2022-10-01 17:46:10 -04:00
parent 3e3afde223
commit e08e3106d6
5 changed files with 46 additions and 7 deletions

View File

@@ -27,6 +27,10 @@ ChannelList::ChannelList()
#endif
, m_menu_dm_copy_id("_Copy ID", true)
, m_menu_dm_close("") // changes depending on if group or not
#ifdef WITH_VOICE
, m_menu_dm_join_voice("Join _Voice", true)
, m_menu_dm_disconnect_voice("_Disconnect Voice", true)
#endif
, m_menu_thread_copy_id("_Copy ID", true)
, m_menu_thread_leave("_Leave", true)
, m_menu_thread_archive("_Archive", true)
@@ -215,6 +219,17 @@ ChannelList::ChannelList()
#endif
m_menu_dm.append(m_menu_dm_toggle_mute);
m_menu_dm.append(m_menu_dm_close);
#ifdef WITH_VOICE
m_menu_dm_join_voice.signal_activate().connect([this]() {
const auto id = static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]);
m_signal_action_join_voice_channel.emit(id);
});
m_menu_dm_disconnect_voice.signal_activate().connect([this]() {
m_signal_action_disconnect_voice.emit();
});
m_menu_dm.append(m_menu_dm_join_voice);
m_menu_dm.append(m_menu_dm_disconnect_voice);
#endif
m_menu_dm.append(m_menu_dm_copy_id);
m_menu_dm.show_all();
@@ -1010,10 +1025,21 @@ void ChannelList::OnDMSubmenuPopup() {
auto iter = m_model->get_iter(m_path_for_menu);
if (!iter) return;
const auto id = static_cast<Snowflake>((*iter)[m_columns.m_id]);
if (Abaddon::Get().GetDiscordClient().IsChannelMuted(id))
auto &discord = Abaddon::Get().GetDiscordClient();
if (discord.IsChannelMuted(id))
m_menu_dm_toggle_mute.set_label("Unmute");
else
m_menu_dm_toggle_mute.set_label("Mute");
#ifdef WITH_VOICE
if (discord.IsConnectedToVoice()) {
m_menu_dm_join_voice.set_sensitive(false);
m_menu_dm_disconnect_voice.set_sensitive(discord.GetVoiceChannelID() == id);
} else {
m_menu_dm_join_voice.set_sensitive(true);
m_menu_dm_disconnect_voice.set_sensitive(false);
}
#endif
}
void ChannelList::OnThreadSubmenuPopup() {

View File

@@ -135,6 +135,10 @@ protected:
Gtk::MenuItem m_menu_dm_copy_id;
Gtk::MenuItem m_menu_dm_close;
Gtk::MenuItem m_menu_dm_toggle_mute;
#ifdef WITH_VOICE
Gtk::MenuItem m_menu_dm_join_voice;
Gtk::MenuItem m_menu_dm_disconnect_voice;
#endif
#ifdef WITH_LIBHANDY
Gtk::MenuItem m_menu_dm_open_tab;

View File

@@ -1180,10 +1180,11 @@ void DiscordClient::AcceptVerificationGate(Snowflake guild_id, VerificationGateI
#ifdef WITH_VOICE
void DiscordClient::ConnectToVoice(Snowflake channel_id) {
auto channel = GetChannel(channel_id);
if (!channel.has_value() || !channel->GuildID.has_value()) return;
if (!channel.has_value()) return;
m_voice_channel_id = channel_id;
VoiceStateUpdateMessage m;
m.GuildID = *channel->GuildID;
if (channel->GuildID.has_value())
m.GuildID = channel->GuildID;
m.ChannelID = channel_id;
m.PreferredRegion = "newark";
m_websocket.Send(m);
@@ -2179,7 +2180,13 @@ void DiscordClient::HandleGatewayVoiceServerUpdate(const GatewayMessage &msg) {
printf("token: %s\n", data.Token.c_str());
m_voice.SetEndpoint(data.Endpoint);
m_voice.SetToken(data.Token);
m_voice.SetServerID(data.GuildID);
if (data.GuildID.has_value()) {
m_voice.SetServerID(*data.GuildID);
} else if (data.ChannelID.has_value()) {
m_voice.SetServerID(*data.ChannelID);
} else {
puts("no guild or channel id in voice server?");
}
m_voice.SetUserID(m_user_data.ID);
m_voice.Start();
}

View File

@@ -666,13 +666,14 @@ void to_json(nlohmann::json &j, const VoiceStateUpdateMessage &m) {
void from_json(const nlohmann::json &j, VoiceServerUpdateData &m) {
JS_D("token", m.Token);
JS_D("guild_id", m.GuildID);
JS_D("endpoint", m.Endpoint);
JS_ON("guild_id", m.GuildID);
JS_ON("channel_id", m.ChannelID);
}
#endif
void from_json(const nlohmann::json &j, VoiceState &m) {
JS_O("guild_id", m.GuildID);
JS_ON("guild_id", m.GuildID);
JS_N("channel_id", m.ChannelID);
JS_D("deaf", m.IsDeafened);
JS_D("mute", m.IsMuted);

View File

@@ -891,8 +891,9 @@ struct VoiceStateUpdateMessage {
struct VoiceServerUpdateData {
std::string Token;
Snowflake GuildID;
std::string Endpoint;
std::optional<Snowflake> GuildID;
std::optional<Snowflake> ChannelID;
friend void from_json(const nlohmann::json &j, VoiceServerUpdateData &m);
};