Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ARTPush/getDevicePushDetails method for simplifying push state access #1186

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Ably.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
84569FA626B46F4E00457CF5 /* ClientOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84569FA226B46ADC00457CF5 /* ClientOptionsTests.swift */; };
84569FA726B46F4F00457CF5 /* ClientOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84569FA226B46ADC00457CF5 /* ClientOptionsTests.swift */; };
84569FA826B46F5100457CF5 /* ClientOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84569FA226B46ADC00457CF5 /* ClientOptionsTests.swift */; };
8471D15D278B583800382E9B /* ARTDevicePushDetails+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 8471D15C278B583800382E9B /* ARTDevicePushDetails+Private.h */; };
8471D15E278B583800382E9B /* ARTDevicePushDetails+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 8471D15C278B583800382E9B /* ARTDevicePushDetails+Private.h */; };
8471D15F278B583800382E9B /* ARTDevicePushDetails+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 8471D15C278B583800382E9B /* ARTDevicePushDetails+Private.h */; };
848ED97326E50D0F0087E800 /* ObjcppTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 848ED97226E50D0F0087E800 /* ObjcppTest.mm */; settings = {COMPILER_FLAGS = "-fmodules"; }; };
848ED97426E50D0F0087E800 /* ObjcppTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 848ED97226E50D0F0087E800 /* ObjcppTest.mm */; settings = {COMPILER_FLAGS = "-fmodules"; }; };
848ED97526E50D0F0087E800 /* ObjcppTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 848ED97226E50D0F0087E800 /* ObjcppTest.mm */; settings = {COMPILER_FLAGS = "-fmodules"; }; };
Expand Down Expand Up @@ -1007,6 +1010,7 @@
8412FDF22661AC7B001FE9E6 /* SwiftyJSON.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = SwiftyJSON.xcframework; path = Carthage/Build/SwiftyJSON.xcframework; sourceTree = "<group>"; };
8412FDF42661AC7B001FE9E6 /* Nimble.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Nimble.xcframework; path = Carthage/Build/Nimble.xcframework; sourceTree = "<group>"; };
84569FA226B46ADC00457CF5 /* ClientOptionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientOptionsTests.swift; sourceTree = "<group>"; };
8471D15C278B583800382E9B /* ARTDevicePushDetails+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ARTDevicePushDetails+Private.h"; sourceTree = "<group>"; };
848ED97226E50D0F0087E800 /* ObjcppTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ObjcppTest.mm; sourceTree = "<group>"; };
850BFB4A1B79323C009D0ADD /* ARTPaginatedResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTPaginatedResult.h; sourceTree = "<group>"; };
850BFB4B1B79323C009D0ADD /* ARTPaginatedResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTPaginatedResult.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1589,12 +1593,6 @@
D7AE18C71E5B40C900478D82 /* ARTPushAdmin.h */,
EBFFAC1A1E97EF5C003E7326 /* ARTPushAdmin+Private.h */,
D7AE18C81E5B40C900478D82 /* ARTPushAdmin.m */,
D7AE18CC1E5B40FE00478D82 /* ARTPushDeviceRegistrations.h */,
EB1B541422FB1CE1006A59AC /* ARTPushDeviceRegistrations+Private.h */,
D7AE18CD1E5B40FE00478D82 /* ARTPushDeviceRegistrations.m */,
D7AE18D01E5B410F00478D82 /* ARTPushChannelSubscriptions.h */,
EB1B541822FB1D7F006A59AC /* ARTPushChannelSubscriptions+Private.h */,
D7AE18D11E5B410F00478D82 /* ARTPushChannelSubscriptions.m */,
);
name = Admin;
sourceTree = "<group>";
Expand Down Expand Up @@ -1836,9 +1834,16 @@
D7B621971E4A762A00684474 /* ARTPushChannel.m */,
D785C4271E549E33008FEC05 /* ARTPushChannelSubscription.h */,
D785C4281E549E33008FEC05 /* ARTPushChannelSubscription.m */,
D7AE18CC1E5B40FE00478D82 /* ARTPushDeviceRegistrations.h */,
EB1B541422FB1CE1006A59AC /* ARTPushDeviceRegistrations+Private.h */,
D7AE18CD1E5B40FE00478D82 /* ARTPushDeviceRegistrations.m */,
D7AE18D01E5B410F00478D82 /* ARTPushChannelSubscriptions.h */,
EB1B541822FB1D7F006A59AC /* ARTPushChannelSubscriptions+Private.h */,
D7AE18D11E5B410F00478D82 /* ARTPushChannelSubscriptions.m */,
D7B621921E4A6FE600684474 /* ARTDeviceDetails.h */,
D7B621931E4A6FE600684474 /* ARTDeviceDetails.m */,
D768C6AA1E4B5B0200436011 /* ARTDevicePushDetails.h */,
8471D15C278B583800382E9B /* ARTDevicePushDetails+Private.h */,
D768C6AB1E4B5B0200436011 /* ARTDevicePushDetails.m */,
D777EEDE206285CF002EBA03 /* ARTDeviceIdentityTokenDetails.h */,
D777EEDF206285CF002EBA03 /* ARTDeviceIdentityTokenDetails.m */,
Expand Down Expand Up @@ -1921,6 +1926,7 @@
D7D5A69A1CA3D9040071BD6D /* ARTAuthOptions+Private.h in Headers */,
96A507B51A37881C0077CDF8 /* ARTNSDate+ARTUtil.h in Headers */,
D5BB211926AA9A9F00AA5F3E /* ARTNSMutableDictionary+ARTDictionaryUtil.h in Headers */,
8471D15D278B583800382E9B /* ARTDevicePushDetails+Private.h in Headers */,
967A43211A39AEAF00E4CE23 /* ARTNSArray+ARTFunctional.h in Headers */,
D7C1B8791BBF5F810087B55F /* ARTAuth+Private.h in Headers */,
EB1B541122FB1AB4006A59AC /* ARTPushChannel+Private.h in Headers */,
Expand Down Expand Up @@ -2136,6 +2142,7 @@
D710D56A21949CB9008F54AD /* ARTPushAdmin.h in Headers */,
D710D48321949A4E008F54AD /* ARTDefault+Private.h in Headers */,
D70C36C4233E6831002FD6E3 /* ARTFormEncode.h in Headers */,
8471D15E278B583800382E9B /* ARTDevicePushDetails+Private.h in Headers */,
D710D59021949D29008F54AD /* ARTStatus.h in Headers */,
D5BB213A26AAA60500AA5F3E /* ARTNSError+ARTUtils.h in Headers */,
D710D61D21949DEC008F54AD /* ARTHTTPPaginatedResponse+Private.h in Headers */,
Expand Down Expand Up @@ -2278,6 +2285,7 @@
EB1B53FF22F8D91C006A59AC /* ARTQueuedDealloc.h in Headers */,
D710D57021949CBA008F54AD /* ARTPushAdmin.h in Headers */,
D710D48521949A4F008F54AD /* ARTDefault+Private.h in Headers */,
8471D15F278B583800382E9B /* ARTDevicePushDetails+Private.h in Headers */,
D70C36C5233E6831002FD6E3 /* ARTFormEncode.h in Headers */,
D710D5B621949D2A008F54AD /* ARTStatus.h in Headers */,
D710D62921949DED008F54AD /* ARTHTTPPaginatedResponse+Private.h in Headers */,
Expand Down
13 changes: 13 additions & 0 deletions Source/ARTDevicePushDetails+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <Ably/ARTDevicePushDetails.h>

