这份文档还在翻译中,预期年底前完成。欢迎您提供宝贵的意见及建议。

Handling pagination

This guide covers the process loading and displaying chunks of conversation events at a time.

NOTE: A step-by-step tutorial to build a chat application is available here.

Given a Conversation you are already a Member of, you can download chunks (pages) of events existing within this conversation.

Load first page of events:

val conversationEventsListener = object : NexmoRequestListener<NexmoEventsPage> {
    override fun onSuccess(nexmoEventsPage: NexmoEventsPage?) {
        nexmoEventsPage?.pageResponse?.data?.let {
            val events = nexmoEventsPage?.data
        }
    }

    override fun onError(apiError: NexmoApiError) {
        Log.d("TAG", "Error: Unable to load conversation events ${apiError.message}")
    }
}

conversation?.getEvents(100, NexmoPageOrder.NexmoMPageOrderAsc, null, conversationEventsListener)
NexmoRequestListener<NexmoEventsPage> conversationEventsListener = new NexmoRequestListener<NexmoEventsPage>() {
    @Override
    public void onSuccess(@Nullable NexmoEventsPage eventsPage) {
        Collection<NexmoEvent> events = eventsPage.getData();
    }

    @Override
    public void onError(@NonNull NexmoApiError apiError) {
        Log.d("TAG", "Error: Unable to load conversation events %s", apiError.getMessage());
    }
};

conversation.getEvents(100, NexmoPageOrder.NexmoMPageOrderAsc, null, conversationEventsListener);

After loading the first chunk of events you will get the reference to the current Nexmo Events Page. This reference allows to retrieve following event pages:

if(nexmoEventsPage.isNextPageExist) {
    nexmoEventsPage.getNext(conversationEventsListener)
}
if(eventsPage.isNextPageExist()) {
    eventsPage.getNext(conversationEventsListener);
}

Preceding pages can also be retrieved using a similar technique:

if(nexmoEventsPage.isPrevPageExist) {
    nexmoEventsPage.getPrev(conversationEventsListener)
}
if(eventsPage.isPrevPageExist()) {
    eventsPage.getPrev(conversationEventsListener);
}