diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-23 02:09:07 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-23 02:09:07 -0400 |
commit | 41d60e5e907aa0d6f625796e15c6317074e2af7d (patch) | |
tree | 88286b7248931b3394be5813db01358701b5c77a | |
parent | 7db2675087a563ec82574937759137fa2e57298c (diff) | |
download | abaddon-portaudio-41d60e5e907aa0d6f625796e15c6317074e2af7d.tar.gz abaddon-portaudio-41d60e5e907aa0d6f625796e15c6317074e2af7d.zip |
update pins window on pin/unpin
-rw-r--r-- | components/chatlist.cpp | 6 | ||||
-rw-r--r-- | components/chatlist.hpp | 1 | ||||
-rw-r--r-- | discord/discord.cpp | 40 | ||||
-rw-r--r-- | discord/discord.hpp | 6 | ||||
-rw-r--r-- | windows/pinnedwindow.cpp | 10 | ||||
-rw-r--r-- | windows/pinnedwindow.hpp | 2 |
6 files changed, 61 insertions, 4 deletions
diff --git a/components/chatlist.cpp b/components/chatlist.cpp index 57d797f..8fd28a5 100644 --- a/components/chatlist.cpp +++ b/components/chatlist.cpp @@ -280,6 +280,12 @@ void ChatList::SetUsePinnedMenu() { m_use_pinned_menu = true; } +void ChatList::ActuallyRemoveMessage(Snowflake id) { + auto it = m_id_to_widget.find(id); + if (it != m_id_to_widget.end()) + RemoveMessageAndHeader(it->second); +} + void ChatList::OnScrollEdgeOvershot(Gtk::PositionType pos) { if (pos == Gtk::POS_TOP) m_signal_action_chat_load_history.emit(m_active_channel); diff --git a/components/chatlist.hpp b/components/chatlist.hpp index 2f63900..7f9dab7 100644 --- a/components/chatlist.hpp +++ b/components/chatlist.hpp @@ -22,6 +22,7 @@ public: std::vector<Snowflake> GetRecentAuthors(); void SetSeparateAll(bool separate); void SetUsePinnedMenu(); // i think i need a better way to do menus + void ActuallyRemoveMessage(Snowflake id); // perhaps not the best method name private: void OnScrollEdgeOvershot(Gtk::PositionType pos); diff --git a/discord/discord.cpp b/discord/discord.cpp index 89107df..a56481e 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -1632,15 +1632,39 @@ void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) { m_websocket.StartConnection(GetGatewayURL()); } +bool IsCompleteMessageObject(const nlohmann::json &j) { + const auto required = { "id", "channel_id", "author", "content", "timestamp", "edited_timestamp", "tts", "mention_everyone", "mention_roles", "attachments", "embeds", "pinned", "type" }; + for (const auto &str : required) { + if (!j.contains(str)) return false; + } + return true; +} + void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) { Snowflake id = msg.Data.at("id"); auto current = m_store.GetMessage(id); - if (!current.has_value()) - return; + if (!current.has_value()) { + // im not sure how the client determines if a MESSAGE_UPDATE is suitable to be stored as a full message but i guess its something like this + if (IsCompleteMessageObject(msg.Data)) { + current = msg.Data; + m_store.SetMessage(id, *current); + // this doesnt mean a message is newly pinned when called here + // it just means theres an (old) message that the client is now aware of that is also pinned + m_signal_message_pinned.emit(*current); + } else + return; + } else { + const bool old_pinned = current->IsPinned; - current->from_json_edited(msg.Data); - m_store.SetMessage(id, *current); + current->from_json_edited(msg.Data); + m_store.SetMessage(id, *current); + + if (old_pinned && !current->IsPinned) + m_signal_message_unpinned.emit(*current); + else if (!old_pinned && current->IsPinned) + m_signal_message_pinned.emit(*current); + } m_signal_message_update.emit(id, current->ChannelID); } @@ -2035,6 +2059,14 @@ DiscordClient::type_signal_relationship_add DiscordClient::signal_relationship_a return m_signal_relationship_add; } +DiscordClient::type_signal_message_unpinned DiscordClient::signal_message_unpinned() { + return m_signal_message_unpinned; +} + +DiscordClient::type_signal_message_pinned DiscordClient::signal_message_pinned() { + return m_signal_message_pinned; +} + DiscordClient::type_signal_message_sent DiscordClient::signal_message_sent() { return m_signal_message_sent; } diff --git a/discord/discord.hpp b/discord/discord.hpp index 5c10033..d647f03 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -326,6 +326,8 @@ public: typedef sigc::signal<void, GuildJoinRequestDeleteData> type_signal_guild_join_request_delete; 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_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 @@ -361,6 +363,8 @@ public: type_signal_guild_join_request_delete signal_guild_join_request_delete(); type_signal_relationship_remove signal_relationship_remove(); type_signal_relationship_add signal_relationship_add(); + type_signal_message_unpinned signal_message_unpinned(); + type_signal_message_pinned signal_message_pinned(); type_signal_message_sent signal_message_sent(); type_signal_message_send_fail signal_message_send_fail(); type_signal_disconnected signal_disconnected(); @@ -397,6 +401,8 @@ protected: type_signal_guild_join_request_delete m_signal_guild_join_request_delete; type_signal_relationship_remove m_signal_relationship_remove; type_signal_relationship_add m_signal_relationship_add; + type_signal_message_unpinned m_signal_message_unpinned; + type_signal_message_pinned m_signal_message_pinned; type_signal_message_sent m_signal_message_sent; type_signal_message_send_fail m_signal_message_send_fail; type_signal_disconnected m_signal_disconnected; diff --git a/windows/pinnedwindow.cpp b/windows/pinnedwindow.cpp index 99b8c1e..fc6230c 100644 --- a/windows/pinnedwindow.cpp +++ b/windows/pinnedwindow.cpp @@ -21,9 +21,19 @@ PinnedWindow::PinnedWindow(const ChannelData &data) m_chat.SetActiveChannel(ChannelID); m_chat.SetUsePinnedMenu(); + Abaddon::Get().GetDiscordClient().signal_message_pinned().connect(sigc::mem_fun(*this, &PinnedWindow::OnMessagePinned)); + Abaddon::Get().GetDiscordClient().signal_message_unpinned().connect(sigc::mem_fun(*this, &PinnedWindow::OnMessageUnpinned)); FetchPinned(); } +void PinnedWindow::OnMessagePinned(const Message &msg) { + FetchPinned(); +} + +void PinnedWindow::OnMessageUnpinned(const Message &msg) { + m_chat.ActuallyRemoveMessage(msg.ID); +} + void PinnedWindow::FetchPinned() { Abaddon::Get().GetDiscordClient().FetchPinned(ChannelID, sigc::mem_fun(*this, &PinnedWindow::OnFetchedPinned)); } diff --git a/windows/pinnedwindow.hpp b/windows/pinnedwindow.hpp index a118876..56461a5 100644 --- a/windows/pinnedwindow.hpp +++ b/windows/pinnedwindow.hpp @@ -13,6 +13,8 @@ public: Snowflake ChannelID; private: + void OnMessagePinned(const Message &msg); + void OnMessageUnpinned(const Message &msg); void FetchPinned(); void OnFetchedPinned(const std::vector<Message> &msgs, DiscordError code); |