diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-23 02:24:24 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-23 02:24:24 -0400 |
commit | 6e75c4a95dcf0e601aba324ab5ae5f34ebd1a00d (patch) | |
tree | 680c741a0664361beca4b7e3578d695b4e79e17b | |
parent | 41d60e5e907aa0d6f625796e15c6317074e2af7d (diff) | |
download | abaddon-portaudio-6e75c4a95dcf0e601aba324ab5ae5f34ebd1a00d.tar.gz abaddon-portaudio-6e75c4a95dcf0e601aba324ab5ae5f34ebd1a00d.zip |
add pin menu item to messages
-rw-r--r-- | components/chatlist.cpp | 15 | ||||
-rw-r--r-- | components/chatlist.hpp | 1 | ||||
-rw-r--r-- | discord/discord.cpp | 9 | ||||
-rw-r--r-- | discord/discord.hpp | 3 |
4 files changed, 24 insertions, 4 deletions
diff --git a/components/chatlist.cpp b/components/chatlist.cpp index 8fd28a5..86460b9 100644 --- a/components/chatlist.cpp +++ b/components/chatlist.cpp @@ -73,6 +73,12 @@ ChatList::ChatList() { }); m_menu.append(*m_menu_unpin); + m_menu_pin = Gtk::manage(new Gtk::MenuItem("Pin")); + m_menu_pin->signal_activate().connect([this] { + Abaddon::Get().GetDiscordClient().Pin(m_active_channel, m_menu_selected_message, [](...) {}); + }); + m_menu.append(*m_menu_pin); + m_menu.show(); } @@ -159,12 +165,15 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) { if (ev->type == GDK_BUTTON_PRESS && ev->button == GDK_BUTTON_SECONDARY) { m_menu_selected_message = id; + const auto &client = Abaddon::Get().GetDiscordClient(); + const auto data = client.GetMessage(id); + if (!data.has_value()) return false; + m_menu_edit_message->set_visible(!m_use_pinned_menu); m_menu_reply_to->set_visible(!m_use_pinned_menu); - m_menu_unpin->set_visible(m_use_pinned_menu); + m_menu_unpin->set_visible(data->IsPinned); + m_menu_pin->set_visible(!data->IsPinned); - const auto &client = Abaddon::Get().GetDiscordClient(); - const auto data = client.GetMessage(id); if (data->IsDeleted()) { m_menu_delete_message->set_sensitive(false); m_menu_edit_message->set_sensitive(false); diff --git a/components/chatlist.hpp b/components/chatlist.hpp index 7f9dab7..2122e49 100644 --- a/components/chatlist.hpp +++ b/components/chatlist.hpp @@ -38,6 +38,7 @@ private: Gtk::MenuItem *m_menu_edit_message; Gtk::MenuItem *m_menu_reply_to; Gtk::MenuItem *m_menu_unpin; + Gtk::MenuItem *m_menu_pin; Snowflake m_menu_selected_message; Snowflake m_active_channel; diff --git a/discord/discord.cpp b/discord/discord.cpp index a56481e..ef93360 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -710,6 +710,15 @@ void DiscordClient::PutRelationship(Snowflake id, sigc::slot<void(bool success, }); } +void DiscordClient::Pin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback) { + m_http.MakePUT("/channels/" + std::to_string(channel_id) + "/pins/" + std::to_string(message_id), "", [this, callback](const http::response_type &response) { + if (CheckCode(response, 204)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + void DiscordClient::Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback) { m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/pins/" + std::to_string(message_id), [this, callback](const http::response_type &response) { if (CheckCode(response, 204)) diff --git a/discord/discord.hpp b/discord/discord.hpp index d647f03..10da6e8 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -138,6 +138,7 @@ public: void RemoveRelationship(Snowflake id, sigc::slot<void(bool success)> callback); void SendFriendRequest(const Glib::ustring &username, int discriminator, sigc::slot<void(bool success, DiscordError code)> callback); void PutRelationship(Snowflake id, sigc::slot<void(bool success, 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); bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const; @@ -327,7 +328,7 @@ public: typedef sigc::signal<void, Snowflake, RelationshipType> type_signal_relationship_remove; typedef sigc::signal<void, RelationshipAddData> type_signal_relationship_add; typedef sigc::signal<void, Message> type_signal_message_unpinned; // not a real event - typedef sigc::signal<void, Message> type_signal_message_pinned; // not a real event either + typedef sigc::signal<void, Message> type_signal_message_pinned; // not a real event either typedef sigc::signal<void, Message> type_signal_message_sent; typedef sigc::signal<void, std::string /* nonce */, float /* retry_after */> type_signal_message_send_fail; // retry after param will be 0 if it failed for a reason that isnt slowmode typedef sigc::signal<void, bool, GatewayCloseCode> type_signal_disconnected; // bool true if reconnecting |