summaryrefslogtreecommitdiff
path: root/src/components/channellist/classic/guildlist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/channellist/classic/guildlist.cpp')
-rw-r--r--src/components/channellist/classic/guildlist.cpp55
1 files changed, 49 insertions, 6 deletions
diff --git a/src/components/channellist/classic/guildlist.cpp b/src/components/channellist/classic/guildlist.cpp
index 6c1fbc3..7a4b87c 100644
--- a/src/components/channellist/classic/guildlist.cpp
+++ b/src/components/channellist/classic/guildlist.cpp
@@ -12,15 +12,37 @@ void GuildList::UpdateListing() {
Clear();
// does this function still even work ??lol
- const auto ids = discord.GetUserSortedGuilds();
- for (const auto id : ids) {
- AddGuild(id);
+ const auto folders = discord.GetUserSettings().GuildFolders;
+ const auto guild_ids = discord.GetUserSortedGuilds();
+
+ // same logic from ChannelListTree
+
+ std::set<Snowflake> foldered_guilds;
+ for (const auto &group : folders) {
+ foldered_guilds.insert(group.GuildIDs.begin(), group.GuildIDs.end());
+ }
+
+ for (auto iter = guild_ids.crbegin(); iter != guild_ids.crend(); iter++) {
+ if (foldered_guilds.find(*iter) == foldered_guilds.end()) {
+ AddGuild(*iter);
+ }
+ }
+
+ for (const auto &group : folders) {
+ AddFolder(group);
}
}
void GuildList::AddGuild(Snowflake id) {
+ if (auto item = CreateGuildWidget(id)) {
+ item->show();
+ add(*item);
+ }
+}
+
+GuildListGuildItem *GuildList::CreateGuildWidget(Snowflake id) {
const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(id);
- if (!guild.has_value()) return;
+ if (!guild.has_value()) return nullptr;
auto *item = Gtk::make_managed<GuildListGuildItem>(*guild);
item->signal_button_press_event().connect([this, id](GdkEventButton *event) -> bool {
@@ -29,8 +51,29 @@ void GuildList::AddGuild(Snowflake id) {
}
return true;
});
- item->show();
- add(*item);
+
+ return item;
+}
+
+void GuildList::AddFolder(const UserSettingsGuildFoldersEntry &folder) {
+ // groups with no ID arent actually folders
+ if (!folder.ID.has_value()) {
+ if (!folder.GuildIDs.empty()) {
+ AddGuild(folder.GuildIDs[0]);
+ }
+ return;
+ }
+
+ auto *folder_widget = Gtk::make_managed<GuildListFolderItem>();
+ for (const auto guild_id : folder.GuildIDs) {
+ if (auto *guild_widget = CreateGuildWidget(guild_id)) {
+ guild_widget->show();
+ folder_widget->AddGuildWidget(guild_widget);
+ }
+ }
+
+ folder_widget->show();
+ add(*folder_widget);
}
void GuildList::Clear() {