diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-12-29 23:51:12 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-12-29 23:51:12 -0500 |
commit | ea7464722b00501e077b4cb8ae267200ee6df220 (patch) | |
tree | 1bc6880a1814eb3b45230093cd98e72e63a07c53 /src | |
parent | d6da646d879a1b7f0ea2d09db2b266e3b6d0f3fa (diff) | |
download | abaddon-portaudio-ea7464722b00501e077b4cb8ae267200ee6df220.tar.gz abaddon-portaudio-ea7464722b00501e077b4cb8ae267200ee6df220.zip |
handle change of mute state for guilds
Diffstat (limited to 'src')
-rw-r--r-- | src/components/channels.cpp | 12 | ||||
-rw-r--r-- | src/components/channels.hpp | 2 | ||||
-rw-r--r-- | src/discord/discord.cpp | 28 | ||||
-rw-r--r-- | src/discord/discord.hpp | 6 |
4 files changed, 48 insertions, 0 deletions
diff --git a/src/components/channels.cpp b/src/components/channels.cpp index c6606e4..b631023 100644 --- a/src/components/channels.cpp +++ b/src/components/channels.cpp @@ -186,6 +186,8 @@ ChannelList::ChannelList() discord.signal_message_ack().connect(sigc::mem_fun(*this, &ChannelList::OnMessageAck)); discord.signal_channel_muted().connect(sigc::mem_fun(*this, &ChannelList::OnChannelMute)); discord.signal_channel_unmuted().connect(sigc::mem_fun(*this, &ChannelList::OnChannelUnmute)); + discord.signal_guild_muted().connect(sigc::mem_fun(*this, &ChannelList::OnGuildMute)); + discord.signal_guild_unmuted().connect(sigc::mem_fun(*this, &ChannelList::OnGuildUnmute)); } void ChannelList::UsePanedHack(Gtk::Paned &paned) { @@ -392,6 +394,16 @@ void ChannelList::OnChannelUnmute(Snowflake id) { m_model->row_changed(m_model->get_path(iter), iter); } +void ChannelList::OnGuildMute(Snowflake id) { + if (auto iter = GetIteratorForGuildFromID(id)) + m_model->row_changed(m_model->get_path(iter), iter); +} + +void ChannelList::OnGuildUnmute(Snowflake id) { + if (auto iter = GetIteratorForGuildFromID(id)) + m_model->row_changed(m_model->get_path(iter), iter); +} + // create a temporary channel row for non-joined threads // and delete them when the active channel switches off of them if still not joined void ChannelList::SetActiveChannel(Snowflake id) { diff --git a/src/components/channels.hpp b/src/components/channels.hpp index dd861b7..dd2a4d9 100644 --- a/src/components/channels.hpp +++ b/src/components/channels.hpp @@ -39,6 +39,8 @@ protected: void DeleteThreadRow(Snowflake id); void OnChannelMute(Snowflake id); void OnChannelUnmute(Snowflake id); + void OnGuildMute(Snowflake id); + void OnGuildUnmute(Snowflake id); void OnThreadJoined(Snowflake id); void OnThreadRemoved(Snowflake id); diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 7b0db38..0536a4e 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1919,6 +1919,26 @@ void DiscordClient::HandleGatewayUserGuildSettingsUpdate(const GatewayMessage &m const auto channels = GetChannelsInGuild(data.Settings.GuildID); std::set<Snowflake> now_muted_channels; const auto now = Snowflake::FromNow(); + + const bool was_muted = IsGuildMuted(data.Settings.GuildID); + bool now_muted = false; + if (data.Settings.Muted) { + if (data.Settings.MuteConfig.EndTime.has_value()) { + const auto end = Snowflake::FromISO8601(*data.Settings.MuteConfig.EndTime); + if (end.IsValid() && end > now) + now_muted = true; + } else { + now_muted = true; + } + } + if (was_muted && !now_muted) { + m_muted_guilds.erase(data.Settings.GuildID); + m_signal_guild_unmuted.emit(data.Settings.GuildID); + } else if (!was_muted && now_muted) { + m_muted_guilds.insert(data.Settings.GuildID); + m_signal_guild_muted.emit(data.Settings.GuildID); + } + for (const auto &override : data.Settings.ChannelOverrides) { if (override.Muted) { if (override.MuteConfig.EndTime.has_value()) { @@ -2575,6 +2595,14 @@ DiscordClient::type_signal_channel_unmuted DiscordClient::signal_channel_unmuted return m_signal_channel_unmuted; } +DiscordClient::type_signal_guild_muted DiscordClient::signal_guild_muted() { + return m_signal_guild_muted; +} + +DiscordClient::type_signal_guild_unmuted DiscordClient::signal_guild_unmuted() { + return m_signal_guild_unmuted; +} + DiscordClient::type_signal_message_send_fail DiscordClient::signal_message_send_fail() { return m_signal_message_send_fail; } diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 4374396..1f8daa5 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -372,6 +372,8 @@ public: typedef sigc::signal<void, Message> type_signal_message_sent; typedef sigc::signal<void, Snowflake> type_signal_channel_muted; typedef sigc::signal<void, Snowflake> type_signal_channel_unmuted; + typedef sigc::signal<void, Snowflake> type_signal_guild_muted; + typedef sigc::signal<void, Snowflake> type_signal_guild_unmuted; typedef sigc::signal<void, std::string /* nonce */, float /* retry_after */> type_signal_message_send_fail; // retry after param will be 0 if it failed for a reason that isnt slowmode typedef sigc::signal<void, bool, GatewayCloseCode> type_signal_disconnected; // bool true if reconnecting @@ -422,6 +424,8 @@ public: type_signal_message_sent signal_message_sent(); type_signal_channel_muted signal_channel_muted(); type_signal_channel_unmuted signal_channel_unmuted(); + type_signal_guild_muted signal_guild_muted(); + type_signal_guild_unmuted signal_guild_unmuted(); type_signal_message_send_fail signal_message_send_fail(); type_signal_disconnected signal_disconnected(); type_signal_connected signal_connected(); @@ -472,6 +476,8 @@ protected: type_signal_message_sent m_signal_message_sent; type_signal_channel_muted m_signal_channel_muted; type_signal_channel_unmuted m_signal_channel_unmuted; + type_signal_guild_muted m_signal_guild_muted; + type_signal_guild_unmuted m_signal_guild_unmuted; type_signal_message_send_fail m_signal_message_send_fail; type_signal_disconnected m_signal_disconnected; type_signal_connected m_signal_connected; |