refactor: check if ref is nil to determine TreeNode is channel or not

This commit is contained in:
ayntgl 2021-10-18 15:59:36 +04:00
parent a62e179d80
commit 685cd7d5e7

9
ui.go
View file

@ -58,11 +58,12 @@ func onChannelsTreeSelected(n *tview.TreeNode) {
// Unhighlight the already-highlighted regions.
messagesView.Highlight()
if len(n.GetChildren()) != 0 || n.GetText() == "Direct Messages" {
ref := n.GetReference()
// If the node's reference is nil, the selected node is a guild or direct messages node; expand or collapse accordingly.
if ref == nil {
n.SetExpanded(!n.IsExpanded())
} else {
cID := n.GetReference().(string)
c, err := session.State.Channel(cID)
c, err := session.State.Channel(ref.(string))
if err != nil {
return
}
@ -87,7 +88,7 @@ func onChannelsTreeSelected(n *tview.TreeNode) {
}
go func() {
ms, err := session.ChannelMessages(cID, conf.GetMessagesLimit, "", "", "")
ms, err := session.ChannelMessages(c.ID, conf.GetMessagesLimit, "", "", "")
if err != nil {
return
}