Skip to content

Commit

Permalink
fix(subscribe): fix user timetoken parse
Browse files Browse the repository at this point in the history
Fix issue with `PNSubscribeCursorData` which should have optional `region` to handle  user
timetoken in received real-time messages.
  • Loading branch information
parfeon committed Jul 5, 2024
1 parent 4d2d858 commit 741f4dc
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 1 deletion.
4 changes: 4 additions & 0 deletions PubNub/Network/Responses/Subscribe/PNSubscribeCursorData.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ @implementation PNSubscribeCursorData
};
}

+ (NSArray<NSString *> *)optionalKeys {
return @[@"region"];
}

#pragma mark -


Expand Down
2 changes: 1 addition & 1 deletion PubNub/Network/Responses/Subscribe/PNSubscribeEventData.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ @implementation PNSubscribeEventData
}

+ (NSArray<NSString *> *)ignoredKeys {
return @[@"timetoken"];
return @[@"timetoken", @"region"];
}

- (NSString *)subscription {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
[
{
"id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917",
"data" : {
"method" : "get",
"cls" : "NSURLRequest",
"cellular" : true,
"cache" : 1,
"timeout" : 60,
"cookies" : true,
"headers" : {
"User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version",
"Accept" : "*\/*",
"Connection" : "keep-alive",
"Accept-Encoding" : "gzip,deflate"
},
"pipeline" : false,
"network" : 0,
"url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&tt=0&heartbeat=20"
},
"type" : 0
},
{
"id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917",
"data" : {
"status" : 200,
"cls" : "NSHTTPURLResponse",
"url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&tt=0&heartbeat=20",
"headers" : {
"Access-Control-Allow-Methods" : "GET",
"Content-Type" : "text\/javascript; charset=\"UTF-8\"",
"Access-Control-Allow-Origin" : "*",
"Date" : "Tue, 04 Feb 2020 13:10:11 GMT",
"Content-Length" : "45",
"Cache-Control" : "no-cache",
"Connection" : "keep-alive"
}
},
"type" : 1
},
{
"id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917",
"data" : {
"cls" : "NSData",
"base64" : "eyJ0Ijp7InQiOiIxNTgwODIxODExNDczMDU1OSIsInIiOjEyfSwibSI6W119"
},
"type" : 2
},
{
"id" : "6D9CF0BE-C72E-451C-BD56-ADC3759E4917",
"type" : 4
},
{
"id" : "56380FEF-3510-4D26-8D88-22A028B35217",
"data" : {
"method" : "get",
"cls" : "NSURLRequest",
"cellular" : true,
"cache" : 1,
"timeout" : 60,
"cookies" : true,
"headers" : {
"User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version",
"Accept" : "*\/*",
"Connection" : "keep-alive",
"Accept-Encoding" : "gzip,deflate"
},
"pipeline" : false,
"network" : 0,
"url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218114730559&heartbeat=20&tr=12"
},
"type" : 0
},
{
"id" : "9060F768-F824-4970-93AC-4BF1FA1121D5",
"data" : {
"method" : "get",
"cls" : "NSURLRequest",
"cellular" : true,
"cache" : 1,
"timeout" : 60,
"cookies" : true,
"headers" : {
"User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version",
"Accept" : "*\/*",
"Connection" : "keep-alive",
"Accept-Encoding" : "gzip,deflate"
},
"pipeline" : false,
"network" : 0,
"url" : "https:\/\/ps.pndsn.com\/publish\/demo\/demo\/0\/test-channel1\/0\/%7B%22test-message%22:%5B%22message%22%5D%7D?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&seqn=1"
},
"type" : 0
},
{
"id" : "9060F768-F824-4970-93AC-4BF1FA1121D5",
"data" : {
"status" : 200,
"cls" : "NSHTTPURLResponse",
"url" : "https:\/\/ps.pndsn.com\/publish\/demo\/demo\/0\/test-channel1\/0\/%7B%22test-message%22:%5B%22message%22%5D%7D?pnsdk=PubNub-ObjC-iOS\/4.x.x&seqn=1&uuid=Serhii",
"headers" : {
"Access-Control-Allow-Methods" : "GET",
"Content-Type" : "text\/javascript; charset=\"UTF-8\"",
"Access-Control-Allow-Origin" : "*",
"Date" : "Tue, 04 Feb 2020 13:10:14 GMT",
"Content-Length" : "30",
"Cache-Control" : "no-cache",
"Connection" : "keep-alive"
}
},
"type" : 1
},
{
"id" : "9060F768-F824-4970-93AC-4BF1FA1121D5",
"data" : {
"cls" : "NSData",
"base64" : "WzEsIlNlbnQiLCIxNTgwODIxODE0ODc5NTIwMCJd"
},
"type" : 2
},
{
"id" : "9060F768-F824-4970-93AC-4BF1FA1121D5",
"type" : 4
},
{
"id" : "56380FEF-3510-4D26-8D88-22A028B35217",
"data" : {
"status" : 200,
"cls" : "NSHTTPURLResponse",
"url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218114730559&heartbeat=20&tr=12",
"headers" : {
"Access-Control-Allow-Methods" : "GET",
"Content-Type" : "text\/javascript; charset=\"UTF-8\"",
"Access-Control-Allow-Origin" : "*",
"Date" : "Tue, 04 Feb 2020 13:10:14 GMT",
"Content-Length" : "291",
"Cache-Control" : "no-cache",
"Connection" : "keep-alive"
}
},
"type" : 1
},
{
"id" : "56380FEF-3510-4D26-8D88-22A028B35217",
"data" : {
"cls" : "NSData",
"base64" : "eyJ0Ijp7InQiOiIxNTgwODIxODE0ODgwNDc4NyIsInIiOjEyfSwibSI6W3siYSI6IjUiLCJmIjowLCJpIjoiU2VyaGlpIiwicyI6MTAsInAiOnsidCI6IjE1ODA4MjE4MTQ4Nzk1MjAwIiwiciI6MTJ9LCJvIjp7InQiOiIxNTgwODIxODE0ODc5NTE5OSJ9LCJrIjoiZGVtbyIsImMiOiJ0ZXN0LWNoYW5uZWwxIiwiZCI6eyJ0ZXN0LW1lc3NhZ2UiOlsibWVzc2FnZSJdfX1dfQ=="
},
"type" : 2
},
{
"id" : "56380FEF-3510-4D26-8D88-22A028B35217",
"type" : 4
},
{
"id" : "8166D76F-F897-4ABB-934A-13726D856948",
"data" : {
"method" : "get",
"cls" : "NSURLRequest",
"cellular" : true,
"cache" : 1,
"timeout" : 60,
"cookies" : true,
"headers" : {
"User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version",
"Accept" : "*\/*",
"Connection" : "keep-alive",
"Accept-Encoding" : "gzip,deflate"
},
"pipeline" : false,
"network" : 0,
"url" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218148804787&heartbeat=20&tr=12"
},
"type" : 0
},
{
"id" : "8166D76F-F897-4ABB-934A-13726D856948",
"data" : {
"code" : -999,
"info" : {
"NSErrorFailingURLStringKey" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218148804787&heartbeat=20&tr=12",
"NSLocalizedDescription" : "cancelled",
"NSErrorFailingURLKey" : "https:\/\/ps.pndsn.com\/v2\/subscribe\/demo\/test-channel1\/0?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x&tt=15808218148804787&heartbeat=20&tr=12"
},
"cls" : "NSError",
"domain" : "NSURLErrorDomain"
},
"type" : 3
},
{
"id" : "1966F67F-1E40-41C0-B669-9A9607D9514C",
"data" : {
"method" : "get",
"cls" : "NSURLRequest",
"cellular" : true,
"cache" : 1,
"timeout" : 60,
"cookies" : true,
"headers" : {
"User-Agent" : "iPhone; CPU iPhone OS 12.4.0 Version",
"Accept" : "*\/*",
"Connection" : "keep-alive",
"Accept-Encoding" : "gzip,deflate"
},
"pipeline" : false,
"network" : 0,
"url" : "https:\/\/ps.pndsn.com\/v2\/presence\/sub_key\/demo\/channel\/test-channel1\/leave?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x"
},
"type" : 0
},
{
"id" : "1966F67F-1E40-41C0-B669-9A9607D9514C",
"data" : {
"status" : 200,
"cls" : "NSHTTPURLResponse",
"url" : "https:\/\/ps.pndsn.com\/v2\/presence\/sub_key\/demo\/channel\/test-channel1\/leave?uuid=Serhii&pnsdk=PubNub-ObjC-iOS\/4.x.x",
"headers" : {
"Access-Control-Allow-Methods" : "OPTIONS, GET, POST",
"Content-Type" : "text\/javascript; charset=\"UTF-8\"",
"Server" : "Pubnub Presence",
"Access-Control-Allow-Origin" : "*",
"Age" : "0",
"Date" : "Tue, 04 Feb 2020 13:10:15 GMT",
"Accept-Ranges" : "bytes",
"Content-Length" : "74",
"Cache-Control" : "no-cache",
"Connection" : "keep-alive"
}
},
"type" : 1
},
{
"id" : "1966F67F-1E40-41C0-B669-9A9607D9514C",
"data" : {
"cls" : "NSData",
"base64" : "eyJzdGF0dXMiOiAyMDAsICJtZXNzYWdlIjogIk9LIiwgImFjdGlvbiI6ICJsZWF2ZSIsICJzZXJ2aWNlIjogIlByZXNlbmNlIn0="
},
"type" : 2
},
{
"id" : "1966F67F-1E40-41C0-B669-9A9607D9514C",
"type" : 4
}
]
34 changes: 34 additions & 0 deletions Tests/Tests/Integration/PNSubscribeIntegrationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @copyright © 2010-2020 PubNub, Inc.
*/
#import "PNRecordableTestCase.h"
#import "PNSubscribeEventData+Private.h"
#import "NSString+PNTest.h"


Expand Down Expand Up @@ -1387,6 +1388,39 @@ - (void)testItShouldSubscribeToSingleChannelAndReceiveMessageWhenPublished {
}];
}

