Pagination

페이지네이션을 사용하면 채널 목록 조회 및 특정 채널의 사용자 또는 메시지 목록 등을 조회할 수 있습니다. 목록을 일관되게 조회하기 위해 페이지네이션은 이전 페이지에 있던 목록의 마지막 요소의 ID에 의존합니다.

예를 들어, 50개의 채널 목록을 가져온 후 그 다음 50개의 채널을 추가로 조회하고 싶을 때, 처음 받았던 채널 목록의 마지막 채널 ID를 그 다음 페이지 요청할 때 전달해야 합니다. 조회된 목록 이후에 추가 페이지가 있는지 여부는 결과물에 있는 hasNext 필드를 참고하시면 됩니다.

채널 목록 조회 예제:

// 내가 가입한 채널 목록 조회
const numOfRows = 50;
const resp = await client.getChannels({limit: numOfRows});

// 다음 페이지가 있을 시, 추가 조회
if (resp.hasNext) {
    const lastChannelId = resp.channels[resp.channels.length - 1].id;
    const moreChannelsResp = await client.getChannels({lastChannelId, limit: numOfRows});
}

채널 사용자 목록 조회 예제:

// 'my_channel'이라는 ID를 가진 채널의 멤버 목록 조회
const numOfRows = 50;
const resp = await client.getChannelMembers({
    channelId: 'my_channel',
});

// 다음 페이지가 있을 시, 추가 조회
if (resp.hasNext) {
    const lastUserId = resp.users[resp.users.length - 1].id;
    const moreResp = await client.getChannelMembers({lastUserId, limit: numOfRows});
}

Last updated