refactor: check if ref is nil to determine TreeNode is channel or not
This commit is contained in:
parent
a62e179d80
commit
685cd7d5e7
1 changed files with 5 additions and 4 deletions
9
ui.go
9
ui.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue