Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added attachOnSubscribe check before implicit attach on channel subsc…
…ribe
  • Loading branch information
sacOO7 committed Sep 16, 2024
commit 630c70dc238f399a2c78844fef84cccb6d5bed47
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