diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-02-18 12:45:14 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-02-18 12:45:14 -0500 |
commit | 4df9b148e2d7ca35a4de9acfd46daac597252709 (patch) | |
tree | d8e3a926c02e2f36cc9d555aa8851e1b2c812aa3 | |
parent | 614c6ea59566441fdf91cc4329251b8b0a5561c0 (diff) | |
download | abaddon-portaudio-4df9b148e2d7ca35a4de9acfd46daac597252709.tar.gz abaddon-portaudio-4df9b148e2d7ca35a4de9acfd46daac597252709.zip |
add option to remove user from group dm in menu
also fix a crash when opening empty group dms
-rw-r--r-- | abaddon.cpp | 27 | ||||
-rw-r--r-- | abaddon.hpp | 2 | ||||
-rw-r--r-- | discord/discord.cpp | 6 | ||||
-rw-r--r-- | discord/discord.hpp | 1 |
4 files changed, 35 insertions, 1 deletions
diff --git a/abaddon.cpp b/abaddon.cpp index 42fe5e5..d25d29d 100644 --- a/abaddon.cpp +++ b/abaddon.cpp @@ -86,6 +86,7 @@ int Abaddon::StartGTK() { m_user_menu_open_dm = Gtk::manage(new Gtk::MenuItem("Open DM")); m_user_menu_roles = Gtk::manage(new Gtk::MenuItem("Roles")); m_user_menu_info = Gtk::manage(new Gtk::MenuItem("View Profile")); + m_user_menu_remove_recipient = Gtk::manage(new Gtk::MenuItem("Remove From Group")); m_user_menu_roles_submenu = Gtk::manage(new Gtk::Menu); m_user_menu_roles->set_submenu(*m_user_menu_roles_submenu); m_user_menu_insert_mention->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_insert_mention)); @@ -93,17 +94,27 @@ int Abaddon::StartGTK() { m_user_menu_kick->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_kick)); m_user_menu_copy_id->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_copy_id)); m_user_menu_open_dm->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_open_dm)); + m_user_menu_remove_recipient->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_remove_recipient)); m_user_menu_info->signal_activate().connect([this]() { auto *window = new ProfileWindow(m_shown_user_menu_id); window->show(); }); + + m_user_menu_remove_recipient->override_color(Gdk::RGBA("#BE3C3D")); + m_user_menu->append(*m_user_menu_info); m_user_menu->append(*m_user_menu_insert_mention); + m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem)); m_user_menu->append(*m_user_menu_ban); m_user_menu->append(*m_user_menu_kick); + m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem)); m_user_menu->append(*m_user_menu_open_dm); m_user_menu->append(*m_user_menu_roles); + m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem)); + m_user_menu->append(*m_user_menu_remove_recipient); + m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem)); m_user_menu->append(*m_user_menu_copy_id); + m_user_menu->show_all(); m_main_window->signal_action_connect().connect(sigc::mem_fun(*this, &Abaddon::ActionConnect)); @@ -300,6 +311,14 @@ void Abaddon::ShowUserMenu(const GdkEvent *event, Snowflake id, Snowflake guild_ m_user_menu_open_dm->set_visible(true); } + m_user_menu_remove_recipient->hide(); + if (me != id) { + const auto channel_id = m_main_window->GetChatActiveChannel(); + const auto channel = m_discord.GetChannel(channel_id); + if (channel.has_value() && channel->Type == ChannelType::GROUP_DM && id != *channel->OwnerID) + m_user_menu_remove_recipient->show(); + } + m_user_menu->popup_at_pointer(event); } @@ -335,6 +354,10 @@ void Abaddon::on_user_menu_open_dm() { }); } +void Abaddon::on_user_menu_remove_recipient() { + m_discord.RemoveGroupDMRecipient(m_main_window->GetChatActiveChannel(), m_shown_user_menu_id); +} + void Abaddon::ActionConnect() { if (!m_discord.IsStarted()) StartDiscord(); @@ -386,8 +409,10 @@ void Abaddon::ActionChannelOpened(Snowflake id) { const auto recipients = channel->GetDMRecipients(); if (recipients.size() > 1) display = std::to_string(recipients.size()) + " users"; - else + else if (recipients.size() == 1) display = recipients[0].Username; + else + display = "Empty group"; m_main_window->set_title(std::string(APP_TITLE) + " - " + display); } m_main_window->UpdateChatActiveChannel(id); diff --git a/abaddon.hpp b/abaddon.hpp index af2ff6e..bb7558e 100644 --- a/abaddon.hpp +++ b/abaddon.hpp @@ -90,6 +90,7 @@ protected: Gtk::MenuItem *m_user_menu_copy_id; Gtk::MenuItem *m_user_menu_open_dm; Gtk::MenuItem *m_user_menu_roles; + Gtk::MenuItem *m_user_menu_remove_recipient; Gtk::Menu *m_user_menu_roles_submenu; void on_user_menu_insert_mention(); @@ -97,6 +98,7 @@ protected: void on_user_menu_kick(); void on_user_menu_copy_id(); void on_user_menu_open_dm(); + void on_user_menu_remove_recipient(); private: SettingsManager m_settings; diff --git a/discord/discord.cpp b/discord/discord.cpp index 0b97a8a..0055229 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -522,6 +522,12 @@ void DiscordClient::DeleteInvite(const std::string &code, sigc::slot<void(bool s }); } +void DiscordClient::RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id) { + m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), [this](const http::response_type &response) { + CheckCode(response); + }); +} + std::vector<BanData> DiscordClient::GetBansInGuild(Snowflake guild_id) { return m_store.GetBans(guild_id); } diff --git a/discord/discord.hpp b/discord/discord.hpp index 6ac714d..0fdf0e4 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -120,6 +120,7 @@ public: void UnbanUser(Snowflake guild_id, Snowflake user_id, sigc::slot<void(bool success)> callback); void DeleteInvite(const std::string &code); void DeleteInvite(const std::string &code, sigc::slot<void(bool success)> callback); + void RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id); // FetchGuildBans fetches all bans+reasons via api, this func fetches stored bans (so usually just GUILD_BAN_ADD data) std::vector<BanData> GetBansInGuild(Snowflake guild_id); |