[feature/frontend] Respect prefers-reduced-motion for avatars, headers, and emojis (#3118)

* [feature/frontend] Respect `prefers-reduced-motion` for avatars, headers, and emojis

* go fmt

* fix tests

* use static version of instance thumbnail when appropriate

* use prefers-reduced-motion

* simplify account conversion a bit

* fix c&p error
This commit is contained in:
tobi 2024-07-21 14:22:08 +02:00 committed by GitHub
commit 027a93facc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 435 additions and 140 deletions

View file

@ -762,6 +762,8 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() {
},
"thumbnail": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/attachment/original/`+instanceAccount.AvatarMediaAttachment.ID+`.gif",`+`
"thumbnail_type": "image/gif",
"thumbnail_static": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/attachment/small/`+instanceAccount.AvatarMediaAttachment.ID+`.webp",`+`
"thumbnail_static_type": "image/webp",
"thumbnail_description": "A bouncing little green peglin.",
"contact_account": {
"id": "01F8MH17FWEB39HZJ76B6VXSKF",
@ -818,6 +820,8 @@ func (suite *InstancePatchTestSuite) TestInstancePatch8() {
suite.Equal(`{
"url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/attachment/original/`+instanceAccount.AvatarMediaAttachment.ID+`.gif",`+`
"thumbnail_type": "image/gif",
"static_url": "http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/attachment/small/`+instanceAccount.AvatarMediaAttachment.ID+`.webp",`+`
"thumbnail_static_type": "image/webp",
"thumbnail_description": "A bouncing little green peglin.",
"blurhash": "LE9kG#M}4YtO%dRkWEt5Dmoxx?WC"
}`, string(instanceV2ThumbnailJson))

View file

@ -110,17 +110,27 @@ type Account struct {
// If set, indicates that this account is currently inactive, and has migrated to the given account.
// Key/value omitted for accounts that haven't moved, and for suspended accounts.
Moved *Account `json:"moved,omitempty"`
}
// Additional fields not exposed via JSON
// (used only internally for templating etc).
// WebAccount is like Account, but with
// additional fields not exposed via JSON;
// used only internally for templating etc.
//
// swagger:ignore
type WebAccount struct {
*Account
// Proper attachment model for the avatar.
//
// Only set if this model was converted via
// AccountToWebAccount, AND this account had
// an avatar set (and not just the default
// "blank" avatar image.)
AvatarAttachment *Attachment `json:"-"`
// Only set if this account had an avatar set
// (and not just the default "blank" image.)
AvatarAttachment *WebAttachment `json:"-"`
// Proper attachment model for the header.
//
// Only set if this account had a header set
// (and not just the default "blank" image.)
HeaderAttachment *WebAttachment `json:"-"`
}
// MutedAccount extends Account with a field used only by the muted user list.

View file

@ -107,6 +107,10 @@ type WebAttachment struct {
// MIME type of
// the attachment.
MIMEType string
// MIME type of
// the thumbnail.
PreviewMIMEType string
}
// MediaMeta models media metadata.

View file

@ -85,6 +85,12 @@ type InstanceV1 struct {
// MIME type of the instance thumbnail.
// example: image/png
ThumbnailType string `json:"thumbnail_type,omitempty"`
// URL of the static instance avatar/banner image.
// example: https://example.org/files/instance/static/thumbnail.webp
ThumbnailStatic string `json:"thumbnail_static,omitempty"`
// MIME type of the static instance thumbnail.
// example: image/webp
ThumbnailStaticType string `json:"thumbnail_static_type,omitempty"`
// Description of the instance thumbnail.
// example: picture of a cute lil' friendly sloth
ThumbnailDescription string `json:"thumbnail_description,omitempty"`

View file

@ -102,6 +102,13 @@ type InstanceV2Thumbnail struct {
// Key/value not set if thumbnail image type unknown.
// example: image/png
Type string `json:"thumbnail_type,omitempty"`
// StaticURL version of the thumbnail image.
// example: https://example.org/fileserver/01BPSX2MKCRVMD4YN4D71G9CP5/attachment/static/01H88X0KQ2DFYYDSWYP93VDJZA.webp
StaticURL string `json:"static_url,omitempty"`
// MIME type of the instance thumbnail.
// Key/value not set if thumbnail image type unknown.
// example: image/png
StaticType string `json:"thumbnail_static_type,omitempty"`
// Description of the instance thumbnail.
// Key/value not set if no description available.
// example: picture of a cute lil' friendly sloth

View file

@ -113,6 +113,9 @@ type Status struct {
type WebStatus struct {
*Status
// Override API account with web account.
Account *WebAccount `json:"account"`
// Web version of media
// attached to this status.
MediaAttachments []*WebAttachment `json:"media_attachments"`

View file

@ -84,7 +84,7 @@ func OGBase(instance *apimodel.InstanceV1) *OGMeta {
// WithAccount uses the given account to build an ogMeta
// struct specific to that account. It's suitable for serving
// at account profile pages.
func (og *OGMeta) WithAccount(account *apimodel.Account) *OGMeta {
func (og *OGMeta) WithAccount(account *apimodel.WebAccount) *OGMeta {
og.Title = AccountTitle(account, og.SiteName)
og.Type = "profile"
og.URL = account.URL
@ -148,7 +148,7 @@ func (og *OGMeta) WithStatus(status *apimodel.WebStatus) *OGMeta {
}
// AccountTitle parses a page title from account and accountDomain
func AccountTitle(account *apimodel.Account, accountDomain string) string {
func AccountTitle(account *apimodel.WebAccount, accountDomain string) string {
user := "@" + account.Acct + "@" + accountDomain
if len(account.DisplayName) == 0 {

View file

@ -51,13 +51,15 @@ func (suite *OpenGraphTestSuite) TestWithAccountWithNote() {
Languages: []string{"en"},
})
accountMeta := baseMeta.WithAccount(&apimodel.Account{
acct := &apimodel.Account{
Acct: "example_account",
DisplayName: "example person!!",
URL: "https://example.org/@example_account",
Note: "<p>This is my profile, read it and weep! Weep then!</p>",
Username: "example_account",
})
}
accountMeta := baseMeta.WithAccount(&apimodel.WebAccount{Account: acct})
suite.EqualValues(OGMeta{
Title: "example person!!, @example_account@example.org",
@ -84,13 +86,15 @@ func (suite *OpenGraphTestSuite) TestWithAccountNoNote() {
Languages: []string{"en"},
})
accountMeta := baseMeta.WithAccount(&apimodel.Account{
acct := &apimodel.Account{
Acct: "example_account",
DisplayName: "example person!!",
URL: "https://example.org/@example_account",
Note: "", // <- empty
Username: "example_account",
})
}
accountMeta := baseMeta.WithAccount(&apimodel.WebAccount{Account: acct})
suite.EqualValues(OGMeta{
Title: "example person!!, @example_account@example.org",