From 7f34127560908fff1771313bfca8f0a58395bef5 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Thu, 21 May 2026 20:42:01 -0400 Subject: [PATCH] refactor(chat): flatten open() into a switch --- internal/ui/chat/messages_list.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/internal/ui/chat/messages_list.go b/internal/ui/chat/messages_list.go index 79d0ce8..c882fed 100644 --- a/internal/ui/chat/messages_list.go +++ b/internal/ui/chat/messages_list.go @@ -1080,24 +1080,20 @@ func (ml *messagesList) open() tview.Cmd { } urls := messageURLs(*msg) - - if len(urls) == 0 && len(msg.Attachments) == 0 { + switch total := len(urls) + len(msg.Attachments); { + case total == 0: return nil + case total > 1: + return ml.showAttachmentsList(urls, msg.Attachments) + case len(urls) == 1: + return ml.openURL(urls[0]) } - if len(urls)+len(msg.Attachments) == 1 { - if len(urls) == 1 { - return ml.openURL(urls[0]) - } else { - attachment := msg.Attachments[0] - if strings.HasPrefix(attachment.ContentType, "image/") { - return ml.openAttachment(attachment) - } - return ml.openURL(attachment.URL) - } - } else { - return ml.showAttachmentsList(urls, msg.Attachments) + attachment := msg.Attachments[0] + if strings.HasPrefix(attachment.ContentType, "image/") { + return ml.openAttachment(attachment) } + return ml.openURL(attachment.URL) } func extractURLs(content string) []string {