NS_ASSUME_NONNULL_BEGIN

@interface ARTDevicePushDetails ()

- (NSString *)stateString;

+ (ARTPushState)stateFromJsonString:(NSString *)string;

@end

NS_ASSUME_NONNULL_END
6 changes: 3 additions & 3 deletions Source/ARTDevicePushDetails.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#import <Foundation/Foundation.h>
#import <Ably/ARTTypes.h>

@class ARTErrorInfo;

NS_ASSUME_NONNULL_BEGIN

@interface ARTDevicePushDetails : NSObject

@property (nonatomic) NSMutableDictionary<NSString *, NSString *> *recipient;
@property (nullable, nonatomic) NSString *state;
@property (nonatomic) ARTPushState state;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change (string to enum) can be a separate thing, which we should do regardless of how we solve the LocalDevice issue. I've created an issue for it: #1264.

@property (nullable, nonatomic) ARTErrorInfo *errorReason;
@property (nonatomic) NSMutableDictionary<NSString *, NSString *> *recipient;

- (instancetype)init;

Expand Down
30 changes: 29 additions & 1 deletion Source/ARTDevicePushDetails.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "ARTDevicePushDetails.h"
#import "ARTDevicePushDetails+Private.h"
#import "ARTPush.h"

@implementation ARTDevicePushDetails
Expand All @@ -20,8 +21,35 @@ - (id)copyWithZone:(NSZone *)zone {
return push;
}

