preliminary speaker checks

This commit is contained in:
ouwou committed 2024-03-14 01:08:13 -04:00
1 parent 019ae0428b
commit 533157ece2
11 files changed
+51 -12

No files matched your search

@@ -6,7 +6,7 @@
#include <gtkmm/cellrendererpixbuf.h>
#include <gtkmm/cellrenderertext.h>
#include "discord/snowflake.hpp"
#include "discord/voicestateflags.hpp"
#include "discord/voicestate.hpp"
#include "misc/bitwise.hpp"
enum class RenderType : uint8_t {
@@ -1061,7 +1061,7 @@ Gtk::TreeModel::iterator ChannelListTree::CreateVoiceParticipantRow(const UserDa
const auto voice_state = Abaddon::Get().GetDiscordClient().GetVoiceState(user.ID);
if (voice_state.has_value()) {
row[m_columns.m_voice_flags] = voice_state->second;
row[m_columns.m_voice_flags] = voice_state->second.Flags;
}
auto &img = Abaddon::Get().GetImageManager();
+7 -2
View File
@@ -1290,13 +1290,18 @@ std::optional<uint32_t> DiscordClient::GetSSRCOfUser(Snowflake id) const {
return m_voice.GetSSRCOfUser(id);
}
std::optional<std::pair<Snowflake, VoiceStateFlags>> DiscordClient::GetVoiceState(Snowflake user_id) const {
std::optional<std::pair<Snowflake, PackedVoiceState>> DiscordClient::GetVoiceState(Snowflake user_id) const {
if (const auto it = m_voice_states.find(user_id); it != m_voice_states.end()) {
return it->second;
}
return std::nullopt;
}
bool DiscordClient::IsUserSpeaker(Snowflake user_id) const {
const auto state = GetVoiceState(user_id);
return state.has_value() && state->second.IsSpeaker();
}
DiscordVoiceClient &DiscordClient::GetVoiceClient() {
return m_voice;
}
@@ -2962,7 +2967,7 @@ void DiscordClient::SetVoiceState(Snowflake user_id, const VoiceState &state) {
if (state.IsSelfVideo) flags |= VoiceStateFlags::SelfVideo;
if (state.IsSuppressed) flags |= VoiceStateFlags::Suppressed;
m_voice_states[user_id] = std::make_pair(*state.ChannelID, flags);
m_voice_states[user_id] = std::make_pair(*state.ChannelID, PackedVoiceState { flags, state.RequestToSpeakTimestamp });
m_voice_state_channel_users[*state.ChannelID].insert(user_id);
m_signal_voice_state_set.emit(user_id, *state.ChannelID, flags);
+4 -3
View File
@@ -5,7 +5,7 @@
#include "objects.hpp"
#include "store.hpp"
#include "voiceclient.hpp"
#include "voicestateflags.hpp"
#include "voicestate.hpp"
#include "websocket.hpp"
#include <gdkmm/rgba.h>
#include <sigc++/sigc++.h>
@@ -202,7 +202,8 @@ public:
[[nodiscard]] Snowflake GetVoiceChannelID() const noexcept;
[[nodiscard]] std::unordered_set<Snowflake> GetUsersInVoiceChannel(Snowflake channel_id);
[[nodiscard]] std::optional<uint32_t> GetSSRCOfUser(Snowflake id) const;
[[nodiscard]] std::optional<std::pair<Snowflake, VoiceStateFlags>> GetVoiceState(Snowflake user_id) const;
[[nodiscard]] std::optional<std::pair<Snowflake, PackedVoiceState>> GetVoiceState(Snowflake user_id) const;
[[nodiscard]] bool IsUserSpeaker(Snowflake user_id) const;
DiscordVoiceClient &GetVoiceClient();
@@ -380,7 +381,7 @@ private:
Snowflake m_voice_channel_id;
// todo sql i guess
std::unordered_map<Snowflake, std::pair<Snowflake, VoiceStateFlags>> m_voice_states;
std::unordered_map<Snowflake, std::pair<Snowflake, PackedVoiceState>> m_voice_states;
std::unordered_map<Snowflake, std::unordered_set<Snowflake>> m_voice_state_channel_users;
void SendVoiceStateUpdate();
+1
View File
@@ -714,4 +714,5 @@ void from_json(const nlohmann::json &j, VoiceState &m) {
JS_D("user_id", m.UserID);
JS_ON("member", m.Member);
JS_D("session_id", m.SessionID);
JS_ON("request_to_speak_timestamp", m.RequestToSpeakTimestamp);
}
+1
View File
@@ -921,6 +921,7 @@ struct VoiceState {
std::string SessionID;
bool IsSuppressed;
Snowflake UserID;
std::optional<std::string> RequestToSpeakTimestamp;
friend void from_json(const nlohmann::json &j, VoiceState &m);
};
+5
View File
@@ -0,0 +1,5 @@
#include "voicestate.hpp"
bool PackedVoiceState::IsSpeaker() const noexcept {
return ((Flags & VoiceStateFlags::Suppressed) != VoiceStateFlags::Suppressed) && !RequestToSpeakTimestamp.has_value();
}
@@ -1,7 +1,10 @@
#pragma once
#include <cstdint>
#include <optional>
#include <string>
#include "misc/bitwise.hpp"
// this is packed into a enum cuz it makes implementing tree models easier
enum class VoiceStateFlags : uint8_t {
Clear = 0,
Deaf = 1 << 0,
@@ -13,6 +16,13 @@ enum class VoiceStateFlags : uint8_t {
Suppressed = 1 << 6,
};
struct PackedVoiceState {
VoiceStateFlags Flags;
std::optional<std::string> RequestToSpeakTimestamp;
[[nodiscard]] bool IsSpeaker() const noexcept;
};
template<>
struct Bitwise<VoiceStateFlags> {
static const bool enable = true;
+7
View File
@@ -1,6 +1,13 @@
#pragma once
#include <type_traits>
namespace util {
template<typename T>
bool FlagSet(T flags, T value) {
return (flags & value) == value;
}
} // namespace util
template<typename T>
struct Bitwise {
static const bool enable = false;
+13 -5
View File
@@ -29,14 +29,17 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
auto &discord = Abaddon::Get().GetDiscordClient();
auto &audio = Abaddon::Get().GetAudio();
const auto channel = discord.GetChannel(m_channel_id);
m_is_stage = channel.has_value() && channel->Type == ChannelType::GUILD_STAGE_VOICE;
SetUsers(discord.GetUsersInVoiceChannel(m_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));
if (const auto self_state = discord.GetVoiceState(discord.GetUserData().ID); self_state.has_value()) {
m_mute.set_active((self_state->second & VoiceStateFlags::SelfMute) == VoiceStateFlags::SelfMute);
m_deafen.set_active((self_state->second & VoiceStateFlags::SelfDeaf) == VoiceStateFlags::SelfDeaf);
m_mute.set_active(util::FlagSet(self_state->second.Flags, VoiceStateFlags::SelfMute));
m_deafen.set_active(util::FlagSet(self_state->second.Flags, VoiceStateFlags::SelfDeaf));
}
m_mute.signal_toggled().connect(sigc::mem_fun(*this, &VoiceWindow::OnMuteChanged));
@@ -214,10 +217,13 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
}
void VoiceWindow::SetUsers(const std::unordered_set<Snowflake> &user_ids) {
const auto me = Abaddon::Get().GetDiscordClient().GetUserData().ID;
auto &discord = Abaddon::Get().GetDiscordClient();
const auto me = discord.GetUserData().ID;
for (auto id : user_ids) {
if (id == me) continue;
m_user_list.add(*CreateRow(id));
if (discord.IsUserSpeaker(id)) {
m_user_list.add(*CreateRow(id));
}
}
}
@@ -283,7 +289,9 @@ void VoiceWindow::UpdateVADParamValue() {
void VoiceWindow::OnUserConnect(Snowflake user_id, Snowflake to_channel_id) {
if (m_channel_id == to_channel_id) {
if (auto it = m_rows.find(user_id); it == m_rows.end()) {
m_user_list.add(*CreateRow(user_id));
if (Abaddon::Get().GetDiscordClient().IsUserSpeaker(user_id)) {
m_user_list.add(*CreateRow(user_id));
}
}
}
}
+1
View File
@@ -62,6 +62,7 @@ private:
Gtk::ComboBox m_capture_combo;
Snowflake m_channel_id;
bool m_is_stage;
std::unordered_map<Snowflake, VoiceWindowUserListEntry *> m_rows;