Handle pagination for the federated actions & followers responses (#1731)
* Add pagination for admin social list * Use Paginated API for followers tab on frontend
This commit is contained in:
@@ -160,12 +160,19 @@ func SetFederationBlockDomains(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// GetFederatedActions will return the saved list of accepted inbound
|
||||
// federated activities.
|
||||
func GetFederatedActions(w http.ResponseWriter, r *http.Request) {
|
||||
activities, err := persistence.GetInboundActivities(100, 0)
|
||||
func GetFederatedActions(page int, pageSize int, w http.ResponseWriter, r *http.Request) {
|
||||
offset := pageSize * page
|
||||
|
||||
activities, total, err := persistence.GetInboundActivities(pageSize, offset)
|
||||
if err != nil {
|
||||
controllers.WriteSimpleResponse(w, false, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
controllers.WriteResponse(w, activities)
|
||||
response := controllers.PaginatedResponse{
|
||||
Total: total,
|
||||
Results: activities,
|
||||
}
|
||||
|
||||
controllers.WriteResponse(w, response)
|
||||
}
|
||||
|
||||
@@ -7,12 +7,16 @@ import (
|
||||
)
|
||||
|
||||
// GetFollowers will handle an API request to fetch the list of followers (non-activitypub response).
|
||||
func GetFollowers(w http.ResponseWriter, r *http.Request) {
|
||||
followers, err := persistence.GetFederationFollowers(-1, 0)
|
||||
func GetFollowers(offset int, limit int, w http.ResponseWriter, r *http.Request) {
|
||||
followers, total, err := persistence.GetFederationFollowers(limit, offset)
|
||||
if err != nil {
|
||||
WriteSimpleResponse(w, false, "unable to fetch followers")
|
||||
return
|
||||
}
|
||||
|
||||
WriteResponse(w, followers)
|
||||
response := PaginatedResponse{
|
||||
Total: total,
|
||||
Results: followers,
|
||||
}
|
||||
WriteResponse(w, response)
|
||||
}
|
||||
|
||||
7
controllers/pagination.go
Normal file
7
controllers/pagination.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package controllers
|
||||
|
||||
// PaginatedResponse is a structure for returning a total count with results.
|
||||
type PaginatedResponse struct {
|
||||
Total int `json:"total"`
|
||||
Results interface{} `json:"results"`
|
||||
}
|
||||
Reference in New Issue
Block a user