mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-29 07:07:42 +00:00
fix the things for messages
This commit is contained in:
parent
62796df6de
commit
42243def97
1 changed files with 54 additions and 22 deletions
|
@ -139,16 +139,40 @@ 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]
|
||||||
|
|
||||||
|
var things *reddit.ListingResponse
|
||||||
|
if kind == "t4" {
|
||||||
|
snc.logger.WithFields(logrus.Fields{
|
||||||
|
"account#username": account.NormalizedUsername(),
|
||||||
|
"thing#id": account.LastMessageID,
|
||||||
|
}).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 {
|
if err != nil {
|
||||||
snc.logger.WithFields(logrus.Fields{
|
snc.logger.WithFields(logrus.Fields{
|
||||||
"err": err,
|
"err": err,
|
||||||
}).Error("failed to fetch last thing")
|
}).Error("failed to fetch last thing")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastAlertedAt := 0.0
|
||||||
|
|
||||||
|
if things.Count > 1 {
|
||||||
|
for _, thing := range things.Children {
|
||||||
|
if thing.FullName() != account.LastMessageID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if things.Count == 1 {
|
|
||||||
thing := things.Children[0]
|
|
||||||
if thing.Author != "[deleted]" {
|
if thing.Author != "[deleted]" {
|
||||||
snc.logger.WithFields(logrus.Fields{
|
snc.logger.WithFields(logrus.Fields{
|
||||||
"account#username": account.NormalizedUsername(),
|
"account#username": account.NormalizedUsername(),
|
||||||
|
@ -156,6 +180,9 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
|
||||||
}).Debug("thing exists, returning")
|
}).Debug("thing exists, returning")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastAlertedAt = thing.CreatedAt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snc.logger.WithFields(logrus.Fields{
|
snc.logger.WithFields(logrus.Fields{
|
||||||
|
@ -163,6 +190,7 @@ 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")
|
||||||
|
|
||||||
|
if kind != "t4" {
|
||||||
things, err = rac.MessageInbox()
|
things, err = rac.MessageInbox()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
snc.logger.WithFields(logrus.Fields{
|
snc.logger.WithFields(logrus.Fields{
|
||||||
|
@ -171,10 +199,14 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
|
||||||
}).Error("failed to get message inbox")
|
}).Error("failed to get message inbox")
|
||||||
return
|
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 {
|
||||||
|
|
Loading…
Reference in a new issue