Skip to content

Commit

Permalink
Added extra null channelOptions check while checking for attachOnSubs…
Browse files Browse the repository at this point in the history
…cribe
  • Loading branch information
sacOO7 committed Sep 16, 2024
1 parent 630c70d commit e7fe76e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/io/ably/lib/realtime/Presence.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e7fe76e

Please sign in to comment.