Get channels
Chat UI SDK includes built-in channel retrieval and display logic. When you use the default ChannelListFragment or ChannelFragment, you do not need to call channel query interfaces directly.
To customize the channel list or apply custom filtering, use the nexconn public API (BaseChannel):
BaseChannel.createChannelsQuery(ChannelsQueryParams): Load a paginated channel listBaseChannel.getUnreadChannels(List<ChannelType>, ...): Get channels with unread messagesBaseChannel.getChannels(List<ChannelIdentifier>, ...): Get specific channels by identifier
Example
- Kotlin
- Java
kotlin
val query = BaseChannel.createChannelsQuery(
ChannelsQueryParams(
channelTypes = listOf(ChannelType.DIRECT, ChannelType.GROUP, ChannelType.SYSTEM)
).apply {
pageSize = 20
topPriority = true
}
)
query.loadNextPage { page, error ->
if (error != null) return@loadNextPage
val channels = page?.data.orEmpty()
// Custom channel list rendering
}
BaseChannel.getUnreadChannels(
listOf(ChannelType.DIRECT, ChannelType.GROUP)
) { channels, error ->
if (error == null) {
// Unread channels collection
}
}
val identifier = ChannelIdentifier(ChannelType.DIRECT, "user_001")
BaseChannel.getChannels(listOf(identifier)) { channels, error ->
if (error == null) {
val channel = channels?.firstOrNull()
// Access channel?.draft / channel?.unreadCount / channel?.isPinned etc.
}
}
Java
ChannelsQueryParams params = new ChannelsQueryParams(
Arrays.asList(ChannelType.DIRECT, ChannelType.GROUP, ChannelType.SYSTEM));
params.setPageSize(20);
params.setTopPriority(true);
ChannelsQuery query = BaseChannel.createChannelsQuery(params);
query.loadNextPage((page, error) -> {
if (error != null) return;
List<BaseChannel> channels = page != null ? page.getData() : Collections.emptyList();
// Custom channel list rendering
});
BaseChannel.getUnreadChannels(
Arrays.asList(ChannelType.DIRECT, ChannelType.GROUP),
(channels, error) -> {
if (error == null) {
// Unread channels collection
}
});
ChannelIdentifier identifier = new ChannelIdentifier(ChannelType.DIRECT, "user_001");
BaseChannel.getChannels(Collections.singletonList(identifier), (channels, error) -> {
if (error == null) {
BaseChannel channel = channels != null && !channels.isEmpty() ? channels.get(0) : null;
// Access channel.getDraft() / channel.getUnreadCount() / channel.isPinned() etc.
}
});