From b07bf599de41b1f8f523c8ae073823fabbb9def2 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sun, 17 Oct 2021 11:05:40 -0400 Subject: [PATCH] only alert on non deleted messages --- internal/worker/notifications.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index ae78013..04b068f 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -280,7 +280,14 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { "count": msgs.Count, }).Debug("fetched messages") - account.LastMessageID = msgs.Children[0].FullName() + for i := msgs.Count - 1; i >= 0; i-- { + msg := msgs.Children[i] + + if !msg.IsDeleted() { + account.LastMessageID = msgs.Children[0].FullName() + break + } + } if err = nc.accountRepo.Update(ctx, &account); err != nil { nc.logger.WithFields(logrus.Fields{ @@ -310,6 +317,11 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { // Iterate backwards so we notify from older to newer for i := msgs.Count - 1; i >= 0; i-- { msg := msgs.Children[i] + + if msg.IsDeleted() { + continue + } + notification := &apns2.Notification{} notification.Topic = "com.christianselig.Apollo" notification.Payload = payloadFromMessage(account, msg, msgs.Count)