diff options
author | 2023-11-17 11:35:28 +0100 | |
---|---|---|
committer | 2023-11-17 11:35:28 +0100 | |
commit | fc02d3c6f7db5a7794448f31fd9d6d81d3d224eb (patch) | |
tree | f792f799abadf784e493933af597d8f2292ab776 /internal/processing/account | |
parent | [bugfix] process account delete side effects in serial, not in parallel (#2360) (diff) | |
download | gotosocial-fc02d3c6f7db5a7794448f31fd9d6d81d3d224eb.tar.xz |
[feature] Set/show instance language(s); show post language on frontend (#2362)
* update go text, include text/display
* [feature] Set instance langs, show post lang on frontend
* go fmt
* WebGet
* set language for whole article, don't use FA icon
* mention instance languages + other optional config vars
* little tweak
* put languages in config properly
* warn log language parse
* change some naming around
* tidy up validate a bit
* lint
* rename LanguageTmpl in template
Diffstat (limited to 'internal/processing/account')
-rw-r--r-- | internal/processing/account/statuses.go | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/internal/processing/account/statuses.go b/internal/processing/account/statuses.go index 1bdd3906b..0985bb4ef 100644 --- a/internal/processing/account/statuses.go +++ b/internal/processing/account/statuses.go @@ -133,7 +133,11 @@ func (p *Processor) StatusesGet( // WebStatusesGet fetches a number of statuses (in descending order) // from the given account. It selects only statuses which are suitable // for showing on the public web profile of an account. -func (p *Processor) WebStatusesGet(ctx context.Context, targetAccountID string, maxID string) (*apimodel.PageableResponse, gtserror.WithCode) { +func (p *Processor) WebStatusesGet( + ctx context.Context, + targetAccountID string, + maxID string, +) (*apimodel.PageableResponse, gtserror.WithCode) { account, err := p.state.DB.GetAccountByID(ctx, targetAccountID) if err != nil { if errors.Is(err, db.ErrNoEntries) { @@ -167,10 +171,10 @@ func (p *Processor) WebStatusesGet(ctx context.Context, targetAccountID string, ) for _, s := range statuses { - // Convert fetched statuses to API statuses. - item, err := p.converter.StatusToAPIStatus(ctx, s, nil) + // Convert fetched statuses to web view statuses. + item, err := p.converter.StatusToWebStatus(ctx, s, nil) if err != nil { - log.Errorf(ctx, "error convering to api status: %v", err) + log.Errorf(ctx, "error convering to web status: %v", err) continue } items = append(items, item) @@ -183,8 +187,39 @@ func (p *Processor) WebStatusesGet(ctx context.Context, targetAccountID string, }) } -// PinnedStatusesGet is a shortcut for getting just an account's pinned statuses. -// Under the hood, it just calls StatusesGet using mostly default parameters. -func (p *Processor) PinnedStatusesGet(ctx context.Context, requestingAccount *gtsmodel.Account, targetAccountID string) (*apimodel.PageableResponse, gtserror.WithCode) { - return p.StatusesGet(ctx, requestingAccount, targetAccountID, 0, false, false, "", "", true, false, false) +// WebStatusesGetPinned returns web versions of pinned statuses. +func (p *Processor) WebStatusesGetPinned( + ctx context.Context, + targetAccountID string, +) ([]*apimodel.Status, gtserror.WithCode) { + statuses, err := p.state.DB.GetAccountPinnedStatuses(ctx, targetAccountID) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, gtserror.NewErrorInternalError(err) + } + + webStatuses := make([]*apimodel.Status, 0, len(statuses)) + for _, status := range statuses { + if status.Visibility != gtsmodel.VisibilityPublic { + // Skip non-public + // pinned status. + continue + } + + webStatus, err := p.converter.StatusToWebStatus(ctx, status, nil) + if err != nil { + log.Errorf(ctx, "error convering to web status: %v", err) + continue + } + + // Normally when viewed via the API, 'pinned' is + // only true if the *viewing account* has pinned + // the status being viewed. For web statuses, + // however, we still want to be able to indicate + // a pinned status, so bodge this in here. + webStatus.Pinned = true + + webStatuses = append(webStatuses, webStatus) + } + + return webStatuses, nil } |