add mute/unmute channel menu item

This commit is contained in:
ouwou
2021-12-18 01:58:29 -05:00
parent 1d7529e609
commit f580535d35
7 changed files with 108 additions and 9 deletions
+32 -1
View File
@@ -1,9 +1,11 @@
#include "abaddon.hpp"
#include "discord.hpp"
#include "util.hpp"
#include "abaddon.hpp"
#include <cassert>
#include <cinttypes>
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<void(DiscordE
});
}
void DiscordClient::MuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> 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<void(DiscordError code)> 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<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()) {