ably-cocoa icon indicating copy to clipboard operation
ably-cocoa copied to clipboard

Add per-channel attachResume control to ARTRealtimeChannelOptions

Open Copilot opened this issue 6 months ago • 1 comments

This PR adds the ability to control attach resume behavior on a per-channel basis, allowing clients to disable automatic resume and rely solely on message history when channels reconnect within the 2-minute TTL.

Problem

Previously, attach resume behavior was managed automatically at the channel level based on state transitions. Clients had no way to override this behavior for specific channels, meaning they would always receive missed messages during reconnection within the TTL period. Some use cases require disabling this behavior to rely exclusively on message history.

Solution

Added a new attachResume property to ARTRealtimeChannelOptions:

@property (nonatomic, nullable) NSNumber *attachResume;

The property behavior:

  • nil (default): Uses existing automatic behavior based on channel state
  • @YES: Forces attach resume to be enabled
  • @NO: Forces attach resume to be disabled, allowing sole reliance on message history

Usage Example

// Disable attach resume for this channel
ARTRealtimeChannelOptions *options = [[ARTRealtimeChannelOptions alloc] init];
options.attachResume = @NO;

ARTRealtimeChannel *channel = [client.channels get:@"channel-name" options:options];
// This channel will not use attach resume and will rely on message history

Message Differentiation

The existing ARTChannelStateChange.resumed property can be used to differentiate between messages received during normal operation vs. after a resumed attachment:

[channel on:ARTChannelEventAttached callback:^(ARTChannelStateChange *stateChange) {
    if (stateChange.resumed) {
        // Messages received shortly after are from resume
    }
}];

Implementation Details

  • Added new property to ARTRealtimeChannelOptions with proper getter/setter and copy support
  • Modified attach logic to use shouldUseAttachResume helper method that checks channel options
  • Maintains full backward compatibility - existing behavior unchanged when property is nil
  • Added comprehensive tests covering all three scenarios (enabled, disabled, default)

Fixes #2042.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Aug 29 '25 12:08 Copilot

@umair-ably 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot avatar Aug 29 '25 12:08 Copilot