package com.dmdirc.ktirc.model import com.dmdirc.ktirc.sasl.SaslMechanism internal class SaslState(private val mechanisms: Collection) { var saslBuffer: String = "" var currentMechanism: SaslMechanism? = null set(value) { mechanismState = null field = value } var mechanismState: Any? = null fun getPreferredSaslMechanism(serverMechanisms: String?): SaslMechanism? { val serverSupported = serverMechanisms?.split(',') ?: return null return mechanisms .filter { it.priority < currentMechanism?.priority ?: Int.MAX_VALUE } .filter { serverMechanisms.isEmpty() || it.ircName in serverSupported } .maxBy { it.priority } } fun reset() { saslBuffer = "" currentMechanism = null } }