})
}
-function activityPubCollectionPagination (url: string, page: number, result: ResultList<any>) {
+function activityPubCollection (results: any[]) {
+ return {
+ type: 'OrderedCollection',
+ totalItems: results.length,
+ orderedItems: results
+ }
+}
+
+function activityPubCollectionPagination (url: string, page: any, result: ResultList<any>) {
let next: string
let prev: string
+ // Assert page is a number
+ page = parseInt(page, 10)
+
// There are more results
- if (result.total > ((page + 1) * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)) {
+ if (result.total > page * ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) {
next = url + '?page=' + (page + 1)
}
orderedItems: result.data
}
- const obj = {
- id: url,
- type: 'OrderedCollection',
- totalItems: result.total,
- orderedItems: orderedCollectionPagination
+ if (page === 1) {
+ return activityPubContextify({
+ id: url,
+ type: 'OrderedCollection',
+ totalItems: result.total,
+ first: orderedCollectionPagination
+ })
+ } else {
+ orderedCollectionPagination['totalItems'] = result.total
}
- return activityPubContextify(obj)
+ return orderedCollectionPagination
}
function buildSignedActivity (byAccount: AccountInstance, data: Object) {
export {
activityPubContextify,
activityPubCollectionPagination,
+ activityPubCollection,
buildSignedActivity
}