Skip to main content

Handle unread count

The Nexconn SDK provides methods to get and clear unread message counts.

Get the unread count for a channel

Access the unreadCount property on the channel object to get the current unread message count.

kotlin
val channel = DirectChannel("userId")
val count = channel.unreadCount
Log.d("Unread", "Unread count: $count")

Clear the unread count

Use clearUnreadCount() to reset the unread count for a channel.

kotlin
val channel = DirectChannel("userId")

channel.clearUnreadCount { success, error ->
if (error == null && success == true) {
Log.d("Unread", "Unread count cleared")
}
}

Get the first unread message

Use getFirstUnreadMessage() to retrieve the earliest unread message for navigation purposes.

kotlin
val channel = DirectChannel("userId")

channel.getFirstUnreadMessage { message, error ->
if (error == null && message != null) {
Log.d("Unread", "First unread: ${message.messageId}")
} else if (message == null) {
Log.d("Unread", "No unread messages")
}
}

Get the total unread count across channel types

Use the static BaseChannel.getTotalUnreadCount() method to get the combined unread count for all supported channel types.

kotlin
BaseChannel.getTotalUnreadCount { count, error ->
if (error == null) {
Log.d("Unread", "Total unread: $count")
}
}

Parameters

unreadCount (property)

PropertyTypeDescription
unreadCountIntUnread message count for the current channel.

clearUnreadCount

ParameterTypeDescription
handlerOperationHandler<Boolean>The completion callback.

getFirstUnreadMessage

ParameterTypeDescription
handlerOperationHandler<Message>Callback returning the first unread message, or null if there are no unread messages.

getTotalUnreadCount (static method)

ParameterTypeDescription
handlerOperationHandler<Int>Callback returning the total unread count across all supported channel types.

Important notes

  • The unread count only reflects messages in the local database.
  • Clearing the unread count marks messages as read but does not delete them.
  • Clear the unread count when the user views messages.
  • Open channels do not support unread counts.