feat(cmd): append channel topic to messages list title

This commit is contained in:
ayn2op 2025-08-03 16:05:29 -04:00
parent 9f79196893
commit 137c55ab9f
3 changed files with 43 additions and 32 deletions

View file

@ -94,40 +94,12 @@ func (gt *guildsTree) createGuildNode(n *tview.TreeNode, guild discord.Guild) {
n.AddChild(guildNode)
}
func (gt *guildsTree) channelToString(channel discord.Channel) string {
switch channel.Type {
case discord.DirectMessage, discord.GroupDM:
if channel.Name != "" {
return channel.Name
}
recipients := make([]string, len(channel.DMRecipients))
for i, r := range channel.DMRecipients {
recipients[i] = r.DisplayOrUsername()
}
return strings.Join(recipients, ", ")
case discord.GuildText:
return "#" + channel.Name
case discord.GuildVoice, discord.GuildStageVoice:
return "v-" + channel.Name
case discord.GuildAnnouncement:
return "a-" + channel.Name
case discord.GuildStore:
return "s-" + channel.Name
case discord.GuildForum:
return "f-" + channel.Name
default:
return channel.Name
}
}
func (gt *guildsTree) createChannelNode(node *tview.TreeNode, channel discord.Channel) {
if channel.Type != discord.DirectMessage && channel.Type != discord.GroupDM && !discordState.HasPermissions(channel.ID, discord.PermissionViewChannel) {
return
}
channelNode := tview.NewTreeNode(gt.channelToString(channel)).
channelNode := tview.NewTreeNode(ui.ChannelToString(channel)).
SetReference(channel.ID).
SetTextStyle(gt.getChannelNodeStyle(channel.ID))
node.AddChild(channelNode)
@ -214,10 +186,9 @@ func (gt *guildsTree) onSelected(node *tview.TreeNode) {
}
app.messagesList.reset()
app.messagesList.setTitle(*channel)
app.messagesList.drawMessages(messages)
app.messagesList.
ScrollToEnd().
SetTitle(gt.channelToString(*channel))
app.messagesList.ScrollToEnd()
app.messageInput.SetDisabled(!discordState.HasPermissions(channel.ID, discord.PermissionSendMessages))
gt.selectedChannelID = channel.ID

View file

@ -70,6 +70,15 @@ func (ml *messagesList) reset() {
SetTitle("")
}
func (ml *messagesList) setTitle(channel discord.Channel) {
title := ui.ChannelToString(channel)
if topic := channel.Topic; topic != "" {
title += " - " + topic
}
app.messagesList.SetTitle(title)
}
func (ml *messagesList) drawMessages(messages []discord.Message) {
for _, m := range slices.Backward(messages) {
ml.drawMessage(m)

View file

@ -1,8 +1,11 @@
package ui
import (
"strings"
"github.com/ayn2op/discordo/internal/config"
"github.com/ayn2op/tview"
"github.com/diamondburned/arikawa/discord"
)
// ConfigureBox configures the provided box according to the provided theme.
@ -46,3 +49,31 @@ func Centered(p tview.Primitive, width, height int) tview.Primitive {
SetRows(0, height, 0).
AddItem(p, 1, 1, 1, 1, 0, 0, true)
}
func ChannelToString(channel discord.Channel) string {
switch channel.Type {
case discord.DirectMessage, discord.GroupDM:
if channel.Name != "" {
return channel.Name
}
recipients := make([]string, len(channel.DMRecipients))
for i, r := range channel.DMRecipients {
recipients[i] = r.DisplayOrUsername()
}
return strings.Join(recipients, ", ")
case discord.GuildText:
return "#" + channel.Name
case discord.GuildVoice, discord.GuildStageVoice:
return "v-" + channel.Name
case discord.GuildAnnouncement:
return "a-" + channel.Name
case discord.GuildStore:
return "s-" + channel.Name
case discord.GuildForum:
return "f-" + channel.Name
default:
return channel.Name
}
}