From c262f03380871fb1321eeb866a3b4ae4bf874019 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Sun, 23 Nov 2025 14:51:30 -0500 Subject: [PATCH] refactor(cmd): update channel sorting to use `slices.SortFunc` and `cmp.Compare` instead of `sort.Slice` --- cmd/guilds_tree.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/guilds_tree.go b/cmd/guilds_tree.go index bf495a4..26b629c 100644 --- a/cmd/guilds_tree.go +++ b/cmd/guilds_tree.go @@ -1,9 +1,10 @@ package cmd import ( + "cmp" "fmt" "log/slog" - "sort" + "slices" "github.com/ayn2op/discordo/internal/config" "github.com/ayn2op/discordo/internal/ui" @@ -160,8 +161,8 @@ func (gt *guildsTree) onSelected(node *tview.TreeNode) { return } - sort.Slice(channels, func(i, j int) bool { - return channels[i].Position < channels[j].Position + slices.SortFunc(channels, func(a, b discord.Channel) int { + return cmp.Compare(a.Position, b.Position) }) gt.createChannelNodes(node, channels) @@ -207,14 +208,16 @@ func (gt *guildsTree) onSelected(node *tview.TreeNode) { return } - sort.Slice(channels, func(a, b int) bool { - msgID := func(ch discord.Channel) discord.MessageID { - if ch.LastMessageID.IsValid() { - return ch.LastMessageID - } - return discord.MessageID(ch.ID) + msgID := func(ch discord.Channel) discord.MessageID { + if ch.LastMessageID.IsValid() { + return ch.LastMessageID } - return msgID(channels[a]) > msgID(channels[b]) + return discord.MessageID(ch.ID) + } + + slices.SortFunc(channels, func(a, b discord.Channel) int { + // Descending order + return cmp.Compare(msgID(b), msgID(a)) }) for _, c := range channels {