Skip to content

Commit 83c3c6a

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

3 files changed

Lines changed: 28 additions & 6 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.ably.lib.objects
22

3-
import io.ably.lib.objects.type.BaseLiveObject
4-
import io.ably.lib.objects.type.map.LiveMapValue
53
import io.ably.lib.realtime.ChannelState
64
import io.ably.lib.realtime.CompletionListener
75
import io.ably.lib.types.ChannelMode
@@ -49,6 +47,12 @@ internal fun LiveObjectsAdapter.throwIfInvalidAccessApiConfiguration(channelName
4947
throwIfInChannelState(channelName, arrayOf(ChannelState.detached, ChannelState.failed))
5048
}
5149

50+
internal fun LiveObjectsAdapter.throwIfInvalidWriteApiConfiguration(channelName: String) {
51+
throwIfEchoMessagesDisabled()
52+
throwIfMissingChannelMode(channelName, ChannelMode.object_publish)
53+
throwIfInChannelState(channelName, arrayOf(ChannelState.detached, ChannelState.failed, ChannelState.suspended))
54+
}
55+
5256
// Spec: RTO2
5357
internal fun LiveObjectsAdapter.throwIfMissingChannelMode(channelName: String, channelMode: ChannelMode) {
5458
val channelModes = getChannelModes(channelName)
@@ -65,6 +69,12 @@ internal fun LiveObjectsAdapter.throwIfInChannelState(channelName: String, chann
6569
}
6670
}
6771

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

0 commit comments

Comments
 (0)