[feature] User-selectable preset CSS themes for accounts (#2777)

* [feature] User-selectable preset themes

* docs, more theme stuff

* lint, tests

* fix css name

* correct some little issues

* add another theme

* fix poll background

* okay last theme i swear

* make retrieval of apimodel themes more conventional

* preallocate stylesheet slices
This commit is contained in:
tobi
2024-03-25 18:32:24 +01:00
committed by GitHub
parent b7b42e832a
commit 8953f57d88
32 changed files with 1230 additions and 28 deletions

View File

@ -170,12 +170,13 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
// Bits that vary between remote + local accounts:
// - Account (acct) string.
// - Role.
// - Settings things (enableRSS, customCSS).
// - Settings things (enableRSS, theme, customCSS).
var (
acct string
role *apimodel.AccountRole
enableRSS bool
theme string
customCSS string
)
@ -208,6 +209,7 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
}
enableRSS = *a.Settings.EnableRSS
theme = a.Settings.Theme
customCSS = a.Settings.CustomCSS
}
@ -272,6 +274,7 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A
Emojis: apiEmojis,
Fields: fields,
Suspended: !a.SuspendedAt.IsZero(),
Theme: theme,
CustomCSS: customCSS,
EnableRSS: enableRSS,
Role: role,
@ -1771,3 +1774,16 @@ func (c *Converter) convertTagsToAPITags(ctx context.Context, tags []*gtsmodel.T
return apiTags, errs.Combine()
}
// ThemesToAPIThemes converts a slice of gtsmodel Themes into apimodel Themes.
func (c *Converter) ThemesToAPIThemes(themes []*gtsmodel.Theme) []apimodel.Theme {
apiThemes := make([]apimodel.Theme, len(themes))
for i, theme := range themes {
apiThemes[i] = apimodel.Theme{
Title: theme.Title,
Description: theme.Description,
FileName: theme.FileName,
}
}
return apiThemes
}