commit 5d9e9e0e7f7e026677e843a5897283faecfb2874
parent eba66d3a88880d3a4023ecb57f0ad410426f3bc1
Author: tsmethurst <tobi.smethurst@protonmail.com>
Date: Tue, 25 Jan 2022 12:03:25 +0100
fix up some account conversion logic
Diffstat:
3 files changed, 47 insertions(+), 41 deletions(-)
diff --git 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
@@ -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 {
- return nil, err
+ avatar, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID)
+ if err == nil {
+ a.AvatarMediaAttachment = avatar
}
- a.AvatarMediaAttachment = avatar
}
- iconProperty := streams.NewActivityStreamsIconProperty()
+ if a.AvatarMediaAttachment != nil {
+ iconProperty := streams.NewActivityStreamsIconProperty()
- iconImage := streams.NewActivityStreamsImage()
+ iconImage := streams.NewActivityStreamsImage()
- mediaType := streams.NewActivityStreamsMediaTypeProperty()
- mediaType.Set(a.AvatarMediaAttachment.File.ContentType)
- iconImage.SetActivityStreamsMediaType(mediaType)
+ 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)
+ 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)
+ 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 {
- return nil, err
+ header, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID)
+ if err == nil {
+ a.HeaderMediaAttachment = header
}
- a.HeaderMediaAttachment = header
}
- headerProperty := streams.NewActivityStreamsImageProperty()
+ if a.HeaderMediaAttachment != nil {
+ headerProperty := streams.NewActivityStreamsImageProperty()
- headerImage := streams.NewActivityStreamsImage()
+ headerImage := streams.NewActivityStreamsImage()
- mediaType := streams.NewActivityStreamsMediaTypeProperty()
- mediaType.Set(a.HeaderMediaAttachment.File.ContentType)
- headerImage.SetActivityStreamsMediaType(mediaType)
+ 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)
+ 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)
+ headerProperty.AppendActivityStreamsImage(headerImage)
+ person.SetActivityStreamsImage(headerProperty)
+ }
}
return person, nil
diff --git 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