private fun getUnreadMessageCount(newMessageState: NewMessageState? = currentMessagesState.newMessageState): Int { if (newMessageState == null || newMessageState == MyOwn) return 0  val messageItems = currentMessagesState.messageItems val lastSeenMessagePosition = getLastSeenMessagePosition(if (isInThread) lastSeenThreadMessage else lastSeenChannelMessage) var unreadCount = 0  for (i in 0..lastSeenMessagePosition) { val messageItem = messageItems[i]  if (messageItem is MessageItemState && !messageItem.isMine && messageItem.message.deletedAt == null) { unreadCount++ } }  return unreadCount }
Counts how many messages the user hasn't read already. This is based on what the last message they've seen is, and the current message state.