diff --git a/src/components/channels.cpp b/src/components/channels.cpp index 5385b23..c0d1a8b 100644 --- a/src/components/channels.cpp +++ b/src/components/channels.cpp @@ -22,7 +22,8 @@ ChannelList::ChannelList() , m_menu_thread_copy_id("_Copy ID", true) , m_menu_thread_leave("_Leave", true) , m_menu_thread_archive("_Archive", true) - , m_menu_thread_unarchive("_Unarchive", true) { + , m_menu_thread_unarchive("_Unarchive", true) + , m_menu_thread_mark_as_read("Mark as _Read", true) { get_style_context()->add_class("channel-list"); // todo: move to method @@ -187,10 +188,23 @@ ChannelList::ChannelList() m_menu_thread_unarchive.signal_activate().connect([this] { Abaddon::Get().GetDiscordClient().UnArchiveThread(static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), [](...) {}); }); - m_menu_thread.append(m_menu_thread_copy_id); + m_menu_thread_mark_as_read.signal_activate().connect([this] { + Abaddon::Get().GetDiscordClient().MarkChannelAsRead(static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), NOOP_CALLBACK); + }); + m_menu_thread_toggle_mute.signal_activate().connect([this] { + const auto id = static_cast((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); + auto &discord = Abaddon::Get().GetDiscordClient(); + if (discord.IsChannelMuted(id)) + discord.UnmuteThread(id, NOOP_CALLBACK); + else + discord.MuteThread(id, NOOP_CALLBACK); + }); + m_menu_thread.append(m_menu_thread_mark_as_read); + m_menu_thread.append(m_menu_thread_toggle_mute); m_menu_thread.append(m_menu_thread_leave); m_menu_thread.append(m_menu_thread_archive); m_menu_thread.append(m_menu_thread_unarchive); + m_menu_thread.append(m_menu_thread_copy_id); m_menu_thread.show_all(); m_menu_guild.signal_popped_up().connect(sigc::mem_fun(*this, &ChannelList::OnGuildSubmenuPopup)); @@ -914,7 +928,14 @@ void ChannelList::OnThreadSubmenuPopup(const Gdk::Rectangle *flipped_rect, const auto &discord = Abaddon::Get().GetDiscordClient(); auto iter = m_model->get_iter(m_path_for_menu); if (!iter) return; - auto channel = discord.GetChannel(static_cast((*iter)[m_columns.m_id])); + const auto id = static_cast((*iter)[m_columns.m_id]); + + if (discord.IsChannelMuted(id)) + m_menu_thread_toggle_mute.set_label("Unmute"); + else + m_menu_thread_toggle_mute.set_label("Mute"); + + auto channel = discord.GetChannel(id); if (!channel.has_value() || !channel->ThreadMetadata.has_value()) return; if (!discord.HasGuildPermission(discord.GetUserData().ID, *channel->GuildID, Permission::MANAGE_THREADS)) return; diff --git a/src/components/channels.hpp b/src/components/channels.hpp index 4ec0587..a2553fd 100644 --- a/src/components/channels.hpp +++ b/src/components/channels.hpp @@ -131,6 +131,8 @@ protected: Gtk::MenuItem m_menu_thread_leave; Gtk::MenuItem m_menu_thread_archive; Gtk::MenuItem m_menu_thread_unarchive; + Gtk::MenuItem m_menu_thread_mark_as_read; + Gtk::MenuItem m_menu_thread_toggle_mute; void OnGuildSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y); void OnCategorySubmenuPopup(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 ab821a8..8d1cf12 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -983,6 +983,24 @@ void DiscordClient::UnmuteGuild(Snowflake id, sigc::slot callback) { + m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/settings", R"({"muted":true})", [this, callback](const http::response_type &response) { + if (CheckCode(response)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + +void DiscordClient::UnmuteThread(Snowflake id, sigc::slot callback) { + m_http.MakePATCH("/channels/" + std::to_string(id) + "/thread-members/@me/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, 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 1a6aa14..4a7593d 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -146,6 +146,8 @@ public: void MarkAllAsRead(sigc::slot callback); void MuteGuild(Snowflake id, sigc::slot callback); void UnmuteGuild(Snowflake id, sigc::slot callback); + void MuteThread(Snowflake id, sigc::slot callback); + void UnmuteThread(Snowflake id, sigc::slot callback); bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const; bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const;