summaryrefslogtreecommitdiff
path: root/src/discord
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2023-05-19 20:20:33 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2023-05-19 20:20:33 -0400
commit3e67e8a7aeb265914d538314b17f36a988017081 (patch)
tree42e6830f3bf9c7bacde92d75be961c591ef2732a /src/discord
parent0a1138fbd025da2c3f28cec73f823d9274ebc4db (diff)
downloadabaddon-portaudio-3e67e8a7aeb265914d538314b17f36a988017081.tar.gz
abaddon-portaudio-3e67e8a7aeb265914d538314b17f36a988017081.zip
add voice state icons to participant rows
Diffstat (limited to 'src/discord')
-rw-r--r--src/discord/discord.cpp47
-rw-r--r--src/discord/discord.hpp10
-rw-r--r--src/discord/voicestateflags.hpp17
3 files changed, 57 insertions, 17 deletions
diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp
index be939be..37d4f28 100644
--- a/src/discord/discord.cpp
+++ b/src/discord/discord.cpp
@@ -1227,8 +1227,8 @@ std::optional<uint32_t> DiscordClient::GetSSRCOfUser(Snowflake id) const {
return m_voice.GetSSRCOfUser(id);
}
-std::optional<Snowflake> DiscordClient::GetVoiceState(Snowflake user_id) const {
- if (const auto it = m_voice_state_user_channel.find(user_id); it != m_voice_state_user_channel.end()) {
+std::optional<std::pair<Snowflake, VoiceStateFlags>> 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;
@@ -2267,9 +2267,9 @@ void DiscordClient::HandleGatewayVoiceStateUpdate(const GatewayMessage &msg) {
if (data.ChannelID.has_value()) {
const auto old_state = GetVoiceState(data.UserID);
- SetVoiceState(data.UserID, *data.ChannelID);
- if (old_state.has_value() && *old_state != *data.ChannelID) {
- m_signal_voice_user_disconnect.emit(data.UserID, *old_state);
+ 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);
} else if (!old_state.has_value()) {
m_signal_voice_user_connect.emit(data.UserID, *data.ChannelID);
@@ -2278,7 +2278,7 @@ void DiscordClient::HandleGatewayVoiceStateUpdate(const GatewayMessage &msg) {
const auto old_state = GetVoiceState(data.UserID);
ClearVoiceState(data.UserID);
if (old_state.has_value()) {
- m_signal_voice_user_disconnect.emit(data.UserID, *old_state);
+ m_signal_voice_user_disconnect.emit(data.UserID, old_state->first);
}
}
}
@@ -2333,7 +2333,7 @@ void DiscordClient::HandleGatewayReadySupplemental(const GatewayMessage &msg) {
for (const auto &g : data.Guilds) {
for (const auto &s : g.VoiceStates) {
if (s.ChannelID.has_value()) {
- SetVoiceState(s.UserID, *s.ChannelID);
+ SetVoiceState(s.UserID, s);
}
}
}
@@ -2798,18 +2798,33 @@ void DiscordClient::SendVoiceStateUpdate() {
m_websocket.Send(msg);
}
-void DiscordClient::SetVoiceState(Snowflake user_id, Snowflake channel_id) {
- spdlog::get("discord")->debug("SetVoiceState: {} -> {}", user_id, channel_id);
- m_voice_state_user_channel[user_id] = channel_id;
- m_voice_state_channel_users[channel_id].insert(user_id);
+void DiscordClient::SetVoiceState(Snowflake user_id, const VoiceState &state) {
+ if (!state.ChannelID.has_value()) {
+ spdlog::get("discord")->error("SetVoiceState called with missing channel ID");
+ return;
+ }
+ spdlog::get("discord")->debug("SetVoiceState: {} -> {}", user_id, *state.ChannelID);
+
+ auto flags = VoiceStateFlags::Clear;
+ if (state.IsSelfMuted) flags |= VoiceStateFlags::SelfMute;
+ if (state.IsSelfDeafened) flags |= VoiceStateFlags::SelfDeaf;
+ if (state.IsMuted) flags |= VoiceStateFlags::Mute;
+ if (state.IsDeafened) flags |= VoiceStateFlags::Deaf;
+ if (state.IsSelfStream) flags |= VoiceStateFlags::SelfStream;
+ if (state.IsSelfVideo) flags |= VoiceStateFlags::SelfVideo;
+
+ m_voice_states[user_id] = std::make_pair(*state.ChannelID, flags);
+ m_voice_state_channel_users[*state.ChannelID].insert(user_id);
+
+ m_signal_voice_state_set.emit(user_id, *state.ChannelID, flags);
}
void DiscordClient::ClearVoiceState(Snowflake user_id) {
spdlog::get("discord")->debug("ClearVoiceState: {}", user_id);
- if (const auto it = m_voice_state_user_channel.find(user_id); it != m_voice_state_user_channel.end()) {
- m_voice_state_channel_users[it->second].erase(user_id);
+ if (const auto it = m_voice_states.find(user_id); it != m_voice_states.end()) {
+ m_voice_state_channel_users[it->second.first].erase(user_id);
// invalidated
- m_voice_state_user_channel.erase(user_id);
+ m_voice_states.erase(user_id);
}
}
@@ -3119,4 +3134,8 @@ DiscordClient::type_signal_voice_client_state_update DiscordClient::signal_voice
DiscordClient::type_signal_voice_channel_changed DiscordClient::signal_voice_channel_changed() {
return m_signal_voice_channel_changed;
}
+
+DiscordClient::type_signal_voice_state_set DiscordClient::signal_voice_state_set() {
+ return m_signal_voice_state_set;
+}
#endif
diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp
index cb76ef6..7f7518c 100644
--- a/src/discord/discord.hpp
+++ b/src/discord/discord.hpp
@@ -5,6 +5,7 @@
#include "objects.hpp"
#include "store.hpp"
#include "voiceclient.hpp"
+#include "voicestateflags.hpp"
#include "websocket.hpp"
#include <sigc++/sigc++.h>
#include <nlohmann/json.hpp>
@@ -192,7 +193,7 @@ 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<Snowflake> GetVoiceState(Snowflake user_id) const;
+ [[nodiscard]] std::optional<std::pair<Snowflake, VoiceStateFlags>> GetVoiceState(Snowflake user_id) const;
DiscordVoiceClient &GetVoiceClient();
@@ -360,12 +361,12 @@ private:
Snowflake m_voice_channel_id;
// todo sql i guess
- std::unordered_map<Snowflake, Snowflake> m_voice_state_user_channel;
+ std::unordered_map<Snowflake, std::pair<Snowflake, VoiceStateFlags>> m_voice_states;
std::unordered_map<Snowflake, std::unordered_set<Snowflake>> m_voice_state_channel_users;
void SendVoiceStateUpdate();
- void SetVoiceState(Snowflake user_id, Snowflake channel_id);
+ void SetVoiceState(Snowflake user_id, const VoiceState &state);
void ClearVoiceState(Snowflake user_id);
void OnVoiceConnected();
@@ -455,6 +456,7 @@ public:
using type_signal_voice_requested_disconnect = sigc::signal<void()>;
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)>;
#endif
type_signal_gateway_ready signal_gateway_ready();
@@ -522,6 +524,7 @@ public:
type_signal_voice_requested_disconnect signal_voice_requested_disconnect();
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();
#endif
protected:
@@ -590,5 +593,6 @@ protected:
type_signal_voice_requested_disconnect m_signal_voice_requested_disconnect;
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;
#endif
};
diff --git a/src/discord/voicestateflags.hpp b/src/discord/voicestateflags.hpp
new file mode 100644
index 0000000..e369001
--- /dev/null
+++ b/src/discord/voicestateflags.hpp
@@ -0,0 +1,17 @@
+#pragma once
+#include <cstdint>
+
+enum class VoiceStateFlags : uint8_t {
+ Clear = 0,
+ Deaf = 1 << 0,
+ Mute = 1 << 1,
+ SelfDeaf = 1 << 2,
+ SelfMute = 1 << 3,
+ SelfStream = 1 << 4,
+ SelfVideo = 1 << 5,
+};
+
+template<>
+struct Bitwise<VoiceStateFlags> {
+ static const bool enable = true;
+};