- (void)testItShouldSubscribeToSingleChannelAndReceiveMessageWithUserTimetokenWhenPublished {
NSDictionary *publishedMessage = @{ @"test-message": [self randomizedValuesWithValues:@[@"message"]] };
NSString *channel = [self channelWithName:@"test-channel1"];


[self subscribeClient:self.client toChannels:@[channel] withPresence:NO];
[self waitTask:@"waitForDistribution" completionFor:(YHVVCR.cassette.isNewCassette ? 3.f : 0.f)];


[self waitToCompleteIn:self.testCompletionDelay codeBlock:^(dispatch_block_t handler) {
[self addMessageHandlerForClient:self.client
withBlock:^(PubNub *client, PNMessageResult *message, BOOL *remove) {

if ([message.data.publisher isEqualToString:self.client.currentConfiguration.userID]) {
XCTAssertEqualObjects(message.data.message, publishedMessage);
XCTAssertEqualObjects(message.data.subscription, channel);
XCTAssertEqualObjects(message.data.channel, channel);
XCTAssertEqualObjects(message.data.userTimetoken.timetoken,
@(message.data.timetoken.unsignedIntegerValue - 1));
XCTAssertNil(message.data.userTimetoken.region);
XCTAssertNotNil(message.data.userTimetoken);
*remove = YES;

handler();
}
}];

[self.client publish:publishedMessage toChannel:channel withCompletion:^(PNPublishStatus *status) {
XCTAssertFalse(status.isError);
}];
}];
}

/**
* @brief Follow instructions to simulate server response with "broken" payload.
*
Expand Down

0 comments on commit 741f4dc

Please sign in to comment.