- (NSString *)stateString {
switch (_state) {
case ARTPushStateActive:
return @"ARTPushStateActive";
case ARTPushStateFailing:
return @"ARTPushStateFailing";
case ARTPushStateFailed:
return @"ARTPushStateFailed";
default:
return @"ARTPushStateUnknown";
}
}

+ (ARTPushState)stateFromJsonString:(NSString *)string {
string = string.lowercaseString;
if ([string isEqualToString:@"active"]) {
return ARTPushStateActive;
}
else if ([string isEqualToString:@"failing"]) {
return ARTPushStateFailing;
}
else if ([string isEqualToString:@"failed"]) {
return ARTPushStateFailed;
}
return ARTPushStateUnknown;
}

- (NSString *)description {
return [NSString stringWithFormat:@"%@ - \n\t recipient: %@; \n\t state: %@; \n\t errorReason: %@;", [super description], self.recipient, self.state, self.errorReason];
return [NSString stringWithFormat:@"%@ - \n\t recipient: %@; \n\t state: %@; \n\t errorReason: %@;", [super description], self.recipient, self.stateString, self.errorReason];
ben-xD marked this conversation as resolved.
Show resolved Hide resolved
}

@end
12 changes: 7 additions & 5 deletions Source/ARTJsonLikeEncoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#import "ARTPush.h"
#import "ARTDeviceDetails.h"
#import "ARTDeviceIdentityTokenDetails.h"
#import "ARTDevicePushDetails.h"
#import "ARTDevicePushDetails+Private.h"
#import "ARTConnectionDetails.h"
#import "ARTRest+Private.h"
#import "ARTJsonEncoder.h"
Expand Down Expand Up @@ -693,10 +693,12 @@ - (ARTDevicePushDetails *)devicePushDetailsFromDictionary:(NSDictionary *)input
}

ARTDevicePushDetails *devicePushDetails = [[ARTDevicePushDetails alloc] init];
devicePushDetails.state = [input artString:@"state"];
NSDictionary *errorReason = [input valueForKey:@"errorReason"];
if (errorReason) {
devicePushDetails.errorReason = [ARTErrorInfo createWithCode:[[errorReason artNumber:@"code"] intValue] status:[[errorReason artNumber:@"statusCode"] intValue] message:[errorReason artString:@"message"]];
devicePushDetails.state = [ARTDevicePushDetails stateFromJsonString:[input artString:@"state"]];
NSDictionary *errorDict = [input valueForKey:@"error"];
if (errorDict) {
devicePushDetails.errorReason = [ARTErrorInfo createWithCode:[[errorDict artNumber:@"code"] intValue]
status:[[errorDict artNumber:@"statusCode"] intValue]
message:[errorDict artString:@"message"]];
}
devicePushDetails.recipient = [input valueForKey:@"recipient"];

Expand Down
5 changes: 5 additions & 0 deletions Source/ARTPush+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import <Ably/ARTPush.h>
#import <Ably/ARTPushAdmin+Private.h>
#import <Ably/ARTPushDeviceRegistrations+Private.h>
#import <Ably/ARTPushChannelSubscriptions+Private.h>
#import "ARTQueuedDealloc.h"

@class ARTPushActivationStateMachine;
Expand All @@ -11,6 +13,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface ARTPushInternal : NSObject <ARTPushProtocol>

@property (nonatomic, strong, readonly) ARTPushAdminInternal *admin;
@property (nonatomic, strong, readonly) ARTPushDeviceRegistrationsInternal *deviceRegistrations;
@property (nonatomic, strong, readonly) ARTPushChannelSubscriptionsInternal *channelSubscriptions;

@property (readonly) dispatch_queue_t queue;

- (instancetype)init:(ARTRestInternal *)rest;
Expand Down
6 changes: 6 additions & 0 deletions Source/ARTPush.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import <Foundation/Foundation.h>
#import <Ably/ARTTypes.h>
#import <Ably/ARTPushDeviceRegistrations.h>
#import <Ably/ARTPushChannelSubscriptions.h>

@class ARTRest;
@class ARTRealtime;
Expand Down Expand Up @@ -75,13 +77,17 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)deactivate;

