add mark as unread/toggle mute for threads

This commit is contained in:
ouwou 2022-01-20 02:45:28 -05:00
parent d7f3ee9f98
commit b6b215ee6f
4 changed files with 46 additions and 3 deletions

View File

@ -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<Snowflake>((*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<Snowflake>((*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<Snowflake>((*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<Snowflake>((*iter)[m_columns.m_id]));
const auto id = static_cast<Snowflake>((*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;

View File

@ -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);

View File

@ -983,6 +983,24 @@ void DiscordClient::UnmuteGuild(Snowflake id, sigc::slot<void(DiscordError code)
});
}
void DiscordClient::MuteThread(Snowflake id, sigc::slot<void(DiscordError code)> 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<void(DiscordError code)> 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<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()) {

View File

@ -146,6 +146,8 @@ public:
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);
void MuteThread(Snowflake id, sigc::slot<void(DiscordError code)> callback);
void UnmuteThread(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;