diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go index d0c0e51fa..d50310ff8 100644 --- a/internal/typeutils/astointernal.go +++ b/internal/typeutils/astointernal.go @@ -30,7 +30,7 @@ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable ap.Accountable, update bool) (*gtsmodel.Account, error) { +func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable ap.Accountable, accountDomain string, update bool) (*gtsmodel.Account, error) { // first check if we actually already know this account uriProp := accountable.GetJSONLDId() if uriProp == nil || !uriProp.IsIRI() { @@ -63,7 +63,11 @@ func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable a acct.Username = username // Domain - acct.Domain = uri.Host + if accountDomain != "" { + acct.Domain = accountDomain + } else { + acct.Domain = uri.Host + } // avatar aka icon // if this one isn't extractable in a format we recognise we'll just skip it diff --git a/internal/typeutils/astointernal_test.go b/internal/typeutils/astointernal_test.go index 25fe0884a..dbd852d3f 100644 --- a/internal/typeutils/astointernal_test.go +++ b/internal/typeutils/astointernal_test.go @@ -38,7 +38,7 @@ type ASToInternalTestSuite struct { func (suite *ASToInternalTestSuite) TestParsePerson() { testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"] - acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, false) + acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, "", false) suite.NoError(err) suite.Equal("https://unknown-instance.com/users/brand_new_person", acct.URI) @@ -106,7 +106,7 @@ func (suite *ASToInternalTestSuite) TestParseGargron() { rep, ok := t.(ap.Accountable) suite.True(ok) - acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, false) + acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", false) suite.NoError(err) fmt.Printf("%+v", acct) @@ -168,7 +168,7 @@ func (suite *ASToInternalTestSuite) TestParseOwncastService() { rep, ok := t.(ap.Accountable) suite.True(ok) - acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, false) + acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", false) suite.NoError(err) suite.Equal("rgh", acct.Username) diff --git a/internal/typeutils/converter.go b/internal/typeutils/converter.go index cf1a9d487..b2f12a592 100644 --- a/internal/typeutils/converter.go +++ b/internal/typeutils/converter.go @@ -99,7 +99,10 @@ type TypeConverter interface { // If update is false, and the account is already known in the database, then the existing account entry will be returned. // If update is true, then even if the account is already known, all fields in the accountable will be parsed and a new *gtsmodel.Account // will be generated. This is useful when one needs to force refresh of an account, eg., during an Update of a Profile. - ASRepresentationToAccount(ctx context.Context, accountable ap.Accountable, update bool) (*gtsmodel.Account, error) + // + // If accountDomain is set (not an empty string) then this value will be used as the account's Domain. If not set, + // then the Host of the accountable's AP ID will be used instead. + ASRepresentationToAccount(ctx context.Context, accountable ap.Accountable, accountDomain string, update bool) (*gtsmodel.Account, error) // ASStatus converts a remote activitystreams 'status' representation into a gts model status. ASStatusToStatus(ctx context.Context, statusable ap.Statusable) (*gtsmodel.Status, error) // ASFollowToFollowRequest converts a remote activitystreams `follow` representation into gts model follow request.