diff --git a/internal/api/client/account/accountverify_test.go b/internal/api/client/account/accountverify_test.go index 1b5989704..b5dfdd5e8 100644 --- a/internal/api/client/account/accountverify_test.go +++ b/internal/api/client/account/accountverify_test.go @@ -67,7 +67,7 @@ func (suite *AccountVerifyTestSuite) TestAccountVerifyGet() { suite.NoError(err) lastStatusAt, err := time.Parse(time.RFC3339, apimodelAccount.LastStatusAt) suite.NoError(err) -aaaaaaaaaaaaaaaaaaa + suite.Equal(testAccount.ID, apimodelAccount.ID) suite.Equal(testAccount.Username, apimodelAccount.Username) suite.Equal(testAccount.Username, apimodelAccount.Acct) diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go index b3aaafff0..8e28bf0f0 100644 --- a/internal/typeutils/internaltoas.go +++ b/internal/typeutils/internaltoas.go @@ -215,62 +215,64 @@ func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab // Used as profile avatar. if a.AvatarMediaAttachmentID != "" { if a.AvatarMediaAttachment == nil { - avatar := >smodel.MediaAttachment{} - if err := c.db.GetByID(ctx, a.AvatarMediaAttachmentID, avatar); err != nil { + avatar, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID) + if err == nil { + a.AvatarMediaAttachment = avatar + } + } + + if a.AvatarMediaAttachment != nil { + iconProperty := streams.NewActivityStreamsIconProperty() + + iconImage := streams.NewActivityStreamsImage() + + mediaType := streams.NewActivityStreamsMediaTypeProperty() + mediaType.Set(a.AvatarMediaAttachment.File.ContentType) + iconImage.SetActivityStreamsMediaType(mediaType) + + avatarURLProperty := streams.NewActivityStreamsUrlProperty() + avatarURL, err := url.Parse(a.AvatarMediaAttachment.URL) + if err != nil { return nil, err } - a.AvatarMediaAttachment = avatar + avatarURLProperty.AppendIRI(avatarURL) + iconImage.SetActivityStreamsUrl(avatarURLProperty) + + iconProperty.AppendActivityStreamsImage(iconImage) + person.SetActivityStreamsIcon(iconProperty) } - - iconProperty := streams.NewActivityStreamsIconProperty() - - iconImage := streams.NewActivityStreamsImage() - - mediaType := streams.NewActivityStreamsMediaTypeProperty() - mediaType.Set(a.AvatarMediaAttachment.File.ContentType) - iconImage.SetActivityStreamsMediaType(mediaType) - - avatarURLProperty := streams.NewActivityStreamsUrlProperty() - avatarURL, err := url.Parse(a.AvatarMediaAttachment.URL) - if err != nil { - return nil, err - } - avatarURLProperty.AppendIRI(avatarURL) - iconImage.SetActivityStreamsUrl(avatarURLProperty) - - iconProperty.AppendActivityStreamsImage(iconImage) - person.SetActivityStreamsIcon(iconProperty) } // image // Used as profile header. if a.HeaderMediaAttachmentID != "" { if a.HeaderMediaAttachment == nil { - header := >smodel.MediaAttachment{} - if err := c.db.GetByID(ctx, a.HeaderMediaAttachmentID, header); err != nil { + header, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID) + if err == nil { + a.HeaderMediaAttachment = header + } + } + + if a.HeaderMediaAttachment != nil { + headerProperty := streams.NewActivityStreamsImageProperty() + + headerImage := streams.NewActivityStreamsImage() + + mediaType := streams.NewActivityStreamsMediaTypeProperty() + mediaType.Set(a.HeaderMediaAttachment.File.ContentType) + headerImage.SetActivityStreamsMediaType(mediaType) + + headerURLProperty := streams.NewActivityStreamsUrlProperty() + headerURL, err := url.Parse(a.HeaderMediaAttachment.URL) + if err != nil { return nil, err } - a.HeaderMediaAttachment = header + headerURLProperty.AppendIRI(headerURL) + headerImage.SetActivityStreamsUrl(headerURLProperty) + + headerProperty.AppendActivityStreamsImage(headerImage) + person.SetActivityStreamsImage(headerProperty) } - - headerProperty := streams.NewActivityStreamsImageProperty() - - headerImage := streams.NewActivityStreamsImage() - - mediaType := streams.NewActivityStreamsMediaTypeProperty() - mediaType.Set(a.HeaderMediaAttachment.File.ContentType) - headerImage.SetActivityStreamsMediaType(mediaType) - - headerURLProperty := streams.NewActivityStreamsUrlProperty() - headerURL, err := url.Parse(a.HeaderMediaAttachment.URL) - if err != nil { - return nil, err - } - headerURLProperty.AppendIRI(headerURL) - headerImage.SetActivityStreamsUrl(headerURLProperty) - - headerProperty.AppendActivityStreamsImage(headerImage) - person.SetActivityStreamsImage(headerProperty) } return person, nil diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 52e89b7d2..989bf4a1e 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -104,10 +104,12 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A avi, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID) if err == nil { a.AvatarMediaAttachment = avi - aviURL = a.AvatarMediaAttachment.URL - aviURLStatic = a.AvatarMediaAttachment.Thumbnail.URL } } + if a.AvatarMediaAttachment != nil { + aviURL = a.AvatarMediaAttachment.URL + aviURLStatic = a.AvatarMediaAttachment.Thumbnail.URL + } } // set account header fields if available @@ -118,10 +120,12 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A avi, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID) if err == nil { a.HeaderMediaAttachment = avi - headerURL = a.HeaderMediaAttachment.URL - headerURLStatic = a.HeaderMediaAttachment.Thumbnail.URL } } + if a.HeaderMediaAttachment != nil { + headerURL = a.HeaderMediaAttachment.URL + headerURLStatic = a.HeaderMediaAttachment.Thumbnail.URL + } } // get the fields set on this account