- (void)getDevicePushDetails:(ARTPushStateCallback)callback;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be agreed cross-platform (i.e. via the features spec) before we add it here. I think https://github.com/ably/docs/issues/1288 would be the best place to come to a consensus on this.


#endif

@end

@interface ARTPush : NSObject <ARTPushProtocol>

@property (readonly) ARTPushAdmin *admin;
@property (readonly) ARTPushDeviceRegistrations *deviceRegistrations;
@property (readonly) ARTPushChannelSubscriptions *channelSubscriptions;

@end

Expand Down
24 changes: 24 additions & 0 deletions Source/ARTPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ - (ARTPushAdmin *)admin {
return [[ARTPushAdmin alloc] initWithInternal:_internal.admin queuedDealloc:_dealloc];
}

- (ARTPushDeviceRegistrations *)deviceRegistrations {
return [[ARTPushDeviceRegistrations alloc] initWithInternal:_internal.deviceRegistrations queuedDealloc:_dealloc];
}

- (ARTPushChannelSubscriptions *)channelSubscriptions {
return [[ARTPushChannelSubscriptions alloc] initWithInternal:_internal.channelSubscriptions queuedDealloc:_dealloc];
}

#if TARGET_OS_IOS

+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken rest:(ARTRest *)rest; {
Expand All @@ -61,6 +69,10 @@ - (void)deactivate {
[_internal deactivate];
}

- (void)getDevicePushDetails:(nonnull ARTPushStateCallback)callback {
[_internal getDevicePushDetails:callback];
}

#endif

@end
Expand All @@ -82,6 +94,8 @@ - (instancetype)init:(ARTRestInternal *)rest {
_rest = rest;
_logger = [rest logger];
_admin = [[ARTPushAdminInternal alloc] initWithRest:rest];
_deviceRegistrations = [[ARTPushDeviceRegistrationsInternal alloc] initWithRest:rest];
_channelSubscriptions = [[ARTPushChannelSubscriptionsInternal alloc] initWithRest:rest];
_activationMachine = nil;
_activationMachineLock = [[NSLock alloc] init];
_activationMachineLock.name = @"ActivationMachineLock";
Expand Down Expand Up @@ -235,6 +249,16 @@ - (void)deactivate {
}];
}

- (void)getDevicePushDetails:(nonnull ARTPushStateCallback)callback {
[_deviceRegistrations get:_rest.device.id callback:^(ARTDeviceDetails *device, ARTErrorInfo *error) {
if (error != nil) {
callback(nil, error);
return;
}
callback(device.push, nil);
}];
}

#endif

@end
5 changes: 0 additions & 5 deletions Source/ARTPushAdmin+Private.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#import <Ably/ARTPushAdmin.h>
#import <Ably/ARTPushDeviceRegistrations+Private.h>
#import <Ably/ARTPushChannelSubscriptions+Private.h>
#import "ARTQueuedDealloc.h"

