diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-06 21:28:07 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-06 21:28:07 -0400 |
commit | 66cc4b3cc7c7170bd7ff0347ed377d317dcdce91 (patch) | |
tree | 4c25bc8cdb68a482aac45e4417c8caca422ba7bb /components | |
parent | 10e547c4947849647463c6f302edbbefc46aac80 (diff) | |
download | abaddon-portaudio-66cc4b3cc7c7170bd7ff0347ed377d317dcdce91.tar.gz abaddon-portaudio-66cc4b3cc7c7170bd7ff0347ed377d317dcdce91.zip |
refactor (store)
Diffstat (limited to 'components')
-rw-r--r-- | components/channels.cpp | 29 | ||||
-rw-r--r-- | components/channels.hpp | 4 |
2 files changed, 12 insertions, 21 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index fcbe8ef..7982d1b 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -39,7 +39,7 @@ Gtk::Widget *ChannelList::GetRoot() const { return m_main; } -void ChannelList::SetListingFromGuilds(const DiscordClient::Guilds_t &guilds) { +void ChannelList::SetListingFromGuilds(const DiscordClient::guilds_type &guilds) { std::scoped_lock<std::mutex> guard(m_update_mutex); m_update_queue.push(guilds); m_update_dispatcher.emit(); @@ -47,7 +47,7 @@ void ChannelList::SetListingFromGuilds(const DiscordClient::Guilds_t &guilds) { void ChannelList::ClearListing() { std::scoped_lock<std::mutex> guard(m_update_mutex); - m_update_queue.push(DiscordClient::Guilds_t()); + m_update_queue.push(DiscordClient::guilds_type()); m_update_dispatcher.emit(); } @@ -138,10 +138,11 @@ void ChannelList::AddPrivateChannels() { } void ChannelList::SetListingFromGuildsInternal() { - DiscordClient::Guilds_t *guilds; + DiscordClient::guilds_type guilds; { std::scoped_lock<std::mutex> guard(m_update_mutex); - guilds = &m_update_queue.front(); + guilds = m_update_queue.front(); + m_update_queue.pop(); } auto children = m_list->get_children(); @@ -154,19 +155,13 @@ void ChannelList::SetListingFromGuildsInternal() { m_guild_count = 0; - if (guilds->empty()) { - std::scoped_lock<std::mutex> guard(m_update_mutex); - m_update_queue.pop(); - return; - } - AddPrivateChannels(); // map each category to its channels std::unordered_map<Snowflake, std::vector<const ChannelData *>> cat_to_channels; std::unordered_map<Snowflake, std::vector<const ChannelData *>> orphan_channels; - for (const auto &[gid, guild] : *guilds) { + for (const auto &[gid, guild] : guilds) { for (const auto &chan : guild.Channels) { switch (chan.Type) { case ChannelType::GUILD_TEXT: { @@ -306,14 +301,10 @@ void ChannelList::SetListingFromGuildsInternal() { m_infos[guild_row] = std::move(info); }; - const auto &sorted_guilds = m_abaddon->GetDiscordClient().GetUserSortedGuilds(); - for (const auto &[id, guild] : sorted_guilds) { - add_guild(id, guild); - } - - { - std::scoped_lock<std::mutex> guard(m_update_mutex); - m_update_queue.pop(); + const auto &discord = m_abaddon->GetDiscordClient(); + const auto &sorted_guilds = discord.GetUserSortedGuilds(); + for (const auto &id : sorted_guilds) { + add_guild(id, *discord.GetGuild(id)); } } diff --git a/components/channels.hpp b/components/channels.hpp index 83b242c..2747724 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -11,7 +11,7 @@ class ChannelList { public: ChannelList(); Gtk::Widget *GetRoot() const; - void SetListingFromGuilds(const DiscordClient::Guilds_t &guilds); + void SetListingFromGuilds(const DiscordClient::guilds_type &guilds); void ClearListing(); void SetAbaddon(Abaddon *ptr); @@ -50,7 +50,7 @@ protected: Glib::Dispatcher m_update_dispatcher; mutable std::mutex m_update_mutex; - std::queue<DiscordClient::Guilds_t> m_update_queue; + std::queue<DiscordClient::guilds_type> m_update_queue; void AddPrivateChannels(); // retard moment void SetListingFromGuildsInternal(); void AttachMenuHandler(Gtk::ListBoxRow *row); |