Skip to content

Commit de0225c

Browse files
committed
Removed asQueryItems: towards more simple asQueryParams.
1 parent 4cf2787 commit de0225c

7 files changed

Lines changed: 17 additions & 53 deletions

File tree

Source/ARTDataQuery.m

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,8 @@ - (instancetype)init {
2222
}
2323
}
2424

25-
- (NSMutableArray *)asQueryItems:(NSError *_Nullable*)error {
26-
NSMutableArray *items = [NSMutableArray array];
27-
28-
if (self.start) {
29-
[items addObject:[NSURLQueryItem queryItemWithName:@"start" value:[NSString stringWithFormat:@"%llu", dateToMilliseconds(self.start)]]];
30-
}
31-
if (self.end) {
32-
[items addObject:[NSURLQueryItem queryItemWithName:@"end" value:[NSString stringWithFormat:@"%llu", dateToMilliseconds(self.end)]]];
33-
}
34-
35-
[items addObject:[NSURLQueryItem queryItemWithName:@"limit" value:[NSString stringWithFormat:@"%hu", self.limit]]];
36-
[items addObject:[NSURLQueryItem queryItemWithName:@"direction" value:queryDirectionToString(self.direction)]];
37-
38-
return items;
39-
}
40-
4125
- (NSStringDictionary *)asQueryParams {
42-
NSMutableDictionary *items = [NSMutableDictionary dictionary];
26+
NSMutableStringDictionary *items = [NSMutableStringDictionary dictionary];
4327

4428
if (self.start) {
4529
items[@"start"] = [NSString stringWithFormat:@"%llu", dateToMilliseconds(self.start)];
@@ -58,20 +42,10 @@ - (NSStringDictionary *)asQueryParams {
5842

5943
@implementation ARTRealtimeHistoryQuery
6044

61-
- (NSMutableArray *)asQueryItems:(NSError **)errorPtr {
62-
NSMutableArray *items = [super asQueryItems:errorPtr];
63-
if (*errorPtr) {
64-
return nil;
65-
}
66-
if (self.untilAttach) {
67-
NSAssert(self.realtimeChannel, @"ARTRealtimeHistoryQuery used from outside ARTRealtimeChannel.history");
68-
if (self.realtimeChannel.state_nosync != ARTRealtimeChannelAttached) {
69-
*errorPtr = [NSError errorWithDomain:ARTAblyErrorDomain code:ARTRealtimeHistoryErrorNotAttached userInfo:@{NSLocalizedDescriptionKey:@"ARTRealtimeHistoryQuery: untilAttach used in channel that isn't attached"}];
70-
return nil;
71-
}
72-
[items addObject:[NSURLQueryItem queryItemWithName:@"fromSerial" value:self.realtimeChannel.attachSerial]];
73-
}
74-
return items;
45+
- (NSStringDictionary *)asQueryParams {
46+
NSMutableStringDictionary *params = super.asQueryParams.mutableCopy;
47+
params[@"fromSerial"] = self.realtimeChannelAttachSerial;
48+
return params;
7549
}
7650

7751
@end

Source/ARTRealtimeChannel.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,15 @@ - (void)historyWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAge
12071207
[self history:[[ARTRealtimeHistoryQuery alloc] init] wrapperSDKAgents:wrapperSDKAgents callback:callback error:nil];
12081208
}
12091209

1210-
- (BOOL)history:(ARTRealtimeHistoryQuery *)query wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTPaginatedMessagesCallback)callback error:(NSError **)errorPtr {
1211-
query.realtimeChannel = self;
1210+
- (BOOL)history:(ARTRealtimeHistoryQuery *)query
1211+
wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
1212+
callback:(ARTPaginatedMessagesCallback)callback
1213+
error:(NSError **)errorPtr {
1214+
if (query.untilAttach && self.state_nosync != ARTRealtimeChannelAttached) { // RTL10b
1215+
*errorPtr = [NSError errorWithDomain:ARTAblyErrorDomain code:ARTRealtimeHistoryErrorNotAttached userInfo:@{NSLocalizedDescriptionKey:@"ARTRealtimeHistoryQuery: untilAttach used in channel that isn't attached"}];
1216+
return false;
1217+
}
1218+
query.realtimeChannelAttachSerial = self.attachSerial;
12121219
return [_restChannel history:query wrapperSDKAgents:wrapperSDKAgents callback:callback error:errorPtr];
12131220
}
12141221

Source/ARTRealtimePresence.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ - (void)historyWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAge
279279
}
280280

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

Source/ARTStats.m

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ - (instancetype)init {
2525
}
2626
}
2727

28-
- (NSMutableArray *)asQueryItems:(NSError **)error {
29-
NSMutableArray *items = [super asQueryItems:error];
30-
if (*error) {
31-
return nil;
32-
}
33-
[items addObject:[NSURLQueryItem queryItemWithName:@"unit" value:statsUnitToString(self.unit)]];
34-
return items;
35-
}
36-
3728
- (NSStringDictionary *)asQueryParams {
3829
NSMutableDictionary *items = (NSMutableDictionary *)[super asQueryParams];
3930
items[@"unit"] = statsUnitToString(self.unit);

Source/PrivateHeaders/Ably/ARTDataQuery+Private.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ NS_ASSUME_NONNULL_BEGIN
55

66
@interface ARTDataQuery (Private)
77

8-
- (nullable NSMutableArray /* <NSURLQueryItem *> */ *)asQueryItems:(NSError *_Nullable *)error;
9-
108
- (NSStringDictionary *)asQueryParams;
119

1210
@end
1311

1412
@interface ARTRealtimeHistoryQuery ()
1513

16-
@property (readwrite) ARTRealtimeChannelInternal *realtimeChannel;
14+
@property (readwrite, copy) NSString *realtimeChannelAttachSerial;
1715

1816
@end
1917

Source/PrivateHeaders/Ably/ARTPresence+Private.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#import <Ably/ARTPresence.h>
22
#import "ARTChannel.h"
33

4-
@interface ARTPresenceQuery ()
5-
6-
- (NSMutableArray<NSURLQueryItem *> *)asQueryItems;
7-
8-
@end
9-
104
@interface ARTPresence ()
115

126
@property (readonly, getter=getChannel) ARTChannel *channel;

Source/include/Ably/ARTTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ typedef NS_ENUM(NSInteger, ARTDataQueryError) {
188188
/// :nodoc:
189189
NS_SWIFT_SENDABLE
190190
typedef NS_ENUM(NSInteger, ARTRealtimeHistoryError) {
191-
ARTRealtimeHistoryErrorNotAttached = ARTDataQueryErrorTimestampRange + 1
191+
ARTRealtimeHistoryErrorNotAttached = ARTDataQueryErrorTimestampRange + 1 // TODO: overlaps with ARTDataQueryErrorMissingRequiredFields
192192
};
193193

194194
/// :nodoc:
@@ -480,6 +480,7 @@ NS_SWIFT_SENDABLE
480480

481481
/// :nodoc:
482482
typedef NSDictionary<NSString *, NSString *> NSStringDictionary;
483+
typedef NSMutableDictionary<NSString *, NSString *> NSMutableStringDictionary;
483484

484485
// Below are the typedefs of completion handlers to improve readability and maintainability in properties and method parameters.
485486
// Either result/response or error can be nil but not both.

0 commit comments

Comments
 (0)