55package activitypub
66
77import (
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