Skip to main content

Get unread messages

The Nexconn SDK supports retrieving unread messages from a channel, enabling features like jumping to the first unread message or displaying all unread mentions.

Get the first unread message

Retrieve the earliest unread message in a channel.

kotlin
val channel = DirectChannel("userId")

channel.getFirstUnreadMessage { message, error ->
if (error == null && message != null) {
println("First unread message: ${message.messageId}")
}
}

Get unread mention messages

Retrieve all unread messages that mention the current user. The returned list is sorted by time.

kotlin
val channel = DirectChannel("userId")

channel.getUnreadMentionedMessages { messages, error ->
if (error == null && messages != null) {
messages.forEach { msg ->
println("Mention message: ${msg.messageId}")
}
}
}

Get channels with unread mentions

Use BaseChannel.createUnreadMentionMeChannelsQuery to create a paginated query for channels that contain unread messages mentioning the current user.

UnreadMentionMeChannelsQueryParams

ParameterTypeDescription
channelTypesList<ChannelType>Channel types to query. Supports: direct, group, system, community.
topPriorityBooleanWhether to prioritize pinned channels. Default: true.
startTimeLongStart time in milliseconds. Pass 0 for the latest. For pagination, pass the timestamp of the last channel from the previous page. Default: 0.
pageSizeIntResults per page. Valid range: 1-100. Default: 20.
kotlin
val params = UnreadMentionMeChannelsQueryParams(
channelTypes = listOf(ChannelType.DIRECT, ChannelType.GROUP, ChannelType.SYSTEM, ChannelType.COMMUNITY)
).apply {
topPriority = true
pageSize = 20
}

val query = BaseChannel.createUnreadMentionMeChannelsQuery(params)

query.loadNextPage { page, error ->
if (error == null && page != null) {
page.data.forEach { channel ->
println("Channel ${channel.channelId} has unread mentions")
}
}
}