summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-12-18 01:58:29 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-12-18 01:58:29 -0500
commitf580535d3570de59125cc377b01188601c82b5b9 (patch)
tree01a6d40ac08fde25e0e0705e8088c26f76cb6f12 /src
parent1d7529e60925c36af5aa5a8702e7a0827e646f00 (diff)
downloadabaddon-portaudio-f580535d3570de59125cc377b01188601c82b5b9.tar.gz
abaddon-portaudio-f580535d3570de59125cc377b01188601c82b5b9.zip
add mute/unmute channel menu item
Diffstat (limited to 'src')
-rw-r--r--src/components/channels.cpp24
-rw-r--r--src/components/channels.hpp2
-rw-r--r--src/components/channelscellrenderer.cpp2
-rw-r--r--src/discord/discord.cpp33
-rw-r--r--src/discord/discord.hpp2
-rw-r--r--src/discord/objects.cpp38
-rw-r--r--src/discord/objects.hpp16
7 files changed, 108 insertions, 9 deletions
diff --git a/src/components/channels.cpp b/src/components/channels.cpp
index d49afca..76fd69d 100644
--- a/src/components/channels.cpp
+++ b/src/components/channels.cpp
@@ -1,8 +1,8 @@
-#include "channels.hpp"
#include "abaddon.hpp"
+#include "channels.hpp"
#include "imgmanager.hpp"
-#include "util.hpp"
#include "statusindicator.hpp"
+#include "util.hpp"
#include <algorithm>
#include <map>
#include <unordered_map>
@@ -117,7 +117,16 @@ ChannelList::ChannelList()
m_menu_channel_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]), [](...) {});
});
+ m_menu_channel_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.UnmuteChannel(id, [](...) {});
+ else
+ discord.MuteChannel(id, [](...) {});
+ });
m_menu_channel.append(m_menu_channel_mark_as_read);
+ m_menu_channel.append(m_menu_channel_toggle_mute);
m_menu_channel.append(m_menu_channel_copy_id);
m_menu_channel.show_all();
@@ -158,6 +167,7 @@ ChannelList::ChannelList()
m_menu_thread.append(m_menu_thread_unarchive);
m_menu_thread.show_all();
+ 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));
auto &discord = Abaddon::Get().GetDiscordClient();
@@ -805,6 +815,16 @@ void ChannelList::MoveRow(const Gtk::TreeModel::iterator &iter, const Gtk::TreeM
m_model->erase(iter);
}
+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;
+ const auto id = static_cast<Snowflake>((*iter)[m_columns.m_id]);
+ if (Abaddon::Get().GetDiscordClient().IsChannelMuted(id))
+ m_menu_channel_toggle_mute.set_label("Unmute");
+ else
+ m_menu_channel_toggle_mute.set_label("Mute");
+}
+
void ChannelList::OnThreadSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y) {
m_menu_thread_archive.set_visible(false);
m_menu_thread_unarchive.set_visible(false);
diff --git a/src/components/channels.hpp b/src/components/channels.hpp
index 16e6360..bc7dfc2 100644
--- a/src/components/channels.hpp
+++ b/src/components/channels.hpp
@@ -115,6 +115,7 @@ protected:
Gtk::Menu m_menu_channel;
Gtk::MenuItem m_menu_channel_copy_id;
Gtk::MenuItem m_menu_channel_mark_as_read;
+ Gtk::MenuItem m_menu_channel_toggle_mute;
Gtk::Menu m_menu_dm;
Gtk::MenuItem m_menu_dm_copy_id;
@@ -126,6 +127,7 @@ protected:
Gtk::MenuItem m_menu_thread_archive;
Gtk::MenuItem m_menu_thread_unarchive;
+ 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);
bool m_updating_listing = false;
diff --git a/src/components/channelscellrenderer.cpp b/src/components/channelscellrenderer.cpp
index f507802..df9f03d 100644
--- a/src/components/channelscellrenderer.cpp
+++ b/src/components/channelscellrenderer.cpp
@@ -1,7 +1,7 @@
#include "channelscellrenderer.hpp"
#include "abaddon.hpp"
-#include <gtkmm.h>
#include "unreadrenderer.hpp"
+#include <gtkmm.h>
CellRendererChannels::CellRendererChannels()
: Glib::ObjectBase(typeid(CellRendererChannels))
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 <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()) {
diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp
index 90919b6..9e526f9 100644
--- a/src/discord/discord.hpp
+++ b/src/discord/discord.hpp
@@ -140,6 +140,8 @@ public:
void UnArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
void MarkChannelAsRead(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
void MarkGuildAsRead(Snowflake guild_id, sigc::slot<void(DiscordError code)> callback);
+ void MuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
+ void UnmuteChannel(Snowflake channel_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;
diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp
index a41b664..9e3741f 100644
--- a/src/discord/objects.cpp
+++ b/src/discord/objects.cpp
@@ -143,6 +143,27 @@ void from_json(const nlohmann::json &j, UserGuildSettingsChannelOverride &m) {
JS_D("channel_id", m.ChannelID);
}
+void to_json(nlohmann::json &j, const UserGuildSettingsChannelOverride &m) {
+ j["channel_id"] = m.ChannelID;
+ j["collapsed"] = m.Collapsed;
+ j["message_notifications"] = m.MessageNotifications;
+ j["mute_config"] = m.MuteConfig;
+ j["muted"] = m.Muted;
+}
+
+void from_json(const nlohmann::json &j, MuteConfigData &m) {
+ JS_ON("end_time", m.EndTime);
+ JS_D("selected_time_window", m.SelectedTimeWindow);
+}
+
+void to_json(nlohmann::json &j, const MuteConfigData &m) {
+ if (m.EndTime.has_value())
+ j["end_time"] = *m.EndTime;
+ else
+ j["end_time"] = nullptr;
+ j["selected_time_window"] = m.SelectedTimeWindow;
+}
+
void from_json(const nlohmann::json &j, UserGuildSettingsEntry &m) {
JS_D("version", m.Version);
JS_D("suppress_roles", m.SuppressRoles);
@@ -151,13 +172,26 @@ void from_json(const nlohmann::json &j, UserGuildSettingsEntry &m) {
JS_D("mobile_push", m.MobilePush);
JS_D("message_notifications", m.MessageNotifications);
JS_D("hide_muted_channels", m.HideMutedChannels);
- JS_D("guild_id", m.GuildID);
+ JS_N("guild_id", m.GuildID);
JS_D("channel_overrides", m.ChannelOverrides);
}
+void to_json(nlohmann::json &j, const UserGuildSettingsEntry &m) {
+ j["channel_overrides"] = m.ChannelOverrides;
+ j["guild_id"] = m.GuildID;
+ j["hide_muted_channels"] = m.HideMutedChannels;
+ j["message_notifications"] = m.MessageNotifications;
+ j["mobile_push"] = m.MobilePush;
+ j["mute_config"] = m.MuteConfig;
+ j["muted"] = m.Muted;
+ j["suppress_everyone"] = m.SuppressEveryone;
+ j["suppress_roles"] = m.SuppressRoles;
+ j["version"] = m.Version;
+}
+
void from_json(const nlohmann::json &j, UserGuildSettingsData &m) {
JS_D("version", m.Version);
- JS_D("partial", m.IsParital);
+ JS_D("partial", m.IsPartial);
JS_D("entries", m.Entries);
}
diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp
index 69ad422..c72361b 100644
--- a/src/discord/objects.hpp
+++ b/src/discord/objects.hpp
@@ -244,14 +244,23 @@ struct ReadStateData {
friend void from_json(const nlohmann::json &j, ReadStateData &m);
};
+struct MuteConfigData {
+ std::optional<std::string> EndTime; // nullopt is encoded as null
+ int SelectedTimeWindow;
+
+ friend void from_json(const nlohmann::json &j, MuteConfigData &m);
+ friend void to_json(nlohmann::json &j, const MuteConfigData &m);
+};
+
struct UserGuildSettingsChannelOverride {
bool Muted;
- // MuteConfig
+ MuteConfigData MuteConfig;
int MessageNotifications;
bool Collapsed;
Snowflake ChannelID;
friend void from_json(const nlohmann::json &j, UserGuildSettingsChannelOverride &m);
+ friend void to_json(nlohmann::json &j, const UserGuildSettingsChannelOverride &m);
};
struct UserGuildSettingsEntry {
@@ -259,7 +268,7 @@ struct UserGuildSettingsEntry {
bool SuppressRoles;
bool SuppressEveryone;
bool Muted;
- // MuteConfig
+ MuteConfigData MuteConfig;
bool MobilePush;
int MessageNotifications;
bool HideMutedChannels;
@@ -267,11 +276,12 @@ struct UserGuildSettingsEntry {
std::vector<UserGuildSettingsChannelOverride> ChannelOverrides;
friend void from_json(const nlohmann::json &j, UserGuildSettingsEntry &m);
+ friend void to_json(nlohmann::json &j, const UserGuildSettingsEntry &m);
};
struct UserGuildSettingsData {
int Version;
- bool IsParital;
+ bool IsPartial;
std::vector<UserGuildSettingsEntry> Entries;
friend void from_json(const nlohmann::json &j, UserGuildSettingsData &m);