Skip to content

Commit 3e3c853

Browse files
committed
[ECO-5482] Implemented helper method to validate write api config
1 parent 25f37c8 commit 3e3c853

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

lib/src/main/java/io/ably/lib/objects/Adapter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import io.ably.lib.realtime.AblyRealtime;
44
import io.ably.lib.realtime.ChannelState;
55
import io.ably.lib.realtime.CompletionListener;
6-
import io.ably.lib.types.AblyException;
7-
import io.ably.lib.types.ChannelMode;
8-
import io.ably.lib.types.ChannelOptions;
9-
import io.ably.lib.types.ProtocolMessage;
6+
import io.ably.lib.types.*;
107
import io.ably.lib.util.Log;
118
import org.jetbrains.annotations.NotNull;
129

@@ -65,4 +62,9 @@ public ChannelState getChannelState(@NotNull String channelName) {
6562
Log.e(TAG, "getChannelState(): channel not found: " + channelName);
6663
return null;
6764
}
65+
66+
@Override
67+
public @NotNull ClientOptions getClientOptions() {
68+
return ably.options;
69+
}
6870
}

lib/src/main/java/io/ably/lib/objects/LiveObjectsAdapter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.ably.lib.realtime.CompletionListener;
55
import io.ably.lib.types.AblyException;
66
import io.ably.lib.types.ChannelMode;
7+
import io.ably.lib.types.ClientOptions;
78
import io.ably.lib.types.ProtocolMessage;
89
import org.jetbrains.annotations.NotNull;
910
import org.jetbrains.annotations.Nullable;
@@ -53,5 +54,14 @@ public interface LiveObjectsAdapter {
5354
* @return the current state of the specified channel, or null if the channel is not found
5455
*/
5556
@Nullable ChannelState getChannelState(@NotNull String channelName);
57+
58+
/**
59+
* Retrieves the client options configured for the Ably client.
60+
* Used to access client configuration parameters such as echoMessages setting
61+
* that affect the behavior of LiveObjects operations.
62+
*
63+
* @return the client options containing configuration parameters
64+
*/
65+
@NotNull ClientOptions getClientOptions();
5666
}
5767

live-objects/src/main/kotlin/io/ably/lib/objects/Helpers.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ internal fun LiveObjectsAdapter.throwIfInvalidAccessApiConfiguration(channelName
4949
throwIfInChannelState(channelName, arrayOf(ChannelState.detached, ChannelState.failed))
5050
}
5151

52+
internal fun LiveObjectsAdapter.throwIfInvalidWriteApiConfiguration(channelName: String) {
53+
throwIfEchoMessagesDisabled()
54+
throwIfMissingChannelMode(channelName, ChannelMode.object_publish)
55+
throwIfInChannelState(channelName, arrayOf(ChannelState.detached, ChannelState.failed, ChannelState.suspended))
56+
}
57+
5258
// Spec: RTO2
5359
internal fun LiveObjectsAdapter.throwIfMissingChannelMode(channelName: String, channelMode: ChannelMode) {
5460
val channelModes = getChannelModes(channelName)
@@ -65,6 +71,12 @@ internal fun LiveObjectsAdapter.throwIfInChannelState(channelName: String, chann
6571
}
6672
}
6773

74+
internal fun LiveObjectsAdapter.throwIfEchoMessagesDisabled() {
75+
if (!clientOptions.echoMessages) {
76+
throw clientError("\"echoMessages\" client option must be enabled for this operation")
77+
}
78+
}
79+
6880
internal class Binary(val data: ByteArray) {
6981
override fun equals(other: Any?): Boolean {
7082
if (this === other) return true

0 commit comments

Comments
 (0)