Skip to content

Commit 2373b41

Browse files
author
Gusted
committed
Add paginition to Person's outbox
1 parent 5ad0387 commit 2373b41

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

models/action.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,15 @@ func (a *Action) GetIssueContent() string {
331331
// GetFeedsOptions options for retrieving feeds
332332
type GetFeedsOptions struct {
333333
db.ListOptions
334-
RequestedUser *user_model.User // the user we want activity for
335-
RequestedTeam *organization.Team // the team we want activity for
336-
RequestedRepo *repo_model.Repository // the repo we want activity for
337-
Actor *user_model.User // the user viewing the activity
338-
IncludePrivate bool // include private actions
339-
OnlyPerformedBy bool // only actions performed by requested user
340-
IncludeDeleted bool // include deleted actions
341-
Date string // the day we want activity for: YYYY-MM-DD
334+
RequestedUser *user_model.User // the user we want activity for
335+
RequestedTeam *organization.Team // the team we want activity for
336+
RequestedRepo *repo_model.Repository // the repo we want activity for
337+
RequestedActionType ActionType // the type of activity we want
338+
Actor *user_model.User // the user viewing the activity
339+
IncludePrivate bool // include private actions
340+
OnlyPerformedBy bool // only actions performed by requested user
341+
IncludeDeleted bool // include deleted actions
342+
Date string // the day we want activity for: YYYY-MM-DD
342343
}
343344

344345
// GetFeeds returns actions according to the provided options
@@ -449,6 +450,10 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
449450
}
450451
}
451452

453+
if opts.RequestedActionType != 0 {
454+
cond = cond.And(builder.Eq{"`action`.op_type": opts.RequestedActionType})
455+
}
456+
452457
return cond, nil
453458
}
454459

routers/api/v1/activitypub/person.go

+32-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package activitypub
66

77
import (
8+
"fmt"
89
"io"
910
"net/http"
1011
"strings"
@@ -15,6 +16,7 @@ import (
1516
user_model "code.gitea.io/gitea/models/user"
1617
"code.gitea.io/gitea/modules/activitypub"
1718
"code.gitea.io/gitea/modules/context"
19+
"code.gitea.io/gitea/modules/convert"
1820
"code.gitea.io/gitea/modules/forgefed"
1921
"code.gitea.io/gitea/modules/log"
2022
"code.gitea.io/gitea/modules/setting"
@@ -164,31 +166,45 @@ func PersonOutbox(ctx *context.APIContext) {
164166

165167
link := setting.AppURL + "api/v1/activitypub/user/" + ctx.ContextUser.Name
166168

167-
outbox := ap.OrderedCollectionNew(ap.IRI(link + "/outbox"))
169+
orderedCollection := ap.OrderedCollectionNew(ap.IRI(link + "/outbox"))
170+
orderedCollection.First = ap.IRI(link + "/outbox?page=1")
171+
172+
outbox := ap.OrderedCollectionPageNew(orderedCollection)
173+
outbox.First = ap.IRI(link + "/outbox?page=1")
168174

169175
feed, err := models.GetFeeds(ctx, models.GetFeedsOptions{
170-
RequestedUser: ctx.ContextUser,
171-
Actor: ctx.ContextUser,
172-
IncludePrivate: false,
173-
IncludeDeleted: false,
174-
ListOptions: db.ListOptions{Page: 1, PageSize: 1000000},
176+
RequestedUser: ctx.ContextUser,
177+
RequestedActionType: models.ActionCreateRepo,
178+
Actor: ctx.Doer,
179+
IncludePrivate: false,
180+
IncludeDeleted: false,
181+
ListOptions: utils.GetListOptions(ctx),
175182
})
183+
184+
// Only specify next if this amount of feed corresponds to the calculated limit.
185+
if len(feed) == convert.ToCorrectPageSize(ctx.FormInt("limit")) {
186+
outbox.Next = ap.IRI(fmt.Sprintf("%s/outbox?page=%d", link, ctx.FormInt("page")+1))
187+
}
188+
189+
// Only specify previous page when there is one.
190+
if ctx.FormInt("page") > 1 {
191+
outbox.Prev = ap.IRI(fmt.Sprintf("%s/outbox?page=%d", link, ctx.FormInt("page")-1))
192+
}
193+
176194
if err != nil {
177195
ctx.ServerError("Couldn't fetch feed", err)
178196
return
179197
}
180198

181199
for _, action := range feed {
182-
if action.OpType == models.ActionCreateRepo {
183-
// Created a repo
184-
object := ap.Note{Type: ap.NoteType, Content: ap.NaturalLanguageValuesNew()}
185-
_ = object.Content.Set("en", ap.Content(action.GetRepoName()))
186-
create := ap.Create{Type: ap.CreateType, Object: object}
187-
err := outbox.OrderedItems.Append(create)
188-
if err != nil {
189-
ctx.ServerError("OrderedItems.Append", err)
190-
return
191-
}
200+
// Created a repo
201+
object := ap.Note{Type: ap.NoteType, Content: ap.NaturalLanguageValuesNew()}
202+
_ = object.Content.Set("en", ap.Content(action.GetRepoName()))
203+
create := ap.Create{Type: ap.CreateType, Object: object}
204+
err := outbox.OrderedItems.Append(create)
205+
if err != nil {
206+
ctx.ServerError("OrderedItems.Append", err)
207+
return
192208
}
193209
}
194210

0 commit comments

Comments
 (0)