summaryrefslogtreecommitdiff
path: root/internal/processing/account/update.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-03-22 14:03:46 +0100
committerLibravatar GitHub <noreply@github.com>2024-03-22 14:03:46 +0100
commit7f4a0a1aeb8a294ee967c63d7a48446df013ec44 (patch)
treeb9b3836fa0abe1d7a5758d07d6ebb6486a353d56 /internal/processing/account/update.go
parent[bugfix] add all possible busy result codes to the sqlite errBusy catching ch... (diff)
downloadgotosocial-7f4a0a1aeb8a294ee967c63d7a48446df013ec44.tar.xz
[chore] Move local account settings to separate db table (#2770)
* [chore] Move local account settings to separate database model * don't use separate settings_id
Diffstat (limited to 'internal/processing/account/update.go')
-rw-r--r--internal/processing/account/update.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go
index 5dc93fa1d..7b5561138 100644
--- a/internal/processing/account/update.go
+++ b/internal/processing/account/update.go
@@ -47,6 +47,11 @@ func (p *Processor) selectNoteFormatter(contentType string) text.FormatFunc {
// Update processes the update of an account with the given form.
func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, gtserror.WithCode) {
+ // Ensure account populated; we'll need settings.
+ if err := p.state.DB.PopulateAccount(ctx, account); err != nil {
+ log.Errorf(ctx, "error(s) populating account, will continue: %s", err)
+ }
+
if form.Discoverable != nil {
account.Discoverable = form.Discoverable
}
@@ -146,7 +151,7 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
}
// Format + set note according to user prefs.
- f := p.selectNoteFormatter(account.StatusContentType)
+ f := p.selectNoteFormatter(account.Settings.StatusContentType)
formatNoteResult := f(ctx, p.parseMention, account.ID, "", account.NoteRaw)
account.Note = formatNoteResult.HTML
@@ -227,11 +232,11 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
if err != nil {
return nil, gtserror.NewErrorBadRequest(err)
}
- account.Language = language
+ account.Settings.Language = language
}
if form.Source.Sensitive != nil {
- account.Sensitive = form.Source.Sensitive
+ account.Settings.Sensitive = form.Source.Sensitive
}
if form.Source.Privacy != nil {
@@ -239,7 +244,7 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorBadRequest(err)
}
privacy := typeutils.APIVisToVis(apimodel.Visibility(*form.Source.Privacy))
- account.Privacy = privacy
+ account.Settings.Privacy = privacy
}
if form.Source.StatusContentType != nil {
@@ -247,7 +252,7 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
- account.StatusContentType = *form.Source.StatusContentType
+ account.Settings.StatusContentType = *form.Source.StatusContentType
}
}
@@ -256,18 +261,21 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form
if err := validate.CustomCSS(customCSS); err != nil {
return nil, gtserror.NewErrorBadRequest(err, err.Error())
}
- account.CustomCSS = text.SanitizeToPlaintext(customCSS)
+ account.Settings.CustomCSS = text.SanitizeToPlaintext(customCSS)
}
if form.EnableRSS != nil {
- account.EnableRSS = form.EnableRSS
+ account.Settings.EnableRSS = form.EnableRSS
}
- err := p.state.DB.UpdateAccount(ctx, account)
- if err != nil {
+ if err := p.state.DB.UpdateAccount(ctx, account); err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("could not update account %s: %s", account.ID, err))
}
+ if err := p.state.DB.UpdateAccountSettings(ctx, account.Settings); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("could not update account settings %s: %s", account.ID, err))
+ }
+
p.state.Workers.EnqueueClientAPI(ctx, messages.FromClientAPI{
APObjectType: ap.ObjectProfile,
APActivityType: ap.ActivityUpdate,