From 8953f57d887c060c3b58f83c38d2010d27a45ef3 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:32:24 +0100 Subject: [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 --- internal/typeutils/internaltofrontend.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'internal/typeutils/internaltofrontend.go') diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 0ff3c2268..bf44c7254 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -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 +} -- cgit v1.2.3