summaryrefslogtreecommitdiff
path: root/components/channels.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-11-14 02:27:23 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-11-14 02:27:23 -0500
commit409af292af53cce77615011667d506bc2b40692a (patch)
tree0ca3e2d168a157fa2c69c9e89d9cc8e2edff1927 /components/channels.cpp
parent2257ff979854867a9aff32aa7d07769bce5edff8 (diff)
parent108002248c0739078302e00d5ca224a44b93ea56 (diff)
downloadabaddon-portaudio-409af292af53cce77615011667d506bc2b40692a.tar.gz
abaddon-portaudio-409af292af53cce77615011667d506bc2b40692a.zip
Merge branch 'master' into store
Diffstat (limited to 'components/channels.cpp')
-rw-r--r--components/channels.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/components/channels.cpp b/components/channels.cpp
index ac11a0c..621d7dc 100644
--- a/components/channels.cpp
+++ b/components/channels.cpp
@@ -380,6 +380,56 @@ void ChannelList::SetActiveChannel(Snowflake id) {
}
}
+void ChannelList::UseExpansionState(const ExpansionStateRoot &root) {
+ auto recurse = [this](auto &self, const ExpansionStateRoot &root) -> void {
+ // and these are only channels
+ for (const auto &[id, state] : root.Children) {
+ if (const auto iter = GetIteratorForChannelFromID(id)) {
+ if (state.IsExpanded)
+ m_view.expand_row(m_model->get_path(iter), false);
+ else
+ m_view.collapse_row(m_model->get_path(iter));
+ }
+
+ self(self, state.Children);
+ }
+ };
+
+ // top level is guild
+ for (const auto &[id, state] : root.Children) {
+ if (const auto iter = GetIteratorForGuildFromID(id)) {
+ if (state.IsExpanded)
+ m_view.expand_row(m_model->get_path(iter), false);
+ else
+ m_view.collapse_row(m_model->get_path(iter));
+ }
+
+ recurse(recurse, state.Children);
+ }
+}
+
+ExpansionStateRoot ChannelList::GetExpansionState() const {
+ ExpansionStateRoot r;
+
+ auto recurse = [this](auto &self, const Gtk::TreeRow &row) -> ExpansionState {
+ ExpansionState r;
+
+ r.IsExpanded = row[m_columns.m_expanded];
+ for (const auto &child : row.children())
+ r.Children.Children[static_cast<Snowflake>(child[m_columns.m_id])] = self(self, child);
+
+ return r;
+ };
+
+ for (const auto &child : m_model->children()) {
+ const auto id = static_cast<Snowflake>(child[m_columns.m_id]);
+ if (static_cast<uint64_t>(id) == 0ULL) continue; // dont save DM header
+ r.Children[id] = recurse(recurse, child);
+ }
+
+ return r;
+}
+
Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
auto &discord = Abaddon::Get().GetDiscordClient();
auto &img = Abaddon::Get().GetImageManager();