From 6ac6f8d614d17910d929981bde7d80d8ec2c0b6e Mon Sep 17 00:00:00 2001 From: Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 31 May 2021 17:36:35 +0200 Subject: Tidy + timeline embetterment (#38) * tidy up timelines a bit + stub out some endpoints * who's faved and who's boosted, reblog notifs * linting * Update progress with new endpoints --- internal/processing/fromcommon.go | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'internal/processing/fromcommon.go') diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go index cb38d4bb4..bdb2a599b 100644 --- a/internal/processing/fromcommon.go +++ b/internal/processing/fromcommon.go @@ -160,5 +160,54 @@ func (p *processor) notifyFave(fave *gtsmodel.StatusFave, receivingAccount *gtsm } func (p *processor) notifyAnnounce(status *gtsmodel.Status) error { + if status.BoostOfID == "" { + // not a boost, nothing to do + return nil + } + + boostedStatus := >smodel.Status{} + if err := p.db.GetByID(status.BoostOfID, boostedStatus); err != nil { + return fmt.Errorf("notifyAnnounce: error getting status with id %s: %s", status.BoostOfID, err) + } + + boostedAcct := >smodel.Account{} + if err := p.db.GetByID(boostedStatus.AccountID, boostedAcct); err != nil { + return fmt.Errorf("notifyAnnounce: error getting account with id %s: %s", boostedStatus.AccountID, err) + } + + if boostedAcct.Domain != "" { + // remote account, nothing to do + return nil + } + + if boostedStatus.AccountID == status.AccountID { + // it's a self boost, nothing to do + return nil + } + + // make sure a notif doesn't already exist for this announce + err := p.db.GetWhere([]db.Where{ + {Key: "notification_type", Value: gtsmodel.NotificationReblog}, + {Key: "target_account_id", Value: boostedAcct.ID}, + {Key: "origin_account_id", Value: status.AccountID}, + {Key: "status_id", Value: status.ID}, + }, >smodel.Notification{}) + if err == nil { + // notification exists already so just bail + return nil + } + + // now create the new reblog notification + notif := >smodel.Notification{ + NotificationType: gtsmodel.NotificationReblog, + TargetAccountID: boostedAcct.ID, + OriginAccountID: status.AccountID, + StatusID: status.ID, + } + + if err := p.db.Put(notif); err != nil { + return fmt.Errorf("notifyAnnounce: error putting notification in database: %s", err) + } + return nil } -- cgit v1.2.3