From f580535d3570de59125cc377b01188601c82b5b9 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 18 Dec 2021 01:58:29 -0500 Subject: add mute/unmute channel menu item --- src/discord/discord.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/discord/discord.cpp') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 9d711c8..1872985 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1,9 +1,11 @@ +#include "abaddon.hpp" #include "discord.hpp" #include "util.hpp" -#include "abaddon.hpp" #include #include +using namespace std::string_literals; + DiscordClient::DiscordClient(bool mem_store) : m_decompress_buf(InflateChunkSize) , m_store(mem_store) { @@ -909,6 +911,35 @@ void DiscordClient::MarkGuildAsRead(Snowflake guild_id, sigc::slot callback) { + const auto channel = GetChannel(channel_id); + if (!channel.has_value()) return; + const auto guild_id_path = channel->GuildID.has_value() ? std::to_string(*channel->GuildID) : "@me"s; + nlohmann::json j; + j["channel_overrides"][std::to_string(channel_id)]["mute_config"] = MuteConfigData { std::nullopt, -1 }; + j["channel_overrides"][std::to_string(channel_id)]["muted"] = true; + m_http.MakePATCH("/users/@me/guilds/" + guild_id_path + "/settings", j.dump(), [this, callback](const http::response_type &response) { + if (CheckCode(response)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + +void DiscordClient::UnmuteChannel(Snowflake channel_id, sigc::slot callback) { + const auto channel = GetChannel(channel_id); + if (!channel.has_value()) return; + const auto guild_id_path = channel->GuildID.has_value() ? std::to_string(*channel->GuildID) : "@me"s; + nlohmann::json j; + j["channel_overrides"][std::to_string(channel_id)]["muted"] = false; + m_http.MakePATCH("/users/@me/guilds/" + guild_id_path + "/settings", j.dump(), [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()) { -- cgit v1.2.3