Bladeren bron

Add channel name and topic as MessagesTextView title on channel select

ayntgl 4 jaren geleden
bovenliggende
commit
f9ed9a7a12
2 gewijzigde bestanden met toevoegingen van 10 en 1 verwijderingen
  1. 9 1
      ui/channels.go
  2. 1 0
      ui/messages.go

+ 9 - 1
ui/channels.go

@@ -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 {

+ 1 - 0
ui/messages.go

@@ -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)