diff options
author | 2022-01-25 13:48:13 +0100 | |
---|---|---|
committer | 2022-01-25 13:48:13 +0100 | |
commit | c156602c6679224fe48b325674022f768aa74d27 (patch) | |
tree | 2cdda8f0bec6c5dbab63185eb241874b0cf1d1a3 /internal/processing/fromfederator.go | |
parent | fix up some account conversion logic (diff) | |
download | gotosocial-c156602c6679224fe48b325674022f768aa74d27.tar.xz |
ensure blocking calls to getRemoteAccount before showing stuff to client
Diffstat (limited to 'internal/processing/fromfederator.go')
-rw-r--r-- | internal/processing/fromfederator.go | 101 |
1 files changed, 98 insertions, 3 deletions
diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go index 8b575dda8..3514614b5 100644 --- 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) } |