diff options
Diffstat (limited to 'internal/processing')
-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 | ||||
-rw-r--r-- | internal/processing/preferences.go | 6 | ||||
-rw-r--r-- | internal/processing/status/create.go | 11 | ||||
-rw-r--r-- | internal/processing/workers/fromfediapi_test.go | 2 |
8 files changed, 37 insertions, 35 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()) } diff --git a/internal/processing/preferences.go b/internal/processing/preferences.go index 90fc86430..0a5f566ae 100644 --- a/internal/processing/preferences.go +++ b/internal/processing/preferences.go @@ -32,9 +32,9 @@ func (p *Processor) PreferencesGet(ctx context.Context, accountID string) (*apim } return &apimodel.Preferences{ - PostingDefaultVisibility: mastoPrefVisibility(act.Privacy), - PostingDefaultSensitive: *act.Sensitive, - PostingDefaultLanguage: act.Language, + PostingDefaultVisibility: mastoPrefVisibility(act.Settings.Privacy), + PostingDefaultSensitive: *act.Settings.Sensitive, + PostingDefaultLanguage: act.Settings.Language, // The Reading* preferences don't appear to actually be settable by the // client, so forcing some sensible defaults here ReadingExpandMedia: "default", diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go index 01ded74bd..d758fc0fb 100644 --- a/internal/processing/status/create.go +++ b/internal/processing/status/create.go @@ -50,6 +50,11 @@ func (p *Processor) Create( *apimodel.Status, gtserror.WithCode, ) { + // Ensure account populated; we'll need settings. + if err := p.state.DB.PopulateAccount(ctx, requester); err != nil { + log.Errorf(ctx, "error(s) populating account, will continue: %s", err) + } + // Generate new ID for status. statusID := id.NewULID() @@ -112,11 +117,11 @@ func (p *Processor) Create( return nil, errWithCode } - if err := processVisibility(form, requester.Privacy, status); err != nil { + if err := processVisibility(form, requester.Settings.Privacy, status); err != nil { return nil, gtserror.NewErrorInternalError(err) } - if err := processLanguage(form, requester.Language, status); err != nil { + if err := processLanguage(form, requester.Settings.Language, status); err != nil { return nil, gtserror.NewErrorInternalError(err) } @@ -369,7 +374,7 @@ func processLanguage(form *apimodel.AdvancedStatusCreateForm, accountDefaultLang func (p *Processor) processContent(ctx context.Context, parseMention gtsmodel.ParseMentionFunc, form *apimodel.AdvancedStatusCreateForm, status *gtsmodel.Status) error { if form.ContentType == "" { // If content type wasn't specified, use the author's preferred content-type. - contentType := apimodel.StatusContentType(status.Account.StatusContentType) + contentType := apimodel.StatusContentType(status.Account.Settings.StatusContentType) form.ContentType = contentType } diff --git a/internal/processing/workers/fromfediapi_test.go b/internal/processing/workers/fromfediapi_test.go index b7466ec73..1dbefca84 100644 --- a/internal/processing/workers/fromfediapi_test.go +++ b/internal/processing/workers/fromfediapi_test.go @@ -362,9 +362,7 @@ func (suite *FromFediAPITestSuite) TestProcessAccountDelete() { suite.Empty(dbAccount.AvatarRemoteURL) suite.Empty(dbAccount.HeaderMediaAttachmentID) suite.Empty(dbAccount.HeaderRemoteURL) - suite.Empty(dbAccount.Reason) suite.Empty(dbAccount.Fields) - suite.True(*dbAccount.HideCollections) suite.False(*dbAccount.Discoverable) suite.WithinDuration(time.Now(), dbAccount.SuspendedAt, 30*time.Second) suite.Equal(dbAccount.ID, dbAccount.SuspensionOrigin) |