Ignore reply events

This commit is contained in:
erroneousboat 2018-03-24 13:56:55 +01:00
parent e6897a6c40
commit f1f0bc1379
2 changed files with 15 additions and 5 deletions

View File

@ -47,6 +47,7 @@ func RegisterEventHandlers(ctx *context.AppContext) {
messageHandler(ctx)
}
// eventHandler will handle events created by the user
func eventHandler(ctx *context.AppContext) {
go func() {
for {
@ -95,6 +96,7 @@ func handleMoreTermboxEvents(ctx *context.AppContext, ev termbox.Event) bool {
}
}
// messageHandler will handle events created by the service
func messageHandler(ctx *context.AppContext) {
go func() {
for {
@ -102,8 +104,12 @@ func messageHandler(ctx *context.AppContext) {
case msg := <-ctx.Service.RTM.IncomingEvents:
switch ev := msg.Data.(type) {
case *slack.MessageEvent:
// Construct message
msg := ctx.Service.CreateMessageFromMessageEvent(ev)
msg, err := ctx.Service.CreateMessageFromMessageEvent(ev)
if err != nil {
continue
}
// Add message to the selected channel
if ev.Channel == ctx.Service.Channels[ctx.View.Channels.SelectedChannel].ID {

View File

@ -397,15 +397,19 @@ func (s *SlackService) CreateMessage(message slack.Message) []components.Message
return msgs
}
func (s *SlackService) CreateMessageFromMessageEvent(message *slack.MessageEvent) []components.Message {
func (s *SlackService) CreateMessageFromMessageEvent(message *slack.MessageEvent) ([]components.Message, error) {
var msgs []components.Message
var name string
// Append (edited) when an edited message is received
if message.SubType == "message_changed" {
switch message.SubType {
case "message_changed":
// Append (edited) when an edited message is received
message = &slack.MessageEvent{Msg: *message.SubMessage}
message.Text = fmt.Sprintf("%s (edited)", message.Text)
case "message_replied":
// Ignore reply events
return nil, errors.New("ignoring reply events")
}
// Get username from cache
@ -462,7 +466,7 @@ func (s *SlackService) CreateMessageFromMessageEvent(message *slack.MessageEvent
msgs = append(msgs, msg)
return msgs
return msgs, nil
}
// parseMessage will parse a message string and find and replace: