Skip to content

Commit d88b250

Browse files
authored
RM-253: Delete pin notifications using DB lookup (#133)
Delete pin notifications using DB lookup Handle channel-pinned bot notifications by querying the tickets DB directly instead of the cached getTicket path. This avoids a race where thread message events can be cached as "not a ticket" before SetChannelId commits. If a pinned-message event from the bot is in a ticket channel, the message is deleted inside a Sentry span; errors are reported to Sentry. The previous getTicket-based check was reorganized and duplicate logic removed.
1 parent ff41037 commit d88b250

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

bot/listeners/message.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,22 @@ func OnMessage(worker *worker.Context, e events.MessageCreate) {
4040
return
4141
}
4242

43-
ticket, isTicket, err := getTicket(span.Context(), e.ChannelId)
44-
if err != nil {
45-
sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e))
43+
// Delete pin notification messages in ticket channels.
44+
if e.Type == message.MessageTypeChannelPinnedMessage && e.Author.Id == worker.BotId {
45+
ticket, ok, err := dbclient.Client.Tickets.GetByChannel(span.Context(), e.ChannelId)
46+
if err == nil && ok && ticket.Id != 0 {
47+
sentry.WithSpan0(span.Context(), "Delete pin notification", func(span *sentry.Span) {
48+
if err := worker.DeleteMessage(e.ChannelId, e.Id); err != nil {
49+
sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e))
50+
}
51+
})
52+
}
4653
return
4754
}
4855

49-
// Delete pin notification messages in ticket channels
50-
if isTicket && ticket.Id != 0 && e.Type == message.MessageTypeChannelPinnedMessage && e.Author.Id == worker.BotId {
51-
sentry.WithSpan0(span.Context(), "Delete pin notification", func(span *sentry.Span) {
52-
if err := worker.DeleteMessage(e.ChannelId, e.Id); err != nil {
53-
sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e))
54-
}
55-
})
56+
ticket, isTicket, err := getTicket(span.Context(), e.ChannelId)
57+
if err != nil {
58+
sentry.ErrorWithContext(err, utils.MessageCreateErrorContext(e))
5659
return
5760
}
5861

0 commit comments

Comments
 (0)