diff options
author | 2024-01-19 14:02:04 +0100 | |
---|---|---|
committer | 2024-01-19 13:02:04 +0000 | |
commit | 5ca86b1c575f9c42ad8d3d4a2b2d3e70c89e90df (patch) | |
tree | 3ac7578cd35b9c2f1dfb3903ef769d32f9c58d3d /internal/typeutils/internaltofrontend.go | |
parent | [performance] overhaul struct (+ result) caching library for simplicity, perf... (diff) | |
download | gotosocial-5ca86b1c575f9c42ad8d3d4a2b2d3e70c89e90df.tar.xz |
[chore] Harden up boolptr logic on Accounts, warn if not set (#2544)
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 941b9e866..ed2979049 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -217,6 +217,31 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A } } + // Bool ptrs should be set, but warn + // and use a default if they're not. + var boolPtrDef = func( + pName string, + p *bool, + d bool, + ) bool { + if p != nil { + return *p + } + + log.Warnf(ctx, + "%s ptr was nil, using default %t", + pName, d, + ) + return d + } + + var ( + locked = boolPtrDef("locked", a.Locked, true) + discoverable = boolPtrDef("discoverable", a.Discoverable, false) + bot = boolPtrDef("bot", a.Bot, false) + enableRSS = boolPtrDef("enableRSS", a.EnableRSS, false) + ) + // Remaining properties are simple and // can be populated directly below. @@ -225,9 +250,9 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A Username: a.Username, Acct: acct, DisplayName: a.DisplayName, - Locked: *a.Locked, - Discoverable: *a.Discoverable, - Bot: *a.Bot, + Locked: locked, + Discoverable: discoverable, + Bot: bot, CreatedAt: util.FormatISO8601(a.CreatedAt), Note: a.Note, URL: a.URL, @@ -243,7 +268,7 @@ func (c *Converter) AccountToAPIAccountPublic(ctx context.Context, a *gtsmodel.A Fields: fields, Suspended: !a.SuspendedAt.IsZero(), CustomCSS: a.CustomCSS, - EnableRSS: *a.EnableRSS, + EnableRSS: enableRSS, Role: role, Moved: moved, } |