commit c156602c6679224fe48b325674022f768aa74d27
parent 5d9e9e0e7f7e026677e843a5897283faecfb2874
Author: tsmethurst <tobi.smethurst@protonmail.com>
Date: Tue, 25 Jan 2022 13:48:13 +0100
ensure blocking calls to getRemoteAccount before showing stuff to client
Diffstat:
2 files changed, 99 insertions(+), 4 deletions(-)
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
@@ -89,7 +89,7 @@ func (d *deref) GetRemoteStatus(ctx context.Context, username string, remoteStat
}
// do this so we know we have the remote account of the status in the db
- _, err = d.GetRemoteAccount(ctx, username, accountURI, false, false)
+ _, err = d.GetRemoteAccount(ctx, username, accountURI, true, false)
if err != nil {
return nil, statusable, new, fmt.Errorf("GetRemoteStatus: couldn't derive status author: %s", err)
}
diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go
@@ -115,6 +115,30 @@ func (p *processor) processCreateStatusFromFederator(ctx context.Context, federa
}
}
+ // make sure the account is pinned
+ if status.Account == nil {
+ a, err := p.db.GetAccountByID(ctx, status.AccountID)
+ if err != nil {
+ return err
+ }
+ status.Account = a
+ }
+
+ // do a BLOCKING get of the remote account to make sure the avi and header are cached
+ if status.Account.Domain != "" {
+ remoteAccountID, err := url.Parse(status.Account.URI)
+ if err != nil {
+ return err
+ }
+
+ a, err := p.federator.GetRemoteAccount(ctx, federatorMsg.ReceivingAccount.Username, remoteAccountID, true, false)
+ if err != nil {
+ return err
+ }
+
+ status.Account = a
+ }
+
if err := p.timelineStatus(ctx, status); err != nil {
return err
}
@@ -133,6 +157,30 @@ func (p *processor) processCreateFaveFromFederator(ctx context.Context, federato
return errors.New("like was not parseable as *gtsmodel.StatusFave")
}
+ // make sure the account is pinned
+ if incomingFave.Account == nil {
+ a, err := p.db.GetAccountByID(ctx, incomingFave.AccountID)
+ if err != nil {
+ return err
+ }
+ incomingFave.Account = a
+ }
+
+ // do a BLOCKING get of the remote account to make sure the avi and header are cached
+ if incomingFave.Account.Domain != "" {
+ remoteAccountID, err := url.Parse(incomingFave.Account.URI)
+ if err != nil {
+ return err
+ }
+
+ a, err := p.federator.GetRemoteAccount(ctx, federatorMsg.ReceivingAccount.Username, remoteAccountID, true, false)
+ if err != nil {
+ return err
+ }
+
+ incomingFave.Account = a
+ }
+
if err := p.notifyFave(ctx, incomingFave); err != nil {
return err
}
@@ -147,6 +195,30 @@ func (p *processor) processCreateFollowRequestFromFederator(ctx context.Context,
return errors.New("incomingFollowRequest was not parseable as *gtsmodel.FollowRequest")
}
+ // make sure the account is pinned
+ if followRequest.Account == nil {
+ a, err := p.db.GetAccountByID(ctx, followRequest.AccountID)
+ if err != nil {
+ return err
+ }
+ followRequest.Account = a
+ }
+
+ // do a BLOCKING get of the remote account to make sure the avi and header are cached
+ if followRequest.Account.Domain != "" {
+ remoteAccountID, err := url.Parse(followRequest.Account.URI)
+ if err != nil {
+ return err
+ }
+
+ a, err := p.federator.GetRemoteAccount(ctx, federatorMsg.ReceivingAccount.Username, remoteAccountID, true, false)
+ if err != nil {
+ return err
+ }
+
+ followRequest.Account = a
+ }
+
if followRequest.TargetAccount == nil {
a, err := p.db.GetAccountByID(ctx, followRequest.TargetAccountID)
if err != nil {
@@ -154,9 +226,8 @@ func (p *processor) processCreateFollowRequestFromFederator(ctx context.Context,
}
followRequest.TargetAccount = a
}
- targetAccount := followRequest.TargetAccount
- if targetAccount.Locked {
+ if followRequest.TargetAccount.Locked {
// if the account is locked just notify the follow request and nothing else
return p.notifyFollowRequest(ctx, followRequest)
}
@@ -171,7 +242,7 @@ func (p *processor) processCreateFollowRequestFromFederator(ctx context.Context,
return err
}
- return p.notifyFollow(ctx, follow, targetAccount)
+ return p.notifyFollow(ctx, follow, followRequest.TargetAccount)
}
// processCreateAnnounceFromFederator handles Activity Create and Object Announce
@@ -181,6 +252,30 @@ func (p *processor) processCreateAnnounceFromFederator(ctx context.Context, fede
return errors.New("announce was not parseable as *gtsmodel.Status")
}
+ // make sure the account is pinned
+ if incomingAnnounce.Account == nil {
+ a, err := p.db.GetAccountByID(ctx, incomingAnnounce.AccountID)
+ if err != nil {
+ return err
+ }
+ incomingAnnounce.Account = a
+ }
+
+ // do a BLOCKING get of the remote account to make sure the avi and header are cached
+ if incomingAnnounce.Account.Domain != "" {
+ remoteAccountID, err := url.Parse(incomingAnnounce.Account.URI)
+ if err != nil {
+ return err
+ }
+
+ a, err := p.federator.GetRemoteAccount(ctx, federatorMsg.ReceivingAccount.Username, remoteAccountID, true, false)
+ if err != nil {
+ return err
+ }
+
+ incomingAnnounce.Account = a
+ }
+
if err := p.federator.DereferenceAnnounce(ctx, incomingAnnounce, federatorMsg.ReceivingAccount.Username); err != nil {
return fmt.Errorf("error dereferencing announce from federator: %s", err)
}