@@ -138,19 +138,20 @@ internal fun LiveObjectsAdapter.throwIfUnpublishableState(channelName: String) {
138138}
139139
140140// Spec: RTO2
141- internal fun LiveObjectsAdapter.throwIfMissingChannelMode (channelName : String , channelMode : ChannelMode ) {
142- val channelModes = getChannelModes(channelName)
143- if (channelModes == null || ! channelModes.contains(channelMode)) {
144- // Spec: RTO2a2, RTO2b2
145- throw ablyException(" \" ${channelMode.name} \" channel mode must be set for this operation" , ErrorCode .ChannelModeRequired )
141+ private fun LiveObjectsAdapter.throwIfMissingChannelMode (channelName : String , channelMode : ChannelMode ) {
142+ getChannelModes(channelName)?.let { modes ->
143+ if (modes.contains(channelMode)) return // If channel modes are set, check if the required mode is present
146144 }
145+ // Spec: RTO2a2, RTO2b2
146+ throw ablyException(" \" ${channelMode.name} \" channel mode must be set for this operation" , ErrorCode .ChannelModeRequired )
147147}
148148
149- internal fun LiveObjectsAdapter.throwIfInChannelState (channelName : String , channelStates : Array <ChannelState >) {
150- val currentState = getChannel(channelName).state
151- if (currentState == null || channelStates.contains(currentState)) {
152- throw ablyException( " Channel is in invalid state: $currentState " , ErrorCode . ChannelStateError )
149+ private fun LiveObjectsAdapter.throwIfInChannelState (channelName : String , channelStates : Array <ChannelState >) {
150+ val currentChannelState = getChannel(channelName).state
151+ currentChannelState?. let {
152+ if ( ! channelStates.contains(it)) return
153153 }
154+ throw ablyException(" Channel is in invalid state: $currentChannelState " , ErrorCode .ChannelStateError )
154155}
155156
156157internal fun LiveObjectsAdapter.throwIfEchoMessagesDisabled () {
0 commit comments