Skip to content

Commit 0dfb7d3

Browse files
committed
Reaction: Post in correct channel
1 parent a80de4d commit 0dfb7d3

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

pkg/ircslack/event_handler.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,36 @@ func getConversationDetails(
146146
ctx *IrcContext,
147147
channelID string,
148148
timestamp string,
149-
) (slack.Message, error) {
149+
) (slack.Message, error, string) {
150150
message, err := ctx.SlackClient.GetConversationHistory(&slack.GetConversationHistoryParameters{
151151
ChannelID: channelID,
152152
Latest: timestamp,
153153
Limit: 1,
154154
Inclusive: true,
155155
})
156156
if err != nil {
157-
return slack.Message{}, err
157+
return slack.Message{}, err, ""
158158
}
159159
if len(message.Messages) > 0 {
160+
parent := message.Messages[0]
160161
// If the timestamps are not equal, we're looking for a threaded message
161-
if message.Messages[0].Timestamp != timestamp {
162-
msgs, _, _, err := ctx.SlackClient.GetConversationReplies(&slack.GetConversationRepliesParameters{ ChannelID: channelID, Timestamp: message.Messages[0].Timestamp })
162+
if parent.Timestamp != timestamp {
163+
msgs, _, _, err := ctx.SlackClient.GetConversationReplies(&slack.GetConversationRepliesParameters{ ChannelID: channelID, Timestamp: parent.Timestamp })
163164
if err == nil {
164165
for _, msg := range msgs {
165-
if msg.Timestamp == timestamp { return msg, nil }
166+
if msg.Timestamp == timestamp {
167+
channame := resolveChannelName(ctx, channelID, parent.Timestamp)
168+
return msg, nil, channame
169+
}
166170
}
167171
}
168172
// TODO: Always find the message, or return better fallback
169-
log.Warningf("Did not find threaded message with timestamp %v from %v", timestamp, message.Messages[0]);
173+
log.Warningf("Did not find threaded message with timestamp %v from %v", timestamp, parent);
170174
}
171-
return message.Messages[0], nil
175+
channame := resolveChannelName(ctx, channelID, "")
176+
return parent, nil, channame
172177
}
173-
return slack.Message{}, fmt.Errorf("No such message found")
178+
return slack.Message{}, fmt.Errorf("No such message found"), ""
174179
}
175180

176181
func replacePermalinkWithText(ctx *IrcContext, text string) string {
@@ -180,7 +185,7 @@ func replacePermalinkWithText(ctx *IrcContext, text string) string {
180185
}
181186
channel := matches[1]
182187
timestamp := matches[2] + "." + matches[3]
183-
message, err := getConversationDetails(ctx, channel, timestamp)
188+
message, err, _ := getConversationDetails(ctx, channel, timestamp)
184189
if err != nil {
185190
log.Printf("could not get message details from permalink %s %s %s %v", matches[0], channel, timestamp, err)
186191
return text
@@ -278,7 +283,7 @@ func eventHandler(ctx *IrcContext, rtm *slack.RTM) {
278283
switch message.SubType {
279284
case "message_changed":
280285
// https://api.slack.com/events/message/message_changed
281-
editedMessage, err := getConversationDetails(ctx, message.Channel, message.Timestamp)
286+
editedMessage, err, _ := getConversationDetails(ctx, message.Channel, message.Timestamp)
282287
if err != nil {
283288
fmt.Printf("could not get changed conversation details %s", err)
284289
continue
@@ -362,7 +367,6 @@ func eventHandler(ctx *IrcContext, rtm *slack.RTM) {
362367
// and slack.MemberLeftChannelEvent.
363368
case *slack.ReactionAddedEvent:
364369
// https://api.slack.com/events/reaction_added
365-
channame := resolveChannelName(ctx, ev.Item.Channel, "")
366370
user := ctx.GetUserInfo(ev.User)
367371
name := ""
368372
if user == nil {
@@ -371,7 +375,8 @@ func eventHandler(ctx *IrcContext, rtm *slack.RTM) {
371375
} else {
372376
name = user.Name
373377
}
374-
msg, err := getConversationDetails(ctx, ev.Item.Channel, ev.Item.Timestamp)
378+
msg, err, channame := getConversationDetails(ctx, ev.Item.Channel, ev.Item.Timestamp)
379+
375380
if err != nil {
376381
fmt.Printf("could not get Conversation details %s", err)
377382
continue

0 commit comments

Comments
 (0)