use accountDomain

This commit is contained in:
tsmethurst 2022-05-31 16:57:32 +02:00
parent 8ffb1a8845
commit 124ff8ca0b
3 changed files with 13 additions and 6 deletions

View file

@ -30,7 +30,7 @@ import (
"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

View file

@ -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)

View file

@ -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.