forked from mirrors/gotosocial
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)
|
suite.NoError(err)
|
||||||
lastStatusAt, err := time.Parse(time.RFC3339, apimodelAccount.LastStatusAt)
|
lastStatusAt, err := time.Parse(time.RFC3339, apimodelAccount.LastStatusAt)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
aaaaaaaaaaaaaaaaaaa
|
|
||||||
suite.Equal(testAccount.ID, apimodelAccount.ID)
|
suite.Equal(testAccount.ID, apimodelAccount.ID)
|
||||||
suite.Equal(testAccount.Username, apimodelAccount.Username)
|
suite.Equal(testAccount.Username, apimodelAccount.Username)
|
||||||
suite.Equal(testAccount.Username, apimodelAccount.Acct)
|
suite.Equal(testAccount.Username, apimodelAccount.Acct)
|
||||||
|
|
|
@ -215,13 +215,13 @@ func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab
|
||||||
// Used as profile avatar.
|
// Used as profile avatar.
|
||||||
if a.AvatarMediaAttachmentID != "" {
|
if a.AvatarMediaAttachmentID != "" {
|
||||||
if a.AvatarMediaAttachment == nil {
|
if a.AvatarMediaAttachment == nil {
|
||||||
avatar := >smodel.MediaAttachment{}
|
avatar, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID)
|
||||||
if err := c.db.GetByID(ctx, a.AvatarMediaAttachmentID, avatar); err != nil {
|
if err == nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
a.AvatarMediaAttachment = avatar
|
a.AvatarMediaAttachment = avatar
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.AvatarMediaAttachment != nil {
|
||||||
iconProperty := streams.NewActivityStreamsIconProperty()
|
iconProperty := streams.NewActivityStreamsIconProperty()
|
||||||
|
|
||||||
iconImage := streams.NewActivityStreamsImage()
|
iconImage := streams.NewActivityStreamsImage()
|
||||||
|
@ -241,18 +241,19 @@ func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab
|
||||||
iconProperty.AppendActivityStreamsImage(iconImage)
|
iconProperty.AppendActivityStreamsImage(iconImage)
|
||||||
person.SetActivityStreamsIcon(iconProperty)
|
person.SetActivityStreamsIcon(iconProperty)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// image
|
// image
|
||||||
// Used as profile header.
|
// Used as profile header.
|
||||||
if a.HeaderMediaAttachmentID != "" {
|
if a.HeaderMediaAttachmentID != "" {
|
||||||
if a.HeaderMediaAttachment == nil {
|
if a.HeaderMediaAttachment == nil {
|
||||||
header := >smodel.MediaAttachment{}
|
header, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID)
|
||||||
if err := c.db.GetByID(ctx, a.HeaderMediaAttachmentID, header); err != nil {
|
if err == nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
a.HeaderMediaAttachment = header
|
a.HeaderMediaAttachment = header
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.HeaderMediaAttachment != nil {
|
||||||
headerProperty := streams.NewActivityStreamsImageProperty()
|
headerProperty := streams.NewActivityStreamsImageProperty()
|
||||||
|
|
||||||
headerImage := streams.NewActivityStreamsImage()
|
headerImage := streams.NewActivityStreamsImage()
|
||||||
|
@ -272,6 +273,7 @@ func (c *converter) AccountToAS(ctx context.Context, a *gtsmodel.Account) (vocab
|
||||||
headerProperty.AppendActivityStreamsImage(headerImage)
|
headerProperty.AppendActivityStreamsImage(headerImage)
|
||||||
person.SetActivityStreamsImage(headerProperty)
|
person.SetActivityStreamsImage(headerProperty)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return person, nil
|
return person, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,11 +104,13 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
|
||||||
avi, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID)
|
avi, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
a.AvatarMediaAttachment = avi
|
a.AvatarMediaAttachment = avi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if a.AvatarMediaAttachment != nil {
|
||||||
aviURL = a.AvatarMediaAttachment.URL
|
aviURL = a.AvatarMediaAttachment.URL
|
||||||
aviURLStatic = a.AvatarMediaAttachment.Thumbnail.URL
|
aviURLStatic = a.AvatarMediaAttachment.Thumbnail.URL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// set account header fields if available
|
// set account header fields if available
|
||||||
var headerURL string
|
var headerURL string
|
||||||
|
@ -118,11 +120,13 @@ func (c *converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
|
||||||
avi, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID)
|
avi, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
a.HeaderMediaAttachment = avi
|
a.HeaderMediaAttachment = avi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if a.HeaderMediaAttachment != nil {
|
||||||
headerURL = a.HeaderMediaAttachment.URL
|
headerURL = a.HeaderMediaAttachment.URL
|
||||||
headerURLStatic = a.HeaderMediaAttachment.Thumbnail.URL
|
headerURLStatic = a.HeaderMediaAttachment.Thumbnail.URL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// get the fields set on this account
|
// get the fields set on this account
|
||||||
fields := []model.Field{}
|
fields := []model.Field{}
|
||||||
|
|
Loading…
Reference in a new issue