Fix edited message in threads

This commit is contained in:
erroneousboat 2019-10-05 12:02:40 +02:00
parent 240deb0607
commit 3e7ef4859c
2 changed files with 21 additions and 5 deletions

View File

@ -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
}

View File

@ -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)
}