Skip to main content

Retrieving channels

The Nexconn SDK generates channels in the local database based on messages sent and received, and maintains a channel list. Your app can query the local database to retrieve this channel list.

Get a specific channel

Construct a channel instance and call reload() to refresh its latest data from the local database.

kotlin
// Get a direct channel
val directChannel = DirectChannel("userId")

directChannel.reload { updatedChannel, error ->
if (error == null && updatedChannel != null) {
println("Channel ID: ${updatedChannel.channelId}")
println("Unread count: ${updatedChannel.unreadCount}")
println("Pinned: ${updatedChannel.isPinned}")
} else {
// Failed: ${error?.message}
}
}

// Get a group channel
val groupChannel = GroupChannel("groupId")

groupChannel.reload { updatedChannel, error ->
if (error == null && updatedChannel != null) {
println("Channel ID: ${updatedChannel.channelId}")
}
}

Get multiple channels

Call BaseChannel.getChannels() to retrieve detailed information for multiple channels at once.

kotlin
val identifiers = listOf(
ChannelIdentifier(ChannelType.DIRECT, "userId1"),
ChannelIdentifier(ChannelType.DIRECT, "userId2"),
ChannelIdentifier(ChannelType.GROUP, "groupId1")
)

BaseChannel.getChannels(identifiers) { channels, error ->
if (error == null && channels != null) {
channels.forEach { channel ->
println("Channel: ${channel.channelId}, Type: ${channel.channelType}")
}
} else {
// Failed: ${error?.message}
}
}

Get a channel list with pagination

Call BaseChannel.createChannelsQuery() to create a paginated query for the channel list.

kotlin
val params = ChannelsQueryParams(
channelTypes = listOf(ChannelType.DIRECT, ChannelType.GROUP)
).apply {
pageSize = 20
}

val query = BaseChannel.createChannelsQuery(params)

query.loadNextPage { page, error ->
if (error == null && page != null) {
page.data?.forEach { channel ->
println("Channel: ${channel.channelId}")
println("Unread: ${channel.unreadCount}")
println("Last message: ${channel.latestMessage?.content}")
}
} else {
// Failed: ${error?.message}
}
}

Query parameters

ChannelsQueryParams supports the following parameters:

ParameterTypeDescription
channelTypesList<ChannelType>List of channel types to query.
pageSizeIntNumber of channels per page. Default is 20.
topPriorityBooleanWhether pinned channels are returned first. Default is true.
startTimeLongStart time for the query in milliseconds. Default is 0L.

Channel properties

Each channel object returned includes the following common properties:

PropertyTypeDescription
channelIdStringChannel ID
channelTypeChannelTypeChannel type
unreadCountIntUnread message count
latestMessageMessage?Last message
isPinnedBooleanWhether the channel is pinned
channelNoDisturbLevelChannelNoDisturbLevelNotification level