Pagination

A lot of GetSocial methods support pagination. The pagination has the same appoach in all of them.

Count

Some paginated methods have a symmetric getCount method which allows to get the total count of elements matching that query.

1
2
3
val query = NotificationsQuery.withStatuses(NotificationStatus.UNREAD)

Notifications.getCount(query, { count: Int -> /** onSuccess **/}, { error: GetSocialError -> /** onError **/ })
1
2
var query = NotificationsQuery.WithStatuses(NotificationStatus.Unread);
Notifications.Count(query, (count) => { /** success **/ }, (error) => { /** error **/ });

Items List

To get a paginated items list you have to wrap the basic query into respective paging query. Paging query allows you to set a limit and also to add the pointer to the next page.

The result of such a call is an object, which contains the pointer to the next page and the list of items for a current page.

If the returned page is the last one, nextCursor will be an empty string. You can also use isLastPage method for convenience.

1
2
3
4
5
6
7
8
9
val query = NotificationsQuery.withStatuses(NotificationStatus.UNREAD)
val pagingQuery = PagingQuery(query)

Notifications.get(pagingQuery, { result: PagingResult<Notification> ->
    val items = result.entries
    if (!result.isLastPage) {
        Notifications.get(pagingQuery.next(result.nextCursor()), { nextPageResult -> /** onSuccess **/ }, { error -> /** onError **/ })
    }
}, { error: GetSocialError -> /** onError **/ })
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
var query = NotificationsQuery.WithStatuses(NotificationStatus.Unread);
var pagingQuery = new PagingQuery<NotificationsQuery>(query);

Notifications.Get(pagingQuery,
    (result) => {
        var items = result.Entries;
        if (!result.IsLastPage)
        {
            Notifications.Get(pagingQuery.Next(result.NextCursor),
                (nextPageResult) => { /** success **/ },
                (error) => { /** error **/ });
        }
    },
    (error) => { /** error **/ });

Missing Features

Currently you’re not able to load previous page or arbitrary page. Ping us in Intercom if you require any of that features.

Give us your feedback! Was this article helpful?

😀 🙁