Add channel name and topic as MessagesTextView title on channel select

This commit is contained in:
ayntgl 2022-03-25 10:45:25 +04:00
parent e4d9332eff
commit f9ed9a7a12
2 changed files with 10 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package ui
import (
"github.com/ayntgl/astatine"
"github.com/ayntgl/discordo/discord"
"github.com/rivo/tview"
)
@ -30,7 +31,8 @@ func (ctv *ChannelsTreeView) onSelected(n *tview.TreeNode) {
ctv.app.SelectedMessage = -1
ctv.app.MessagesTextView.
Highlight().
Clear()
Clear().
SetTitle("")
ctv.app.MessageInputField.SetText("")
c, err := ctv.app.Session.State.Channel(n.GetReference().(string))
@ -46,6 +48,12 @@ func (ctv *ChannelsTreeView) onSelected(n *tview.TreeNode) {
ctv.app.SelectedChannel = c
ctv.app.SetFocus(ctv.app.MessageInputField)
title := discord.ChannelToString(c)
if c.Topic != "" {
title += " - " + discord.ParseMarkdown(c.Topic)
}
ctv.app.MessagesTextView.SetTitle(title)
go func() {
ms, err := ctv.app.Session.ChannelMessages(c.ID, ctv.app.Config.General.FetchMessagesLimit, "", "", "")
if err != nil {

View file

@ -37,6 +37,7 @@ func NewMessagesTextView(app *App) *MessagesTextView {
mtv.SetChangedFunc(func() {
mtv.app.Draw()
})
mtv.SetTitleAlign(tview.AlignLeft)
mtv.SetBorder(true)
mtv.SetBorderPadding(0, 0, 1, 1)
mtv.SetInputCapture(mtv.onInputCapture)