浏览代码

feat(ui/chat): display friend's nickname in DM node (#757)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Ken Perkins 2 月之前
父节点
当前提交
5ed32db323
共有 4 个文件被更改,包括 13 次插入4 次删除
  1. 1 1
      internal/ui/chat/channels_picker.go
  2. 1 1
      internal/ui/chat/guilds_tree.go
  3. 1 1
      internal/ui/chat/messages_list.go
  4. 10 1
      internal/ui/util.go

+ 1 - 1
internal/ui/chat/channels_picker.go

@@ -115,7 +115,7 @@ func (cp *channelsPicker) update() {
 
 func (cp *channelsPicker) addChannel(guild *discord.Guild, channel discord.Channel) {
 	var b strings.Builder
-	b.WriteString(ui.ChannelToString(channel, cp.chatView.cfg.Icons))
+	b.WriteString(ui.ChannelToString(channel, cp.chatView.cfg.Icons, cp.chatView.state))
 
 	if guild != nil {
 		b.WriteString(" - ")

+ 1 - 1
internal/ui/chat/guilds_tree.go

@@ -204,7 +204,7 @@ func (gt *guildsTree) createChannelNode(node *tview.TreeNode, channel discord.Ch
 		return
 	}
 
-	channelNode := tview.NewTreeNode(ui.ChannelToString(channel, gt.cfg.Icons)).SetReference(channel.ID)
+	channelNode := tview.NewTreeNode(ui.ChannelToString(channel, gt.cfg.Icons, gt.chatView.state)).SetReference(channel.ID)
 	if channel.Type == discord.GuildForum {
 		channelNode.SetExpandable(true).SetExpanded(false)
 	}

+ 1 - 1
internal/ui/chat/messages_list.go

@@ -112,7 +112,7 @@ func (ml *messagesList) reset() {
 }
 
 func (ml *messagesList) setTitle(channel discord.Channel) {
-	title := ui.ChannelToString(channel, ml.cfg.Icons)
+	title := ui.ChannelToString(channel, ml.cfg.Icons, ml.chatView.state)
 	if topic := channel.Topic; topic != "" {
 		title += " - " + topic
 	}

+ 10 - 1
internal/ui/util.go

@@ -8,6 +8,7 @@ import (
 	"github.com/ayn2op/discordo/internal/config"
 	"github.com/ayn2op/tview"
 	"github.com/diamondburned/arikawa/v3/discord"
+	"github.com/diamondburned/ningen/v3"
 	"github.com/gdamore/tcell/v3"
 )
 
@@ -61,7 +62,7 @@ func Centered(p tview.Primitive, width, height int) tview.Primitive {
 		AddItem(p, 1, 1, 1, 1, 0, 0, true)
 }
 
-func ChannelToString(channel discord.Channel, icons config.Icons) string {
+func ChannelToString(channel discord.Channel, icons config.Icons, state *ningen.State) string {
 	var icon string
 	switch channel.Type {
 	case discord.DirectMessage, discord.GroupDM:
@@ -71,6 +72,14 @@ func ChannelToString(channel discord.Channel, icons config.Icons) string {
 
 		recipients := make([]string, len(channel.DMRecipients))
 		for i, r := range channel.DMRecipients {
+			if state != nil && channel.Type == discord.DirectMessage {
+				if rel, ok := state.RelationshipState.FullRelationship(r.ID); ok && rel.Type == discord.FriendRelationship {
+					if rel.Nickname != nil && *rel.Nickname != "" {
+						recipients[i] = *rel.Nickname
+						continue
+					}
+				}
+			}
 			recipients[i] = r.DisplayOrUsername()
 		}