From dbad4981ec182cd1a4c136b1ada5a0b12d0e3631 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 19 Aug 2022 16:44:02 -0400 Subject: [PATCH 1/6] Channel Type: Detect more private channels --- pkg/ircslack/channel.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ircslack/channel.go b/pkg/ircslack/channel.go index 09c04ec..adf53dc 100644 --- a/pkg/ircslack/channel.go +++ b/pkg/ircslack/channel.go @@ -101,7 +101,7 @@ func (c *Channel) IsPublicChannel() bool { // IsPrivateChannel returns true if the channel is private. func (c *Channel) IsPrivateChannel() bool { - return c.IsGroup && c.IsPrivate + return (c.IsGroup||c.IsChannel) && c.IsPrivate } // IsMP returns true if it is a multi-party conversation. From caabc523a72b65326d486237fb11394456a2dee8 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 19 Aug 2022 17:23:19 -0400 Subject: [PATCH 2/6] threads: Fix replies --- pkg/ircslack/irc_context.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/ircslack/irc_context.go b/pkg/ircslack/irc_context.go index 76562ff..90cbeab 100644 --- a/pkg/ircslack/irc_context.go +++ b/pkg/ircslack/irc_context.go @@ -98,9 +98,14 @@ func (ic *IrcContext) Start() { opts = append(opts, slack.MsgOptionText(strings.TrimSpace(text), false)) if message.TargetTs != "" { opts = append(opts, slack.MsgOptionTS(message.TargetTs)) + if target[1] == ChannelPrefixThread[0] { + idx := strings.Index(target,message.TargetTs) + // strip the prefixes and the '-timestamp' + target = target[2:idx-1] + } } if _, _, err := ic.SlackClient.PostMessage(target, opts...); err != nil { - log.Warningf("Failed to post message to Slack to target %s: %v", target, err) + log.Warningf("Failed to post message to Slack to target %s: %v (targetTs: %v)", target, err, message.TargetTs) } } textBuffer = make(map[string]string) From 16852e3e8edf102046ff9ae93d2adf0203e9a30e Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 19 Aug 2022 17:39:11 -0400 Subject: [PATCH 3/6] README: Update feature matrix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 91780dd..93ef0e7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ You can also [run it with Docker](#run-it-with-docker). | --- | --- | --- | --- | --- | | from me | works | works | doesn't work ([#168](https://github.com/insomniacslk/irc-slack/issues/168)) | works | | to me | works | works | works | works | -| thread from me | doesn't work ([#168](https://github.com/insomniacslk/irc-slack/issues/168)) | doesn't work ([#168](https://github.com/insomniacslk/irc-slack/issues/168)) | untested | doesn't work ([#166](https://github.com/insomniacslk/irc-slack/issues/166)) | +| thread from me | works | works | untested | doesn't work ([#166](https://github.com/insomniacslk/irc-slack/issues/166)) | | thread to me | works | works | untested | works but sends in the IM chat ([#167](https://github.com/insomniacslk/irc-slack/issues/167)) | ## Encryption From a80de4de9889fe02021b73f4a50a4fc16c56287b Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 19 Aug 2022 20:04:59 -0400 Subject: [PATCH 4/6] Reaction: state that it was applied to correct message --- pkg/ircslack/event_handler.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/ircslack/event_handler.go b/pkg/ircslack/event_handler.go index ddc45a4..71cb7a4 100644 --- a/pkg/ircslack/event_handler.go +++ b/pkg/ircslack/event_handler.go @@ -157,6 +157,17 @@ func getConversationDetails( return slack.Message{}, err } if len(message.Messages) > 0 { + // If the timestamps are not equal, we're looking for a threaded message + if message.Messages[0].Timestamp != timestamp { + msgs, _, _, err := ctx.SlackClient.GetConversationReplies(&slack.GetConversationRepliesParameters{ ChannelID: channelID, Timestamp: message.Messages[0].Timestamp }) + if err == nil { + for _, msg := range msgs { + if msg.Timestamp == timestamp { return msg, nil } + } + } + // TODO: Always find the message, or return better fallback + log.Warningf("Did not find threaded message with timestamp %v from %v", timestamp, message.Messages[0]); + } return message.Messages[0], nil } return slack.Message{}, fmt.Errorf("No such message found") From 0dfb7d35718134e2af93585e1b12d8f6ebb846c6 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Fri, 19 Aug 2022 20:26:01 -0400 Subject: [PATCH 5/6] Reaction: Post in correct channel --- pkg/ircslack/event_handler.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pkg/ircslack/event_handler.go b/pkg/ircslack/event_handler.go index 71cb7a4..4f40c39 100644 --- a/pkg/ircslack/event_handler.go +++ b/pkg/ircslack/event_handler.go @@ -146,7 +146,7 @@ func getConversationDetails( ctx *IrcContext, channelID string, timestamp string, -) (slack.Message, error) { +) (slack.Message, error, string) { message, err := ctx.SlackClient.GetConversationHistory(&slack.GetConversationHistoryParameters{ ChannelID: channelID, Latest: timestamp, @@ -154,23 +154,28 @@ func getConversationDetails( Inclusive: true, }) if err != nil { - return slack.Message{}, err + return slack.Message{}, err, "" } if len(message.Messages) > 0 { + parent := message.Messages[0] // If the timestamps are not equal, we're looking for a threaded message - if message.Messages[0].Timestamp != timestamp { - msgs, _, _, err := ctx.SlackClient.GetConversationReplies(&slack.GetConversationRepliesParameters{ ChannelID: channelID, Timestamp: message.Messages[0].Timestamp }) + if parent.Timestamp != timestamp { + msgs, _, _, err := ctx.SlackClient.GetConversationReplies(&slack.GetConversationRepliesParameters{ ChannelID: channelID, Timestamp: parent.Timestamp }) if err == nil { for _, msg := range msgs { - if msg.Timestamp == timestamp { return msg, nil } + if msg.Timestamp == timestamp { + channame := resolveChannelName(ctx, channelID, parent.Timestamp) + return msg, nil, channame + } } } // TODO: Always find the message, or return better fallback - log.Warningf("Did not find threaded message with timestamp %v from %v", timestamp, message.Messages[0]); + log.Warningf("Did not find threaded message with timestamp %v from %v", timestamp, parent); } - return message.Messages[0], nil + channame := resolveChannelName(ctx, channelID, "") + return parent, nil, channame } - return slack.Message{}, fmt.Errorf("No such message found") + return slack.Message{}, fmt.Errorf("No such message found"), "" } func replacePermalinkWithText(ctx *IrcContext, text string) string { @@ -180,7 +185,7 @@ func replacePermalinkWithText(ctx *IrcContext, text string) string { } channel := matches[1] timestamp := matches[2] + "." + matches[3] - message, err := getConversationDetails(ctx, channel, timestamp) + message, err, _ := getConversationDetails(ctx, channel, timestamp) if err != nil { log.Printf("could not get message details from permalink %s %s %s %v", matches[0], channel, timestamp, err) return text @@ -278,7 +283,7 @@ func eventHandler(ctx *IrcContext, rtm *slack.RTM) { switch message.SubType { case "message_changed": // https://api.slack.com/events/message/message_changed - editedMessage, err := getConversationDetails(ctx, message.Channel, message.Timestamp) + editedMessage, err, _ := getConversationDetails(ctx, message.Channel, message.Timestamp) if err != nil { fmt.Printf("could not get changed conversation details %s", err) continue @@ -362,7 +367,6 @@ func eventHandler(ctx *IrcContext, rtm *slack.RTM) { // and slack.MemberLeftChannelEvent. case *slack.ReactionAddedEvent: // https://api.slack.com/events/reaction_added - channame := resolveChannelName(ctx, ev.Item.Channel, "") user := ctx.GetUserInfo(ev.User) name := "" if user == nil { @@ -371,7 +375,8 @@ func eventHandler(ctx *IrcContext, rtm *slack.RTM) { } else { name = user.Name } - msg, err := getConversationDetails(ctx, ev.Item.Channel, ev.Item.Timestamp) + msg, err, channame := getConversationDetails(ctx, ev.Item.Channel, ev.Item.Timestamp) + if err != nil { fmt.Printf("could not get Conversation details %s", err) continue From 861071cc56a090da51e5db8cd262ab1e51163c9f Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 20 Aug 2022 00:27:30 +0000 Subject: [PATCH 6/6] Fixing style errors. --- pkg/ircslack/channel.go | 2 +- pkg/ircslack/event_handler.go | 6 +++--- pkg/ircslack/irc_context.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/ircslack/channel.go b/pkg/ircslack/channel.go index adf53dc..95fed22 100644 --- a/pkg/ircslack/channel.go +++ b/pkg/ircslack/channel.go @@ -101,7 +101,7 @@ func (c *Channel) IsPublicChannel() bool { // IsPrivateChannel returns true if the channel is private. func (c *Channel) IsPrivateChannel() bool { - return (c.IsGroup||c.IsChannel) && c.IsPrivate + return (c.IsGroup || c.IsChannel) && c.IsPrivate } // IsMP returns true if it is a multi-party conversation. diff --git a/pkg/ircslack/event_handler.go b/pkg/ircslack/event_handler.go index 4f40c39..5525aad 100644 --- a/pkg/ircslack/event_handler.go +++ b/pkg/ircslack/event_handler.go @@ -160,7 +160,7 @@ func getConversationDetails( parent := message.Messages[0] // If the timestamps are not equal, we're looking for a threaded message if parent.Timestamp != timestamp { - msgs, _, _, err := ctx.SlackClient.GetConversationReplies(&slack.GetConversationRepliesParameters{ ChannelID: channelID, Timestamp: parent.Timestamp }) + msgs, _, _, err := ctx.SlackClient.GetConversationReplies(&slack.GetConversationRepliesParameters{ChannelID: channelID, Timestamp: parent.Timestamp}) if err == nil { for _, msg := range msgs { if msg.Timestamp == timestamp { @@ -170,7 +170,7 @@ func getConversationDetails( } } // TODO: Always find the message, or return better fallback - log.Warningf("Did not find threaded message with timestamp %v from %v", timestamp, parent); + log.Warningf("Did not find threaded message with timestamp %v from %v", timestamp, parent) } channame := resolveChannelName(ctx, channelID, "") return parent, nil, channame @@ -376,7 +376,7 @@ func eventHandler(ctx *IrcContext, rtm *slack.RTM) { name = user.Name } msg, err, channame := getConversationDetails(ctx, ev.Item.Channel, ev.Item.Timestamp) - + if err != nil { fmt.Printf("could not get Conversation details %s", err) continue diff --git a/pkg/ircslack/irc_context.go b/pkg/ircslack/irc_context.go index 90cbeab..10a0a09 100644 --- a/pkg/ircslack/irc_context.go +++ b/pkg/ircslack/irc_context.go @@ -99,9 +99,9 @@ func (ic *IrcContext) Start() { if message.TargetTs != "" { opts = append(opts, slack.MsgOptionTS(message.TargetTs)) if target[1] == ChannelPrefixThread[0] { - idx := strings.Index(target,message.TargetTs) + idx := strings.Index(target, message.TargetTs) // strip the prefixes and the '-timestamp' - target = target[2:idx-1] + target = target[2 : idx-1] } } if _, _, err := ic.SlackClient.PostMessage(target, opts...); err != nil {