2828import io .ably .lib .transport .ITransport .TransportParams ;
2929import io .ably .lib .transport .NetworkConnectivity .NetworkConnectivityListener ;
3030import io .ably .lib .types .AblyException ;
31+ import io .ably .lib .types .Callback ;
3132import io .ably .lib .types .ClientOptions ;
3233import io .ably .lib .types .ConnectionDetails ;
3334import io .ably .lib .types .ErrorInfo ;
3435import io .ably .lib .types .Param ;
3536import io .ably .lib .types .ProtocolMessage ;
3637import io .ably .lib .types .ProtocolSerializer ;
38+ import io .ably .lib .types .PublishResult ;
3739import io .ably .lib .util .Log ;
3840import io .ably .lib .util .PlatformAgentProvider ;
3941import io .ably .lib .util .ReconnectionStrategy ;
42+ import org .jetbrains .annotations .Nullable ;
4043
4144public class ConnectionManager implements ConnectListener {
4245 final ExecutorService singleThreadExecutor = Executors .newSingleThreadExecutor ();
@@ -1403,7 +1406,7 @@ private synchronized void onError(ProtocolMessage message) {
14031406 }
14041407
14051408 private void onAck (ProtocolMessage message ) {
1406- pendingMessages .ack (message .msgSerial , message .count , message .error );
1409+ pendingMessages .ack (message .msgSerial , message .count , message .res , message . error );
14071410 }
14081411
14091412 private void onNack (ProtocolMessage message ) {
@@ -1724,14 +1727,14 @@ protected void setLastActivity(long lastActivityTime) {
17241727
17251728 public static class QueuedMessage {
17261729 public final ProtocolMessage msg ;
1727- public final CompletionListener listener ;
1728- public QueuedMessage (ProtocolMessage msg , CompletionListener listener ) {
1730+ public final Callback < PublishResult > listener ;
1731+ public QueuedMessage (ProtocolMessage msg , Callback < PublishResult > listener ) {
17291732 this .msg = msg ;
17301733 this .listener = listener ;
17311734 }
17321735 }
17331736
1734- public void send (ProtocolMessage msg , boolean queueEvents , CompletionListener listener ) throws AblyException {
1737+ public void send (ProtocolMessage msg , boolean queueEvents , Callback < PublishResult > listener ) throws AblyException {
17351738 State state ;
17361739 synchronized (this ) {
17371740 state = this .currentState ;
@@ -1747,7 +1750,7 @@ public void send(ProtocolMessage msg, boolean queueEvents, CompletionListener li
17471750 throw AblyException .fromErrorInfo (state .defaultErrorInfo );
17481751 }
17491752
1750- private void sendImpl (ProtocolMessage message , CompletionListener listener ) throws AblyException {
1753+ private void sendImpl (ProtocolMessage message , Callback < PublishResult > listener ) throws AblyException {
17511754 if (transport == null ) {
17521755 Log .v (TAG , "sendImpl(): Discarding message; transport unavailable" );
17531756 return ;
@@ -1825,7 +1828,7 @@ public synchronized void push(QueuedMessage msg) {
18251828 queue .add (msg );
18261829 }
18271830
1828- public void ack (long msgSerial , int count , ErrorInfo reason ) {
1831+ public void ack (long msgSerial , int count , @ Nullable PublishResult [] results , ErrorInfo reason ) {
18291832 QueuedMessage [] ackMessages = null , nackMessages = null ;
18301833 synchronized (this ) {
18311834 if (queue .isEmpty ()) return ;
@@ -1867,11 +1870,14 @@ public void ack(long msgSerial, int count, ErrorInfo reason) {
18671870 }
18681871 }
18691872 if (ackMessages != null ) {
1870- for (QueuedMessage msg : ackMessages ) {
1873+ for (int i = 0 ; i < ackMessages .length ; i ++) {
1874+ QueuedMessage msg = ackMessages [i ];
18711875 try {
1872- if (msg .listener != null )
1873- msg .listener .onSuccess ();
1874- } catch (Throwable t ) {
1876+ if (msg .listener != null ) {
1877+ PublishResult messageResult = results != null && results .length > i ? results [i ] : null ;
1878+ msg .listener .onSuccess (messageResult );
1879+ }
1880+ } catch (Throwable t ) {
18751881 Log .e (TAG , "ack(): listener exception" , t );
18761882 }
18771883 }
0 commit comments