Add paginition to Person's outbox

This commit is contained in:
Gusted 2022-08-22 19:36:14 +02:00
parent 5ad0387fbd
commit 2373b4177a
No known key found for this signature in database
GPG Key ID: FD821B732837125F
2 changed files with 45 additions and 24 deletions

View File

@ -331,14 +331,15 @@ func (a *Action) GetIssueContent() string {
// GetFeedsOptions options for retrieving feeds // GetFeedsOptions options for retrieving feeds
type GetFeedsOptions struct { type GetFeedsOptions struct {
db.ListOptions db.ListOptions
RequestedUser *user_model.User // the user we want activity for RequestedUser *user_model.User // the user we want activity for
RequestedTeam *organization.Team // the team we want activity for RequestedTeam *organization.Team // the team we want activity for
RequestedRepo *repo_model.Repository // the repo we want activity for RequestedRepo *repo_model.Repository // the repo we want activity for
Actor *user_model.User // the user viewing the activity RequestedActionType ActionType // the type of activity we want
IncludePrivate bool // include private actions Actor *user_model.User // the user viewing the activity
OnlyPerformedBy bool // only actions performed by requested user IncludePrivate bool // include private actions
IncludeDeleted bool // include deleted actions OnlyPerformedBy bool // only actions performed by requested user
Date string // the day we want activity for: YYYY-MM-DD IncludeDeleted bool // include deleted actions
Date string // the day we want activity for: YYYY-MM-DD
} }
// GetFeeds returns actions according to the provided options // GetFeeds returns actions according to the provided options
@ -449,6 +450,10 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
} }
} }
if opts.RequestedActionType != 0 {
cond = cond.And(builder.Eq{"`action`.op_type": opts.RequestedActionType})
}
return cond, nil return cond, nil
} }

View File

@ -5,6 +5,7 @@
package activitypub package activitypub
import ( import (
"fmt"
"io" "io"
"net/http" "net/http"
"strings" "strings"
@ -15,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/activitypub"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/forgefed" "code.gitea.io/gitea/modules/forgefed"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -164,31 +166,45 @@ func PersonOutbox(ctx *context.APIContext) {
link := setting.AppURL + "api/v1/activitypub/user/" + ctx.ContextUser.Name link := setting.AppURL + "api/v1/activitypub/user/" + ctx.ContextUser.Name
outbox := ap.OrderedCollectionNew(ap.IRI(link + "/outbox")) orderedCollection := ap.OrderedCollectionNew(ap.IRI(link + "/outbox"))
orderedCollection.First = ap.IRI(link + "/outbox?page=1")
outbox := ap.OrderedCollectionPageNew(orderedCollection)
outbox.First = ap.IRI(link + "/outbox?page=1")
feed, err := models.GetFeeds(ctx, models.GetFeedsOptions{ feed, err := models.GetFeeds(ctx, models.GetFeedsOptions{
RequestedUser: ctx.ContextUser, RequestedUser: ctx.ContextUser,
Actor: ctx.ContextUser, RequestedActionType: models.ActionCreateRepo,
IncludePrivate: false, Actor: ctx.Doer,
IncludeDeleted: false, IncludePrivate: false,
ListOptions: db.ListOptions{Page: 1, PageSize: 1000000}, IncludeDeleted: false,
ListOptions: utils.GetListOptions(ctx),
}) })
// Only specify next if this amount of feed corresponds to the calculated limit.
if len(feed) == convert.ToCorrectPageSize(ctx.FormInt("limit")) {
outbox.Next = ap.IRI(fmt.Sprintf("%s/outbox?page=%d", link, ctx.FormInt("page")+1))
}
// Only specify previous page when there is one.
if ctx.FormInt("page") > 1 {
outbox.Prev = ap.IRI(fmt.Sprintf("%s/outbox?page=%d", link, ctx.FormInt("page")-1))
}
if err != nil { if err != nil {
ctx.ServerError("Couldn't fetch feed", err) ctx.ServerError("Couldn't fetch feed", err)
return return
} }
for _, action := range feed { for _, action := range feed {
if action.OpType == models.ActionCreateRepo { // Created a repo
// Created a repo object := ap.Note{Type: ap.NoteType, Content: ap.NaturalLanguageValuesNew()}
object := ap.Note{Type: ap.NoteType, Content: ap.NaturalLanguageValuesNew()} _ = object.Content.Set("en", ap.Content(action.GetRepoName()))
_ = object.Content.Set("en", ap.Content(action.GetRepoName())) create := ap.Create{Type: ap.CreateType, Object: object}
create := ap.Create{Type: ap.CreateType, Object: object} err := outbox.OrderedItems.Append(create)
err := outbox.OrderedItems.Append(create) if err != nil {
if err != nil { ctx.ServerError("OrderedItems.Append", err)
ctx.ServerError("OrderedItems.Append", err) return
return
}
} }
} }