diff --git a/cmd/message_input.go b/cmd/message_input.go index e54b7a8..35ed6c1 100644 --- a/cmd/message_input.go +++ b/cmd/message_input.go @@ -156,6 +156,15 @@ func (mi *messageInput) send() { return } + // Close attached files on return + defer func() { + for _, file := range mi.sendMessageData.Files { + if closer, ok := file.Reader.(io.Closer); ok { + closer.Close() + } + } + }() + text = processText(app.chatView.selectedChannel, []byte(text)) if mi.edit { @@ -179,13 +188,6 @@ func (mi *messageInput) send() { } } - // Close the attached files after sending the message. - for _, file := range mi.sendMessageData.Files { - if closer, ok := file.Reader.(io.Closer); ok { - closer.Close() - } - } - mi.reset() app.chatView.messagesList.Highlight() app.chatView.messagesList.ScrollToEnd()