Skip to content

Commit

Permalink
Insert wrapper SDK agents in realtime presence history requests
Browse files Browse the repository at this point in the history
As in b006650.

Resolves #2029.
  • Loading branch information
lawrence-forooghian committed Feb 17, 2025
1 parent 7b25aa7 commit d7c0bc1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 20 deletions.
13 changes: 7 additions & 6 deletions Source/ARTRealtimePresence.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ - (void)unsubscribe:(ARTPresenceAction)action listener:(ARTEventListener *)liste
}

- (void)history:(ARTPaginatedPresenceCallback)callback {
[_internal history:callback];
[_internal historyWithWrapperSDKAgents:nil completion:callback];
}

- (BOOL)history:(ARTRealtimeHistoryQuery *_Nullable)query callback:(ARTPaginatedPresenceCallback)callback error:(NSError *_Nullable *_Nullable)errorPtr {
return [_internal history:query callback:callback error:errorPtr];
return [_internal history:query wrapperSDKAgents:nil callback:callback error:errorPtr];
}

@end
Expand Down Expand Up @@ -272,13 +272,14 @@ - (void)get:(ARTRealtimePresenceQuery *)query callback:(ARTPresenceMessagesCallb

// RTP12

- (void)history:(ARTPaginatedPresenceCallback)callback {
[self history:[[ARTRealtimeHistoryQuery alloc] init] callback:callback error:nil];
- (void)historyWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(ARTPaginatedPresenceCallback)callback {
[self history:[[ARTRealtimeHistoryQuery alloc] init] wrapperSDKAgents:wrapperSDKAgents callback:callback error:nil];
}

- (BOOL)history:(ARTRealtimeHistoryQuery *)query callback:(ARTPaginatedPresenceCallback)callback error:(NSError **)errorPtr {
- (BOOL)history:(ARTRealtimeHistoryQuery *)query wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTPaginatedPresenceCallback)callback error:(NSError **)errorPtr {
query.realtimeChannel = _channel;
return [_channel.restChannel.presence history:query callback:callback error:errorPtr];
return [_channel.restChannel.presence history:query wrapperSDKAgents:wrapperSDKAgents callback:callback error:errorPtr];
}

// RTP8
Expand Down
13 changes: 7 additions & 6 deletions Source/ARTRestPresence.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ - (BOOL)get:(ARTPresenceQuery *)query callback:(ARTPaginatedPresenceCallback)cal
}

- (BOOL)history:(nullable ARTDataQuery *)query callback:(ARTPaginatedPresenceCallback)callback error:(NSError *_Nullable *_Nullable)errorPtr {
return [_internal history:query callback:callback error:errorPtr];
return [_internal history:query wrapperSDKAgents:nil callback:callback error:errorPtr];
}

- (void)history:(ARTPaginatedPresenceCallback)callback {
[_internal history:callback];
[_internal historyWithWrapperSDKAgents:nil completion:callback];
}

@end
Expand Down Expand Up @@ -161,11 +161,12 @@ - (BOOL)get:(ARTPresenceQuery *)query callback:(ARTPaginatedPresenceCallback)cal
return YES;
}

