summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-11-17 11:35:28 +0100
committerLibravatar GitHub <noreply@github.com>2023-11-17 11:35:28 +0100
commitfc02d3c6f7db5a7794448f31fd9d6d81d3d224eb (patch)
treef792f799abadf784e493933af597d8f2292ab776 /internal/processing
parent[bugfix] process account delete side effects in serial, not in parallel (#2360) (diff)
downloadgotosocial-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')
-rw-r--r--internal/processing/account/statuses.go51
-rw-r--r--internal/processing/admin/admin_test.go1
-rw-r--r--internal/processing/status/get.go15
3 files changed, 58 insertions, 9 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
}
diff --git a/internal/processing/admin/admin_test.go b/internal/processing/admin/admin_test.go
index 367924664..01a3a88ff 100644
--- a/internal/processing/admin/admin_test.go
+++ b/internal/processing/admin/admin_test.go
@@ -80,7 +80,6 @@ func (suite *AdminStandardTestSuite) SetupSuite() {
func (suite *AdminStandardTestSuite) SetupTest() {
suite.state.Caches.Init()
-
testrig.InitTestConfig()
testrig.InitTestLog()
diff --git a/internal/processing/status/get.go b/internal/processing/status/get.go
index 170dd0e53..ae6918e3f 100644
--- a/internal/processing/status/get.go
+++ b/internal/processing/status/get.go
@@ -36,6 +36,21 @@ func (p *Processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account
return p.c.GetAPIStatus(ctx, requestingAccount, targetStatus)
}
+// WebGet gets the given status for web use, taking account of privacy settings.
+func (p *Processor) WebGet(ctx context.Context, targetStatusID string) (*apimodel.Status, gtserror.WithCode) {
+ targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, nil, targetStatusID)
+ if errWithCode != nil {
+ return nil, errWithCode
+ }
+
+ webStatus, err := p.converter.StatusToWebStatus(ctx, targetStatus, nil)
+ if err != nil {
+ err = gtserror.Newf("error converting status: %w", err)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+ return webStatus, nil
+}
+
func (p *Processor) contextGet(
ctx context.Context,
requestingAccount *gtsmodel.Account,