mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-24 01:11:00 +00:00
[bugfix] Use null for empty api status language
(#1268)
* [bugfix] Use null for empty api status `language` * update swagger docs
This commit is contained in:
parent
bae73982f7
commit
1d24c1c283
5 changed files with 31 additions and 5 deletions
|
@ -1575,7 +1575,9 @@ definitions:
|
|||
type: string
|
||||
x-go-name: InReplyToID
|
||||
language:
|
||||
description: Primary language of this status (ISO 639 Part 1 two-letter language code).
|
||||
description: |-
|
||||
Primary language of this status (ISO 639 Part 1 two-letter language code).
|
||||
Will be null if language is not known.
|
||||
example: en
|
||||
type: string
|
||||
x-go-name: Language
|
||||
|
@ -1802,7 +1804,9 @@ definitions:
|
|||
type: string
|
||||
x-go-name: InReplyToID
|
||||
language:
|
||||
description: Primary language of this status (ISO 639 Part 1 two-letter language code).
|
||||
description: |-
|
||||
Primary language of this status (ISO 639 Part 1 two-letter language code).
|
||||
Will be null if language is not known.
|
||||
example: en
|
||||
type: string
|
||||
x-go-name: Language
|
||||
|
|
|
@ -46,8 +46,9 @@ type Status struct {
|
|||
// example: unlisted
|
||||
Visibility Visibility `json:"visibility"`
|
||||
// Primary language of this status (ISO 639 Part 1 two-letter language code).
|
||||
// Will be null if language is not known.
|
||||
// example: en
|
||||
Language string `json:"language"`
|
||||
Language *string `json:"language"`
|
||||
// ActivityPub URI of the status. Equivalent to the status's activitypub ID.
|
||||
// example: https://example.org/users/some_user/statuses/01FBVD42CQ3ZEEVMW180SBX03B
|
||||
URI string `json:"uri"`
|
||||
|
|
|
@ -508,6 +508,11 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
interacts = &statusInteractions{}
|
||||
}
|
||||
|
||||
var language *string
|
||||
if s.Language != "" {
|
||||
language = &s.Language
|
||||
}
|
||||
|
||||
apiStatus := &model.Status{
|
||||
ID: s.ID,
|
||||
CreatedAt: util.FormatISO8601(s.CreatedAt),
|
||||
|
@ -516,7 +521,7 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
Sensitive: *s.Sensitive,
|
||||
SpoilerText: s.ContentWarning,
|
||||
Visibility: c.VisToAPIVis(ctx, s.Visibility),
|
||||
Language: s.Language,
|
||||
Language: language,
|
||||
URI: s.URI,
|
||||
URL: s.URL,
|
||||
RepliesCount: repliesCount,
|
||||
|
|
|
@ -96,6 +96,20 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontend() {
|
|||
suite.Equal(`{"id":"01F8MH75CBF9JFX4ZAD54N0W0R","created_at":"2021-10-20T11:36:45.000Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R","url":"http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R","replies_count":0,"reblogs_count":0,"favourites_count":1,"favourited":true,"reblogged":false,"muted":false,"bookmarked":true,"pinned":false,"content":"hello world! #welcome ! first post on the instance :rainbow: !","reblog":null,"application":{"name":"superseriousbusiness","website":"https://superserious.business"},"account":{"id":"01F8MH17FWEB39HZJ76B6VXSKF","username":"admin","acct":"admin","display_name":"","locked":false,"bot":false,"created_at":"2022-05-17T13:10:59.000Z","note":"","url":"http://localhost:8080/@admin","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":1,"following_count":1,"statuses_count":4,"last_status_at":"2021-10-20T10:41:37.000Z","emojis":[],"fields":[],"enable_rss":true,"role":"admin"},"media_attachments":[{"id":"01F8MH6NEM8D7527KZAECTCR76","type":"image","url":"http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpeg","text_url":"http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpeg","preview_url":"http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/small/01F8MH6NEM8D7527KZAECTCR76.jpeg","remote_url":null,"preview_remote_url":null,"meta":{"original":{"width":1200,"height":630,"size":"1200x630","aspect":1.9047619},"small":{"width":256,"height":134,"size":"256x134","aspect":1.9104477},"focus":{"x":0,"y":0}},"description":"Black and white image of some 50's style text saying: Welcome On Board","blurhash":"LNJRdVM{00Rj%Mayt7j[4nWBofRj"}],"mentions":[],"tags":[{"name":"welcome","url":"http://localhost:8080/tags/welcome"}],"emojis":[{"shortcode":"rainbow","url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","static_url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","visible_in_picker":true,"category":"reactions"}],"card":null,"poll":null,"text":"hello world! #welcome ! first post on the instance :rainbow: !"}`, string(b))
|
||||
}
|
||||
|
||||
func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownLanguage() {
|
||||
testStatus := >smodel.Status{}
|
||||
*testStatus = *suite.testStatuses["admin_account_status_1"]
|
||||
testStatus.Language = ""
|
||||
requestingAccount := suite.testAccounts["local_account_1"]
|
||||
apiStatus, err := suite.typeconverter.StatusToAPIStatus(context.Background(), testStatus, requestingAccount)
|
||||
suite.NoError(err)
|
||||
|
||||
b, err := json.Marshal(apiStatus)
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(`{"id":"01F8MH75CBF9JFX4ZAD54N0W0R","created_at":"2021-10-20T11:36:45.000Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":null,"uri":"http://localhost:8080/users/admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R","url":"http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R","replies_count":0,"reblogs_count":0,"favourites_count":1,"favourited":true,"reblogged":false,"muted":false,"bookmarked":true,"pinned":false,"content":"hello world! #welcome ! first post on the instance :rainbow: !","reblog":null,"application":{"name":"superseriousbusiness","website":"https://superserious.business"},"account":{"id":"01F8MH17FWEB39HZJ76B6VXSKF","username":"admin","acct":"admin","display_name":"","locked":false,"bot":false,"created_at":"2022-05-17T13:10:59.000Z","note":"","url":"http://localhost:8080/@admin","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":1,"following_count":1,"statuses_count":4,"last_status_at":"2021-10-20T10:41:37.000Z","emojis":[],"fields":[],"enable_rss":true,"role":"admin"},"media_attachments":[{"id":"01F8MH6NEM8D7527KZAECTCR76","type":"image","url":"http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpeg","text_url":"http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpeg","preview_url":"http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/small/01F8MH6NEM8D7527KZAECTCR76.jpeg","remote_url":null,"preview_remote_url":null,"meta":{"original":{"width":1200,"height":630,"size":"1200x630","aspect":1.9047619},"small":{"width":256,"height":134,"size":"256x134","aspect":1.9104477},"focus":{"x":0,"y":0}},"description":"Black and white image of some 50's style text saying: Welcome On Board","blurhash":"LNJRdVM{00Rj%Mayt7j[4nWBofRj"}],"mentions":[],"tags":[{"name":"welcome","url":"http://localhost:8080/tags/welcome"}],"emojis":[{"shortcode":"rainbow","url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","static_url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/static/01F8MH9H8E4VG3KDYJR9EGPXCQ.png","visible_in_picker":true,"category":"reactions"}],"card":null,"poll":null,"text":"hello world! #welcome ! first post on the instance :rainbow: !"}`, string(b))
|
||||
}
|
||||
|
||||
func (suite *InternalToFrontendTestSuite) TestInstanceToFrontend() {
|
||||
testInstance := >smodel.Instance{
|
||||
CreatedAt: testrig.TimeMustParse("2021-10-20T11:36:45Z"),
|
||||
|
|
|
@ -107,7 +107,9 @@ func (og *ogMeta) withStatus(status *apimodel.Status) *ogMeta {
|
|||
og.Description = parseDescription(status.Text)
|
||||
}
|
||||
|
||||
og.Locale = status.Language
|
||||
if status.Language != nil {
|
||||
og.Locale = *status.Language
|
||||
}
|
||||
og.ResourceType = "article"
|
||||
og.Title = "Post by " + parseTitle(status.Account, og.SiteName)
|
||||
og.URL = status.URL
|
||||
|
|
Loading…
Reference in a new issue