diff --git a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java index 856bb3a4e..bfffef44b 100644 --- a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java +++ b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java @@ -690,6 +690,15 @@ public synchronized void unsubscribe() { eventListeners.clear(); } + /** + * Checks for null channelOptions and checks if options.attachOnSubscribe is true + * Defaults to @true@ when channelOptions is null. + * Spec: RTP6d, RTP6e, TB4 + */ + protected boolean attachOnSubscribeEnabled() { + return options == null || options.attachOnSubscribe; + } + /** * Registers a listener for messages on this channel. * The caller supplies a listener function, which is called each time one or more messages arrives on the channel. @@ -704,7 +713,7 @@ public synchronized void unsubscribe() { public synchronized void subscribe(MessageListener listener) throws AblyException { Log.v(TAG, "subscribe(); channel = " + this.name); listeners.add(listener); - if (options.attachOnSubscribe) { + if (attachOnSubscribeEnabled()) { attach(); } } @@ -741,7 +750,7 @@ public synchronized void unsubscribe(MessageListener listener) { public synchronized void subscribe(String name, MessageListener listener) throws AblyException { Log.v(TAG, "subscribe(); channel = " + this.name + "; event = " + name); subscribeImpl(name, listener); - if (options.attachOnSubscribe) { + if (attachOnSubscribeEnabled()) { attach(); } } @@ -777,7 +786,7 @@ public synchronized void subscribe(String[] names, MessageListener listener) thr Log.v(TAG, "subscribe(); channel = " + this.name + "; (multiple events)"); for(String name : names) subscribeImpl(name, listener); - if (options.attachOnSubscribe) { + if (attachOnSubscribeEnabled()) { attach(); } } diff --git a/lib/src/main/java/io/ably/lib/realtime/Presence.java b/lib/src/main/java/io/ably/lib/realtime/Presence.java index 0a29ab9ab..cae2ec845 100644 --- a/lib/src/main/java/io/ably/lib/realtime/Presence.java +++ b/lib/src/main/java/io/ably/lib/realtime/Presence.java @@ -308,7 +308,7 @@ public void unsubscribe() { * @throws AblyException */ private void implicitAttachOnSubscribe(CompletionListener completionListener) throws AblyException { - if (!channel.options.attachOnSubscribe) { + if (!channel.attachOnSubscribeEnabled()) { completionListener.onSuccess(); return; }