summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/channels.cpp19
-rw-r--r--components/channels.hpp4
-rw-r--r--discord/discord.cpp11
-rw-r--r--discord/discord.hpp1
4 files changed, 34 insertions, 1 deletions
diff --git a/components/channels.cpp b/components/channels.cpp
index e175e8c..ed5de62 100644
--- a/components/channels.cpp
+++ b/components/channels.cpp
@@ -17,7 +17,9 @@ ChannelList::ChannelList()
, m_menu_category_copy_id("_Copy ID", true)
, m_menu_channel_copy_id("_Copy ID", true)
, m_menu_dm_close("") // changes depending on if group or not
- , m_menu_dm_copy_id("_Copy ID", true) {
+ , m_menu_dm_copy_id("_Copy ID", true)
+ , m_menu_thread_copy_id("_Copy ID", true)
+ , m_menu_thread_leave("_Leave", true) {
get_style_context()->add_class("channel-list");
const auto cb = [this](const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *column) {
@@ -121,6 +123,17 @@ ChannelList::ChannelList()
m_menu_dm.append(m_menu_dm_close);
m_menu_dm.show_all();
+ m_menu_thread_copy_id.signal_activate().connect([this] {
+ Gtk::Clipboard::get()->set_text(std::to_string((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]));
+ });
+ m_menu_thread_leave.signal_activate().connect([this] {
+ if (Abaddon::Get().ShowConfirm("Are you sure you want to leave this thread?"))
+ Abaddon::Get().GetDiscordClient().LeaveThread(static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), "Context%20Menu", [](...) {});
+ });
+ m_menu_thread.append(m_menu_thread_copy_id);
+ m_menu_thread.append(m_menu_thread_leave);
+ m_menu_thread.show_all();
+
auto &discord = Abaddon::Get().GetDiscordClient();
discord.signal_message_create().connect(sigc::mem_fun(*this, &ChannelList::OnMessageCreate));
discord.signal_guild_create().connect(sigc::mem_fun(*this, &ChannelList::UpdateNewGuild));
@@ -578,6 +591,10 @@ bool ChannelList::OnButtonPressEvent(GdkEventButton *ev) {
m_menu_dm_close.hide();
m_menu_dm.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev));
} break;
+ case RenderType::Thread: {
+ m_menu_thread.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev));
+ break;
+ } break;
default:
break;
}
diff --git a/components/channels.hpp b/components/channels.hpp
index ed87b57..c131a07 100644
--- a/components/channels.hpp
+++ b/components/channels.hpp
@@ -209,6 +209,10 @@ protected:
Gtk::MenuItem m_menu_dm_copy_id;
Gtk::MenuItem m_menu_dm_close;
+ Gtk::Menu m_menu_thread;
+ Gtk::MenuItem m_menu_thread_copy_id;
+ Gtk::MenuItem m_menu_thread_leave;
+
bool m_updating_listing = false;
public:
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 99ffb0b..6ac2223 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -761,6 +761,17 @@ void DiscordClient::Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot
});
}
+// i dont know if the location parameter is necessary at all but discord's thread implementation is extremely strange
+// so its here just in case
+void DiscordClient::LeaveThread(Snowflake channel_id, const std::string &location, sigc::slot<void(DiscordError code)> callback) {
+ m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/thread-members/@me?location=" + location, [this, callback](const http::response_type& response) {
+ if (CheckCode(response, 204))
+ 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/discord/discord.hpp b/discord/discord.hpp
index 28c719c..156ab45 100644
--- a/discord/discord.hpp
+++ b/discord/discord.hpp
@@ -137,6 +137,7 @@ public:
void PutRelationship(Snowflake id, sigc::slot<void(DiscordError code)> callback); // send fr by id, accept incoming
void Pin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback);
void Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback);
+ void LeaveThread(Snowflake channel_id, const std::string &location, 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;