From 2d027f54c3dfe7e7096c039cbfcabe997f72a562 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Thu, 21 May 2026 21:21:25 -0400 Subject: [PATCH] refactor(chat): collapse forum-thread filtering with isThread --- internal/ui/chat/guilds_tree.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/internal/ui/chat/guilds_tree.go b/internal/ui/chat/guilds_tree.go index 424a047..fa7ca60 100644 --- a/internal/ui/chat/guilds_tree.go +++ b/internal/ui/chat/guilds_tree.go @@ -218,6 +218,15 @@ func (gt *guildsTree) createChannelNodes(node *tview.TreeNode, channels []discor } } +func isThread(t discord.ChannelType) bool { + switch t { + case discord.GuildPublicThread, discord.GuildPrivateThread, discord.GuildAnnouncementThread: + return true + default: + return false + } +} + func (gt *guildsTree) onSelected(node *tview.TreeNode) tview.Cmd { if len(node.GetChildren()) != 0 { node.SetExpanded(!node.IsExpanded()) @@ -245,29 +254,19 @@ func (gt *guildsTree) onSelected(node *tview.TreeNode) tview.Cmd { return nil } - // Handle forum channels differently - they contain threads, not direct messages + // Forums contain threads, not messages; load the threads as children. if channel.Type == discord.GuildForum { - // Get all channels from the guild - this includes active threads from GuildCreateEvent allChannels, err := gt.chat.state.Cabinet.Channels(channel.GuildID) if err != nil { slog.Error("failed to get channels for forum threads", "err", err, "guild_id", channel.GuildID) return nil } - // Filter for threads that belong to this forum channel - var forumThreads []discord.Channel for _, ch := range allChannels { - if ch.ParentID == channel.ID && (ch.Type == discord.GuildPublicThread || - ch.Type == discord.GuildPrivateThread || - ch.Type == discord.GuildAnnouncementThread) { - forumThreads = append(forumThreads, ch) + if ch.ParentID == channel.ID && isThread(ch.Type) { + gt.createChannelNode(node, ch) } } - - // Add threads as child nodes - for _, thread := range forumThreads { - gt.createChannelNode(node, thread) - } node.Expand() return nil }