diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-08-05 04:02:47 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-08-05 04:02:47 -0400 |
commit | 856674506c064ba94396752664aede5167c3ec4b (patch) | |
tree | 6606a051d2ff0985133c360f3b2cc3221db94805 /components | |
parent | 41a63df1b108a9520a8dfcb862f108b42f9a1bb1 (diff) | |
download | abaddon-portaudio-856674506c064ba94396752664aede5167c3ec4b.tar.gz abaddon-portaudio-856674506c064ba94396752664aede5167c3ec4b.zip |
better join/leave thread logic
Diffstat (limited to 'components')
-rw-r--r-- | components/channels.cpp | 30 | ||||
-rw-r--r-- | components/channels.hpp | 6 |
2 files changed, 18 insertions, 18 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index b96b2e6..71a4cd9 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -141,9 +141,9 @@ ChannelList::ChannelList() discord.signal_channel_delete().connect(sigc::mem_fun(*this, &ChannelList::UpdateRemoveChannel)); 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_create().connect(sigc::mem_fun(*this, &ChannelList::UpdateCreateThread)); discord.signal_thread_delete().connect(sigc::mem_fun(*this, &ChannelList::OnThreadDelete)); - discord.signal_thread_members_update().connect(sigc::mem_fun(*this, &ChannelList::OnThreadMembersUpdate)); + 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)); } @@ -280,25 +280,25 @@ void ChannelList::UpdateGuild(Snowflake id) { } } -void ChannelList::OnThreadDelete(const ThreadDeleteData &data) { - UpdateDeleteThread(data.ID); +void ChannelList::OnThreadJoined(Snowflake id) { + if (GetIteratorForChannelFromID(id)) return; + const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id); + if (!channel.has_value()) return; + const auto parent = GetIteratorForChannelFromID(*channel->ParentID); + if (parent) + CreateThreadRow(parent->children(), *channel); } -void ChannelList::OnThreadMembersUpdate(const ThreadMembersUpdateData &data) { - auto &r = data.RemovedMemberIDs; - if (r.has_value() && std::find(r->begin(), r->end(), Abaddon::Get().GetDiscordClient().GetUserData().ID) != r->end()) { - UpdateDeleteThread(data.ID); - } +void ChannelList::OnThreadRemoved(Snowflake id) { + if (GetIteratorForChannelFromID(id)) + DeleteThreadRow(id); } -void ChannelList::UpdateCreateThread(const ChannelData &channel) { - if (GetIteratorForChannelFromID(channel.ID)) return; // dont do anything if already exists - auto parent_row = GetIteratorForChannelFromID(*channel.ParentID); - if (parent_row) - CreateThreadRow(parent_row->children(), channel); +void ChannelList::OnThreadDelete(const ThreadDeleteData &data) { + DeleteThreadRow(data.ID); } -void ChannelList::UpdateDeleteThread(Snowflake id) { +void ChannelList::DeleteThreadRow(Snowflake id) { auto iter = GetIteratorForChannelFromID(id); if (iter) m_model->erase(iter); diff --git a/components/channels.hpp b/components/channels.hpp index fce3546..c1c74a4 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -140,12 +140,12 @@ protected: void UpdateRemoveChannel(Snowflake id); void UpdateChannel(Snowflake id); void UpdateCreateChannel(const ChannelData &channel); - void UpdateCreateThread(const ChannelData &channel); - void UpdateDeleteThread(Snowflake id); void UpdateGuild(Snowflake id); + void DeleteThreadRow(Snowflake id); + void OnThreadJoined(Snowflake id); + void OnThreadRemoved(Snowflake id); void OnThreadDelete(const ThreadDeleteData &data); - void OnThreadMembersUpdate(const ThreadMembersUpdateData &data); Gtk::TreeView m_view; |