Skip to content

Commit

Permalink
Added attachOnSubscribe check before implicit attach on channel subsc…
Browse files Browse the repository at this point in the history
…ribe
  • Loading branch information
sacOO7 committed Sep 16, 2024
1 parent 935ff90 commit 630c70d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 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 @@ -704,7 +704,9 @@ public synchronized void unsubscribe() {
public synchronized void subscribe(MessageListener listener) throws AblyException {
Log.v(TAG, "subscribe(); channel = " + this.name);
listeners.add(listener);
attach();
if (options.attachOnSubscribe) {
attach();
}
}

/**
Expand Down Expand Up @@ -739,7 +741,9 @@ 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);
attach();
if (options.attachOnSubscribe) {
attach();
}
}

/**
Expand Down Expand Up @@ -773,7 +777,9 @@ 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);
attach();
if (options.attachOnSubscribe) {
attach();
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/src/main/java/io/ably/lib/realtime/Presence.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ public void unsubscribe() {
* @throws AblyException
*/
private void implicitAttachOnSubscribe(CompletionListener completionListener) throws AblyException {
if (!channel.options.attachOnSubscribe) {
completionListener.onSuccess();
return;
}
if (channel.state == ChannelState.failed) {
String errorString = String.format(Locale.ROOT, "Channel %s: subscribe in FAILED channel state", channel.name);
Log.v(TAG, errorString);
Expand Down

0 comments on commit 630c70d

Please sign in to comment.