fix the things for messages

This commit is contained in:
Andre Medeiros 2021-10-17 10:47:43 -04:00
parent 62796df6de
commit 42243def97

View file

@ -139,22 +139,49 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
"thing#id": account.LastMessageID, "thing#id": account.LastMessageID,
}).Debug("fetching last thing") }).Debug("fetching last thing")
things, err := rac.AboutInfo(account.LastMessageID) kind := account.LastMessageID[:2]
if err != nil {
var things *reddit.ListingResponse
if kind == "t4" {
snc.logger.WithFields(logrus.Fields{ snc.logger.WithFields(logrus.Fields{
"err": err, "account#username": account.NormalizedUsername(),
}).Error("failed to fetch last thing") "thing#id": account.LastMessageID,
return }).Debug("checking last thing via inbox")
things, err = rac.MessageInbox()
if err != nil {
snc.logger.WithFields(logrus.Fields{
"err": err,
}).Error("failed to fetch last thing via inbox")
return
}
} else {
things, err = rac.AboutInfo(account.LastMessageID)
if err != nil {
snc.logger.WithFields(logrus.Fields{
"err": err,
}).Error("failed to fetch last thing")
return
}
} }
if things.Count == 1 { lastAlertedAt := 0.0
thing := things.Children[0]
if thing.Author != "[deleted]" { if things.Count > 1 {
snc.logger.WithFields(logrus.Fields{ for _, thing := range things.Children {
"account#username": account.NormalizedUsername(), if thing.FullName() != account.LastMessageID {
"thing#id": account.LastMessageID, continue
}).Debug("thing exists, returning") }
return
if thing.Author != "[deleted]" {
snc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(),
"thing#id": account.LastMessageID,
}).Debug("thing exists, returning")
return
}
lastAlertedAt = thing.CreatedAt
} }
} }
@ -163,18 +190,23 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
"thing#id": account.LastMessageID, "thing#id": account.LastMessageID,
}).Info("thing got deleted, resetting") }).Info("thing got deleted, resetting")
things, err = rac.MessageInbox() if kind != "t4" {
if err != nil { things, err = rac.MessageInbox()
snc.logger.WithFields(logrus.Fields{ if err != nil {
"account#username": account.NormalizedUsername(), snc.logger.WithFields(logrus.Fields{
"err": err, "account#username": account.NormalizedUsername(),
}).Error("failed to get message inbox") "err": err,
return }).Error("failed to get message inbox")
return
}
} }
account.LastMessageID = "" account.LastMessageID = ""
if things.Count > 0 { for _, thing := range things.Children {
account.LastMessageID = things.Children[0].FullName() if lastAlertedAt > thing.CreatedAt {
break
}
account.LastMessageID = thing.FullName()
} }
if err := snc.accountRepo.Update(ctx, &account); err != nil { if err := snc.accountRepo.Update(ctx, &account); err != nil {