From 3e7ef4859c43981492aa9df6c1e6c1cd1f930c13 Mon Sep 17 00:00:00 2001 From: erroneousboat Date: Sat, 5 Oct 2019 12:02:40 +0200 Subject: [PATCH] Fix edited message in threads --- components/debug.go | 1 + handlers/event.go | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/debug.go b/components/debug.go index 0fff57a..aa0a26a 100644 --- a/components/debug.go +++ b/components/debug.go @@ -16,6 +16,7 @@ func CreateDebugComponent(inputHeight int) *Debug { debug.List.BorderLabel = "Debug" debug.List.Height = termui.TermHeight() - inputHeight + debug.List.Overflow = "wrap" return debug } diff --git a/handlers/event.go b/handlers/event.go index c0dc125..0c913be 100644 --- a/handlers/event.go +++ b/handlers/event.go @@ -119,8 +119,8 @@ func messageHandler(ctx *context.AppContext) { go func() { for { select { - case msg := <-ctx.Service.RTM.IncomingEvents: - switch ev := msg.Data.(type) { + case rtmEvent := <-ctx.Service.RTM.IncomingEvents: + switch ev := rtmEvent.Data.(type) { case *slack.MessageEvent: // Construct message @@ -132,11 +132,26 @@ func messageHandler(ctx *context.AppContext) { // Add message to the selected channel if ev.Channel == ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].ID { + // Get the thread timestamp of the event, we need to + // check the previous message as well, because edited + // message don't have the thread timestamp + var threadTimestamp string + if ev.ThreadTimestamp != "" { + threadTimestamp = ev.ThreadTimestamp + } else if ev.PreviousMessage.ThreadTimestamp != "" { + threadTimestamp = ev.PreviousMessage.ThreadTimestamp + } else { + threadTimestamp = "" + } + // When timestamp isn't set this is a thread reply, // handle as such - if ev.ThreadTimestamp != "" { - ctx.View.Chat.AddReply(ev.ThreadTimestamp, msg) - } else if ev.ThreadTimestamp == "" && ctx.Focus == context.ChatFocus { + if threadTimestamp != "" { + ctx.View.Debug.Println( + fmt.Sprint("here"), + ) + ctx.View.Chat.AddReply(threadTimestamp, msg) + } else if threadTimestamp == "" && ctx.Focus == context.ChatFocus { ctx.View.Chat.AddMessage(msg) }