summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/bookmarks.go1
-rw-r--r--internal/processing/account/statuses.go36
-rw-r--r--internal/processing/admin/report.go16
-rw-r--r--internal/processing/list/delete.go5
-rw-r--r--internal/processing/list/get.go38
-rw-r--r--internal/processing/report/get.go26
-rw-r--r--internal/processing/timeline/faved.go6
-rw-r--r--internal/processing/timeline/home.go18
-rw-r--r--internal/processing/timeline/list.go18
-rw-r--r--internal/processing/timeline/public.go23
10 files changed, 72 insertions, 115 deletions
diff --git a/internal/processing/account/bookmarks.go b/internal/processing/account/bookmarks.go
index 32075f592..c6b0c14c1 100644
--- a/internal/processing/account/bookmarks.go
+++ b/internal/processing/account/bookmarks.go
@@ -82,6 +82,7 @@ func (p *Processor) BookmarksGet(ctx context.Context, requestingAccount *gtsmode
if bookmark.ID < nextMaxIDValue {
nextMaxIDValue = bookmark.ID // Lowest ID (for paging down).
}
+
if bookmark.ID > prevMinIDValue {
prevMinIDValue = bookmark.ID // Highest ID (for paging up).
}
diff --git a/internal/processing/account/statuses.go b/internal/processing/account/statuses.go
index df7064b79..26684265c 100644
--- a/internal/processing/account/statuses.go
+++ b/internal/processing/account/statuses.go
@@ -93,28 +93,21 @@ func (p *Processor) StatusesGet(
}
var (
- items = make([]interface{}, 0, count)
- nextMaxIDValue string
- prevMinIDValue string
- )
+ items = make([]interface{}, 0, count)
- for i, s := range filtered {
// Set next + prev values before filtering and API
// converting, so caller can still page properly.
- if i == count-1 {
- nextMaxIDValue = s.ID
- }
-
- if i == 0 {
- prevMinIDValue = s.ID
- }
+ nextMaxIDValue = filtered[count-1].ID
+ prevMinIDValue = filtered[0].ID
+ )
+ for _, s := range filtered {
+ // Convert filtered statuses to API statuses.
item, err := p.tc.StatusToAPIStatus(ctx, s, requestingAccount)
if err != nil {
- log.Debugf(ctx, "skipping status %s because it couldn't be converted to its api representation: %s", s.ID, err)
+ log.Errorf(ctx, "error convering to api status: %v", err)
continue
}
-
items = append(items, item)
}
@@ -171,23 +164,20 @@ func (p *Processor) WebStatusesGet(ctx context.Context, targetAccountID string,
}
var (
- items = make([]interface{}, 0, count)
- nextMaxIDValue string
- )
+ items = make([]interface{}, 0, count)
- for i, s := range statuses {
// Set next value before API converting,
// so caller can still page properly.
- if i == count-1 {
- nextMaxIDValue = s.ID
- }
+ nextMaxIDValue = statuses[count-1].ID
+ )
+ for _, s := range statuses {
+ // Convert fetched statuses to API statuses.
item, err := p.tc.StatusToAPIStatus(ctx, s, nil)
if err != nil {
- log.Debugf(ctx, "skipping status %s because it couldn't be converted to its api representation: %s", s.ID, err)
+ log.Errorf(ctx, "error convering to api status: %v", err)
continue
}
-
items = append(items, item)
}
diff --git a/internal/processing/admin/report.go b/internal/processing/admin/report.go
index 174bd3c24..e99cc2ec0 100644
--- a/internal/processing/admin/report.go
+++ b/internal/processing/admin/report.go
@@ -54,22 +54,14 @@ func (p *Processor) ReportsGet(
count := len(reports)
items := make([]interface{}, 0, count)
- nextMaxIDValue := ""
- prevMinIDValue := ""
- for i, r := range reports {
+ nextMaxIDValue := reports[count-1].ID
+ prevMinIDValue := reports[0].ID
+
+ for _, r := range reports {
item, err := p.tc.ReportToAdminAPIReport(ctx, r, account)
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting report to api: %s", err))
}
-
- if i == count-1 {
- nextMaxIDValue = item.ID
- }
-
- if i == 0 {
- prevMinIDValue = item.ID
- }
-
items = append(items, item)
}
diff --git a/internal/processing/list/delete.go b/internal/processing/list/delete.go
index 1c8ee5700..327ac9d16 100644
--- a/internal/processing/list/delete.go
+++ b/internal/processing/list/delete.go
@@ -27,7 +27,8 @@ import (
// Delete deletes one list for the given account.
func (p *Processor) Delete(ctx context.Context, account *gtsmodel.Account, id string) gtserror.WithCode {
- list, errWithCode := p.getList(
+ // Ensure list exists + is owned by requesting account.
+ _, errWithCode := p.getList(
// Use barebones ctx; no embedded
// structs necessary for this call.
gtscontext.SetBarebones(ctx),
@@ -38,7 +39,7 @@ func (p *Processor) Delete(ctx context.Context, account *gtsmodel.Account, id st
return errWithCode
}
- if err := p.state.DB.DeleteListByID(ctx, list.ID); err != nil {
+ if err := p.state.DB.DeleteListByID(ctx, id); err != nil {
return gtserror.NewErrorInternalError(err)
}
diff --git a/internal/processing/list/get.go b/internal/processing/list/get.go
index 3f124fe7c..0fc14f934 100644
--- a/internal/processing/list/get.go
+++ b/internal/processing/list/get.go
@@ -87,7 +87,14 @@ func (p *Processor) GetListAccounts(
limit int,
) (*apimodel.PageableResponse, gtserror.WithCode) {
// Ensure list exists + is owned by requesting account.
- if _, errWithCode := p.getList(ctx, account.ID, listID); errWithCode != nil {
+ _, errWithCode := p.getList(
+ // Use barebones ctx; no embedded
+ // structs necessary for this call.
+ gtscontext.SetBarebones(ctx),
+ account.ID,
+ listID,
+ )
+ if errWithCode != nil {
return nil, errWithCode
}
@@ -106,9 +113,12 @@ func (p *Processor) GetListAccounts(
}
var (
- items = make([]interface{}, count)
- nextMaxIDValue string
- prevMinIDValue string
+ items = make([]interface{}, 0, count)
+
+ // Set next + prev values before filtering and API
+ // converting, so caller can still page properly.
+ nextMaxIDValue = listEntries[count-1].ID
+ prevMinIDValue = listEntries[0].ID
)
// For each list entry, we want the account it points to.
@@ -117,37 +127,29 @@ func (p *Processor) GetListAccounts(
// from that follow.
//
// We do paging not by account ID, but by list entry ID.
- for i, listEntry := range listEntries {
- if i == count-1 {
- nextMaxIDValue = listEntry.ID
- }
-
- if i == 0 {
- prevMinIDValue = listEntry.ID
- }
-
+ for _, listEntry := range listEntries {
if err := p.state.DB.PopulateListEntry(ctx, listEntry); err != nil {
- log.Debugf(ctx, "skipping list entry because of error populating it: %q", err)
+ log.Errorf(ctx, "error populating list entry: %v", err)
continue
}
if err := p.state.DB.PopulateFollow(ctx, listEntry.Follow); err != nil {
- log.Debugf(ctx, "skipping list entry because of error populating follow: %q", err)
+ log.Errorf(ctx, "error populating follow: %v", err)
continue
}
apiAccount, err := p.tc.AccountToAPIAccountPublic(ctx, listEntry.Follow.TargetAccount)
if err != nil {
- log.Debugf(ctx, "skipping list entry because of error converting follow target account: %q", err)
+ log.Errorf(ctx, "error converting to public api account: %v", err)
continue
}
- items[i] = apiAccount
+ items = append(items, apiAccount)
}
return util.PackagePageableResponse(util.PageableResponseParams{
Items: items,
- Path: "api/v1/lists/" + listID + "/accounts",
+ Path: "/api/v1/lists/" + listID + "/accounts",
NextMaxIDValue: nextMaxIDValue,
PrevMinIDValue: prevMinIDValue,
Limit: limit,
diff --git a/internal/processing/report/get.go b/internal/processing/report/get.go
index bfe7dedf0..f39648832 100644
--- a/internal/processing/report/get.go
+++ b/internal/processing/report/get.go
@@ -19,6 +19,7 @@ package report
import (
"context"
+ "errors"
"fmt"
"strconv"
@@ -64,31 +65,24 @@ func (p *Processor) GetMultiple(
limit int,
) (*apimodel.PageableResponse, gtserror.WithCode) {
reports, err := p.state.DB.GetReports(ctx, resolved, account.ID, targetAccountID, maxID, sinceID, minID, limit)
- if err != nil {
- if err == db.ErrNoEntries {
- return util.EmptyPageableResponse(), nil
- }
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
return nil, gtserror.NewErrorInternalError(err)
}
count := len(reports)
+ if count == 0 {
+ return util.EmptyPageableResponse(), nil
+ }
+
items := make([]interface{}, 0, count)
- nextMaxIDValue := ""
- prevMinIDValue := ""
- for i, r := range reports {
+ nextMaxIDValue := reports[count-1].ID
+ prevMinIDValue := reports[0].ID
+
+ for _, r := range reports {
item, err := p.tc.ReportToAPIReport(ctx, r)
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting report to api: %s", err))
}
-
- if i == count-1 {
- nextMaxIDValue = item.ID
- }
-
- if i == 0 {
- prevMinIDValue = item.ID
- }
-
items = append(items, item)
}
diff --git a/internal/processing/timeline/faved.go b/internal/processing/timeline/faved.go
index 0fc92d8fa..556ced4c3 100644
--- a/internal/processing/timeline/faved.go
+++ b/internal/processing/timeline/faved.go
@@ -46,7 +46,7 @@ func (p *Processor) FavedTimelineGet(ctx context.Context, authed *oauth.Auth, ma
for _, s := range statuses {
visible, err := p.filter.StatusVisible(ctx, authed.Account, s)
if err != nil {
- log.Debugf(ctx, "skipping status %s because of an error checking status visibility: %s", s.ID, err)
+ log.Errorf(ctx, "error checking status visibility: %v", err)
continue
}
@@ -56,7 +56,7 @@ func (p *Processor) FavedTimelineGet(ctx context.Context, authed *oauth.Auth, ma
apiStatus, err := p.tc.StatusToAPIStatus(ctx, s, authed.Account)
if err != nil {
- log.Debugf(ctx, "skipping status %s because it couldn't be converted to its api representation: %s", s.ID, err)
+ log.Errorf(ctx, "error convering to api status: %v", err)
continue
}
@@ -65,7 +65,7 @@ func (p *Processor) FavedTimelineGet(ctx context.Context, authed *oauth.Auth, ma
return util.PackagePageableResponse(util.PageableResponseParams{
Items: items,
- Path: "api/v1/favourites",
+ Path: "/api/v1/favourites",
NextMaxIDValue: nextMaxID,
PrevMinIDValue: prevMinID,
Limit: limit,
diff --git a/internal/processing/timeline/home.go b/internal/processing/timeline/home.go
index 807189495..72940175f 100644
--- a/internal/processing/timeline/home.go
+++ b/internal/processing/timeline/home.go
@@ -116,25 +116,17 @@ func (p *Processor) HomeTimelineGet(ctx context.Context, authed *oauth.Auth, max
var (
items = make([]interface{}, count)
- nextMaxIDValue string
- prevMinIDValue string
+ nextMaxIDValue = statuses[count-1].GetID()
+ prevMinIDValue = statuses[0].GetID()
)
- for i, item := range statuses {
- if i == count-1 {
- nextMaxIDValue = item.GetID()
- }
-
- if i == 0 {
- prevMinIDValue = item.GetID()
- }
-
- items[i] = item
+ for i := range statuses {
+ items[i] = statuses[i]
}
return util.PackagePageableResponse(util.PageableResponseParams{
Items: items,
- Path: "api/v1/timelines/home",
+ Path: "/api/v1/timelines/home",
NextMaxIDValue: nextMaxIDValue,
PrevMinIDValue: prevMinIDValue,
Limit: limit,
diff --git a/internal/processing/timeline/list.go b/internal/processing/timeline/list.go
index 830c874a9..80744df15 100644
--- a/internal/processing/timeline/list.go
+++ b/internal/processing/timeline/list.go
@@ -142,25 +142,17 @@ func (p *Processor) ListTimelineGet(ctx context.Context, authed *oauth.Auth, lis
var (
items = make([]interface{}, count)
- nextMaxIDValue string
- prevMinIDValue string
+ nextMaxIDValue = statuses[count-1].GetID()
+ prevMinIDValue = statuses[0].GetID()
)
- for i, item := range statuses {
- if i == count-1 {
- nextMaxIDValue = item.GetID()
- }
-
- if i == 0 {
- prevMinIDValue = item.GetID()
- }
-
- items[i] = item
+ for i := range statuses {
+ items[i] = statuses[i]
}
return util.PackagePageableResponse(util.PageableResponseParams{
Items: items,
- Path: "api/v1/timelines/list/" + listID,
+ Path: "/api/v1/timelines/list/" + listID,
NextMaxIDValue: nextMaxIDValue,
PrevMinIDValue: prevMinIDValue,
Limit: limit,
diff --git a/internal/processing/timeline/public.go b/internal/processing/timeline/public.go
index 67893ecfa..78ca56734 100644
--- a/internal/processing/timeline/public.go
+++ b/internal/processing/timeline/public.go
@@ -43,25 +43,18 @@ func (p *Processor) PublicTimelineGet(ctx context.Context, authed *oauth.Auth, m
}
var (
- items = make([]interface{}, 0, count)
- nextMaxIDValue string
- prevMinIDValue string
- )
+ items = make([]interface{}, 0, count)
- for i, s := range statuses {
// Set next + prev values before filtering and API
// converting, so caller can still page properly.
- if i == count-1 {
- nextMaxIDValue = s.ID
- }
-
- if i == 0 {
- prevMinIDValue = s.ID
- }
+ nextMaxIDValue = statuses[count-1].ID
+ prevMinIDValue = statuses[0].ID
+ )
+ for _, s := range statuses {
timelineable, err := p.filter.StatusPublicTimelineable(ctx, authed.Account, s)
if err != nil {
- log.Debugf(ctx, "skipping status %s because of an error checking StatusPublicTimelineable: %s", s.ID, err)
+ log.Errorf(ctx, "error checking status visibility: %v", err)
continue
}
@@ -71,7 +64,7 @@ func (p *Processor) PublicTimelineGet(ctx context.Context, authed *oauth.Auth, m
apiStatus, err := p.tc.StatusToAPIStatus(ctx, s, authed.Account)
if err != nil {
- log.Debugf(ctx, "skipping status %s because it couldn't be converted to its api representation: %s", s.ID, err)
+ log.Errorf(ctx, "error convert to api status: %v", err)
continue
}
@@ -80,7 +73,7 @@ func (p *Processor) PublicTimelineGet(ctx context.Context, authed *oauth.Auth, m
return util.PackagePageableResponse(util.PageableResponseParams{
Items: items,
- Path: "api/v1/timelines/public",
+ Path: "/api/v1/timelines/public",
NextMaxIDValue: nextMaxIDValue,
PrevMinIDValue: prevMinIDValue,
Limit: limit,