private fun filterMessagesToShow(messages: List<Message>): List<Message> { val currentUser = user.value return messages.filter { val shouldShowIfDeleted = when (deletedMessageVisibility) { DeletedMessageVisibility.ALWAYS_VISIBLE -> true DeletedMessageVisibility.VISIBLE_FOR_CURRENT_USER -> { !(it.deletedAt != null && it.user.id != currentUser?.id) } else -> it.deletedAt == null } val isSystemMessage = it.isSystem() || it.isError()  shouldShowIfDeleted || (isSystemMessage && showSystemMessages) } }
Used to filter messages which we should show to the current user.