diff options
author | 2024-03-22 14:03:46 +0100 | |
---|---|---|
committer | 2024-03-22 14:03:46 +0100 | |
commit | 7f4a0a1aeb8a294ee967c63d7a48446df013ec44 (patch) | |
tree | b9b3836fa0abe1d7a5758d07d6ebb6486a353d56 /internal/processing/account | |
parent | [bugfix] add all possible busy result codes to the sqlite errBusy catching ch... (diff) | |
download | gotosocial-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')
-rw-r--r-- | internal/processing/account/delete.go | 10 | ||||
-rw-r--r-- | internal/processing/account/delete_test.go | 5 | ||||
-rw-r--r-- | internal/processing/account/rss.go | 2 | ||||
-rw-r--r-- | internal/processing/account/update.go | 26 | ||||
-rw-r--r-- | internal/processing/account/update_test.go | 10 |
5 files changed, 26 insertions, 27 deletions
diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go index ff68a4638..2ae00194e 100644 --- a/internal/processing/account/delete.go +++ b/internal/processing/account/delete.go @@ -518,14 +518,9 @@ func stubbifyAccount(account *gtsmodel.Account, origin string) []string { account.Memorial = util.Ptr(false) account.AlsoKnownAsURIs = nil account.MovedToURI = "" - account.Reason = "" account.Discoverable = util.Ptr(false) - account.StatusContentType = "" - account.CustomCSS = "" account.SuspendedAt = now account.SuspensionOrigin = origin - account.HideCollections = util.Ptr(true) - account.EnableRSS = util.Ptr(false) return []string{ "fetched_at", @@ -541,14 +536,9 @@ func stubbifyAccount(account *gtsmodel.Account, origin string) []string { "memorial", "also_known_as_uris", "moved_to_uri", - "reason", "discoverable", - "status_content_type", - "custom_css", "suspended_at", "suspension_origin", - "hide_collections", - "enable_rss", } } diff --git a/internal/processing/account/delete_test.go b/internal/processing/account/delete_test.go index 95df3cec5..de7c8e08c 100644 --- a/internal/processing/account/delete_test.go +++ b/internal/processing/account/delete_test.go @@ -66,14 +66,9 @@ func (suite *AccountDeleteTestSuite) TestAccountDeleteLocal() { suite.Zero(updatedAccount.NoteRaw) suite.False(*updatedAccount.Memorial) suite.Empty(updatedAccount.AlsoKnownAsURIs) - suite.Zero(updatedAccount.Reason) suite.False(*updatedAccount.Discoverable) - suite.Zero(updatedAccount.StatusContentType) - suite.Zero(updatedAccount.CustomCSS) suite.WithinDuration(time.Now(), updatedAccount.SuspendedAt, 1*time.Minute) suite.Equal(suspensionOrigin, updatedAccount.SuspensionOrigin) - suite.True(*updatedAccount.HideCollections) - suite.False(*updatedAccount.EnableRSS) updatedUser, err := suite.db.GetUserByAccountID(ctx, testAccount.ID) if err != nil { diff --git a/internal/processing/account/rss.go b/internal/processing/account/rss.go index df49af21f..f2c6cba5e 100644 --- a/internal/processing/account/rss.go +++ b/internal/processing/account/rss.go @@ -64,7 +64,7 @@ func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string) } // Ensure account has rss feed enabled. - if !*account.EnableRSS { + if !*account.Settings.EnableRSS { err = gtserror.New("account RSS feed not enabled") return nil, never, gtserror.NewErrorNotFound(err) } 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, diff --git a/internal/processing/account/update_test.go b/internal/processing/account/update_test.go index 87b4ebd50..76ad3abe8 100644 --- a/internal/processing/account/update_test.go +++ b/internal/processing/account/update_test.go @@ -126,9 +126,15 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMention() { } func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMarkdownNote() { + // Copy zork. testAccount := >smodel.Account{} *testAccount = *suite.testAccounts["local_account_1"] + // Copy zork's settings. + settings := >smodel.AccountSettings{} + *settings = *suite.testAccounts["local_account_1"].Settings + testAccount.Settings = settings + var ( ctx = context.Background() note = "*hello* ~~here~~ i am!" @@ -136,8 +142,8 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateWithMarkdownNote() { ) // Set status content type of account 1 to markdown for this test. - testAccount.StatusContentType = "text/markdown" - if err := suite.db.UpdateAccount(ctx, testAccount, "status_content_type"); err != nil { + testAccount.Settings.StatusContentType = "text/markdown" + if err := suite.db.UpdateAccountSettings(ctx, testAccount.Settings, "status_content_type"); err != nil { suite.FailNow(err.Error()) } |