From 78e48a8f3bb82c6cab5b7304098a94c5849fbbb2 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 17 Oct 2021 11:02:31 -0400 Subject: [PATCH] check for last alerted thing that wasn't deleted --- internal/reddit/types.go | 4 ++++ internal/worker/stuck_notifications.go | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/reddit/types.go b/internal/reddit/types.go index 1c5614a..4a170ee 100644 --- a/internal/reddit/types.go +++ b/internal/reddit/types.go @@ -85,6 +85,10 @@ func (t *Thing) FullName() string { return fmt.Sprintf("%s_%s", t.Kind, t.ID) } +func (t *Thing) IsDeleted() bool { + return t.Author == "[deleted]" +} + func NewThing(val *fastjson.Value) *Thing { t := &Thing{} diff --git a/internal/worker/stuck_notifications.go b/internal/worker/stuck_notifications.go index d53fe8f..f57ae78 100644 --- a/internal/worker/stuck_notifications.go +++ b/internal/worker/stuck_notifications.go @@ -173,7 +173,7 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) { continue } - if thing.Author != "[deleted]" { + if !thing.IsDeleted() { snc.logger.WithFields(logrus.Fields{ "account#username": account.NormalizedUsername(), "thing#id": account.LastMessageID, @@ -203,9 +203,10 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) { account.LastMessageID = "" for _, thing := range things.Children { - if lastAlertedAt > thing.CreatedAt { + if lastAlertedAt > thing.CreatedAt && !thing.IsDeleted() { break } + account.LastMessageID = thing.FullName() }