diff options
author | 2021-08-10 16:56:59 +0200 | |
---|---|---|
committer | 2021-08-10 16:56:59 +0200 | |
commit | 6acd410426f2f8941a0dbec4bfe07c2a94ce62b7 (patch) | |
tree | dbae658794d294c845640b9244b061cbbf11d94f /internal/federation | |
parent | roll back to sha256 for signatures (diff) | |
download | gotosocial-6acd410426f2f8941a0dbec4bfe07c2a94ce62b7.tar.xz |
Bugfixerino (#133)
* fix some lil bugs
* fmt, lint
Diffstat (limited to 'internal/federation')
-rw-r--r-- | internal/federation/dereference.go | 4 | ||||
-rw-r--r-- | internal/federation/dereferencing/account.go | 18 | ||||
-rw-r--r-- | internal/federation/federator.go | 1 |
3 files changed, 14 insertions, 9 deletions
diff --git a/internal/federation/dereference.go b/internal/federation/dereference.go index 8975d6c0c..07901d5b1 100644 --- a/internal/federation/dereference.go +++ b/internal/federation/dereference.go @@ -11,6 +11,10 @@ func (f *federator) GetRemoteAccount(username string, remoteAccountID *url.URL, return f.dereferencer.GetRemoteAccount(username, remoteAccountID, refresh) } +func (f *federator) EnrichRemoteAccount(username string, account *gtsmodel.Account) (*gtsmodel.Account, error) { + return f.dereferencer.EnrichRemoteAccount(username, account) +} + func (f *federator) GetRemoteStatus(username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error) { return f.dereferencer.GetRemoteStatus(username, remoteStatusID, refresh) } diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go index c403ec66f..72d2e44d7 100644 --- a/internal/federation/dereferencing/account.go +++ b/internal/federation/dereferencing/account.go @@ -41,7 +41,7 @@ import ( // EnrichRemoteAccount is mostly useful for calling after an account has been initially created by // the federatingDB's Create function, or during the federated authorization flow. func (d *deref) EnrichRemoteAccount(username string, account *gtsmodel.Account) (*gtsmodel.Account, error) { - if err := d.populateAccountFields(account, username, false); err != nil { + if err := d.PopulateAccountFields(account, username, false); err != nil { return nil, err } @@ -69,10 +69,10 @@ func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refr if err := d.db.GetWhere([]db.Where{{Key: "uri", Value: remoteAccountID.String()}}, maybeAccount); err == nil { // we've seen this account before so it's not new new = false - - // if we're not being asked to refresh, we can just return the maybeAccount as-is and avoid doing any external calls if !refresh { - return maybeAccount, new, nil + // we're not being asked to refresh, but just in case we don't have the avatar/header cached yet.... + maybeAccount, err = d.EnrichRemoteAccount(username, maybeAccount) + return maybeAccount, new, err } } @@ -81,7 +81,7 @@ func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refr return nil, new, fmt.Errorf("FullyDereferenceAccount: error dereferencing accountable: %s", err) } - gtsAccount, err := d.typeConverter.ASRepresentationToAccount(accountable, false) + gtsAccount, err := d.typeConverter.ASRepresentationToAccount(accountable, refresh) if err != nil { return nil, new, fmt.Errorf("FullyDereferenceAccount: error converting accountable to account: %s", err) } @@ -94,7 +94,7 @@ func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refr } gtsAccount.ID = ulid - if err := d.populateAccountFields(gtsAccount, username, refresh); err != nil { + if err := d.PopulateAccountFields(gtsAccount, username, refresh); err != nil { return nil, new, fmt.Errorf("FullyDereferenceAccount: error populating further account fields: %s", err) } @@ -105,7 +105,7 @@ func (d *deref) GetRemoteAccount(username string, remoteAccountID *url.URL, refr // take the id we already have and do an update gtsAccount.ID = maybeAccount.ID - if err := d.populateAccountFields(gtsAccount, username, refresh); err != nil { + if err := d.PopulateAccountFields(gtsAccount, username, refresh); err != nil { return nil, new, fmt.Errorf("FullyDereferenceAccount: error populating further account fields: %s", err) } @@ -173,9 +173,9 @@ func (d *deref) dereferenceAccountable(username string, remoteAccountID *url.URL return nil, fmt.Errorf("DereferenceAccountable: type name %s not supported", t.GetTypeName()) } -// populateAccountFields populates any fields on the given account that weren't populated by the initial +// PopulateAccountFields populates any fields on the given account that weren't populated by the initial // dereferencing. This includes things like header and avatar etc. -func (d *deref) populateAccountFields(account *gtsmodel.Account, requestingUsername string, refresh bool) error { +func (d *deref) PopulateAccountFields(account *gtsmodel.Account, requestingUsername string, refresh bool) error { l := d.log.WithFields(logrus.Fields{ "func": "PopulateAccountFields", "requestingUsername": requestingUsername, diff --git a/internal/federation/federator.go b/internal/federation/federator.go index ea9e61831..1b5f5441a 100644 --- a/internal/federation/federator.go +++ b/internal/federation/federator.go @@ -60,6 +60,7 @@ type Federator interface { DereferenceAnnounce(announce *gtsmodel.Status, requestingUsername string) error GetRemoteAccount(username string, remoteAccountID *url.URL, refresh bool) (*gtsmodel.Account, bool, error) + EnrichRemoteAccount(username string, account *gtsmodel.Account) (*gtsmodel.Account, error) GetRemoteStatus(username string, remoteStatusID *url.URL, refresh bool) (*gtsmodel.Status, ap.Statusable, bool, error) EnrichRemoteStatus(username string, status *gtsmodel.Status) (*gtsmodel.Status, error) |