@class ARTRestInternal;
Expand All @@ -9,9 +7,6 @@ NS_ASSUME_NONNULL_BEGIN

@interface ARTPushAdminInternal : NSObject <ARTPushAdminProtocol>

@property (nonatomic, readonly) ARTPushDeviceRegistrationsInternal *deviceRegistrations;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving these properties is a change to the public API, and also these properties are described in the features spec; we’d need to update the features spec before making this change and need to make sure we do a new major release of the library afterwards.

@property (nonatomic, readonly) ARTPushChannelSubscriptionsInternal *channelSubscriptions;

- (instancetype)initWithRest:(ARTRestInternal *)rest;

@end
Expand Down
5 changes: 0 additions & 5 deletions Source/ARTPushAdmin.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#import <Foundation/Foundation.h>
#import <Ably/ARTTypes.h>
#import <Ably/ARTPushDeviceRegistrations.h>
#import <Ably/ARTPushChannelSubscriptions.h>

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -16,9 +14,6 @@ NS_ASSUME_NONNULL_BEGIN

@interface ARTPushAdmin : NSObject <ARTPushAdminProtocol>

@property (nonatomic, readonly) ARTPushDeviceRegistrations *deviceRegistrations;
@property (nonatomic, readonly) ARTPushChannelSubscriptions *channelSubscriptions;

@end

NS_ASSUME_NONNULL_END
10 changes: 0 additions & 10 deletions Source/ARTPushAdmin.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ - (void)publish:(ARTPushRecipient *)recipient data:(ARTJsonObject *)data callbac
[_internal publish:recipient data:data callback:callback];
}

- (ARTPushDeviceRegistrations *)deviceRegistrations {
return [[ARTPushDeviceRegistrations alloc] initWithInternal:_internal.deviceRegistrations queuedDealloc:_dealloc];
}

- (ARTPushChannelSubscriptions *)channelSubscriptions {
return [[ARTPushChannelSubscriptions alloc] initWithInternal:_internal.channelSubscriptions queuedDealloc:_dealloc];
}

@end

@implementation ARTPushAdminInternal {
Expand All @@ -45,8 +37,6 @@ - (instancetype)initWithRest:(ARTRestInternal *)rest {
if (self = [super init]) {
_rest = rest;
_logger = [rest logger];
_deviceRegistrations = [[ARTPushDeviceRegistrationsInternal alloc] initWithRest:rest];
_channelSubscriptions = [[ARTPushChannelSubscriptionsInternal alloc] initWithRest:rest];
_userQueue = rest.userQueue;
_queue = rest.queue;
}
Expand Down
9 changes: 9 additions & 0 deletions Source/ARTTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@class ARTStats;
@class ARTPushChannelSubscription;
@class ARTDeviceDetails;
@class ARTDevicePushDetails;
@protocol ARTTokenDetailsCompatible;

// More context
Expand All @@ -38,6 +39,12 @@ typedef NS_ENUM(NSUInteger, ARTAuthMethod) {
ARTAuthMethodToken
};

typedef NS_ENUM(NSUInteger, ARTPushState) {
ARTPushStateUnknown,
ARTPushStateActive,
ARTPushStateFailing,
ARTPushStateFailed
};

#pragma mark - ARTRealtimeConnectionState

Expand Down Expand Up @@ -279,6 +286,8 @@ typedef void (^ARTPaginatedMessagesCallback)(ARTPaginatedResult<ARTMessage *> *_
typedef void (^ARTPaginatedDeviceDetailsCallback)(ARTPaginatedResult<ARTDeviceDetails *> *_Nullable result, ARTErrorInfo *_Nullable error);
typedef void (^ARTPaginatedTextCallback)(ARTPaginatedResult<NSString *> *_Nullable result, ARTErrorInfo *_Nullable error);

typedef void (^ARTPushStateCallback)(ARTDevicePushDetails *_Nullable details, ARTErrorInfo *_Nullable error);

#pragma mark - Functions

/**
Expand Down
Loading