mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
remove user from list on disconnect
This commit is contained in:
@@ -1208,6 +1208,13 @@ 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()) {
|
||||
return it->second;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void DiscordClient::SetVoiceMuted(bool is_mute) {
|
||||
m_mute_requested = is_mute;
|
||||
SendVoiceStateUpdate();
|
||||
@@ -2164,9 +2171,17 @@ void DiscordClient::HandleGatewayVoiceStateUpdate(const GatewayMessage &msg) {
|
||||
m_voice.SetSessionID(data.SessionID);
|
||||
}
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2952,4 +2967,8 @@ DiscordClient::type_signal_voice_disconnected DiscordClient::signal_voice_discon
|
||||
DiscordClient::type_signal_voice_speaking DiscordClient::signal_voice_speaking() {
|
||||
return m_signal_voice_speaking;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_voice_user_disconnect DiscordClient::signal_voice_user_disconnect() {
|
||||
return m_signal_voice_user_disconnect;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -187,6 +187,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;
|
||||
|
||||
void SetVoiceMuted(bool is_mute);
|
||||
void SetVoiceDeafened(bool is_deaf);
|
||||
@@ -435,6 +436,7 @@ public:
|
||||
using type_signal_voice_connected = sigc::signal<void()>;
|
||||
using type_signal_voice_disconnected = sigc::signal<void()>;
|
||||
using type_signal_voice_speaking = sigc::signal<void(VoiceSpeakingData)>;
|
||||
using type_signal_voice_user_disconnect = sigc::signal<void(Snowflake, Snowflake)>;
|
||||
#endif
|
||||
|
||||
type_signal_gateway_ready signal_gateway_ready();
|
||||
@@ -495,6 +497,7 @@ public:
|
||||
type_signal_voice_connected signal_voice_connected();
|
||||
type_signal_voice_disconnected signal_voice_disconnected();
|
||||
type_signal_voice_speaking signal_voice_speaking();
|
||||
type_signal_voice_user_disconnect signal_voice_user_disconnect();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
@@ -556,5 +559,6 @@ protected:
|
||||
type_signal_voice_connected m_signal_voice_connected;
|
||||
type_signal_voice_disconnected m_signal_voice_disconnected;
|
||||
type_signal_voice_speaking m_signal_voice_speaking;
|
||||
type_signal_voice_user_disconnect m_signal_voice_user_disconnect;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -84,6 +84,8 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
SetUsers(discord.GetUsersInVoiceChannel(m_channel_id));
|
||||
|
||||
discord.signal_voice_user_disconnect().connect(sigc::mem_fun(*this, &VoiceWindow::OnUserDisconnect));
|
||||
|
||||
m_mute.signal_toggled().connect(sigc::mem_fun(*this, &VoiceWindow::OnMuteChanged));
|
||||
m_deafen.signal_toggled().connect(sigc::mem_fun(*this, &VoiceWindow::OnDeafenChanged));
|
||||
|
||||
@@ -103,6 +105,7 @@ VoiceWindow::VoiceWindow(Snowflake channel_id)
|
||||
void VoiceWindow::SetUsers(const std::unordered_set<Snowflake> &user_ids) {
|
||||
for (auto id : user_ids) {
|
||||
auto *row = Gtk::make_managed<VoiceWindowUserListEntry>(id);
|
||||
m_rows[id] = row;
|
||||
row->signal_mute_cs().connect([this, id](bool is_muted) {
|
||||
m_signal_mute_user_cs.emit(id, is_muted);
|
||||
});
|
||||
@@ -121,6 +124,15 @@ void VoiceWindow::OnDeafenChanged() {
|
||||
m_signal_deafen.emit(m_deafen.get_active());
|
||||
}
|
||||
|
||||
void VoiceWindow::OnUserDisconnect(Snowflake user_id, Snowflake from_channel_id) {
|
||||
if (m_channel_id == from_channel_id) {
|
||||
if (auto it = m_rows.find(user_id); it != m_rows.end()) {
|
||||
delete it->second;
|
||||
m_rows.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VoiceWindow::type_signal_mute VoiceWindow::signal_mute() {
|
||||
return m_signal_mute;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ public:
|
||||
private:
|
||||
void SetUsers(const std::unordered_set<Snowflake> &user_ids);
|
||||
|
||||
void OnUserDisconnect(Snowflake user_id, Snowflake from_channel_id);
|
||||
|
||||
void OnMuteChanged();
|
||||
void OnDeafenChanged();
|
||||
|
||||
@@ -32,6 +34,8 @@ private:
|
||||
|
||||
Snowflake m_channel_id;
|
||||
|
||||
std::unordered_map<Snowflake, Gtk::ListBoxRow *> m_rows;
|
||||
|
||||
public:
|
||||
using type_signal_mute = sigc::signal<void(bool)>;
|
||||
using type_signal_deafen = sigc::signal<void(bool)>;
|
||||
|
||||
Reference in New Issue
Block a user