diff options
-rw-r--r-- | components/channels.cpp | 26 | ||||
-rw-r--r-- | components/channels.hpp | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 71a4cd9..f8d0fb6 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -142,6 +142,7 @@ ChannelList::ChannelList() discord.signal_channel_update().connect(sigc::mem_fun(*this, &ChannelList::UpdateChannel)); discord.signal_channel_create().connect(sigc::mem_fun(*this, &ChannelList::UpdateCreateChannel)); discord.signal_thread_delete().connect(sigc::mem_fun(*this, &ChannelList::OnThreadDelete)); + discord.signal_thread_list_sync().connect(sigc::mem_fun(*this, &ChannelList::OnThreadListSync)); discord.signal_added_to_thread().connect(sigc::mem_fun(*this, &ChannelList::OnThreadJoined)); discord.signal_removed_from_thread().connect(sigc::mem_fun(*this, &ChannelList::OnThreadRemoved)); discord.signal_guild_update().connect(sigc::mem_fun(*this, &ChannelList::UpdateGuild)); @@ -298,6 +299,31 @@ void ChannelList::OnThreadDelete(const ThreadDeleteData &data) { DeleteThreadRow(data.ID); } +void ChannelList::OnThreadListSync(const ThreadListSyncData &data) { + // get the threads in the guild + std::vector<Snowflake> threads; + auto guild_iter = GetIteratorForGuildFromID(data.GuildID); + std::queue<Gtk::TreeModel::iterator> queue; + queue.push(guild_iter); + + while (!queue.empty()) { + auto item = queue.front(); + queue.pop(); + if ((*item)[m_columns.m_type] == RenderType::Thread) + threads.push_back(static_cast<Snowflake>((*item)[m_columns.m_id])); + for (auto child : item->children()) + queue.push(child); + } + + // delete all threads not present in the synced data + for (auto thread_id : threads) { + if (std::find_if(data.Threads.begin(), data.Threads.end(), [thread_id](const auto& x) { return x.ID == thread_id; }) == data.Threads.end()) { + auto iter = GetIteratorForChannelFromID(thread_id); + m_model->erase(iter); + } + } +} + void ChannelList::DeleteThreadRow(Snowflake id) { auto iter = GetIteratorForChannelFromID(id); if (iter) diff --git a/components/channels.hpp b/components/channels.hpp index c1c74a4..31857ec 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -146,6 +146,7 @@ protected: void OnThreadJoined(Snowflake id); void OnThreadRemoved(Snowflake id); void OnThreadDelete(const ThreadDeleteData &data); + void OnThreadListSync(const ThreadListSyncData &data); Gtk::TreeView m_view; |