- (void)history:(ARTPaginatedPresenceCallback)callback {
[self history:[[ARTDataQuery alloc] init] callback:callback error:nil];
- (void)historyWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(ARTPaginatedPresenceCallback)callback {
[self history:[[ARTDataQuery alloc] init] wrapperSDKAgents:wrapperSDKAgents callback:callback error:nil];
}

- (BOOL)history:(ARTDataQuery *)query callback:(ARTPaginatedPresenceCallback)callback error:(NSError **)errorPtr {
- (BOOL)history:(ARTDataQuery *)query wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTPaginatedPresenceCallback)callback error:(NSError **)errorPtr {
if (callback) {
void (^userCallback)(ARTPaginatedResult<ARTPresenceMessage *> *result, ARTErrorInfo *error) = callback;
callback = ^(ARTPaginatedResult<ARTPresenceMessage *> *result, ARTErrorInfo *error) {
Expand Down Expand Up @@ -217,7 +218,7 @@ - (BOOL)history:(ARTDataQuery *)query callback:(ARTPaginatedPresenceCallback)cal
};

dispatch_async(_queue, ^{
[ARTPaginatedResult executePaginated:self->_channel.rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:nil logger:self->_logger callback:callback];
[ARTPaginatedResult executePaginated:self->_channel.rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:wrapperSDKAgents logger:self->_logger callback:callback];
});
return YES;
}
Expand Down
10 changes: 8 additions & 2 deletions Source/ARTWrapperSDKProxyRealtimePresence.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#import "ARTWrapperSDKProxyRealtimePresence+Private.h"
#import "ARTRealtimePresence+Private.h"
#import "ARTWrapperSDKProxyOptions.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -51,11 +53,15 @@ - (void)get:(nonnull ARTRealtimePresenceQuery *)query callback:(nonnull ARTPrese
}

- (void)history:(nonnull ARTPaginatedPresenceCallback)callback {
[self.underlyingRealtimePresence history:callback];
[self.underlyingRealtimePresence.internal historyWithWrapperSDKAgents:self.proxyOptions.agents
completion:callback];
}

- (BOOL)history:(ARTRealtimeHistoryQuery * _Nullable)query callback:(nonnull ARTPaginatedPresenceCallback)callback error:(NSError * _Nullable __autoreleasing * _Nullable)errorPtr {
return [self.underlyingRealtimePresence history:query callback:callback error:errorPtr];
return [self.underlyingRealtimePresence.internal history:query
wrapperSDKAgents:self.proxyOptions.agents
callback:callback
error:errorPtr];
}

- (void)leave:(id _Nullable)data {
Expand Down
5 changes: 3 additions & 2 deletions Source/PrivateHeaders/Ably/ARTRealtimePresence+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ NS_ASSUME_NONNULL_BEGIN

- (void)unsubscribe:(ARTPresenceAction)action listener:(ARTEventListener *)listener;

- (void)history:(ARTPaginatedPresenceCallback)callback;
- (void)historyWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(ARTPaginatedPresenceCallback)callback;

- (BOOL)history:(ARTRealtimeHistoryQuery *_Nullable)query callback:(ARTPaginatedPresenceCallback)callback error:(NSError *_Nullable *_Nullable)errorPtr;
- (BOOL)history:(ARTRealtimeHistoryQuery *_Nullable)query wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTPaginatedPresenceCallback)callback error:(NSError *_Nullable *_Nullable)errorPtr;

@end

Expand Down
5 changes: 3 additions & 2 deletions Source/PrivateHeaders/Ably/ARTRestPresence+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ NS_ASSUME_NONNULL_BEGIN

- (BOOL)get:(ARTPresenceQuery *)query callback:(ARTPaginatedPresenceCallback)callback error:(NSError *_Nullable *_Nullable)errorPtr;

- (BOOL)history:(nullable ARTDataQuery *)query callback:(ARTPaginatedPresenceCallback)callback error:(NSError *_Nullable *_Nullable)errorPtr;
- (BOOL)history:(nullable ARTDataQuery *)query wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTPaginatedPresenceCallback)callback error:(NSError *_Nullable *_Nullable)errorPtr;

- (void)history:(ARTPaginatedPresenceCallback)callback;
- (void)historyWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(ARTPaginatedPresenceCallback)callback;

@end

Expand Down
4 changes: 2 additions & 2 deletions Test/Tests/RealtimeClientPresenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3569,12 +3569,12 @@ class RealtimeClientPresenceTests: XCTestCase {

var restPresenceHistoryMethodWasCalled = false

let hookRest = channelRest.presence.internal.testSuite_injectIntoMethod(after: #selector(ARTRestPresenceInternal.history(_:callback:))) {
let hookRest = channelRest.presence.internal.testSuite_injectIntoMethod(after: #selector(ARTRestPresenceInternal.history(_:wrapperSDKAgents:callback:))) {
restPresenceHistoryMethodWasCalled = true
}
defer { hookRest.remove() }

let hookRealtime = channelRealtime.presence.internal.testSuite_injectIntoMethod(after: #selector(ARTRestPresenceInternal.history(_:callback:))) {
let hookRealtime = channelRealtime.presence.internal.testSuite_injectIntoMethod(after: #selector(ARTRestPresenceInternal.history(_:wrapperSDKAgents:callback:))) {
restPresenceHistoryMethodWasCalled = true
}
defer { hookRealtime.remove() }
Expand Down
15 changes: 15 additions & 0 deletions Test/Tests/WrapperSDKProxyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,21 @@ class WrapperSDKProxyTests: XCTestCase {
}
#endif

func test_presenceHistory_addsWrapperSDKAgentToRequest() throws {
let test = Test()

try parameterizedTest_addsWrapperSDKAgentToRequests(test: test) { proxyClient in
let channel = proxyClient.channels.get(test.uniqueChannelName())

waitUntil(timeout: testTimeout) { done in
channel.presence.history() { _, error in
XCTAssertNil(error)
done()
}
}
}
}

// MARK: - `agent` channel param

private func parameterizedTest_checkAttachProtocolMessage(
Expand Down

0 comments on commit d7c0bc1

Please sign in to comment.