Skip to content

Commit 9e81158

Browse files
authored
Merge pull request #1096 from ably/ECO-5065/annotation-support
[ECO-5065] feat: add support for managing message annotations
2 parents 41e3213 + 680d474 commit 9e81158

25 files changed

Lines changed: 1849 additions & 77 deletions

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "lib/src/test/resources/ably-common"]
2-
path = lib/src/test/resources/ably-common
3-
url = https://github.com/ably/ably-common.git

lib/src/main/java/io/ably/lib/realtime/ChannelBase.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.ably.lib.http.HttpUtils;
1616
import io.ably.lib.objects.LiveObjects;
1717
import io.ably.lib.objects.LiveObjectsPlugin;
18+
import io.ably.lib.rest.RestAnnotations;
1819
import io.ably.lib.transport.ConnectionManager;
1920
import io.ably.lib.transport.ConnectionManager.QueuedMessage;
2021
import io.ably.lib.transport.Defaults;
@@ -105,6 +106,8 @@ public LiveObjects getObjects() throws AblyException {
105106
return liveObjectsPlugin.getInstance(name);
106107
}
107108

109+
public final RealtimeAnnotations annotations;
110+
108111
/***
109112
* internal
110113
*
@@ -887,7 +890,7 @@ private void onMessage(final ProtocolMessage protocolMessage) {
887890
if(msg.createdAt == null && msg.action == MessageAction.MESSAGE_CREATE) msg.createdAt = msg.timestamp;
888891

889892
try {
890-
msg.decode(options, decodingContext);
893+
if (msg.data != null) msg.decode(options, decodingContext);
891894
} catch (MessageDecodeException e) {
892895
if (e.errorInfo.code == 40018) {
893896
Log.e(TAG, String.format(Locale.ROOT, "Delta message decode failure - %s. Message id = %s, channel = %s", e.errorInfo.message, msg.id, name));
@@ -1310,6 +1313,10 @@ else if(stateChange.current.equals(failureState)) {
13101313
state = ChannelState.initialized;
13111314
this.decodingContext = new DecodingContext();
13121315
this.liveObjectsPlugin = liveObjectsPlugin;
1316+
this.annotations = new RealtimeAnnotations(
1317+
this,
1318+
new RestAnnotations(name, ably.http, ably.options, options)
1319+
);
13131320
}
13141321

13151322
void onChannelMessage(ProtocolMessage msg) {
@@ -1376,6 +1383,9 @@ void onChannelMessage(ProtocolMessage msg) {
13761383
case error:
13771384
setFailed(msg.error);
13781385
break;
1386+
case annotation:
1387+
annotations.onAnnotation(msg);
1388+
break;
13791389
default:
13801390
Log.e(TAG, "onChannelMessage(): Unexpected message action (" + msg.action + ")");
13811391
}
@@ -1402,6 +1412,17 @@ public void once(ChannelState state, ChannelStateListener listener) {
14021412
super.once(state.getChannelEvent(), listener);
14031413
}
14041414

1415+
/**
1416+
* (Internal) Sends a protocol message and provides a callback for completion.
1417+
*
1418+
* @param protocolMessage the protocol message to be sent
1419+
* @param listener the listener to be notified upon completion of the message delivery
1420+
*/
1421+
public void sendProtocolMessage(ProtocolMessage protocolMessage, CompletionListener listener) throws AblyException {
1422+
ConnectionManager connectionManager = ably.connection.connectionManager;
1423+
connectionManager.send(protocolMessage, ably.options.queueMessages, listener);
1424+
}
1425+
14051426
private static final String TAG = Channel.class.getName();
14061427
final AblyRealtime ably;
14071428
final String basePath;

0 commit comments

Comments
 (0)