diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-12-30 01:24:55 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-12-30 01:24:55 -0500 |
commit | d7bb6049e130dcd3a36e1a07fb39d24468c4889b (patch) | |
tree | a18fc8a6c7bf2309a6471e3d2591786d3e50f653 /src | |
parent | ea7464722b00501e077b4cb8ae267200ee6df220 (diff) | |
download | abaddon-portaudio-d7bb6049e130dcd3a36e1a07fb39d24468c4889b.tar.gz abaddon-portaudio-d7bb6049e130dcd3a36e1a07fb39d24468c4889b.zip |
add mute/unmute guild menu item
Diffstat (limited to 'src')
-rw-r--r-- | src/components/channels.cpp | 24 | ||||
-rw-r--r-- | src/components/channels.hpp | 2 | ||||
-rw-r--r-- | src/discord/discord.cpp | 18 | ||||
-rw-r--r-- | src/discord/discord.hpp | 2 |
4 files changed, 44 insertions, 2 deletions
diff --git a/src/components/channels.cpp b/src/components/channels.cpp index b631023..290093d 100644 --- a/src/components/channels.cpp +++ b/src/components/channels.cpp @@ -98,9 +98,18 @@ ChannelList::ChannelList() m_menu_guild_mark_as_read.signal_activate().connect([this] { Abaddon::Get().GetDiscordClient().MarkGuildAsRead(static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), [](...) {}); }); + m_menu_guild_toggle_mute.signal_activate().connect([this] { + const auto id = static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); + auto &discord = Abaddon::Get().GetDiscordClient(); + if (discord.IsGuildMuted(id)) + discord.UnmuteGuild(id, NOOP_CALLBACK); + else + discord.MuteGuild(id, NOOP_CALLBACK); + }); m_menu_guild.append(m_menu_guild_mark_as_read); m_menu_guild.append(m_menu_guild_settings); m_menu_guild.append(m_menu_guild_leave); + m_menu_guild.append(m_menu_guild_toggle_mute); m_menu_guild.append(m_menu_guild_copy_id); m_menu_guild.show_all(); @@ -121,9 +130,9 @@ ChannelList::ChannelList() const auto id = static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); auto &discord = Abaddon::Get().GetDiscordClient(); if (discord.IsChannelMuted(id)) - discord.UnmuteChannel(id, [](...) {}); + discord.UnmuteChannel(id, NOOP_CALLBACK); else - discord.MuteChannel(id, [](...) {}); + discord.MuteChannel(id, NOOP_CALLBACK); }); m_menu_channel.append(m_menu_channel_mark_as_read); m_menu_channel.append(m_menu_channel_toggle_mute); @@ -167,6 +176,7 @@ ChannelList::ChannelList() m_menu_thread.append(m_menu_thread_unarchive); m_menu_thread.show_all(); + m_menu_guild.signal_popped_up().connect(sigc::mem_fun(*this, &ChannelList::OnGuildSubmenuPopup)); m_menu_channel.signal_popped_up().connect(sigc::mem_fun(*this, &ChannelList::OnChannelSubmenuPopup)); m_menu_thread.signal_popped_up().connect(sigc::mem_fun(*this, &ChannelList::OnThreadSubmenuPopup)); @@ -833,6 +843,16 @@ void ChannelList::MoveRow(const Gtk::TreeModel::iterator &iter, const Gtk::TreeM m_model->erase(iter); } +void ChannelList::OnGuildSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y) { + const 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().IsGuildMuted(id)) + m_menu_guild_toggle_mute.set_label("Unmute"); + else + m_menu_guild_toggle_mute.set_label("Mute"); +} + void ChannelList::OnChannelSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y) { const auto iter = m_model->get_iter(m_path_for_menu); if (!iter) return; diff --git a/src/components/channels.hpp b/src/components/channels.hpp index dd2a4d9..40e8358 100644 --- a/src/components/channels.hpp +++ b/src/components/channels.hpp @@ -110,6 +110,7 @@ protected: Gtk::MenuItem m_menu_guild_settings; Gtk::MenuItem m_menu_guild_leave; Gtk::MenuItem m_menu_guild_mark_as_read; + Gtk::MenuItem m_menu_guild_toggle_mute; Gtk::Menu m_menu_category; Gtk::MenuItem m_menu_category_copy_id; @@ -129,6 +130,7 @@ protected: Gtk::MenuItem m_menu_thread_archive; Gtk::MenuItem m_menu_thread_unarchive; + void OnGuildSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y); void OnChannelSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y); void OnThreadSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y); diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 0536a4e..6819375 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -960,6 +960,24 @@ void DiscordClient::MarkAllAsRead(sigc::slot<void(DiscordError code)> callback) }); } +void DiscordClient::MuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback) { + m_http.MakePATCH("/users/@me/guilds/" + std::to_string(id) + "/settings", R"({"muted":true})", [this, callback](const http::response_type &response) { + if (CheckCode(response)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + +void DiscordClient::UnmuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback) { + m_http.MakePATCH("/users/@me/guilds/" + std::to_string(id) + "/settings", R"({"muted":false})", [this, callback](const http::response_type &response) { + if (CheckCode(response)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + void DiscordClient::FetchPinned(Snowflake id, sigc::slot<void(std::vector<Message>, DiscordError code)> callback) { // return from db if we know the pins have already been requested if (m_channels_pinned_requested.find(id) != m_channels_pinned_requested.end()) { diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 1f8daa5..44f02bb 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -143,6 +143,8 @@ public: void MuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback); void UnmuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback); void MarkAllAsRead(sigc::slot<void(DiscordError code)> callback); + void MuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback); + void UnmuteGuild(Snowflake id, sigc::slot<void(DiscordError code)> callback); bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const; bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const; |