mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 15:32:24 -05: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) | 	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,62 +215,64 @@ 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 { | ||||||
|  | 				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 | 				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 | 	// 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 { | ||||||
|  | 				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 | 				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 | 	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) | 			avi, err := c.db.GetAttachmentByID(ctx, a.AvatarMediaAttachmentID) | ||||||
| 			if err == nil { | 			if err == nil { | ||||||
| 				a.AvatarMediaAttachment = avi | 				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 | 	// 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) | 			avi, err := c.db.GetAttachmentByID(ctx, a.HeaderMediaAttachmentID) | ||||||
| 			if err == nil { | 			if err == nil { | ||||||
| 				a.HeaderMediaAttachment = avi | 				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 | 	// get the fields set on this account | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue