mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-11-14 00:37:18 +00:00
fix up some account conversion logic
This commit is contained in:
parent
eba66d3a88
commit
5d9e9e0e7f
3 changed files with 55 additions and 49 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue