From 78f75db905a4c3a6e4e20952ffce61adcb99526d Mon Sep 17 00:00:00 2001 From: ayntgl Date: Fri, 29 Oct 2021 13:31:38 +0400 Subject: [PATCH] refactor: cleanup --- util/discord.go | 3 +++ util/ui.go | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/util/discord.go b/util/discord.go index b2fa6cd..5f27458 100644 --- a/util/discord.go +++ b/util/discord.go @@ -6,6 +6,7 @@ import ( "github.com/ayntgl/discordgo" ) +// ChannelToString constructs a string representation of the given channel. The string representation may vary for different channel types. func ChannelToString(c *discordgo.Channel) string { var repr string if c.Name != "" { @@ -25,6 +26,7 @@ func ChannelToString(c *discordgo.Channel) string { return repr } +// ChannelIsUnread returns `true` if the given channel is marked as read by the client user, otherwise `false`. func ChannelIsUnread(s *discordgo.State, c *discordgo.Channel) bool { if c.LastMessageID == "" { return false @@ -39,6 +41,7 @@ func ChannelIsUnread(s *discordgo.State, c *discordgo.Channel) bool { return false } +// FindMessageByID returns the index and the `*Message` struct of the current message if the given message ID *mID* is equal to the current message ID. If the given message ID *mID* is not found in the given slice *ms*, `-1` and `nil` are returned instead. func FindMessageByID(ms []*discordgo.Message, mID string) (int, *discordgo.Message) { for i, m := range ms { if m.ID == mID { diff --git a/util/ui.go b/util/ui.go index 7f7e838..17cf0ad 100644 --- a/util/ui.go +++ b/util/ui.go @@ -2,8 +2,9 @@ package util import "github.com/rivo/tview" -func GetTreeNodeByReference(tv *tview.TreeView, r interface{}) (mn *tview.TreeNode) { - tv.GetRoot().Walk(func(n, _ *tview.TreeNode) bool { +// GetTreeNodeByReference walks the root `*TreeNode` of the given `*TreeView` *treeView* and returns the TreeNode whose reference is equal to the given reference *r*. If the `*TreeNode` is not found, `nil` is returned instead. +func GetTreeNodeByReference(treeView *tview.TreeView, r interface{}) (mn *tview.TreeNode) { + treeView.GetRoot().Walk(func(n, _ *tview.TreeNode) bool { if n.GetReference() == r { mn = n return false