-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent slack Update policy from posting new messages #298
base: master
Are you sure you want to change the base?
Changes from 1 commit
def4988
d93d8cc
15a938c
b20ac36
21b4f68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,37 +114,40 @@ func (c *threadedClient) SendMessage(ctx context.Context, recipient string, grou | |
options = append(options, sl.MsgOptionTS(ts)) | ||
} | ||
|
||
if ts == "" || policy == Post || policy == PostAndUpdate { | ||
newTs, channelID, err := SendMessageRateLimited( | ||
// Updating an existing message | ||
if ts != "" && (policy == Update || policy == PostAndUpdate) { | ||
_, _, err := SendMessageRateLimited( | ||
c.Client, | ||
ctx, | ||
c.Limiter, | ||
recipient, | ||
sl.MsgOptionPost(), | ||
buildPostOptions(broadcast, options), | ||
c.getChannelID(recipient), | ||
sl.MsgOptionUpdate(ts), | ||
sl.MsgOptionAsUser(true), | ||
sl.MsgOptionCompose(options...), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if groupingKey != "" && ts == "" { | ||
c.setThreadTimestamp(recipient, groupingKey, newTs) | ||
} | ||
c.ChannelIDs[recipient] = channelID | ||
return nil | ||
} | ||
|
||
if ts != "" && (policy == Update || policy == PostAndUpdate) { | ||
_, _, err := SendMessageRateLimited( | ||
// Posting a new message | ||
if policy == Post || policy == PostAndUpdate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why you removed ts == "" check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, it's been a while, but I think this was the source of the problem. Let's suppose that
|
||
newTs, channelID, err := SendMessageRateLimited( | ||
c.Client, | ||
ctx, | ||
c.Limiter, | ||
c.getChannelID(recipient), | ||
sl.MsgOptionUpdate(ts), | ||
sl.MsgOptionAsUser(true), | ||
sl.MsgOptionCompose(options...), | ||
recipient, | ||
sl.MsgOptionPost(), | ||
buildPostOptions(broadcast, options), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if groupingKey != "" && ts == "" { | ||
c.setThreadTimestamp(recipient, groupingKey, newTs) | ||
} | ||
c.ChannelIDs[recipient] = channelID | ||
} | ||
|
||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating is the first condition so it always takes priority. This way, when a message has a policy of
PostAndUpdate
, it always updates the existing message instead of posting a new one in a thread.This might also fix a race condition in which
PostAndUpdate
would post a message in a thread instead of updating the initial message. I didn't encounter this behavior a lot so I'm not 100% sure. Either way, it makes sense for updates to take priority in this case.