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

Add custom message type support #461

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/commands-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Process command
if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true
runs-on:
group: Default
group: organization/Default
steps:
- name: Check referred user
id: user-check
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Check release required
if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true
runs-on:
group: Default
group: organization/Default
outputs:
release: ${{ steps.check.outputs.ready }}
steps:
Expand All @@ -36,7 +36,7 @@ jobs:
needs: check-release
if: needs.check-release.outputs.release == 'true'
runs-on:
group: macos-gh
group: organization/macos-gh
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ env:
LANGUAGE: en_US.UTF-8
LC_ALL: en_US.UTF-8
LC_CTYPE: en_US.UTF-8

jobs:
tests:
name: Integration and Unit tests
runs-on:
group: macos-gh
group: organization/macos-gh
strategy:
fail-fast: true
matrix:
Expand All @@ -44,7 +44,7 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2
bundler-cache: true
bundler-cache: false
- name: Setup CocoaPods
run: gem install cocoapods
- name: Cache installed Pods
Expand All @@ -59,7 +59,7 @@ jobs:
run: xcrun simctl list -j
- name: Install dependencies
run: |
gem install xcpretty
gem install xcpretty -v 0.3.0
cd ./Tests && pod install && cd ..
- name: Configure test environment
run: |
Expand All @@ -73,15 +73,15 @@ jobs:
acceptance-tests:
name: Run Acceptance tests
runs-on:
group: macos-gh
group: organization/macos-gh
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Ruby 3.2.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2
bundler-cache: true
bundler-cache: false
- name: Setup Node.js 20.x
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
features-path: Tests/Support Files/Features
- name: Install dependencies
run: |
gem install xcpretty
gem install xcpretty -v 0.3.0
cd ./Tests && pod install && cd ..
- name: Configure test environment
run: ./Tests/Support\ Files/Scripts/create-configuration.sh
Expand All @@ -132,7 +132,7 @@ jobs:
name: Tests
needs: [tests, acceptance-tests]
runs-on:
group: Default
group: organization/Default
steps:
- name: Tests summary
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"
4 changes: 2 additions & 2 deletions .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
pubnub-yml:
name: "Validate .pubnub.yml"
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand All @@ -40,7 +40,7 @@ jobs:
name: Validations
needs: [pubnub-yml]
runs-on:
group: Default
group: organization/Default
steps:
- name: Validations summary
run: echo -e "\033[38;2;95;215;0m\033[1mAll validations passed"
1 change: 1 addition & 0 deletions PubNub/Core/PubNub+Files.m
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ - (void)handleUploadFileSuccessWithFileIdentifier:(NSString *)fileIdentifier
fileIdentifier:fileIdentifier
name:fileName];
request.arbitraryQueryParameters = sendFileRequest.arbitraryQueryParameters;
request.customMessageType = sendFileRequest.customMessageType;
request.metadata = sendFileRequest.fileMessageMetadata;
request.store = sendFileRequest.fileMessageStore;
request.message = sendFileRequest.message;
Expand Down
23 changes: 20 additions & 3 deletions PubNub/Core/PubNub+Publish.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ @interface PubNub (PublishProtected)
/// - compressed Whether message should be compressed before sending or not.
/// - replicate: Whether message should be replicated across the **PubNub** network and sent simultaneously to all
/// subscribed clients on a channel.
/// - customMessageType: User-specified message type.
/// - metadata: `NSDictionary` with values which should be used by **PubNub** network to filter messages.
/// - queryParameters: List arbitrary query parameters which should be sent along with original API call.
/// - block: Publish completion block which.
Expand All @@ -40,6 +41,7 @@ - (void)publish:(nullable id)message
ttl:(nullable NSNumber *)ttl
compressed:(BOOL)compressed
withReplication:(BOOL)replicate
customMessageType:(nullable NSString *)customMessageType
metadata:(nullable NSDictionary<NSString *, id> *)metadata
queryParameters:(nullable NSDictionary *)queryParameters
completion:(nullable PNPublishCompletionBlock)block;
Expand All @@ -55,10 +57,12 @@ - (void)publish:(nullable id)message
/// - Parameters:
/// - message Object (`NSString`, `NSNumber`, `NSArray`, `NSDictionary`) which will be sent with signal.
/// - channel: Name of the channel to which signal should be sent.
/// - customMessageType: User-specified message type.
/// - queryParameters: List arbitrary query parameters which should be sent along with original API call.
/// - block: Signal completion block.
- (void)signal:(id)message
channel:(NSString *)channel
customMessageType:(nullable NSString *)customMessageType
withQueryParameters:(nullable NSDictionary *)queryParameters
completion:(nullable PNSignalCompletionBlock)block;

Expand Down Expand Up @@ -132,12 +136,13 @@ @implementation PubNub (Publish)
NSString *channel = parameters[NSStringFromSelector(@selector(channel))];
NSNumber *shouldStore = parameters[NSStringFromSelector(@selector(shouldStore))];
NSNumber *ttl = parameters[NSStringFromSelector(@selector(ttl))];

if (shouldStore && !shouldStore.boolValue) ttl = nil;

PNPublishFileMessageRequest *request = [PNPublishFileMessageRequest requestWithChannel:channel
fileIdentifier:identifier
name:filename];
request.customMessageType = parameters[NSStringFromSelector(@selector(customMessageType))];
request.metadata = parameters[NSStringFromSelector(@selector(metadata))];
request.message = parameters[NSStringFromSelector(@selector(message))];
request.arbitraryQueryParameters = parameters[@"queryParam"];
Expand Down Expand Up @@ -188,12 +193,17 @@ @implementation PubNub (Publish)
__weak __typeof(self) weakSelf = self;
builder = [PNSignalAPICallBuilder builderWithExecutionBlock:^(NSArray<NSString *> *flags,
NSDictionary *parameters) {
NSString *customMessageType = parameters[NSStringFromSelector(@selector(customMessageType))];
id message = parameters[NSStringFromSelector(@selector(message))];
NSString *channel = parameters[NSStringFromSelector(@selector(channel))];
NSDictionary *queryParam = parameters[@"queryParam"];
id block = parameters[@"block"];

[weakSelf signal:message channel:channel withQueryParameters:queryParam completion:block];
[weakSelf signal:message
channel:channel
customMessageType:customMessageType
withQueryParameters:queryParam
completion:block];
}];

return ^PNSignalAPICallBuilder * {
Expand Down Expand Up @@ -493,6 +503,7 @@ - (void)publish:(id)message
ttl:nil
compressed:compressed
withReplication:YES
customMessageType:nil
metadata:metadata
queryParameters:nil
completion:block];
Expand All @@ -505,12 +516,15 @@ - (void)publish:(id)message
ttl:(NSNumber *)ttl
compressed:(BOOL)compressed
withReplication:(BOOL)replicate
customMessageType:(nullable NSString *)customMessageType
metadata:(NSDictionary<NSString *, id> *)metadata
queryParameters:(NSDictionary *)queryParameters
completion:(PNPublishCompletionBlock)block {

PNPublishRequest *request = [PNPublishRequest requestWithChannel:channel];

request.arbitraryQueryParameters = queryParameters;
request.customMessageType = customMessageType;
request.replicate = replicate;
request.compress = compressed;
request.metadata = metadata;
Expand Down Expand Up @@ -554,15 +568,17 @@ - (void)sendSignalWithRequest:(PNSignalRequest *)userRequest completion:(PNSigna
}

- (void)signal:(id)message channel:(NSString *)channel withCompletion:(PNSignalCompletionBlock)block {
[self signal:message channel:channel withQueryParameters:nil completion:block];
[self signal:message channel:channel customMessageType:nil withQueryParameters:nil completion:block];
}

- (void)signal:(id)message
channel:(NSString *)channel
customMessageType:(nullable NSString *)customMessageType
withQueryParameters:(NSDictionary *)queryParameters
completion:(PNSignalCompletionBlock)block {

PNSignalRequest *request = [PNSignalRequest requestWithChannel:channel signal:message];
request.customMessageType = customMessageType;
request.arbitraryQueryParameters = queryParameters;
[self sendSignalWithRequest:request completion:block];
}
Expand Down Expand Up @@ -692,6 +708,7 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray<NSString *> *)flags para
ttl:ttl
compressed:compressed.boolValue
withReplication:(replicate ? replicate.boolValue : YES)
customMessageType:parameters[NSStringFromSelector(@selector(customMessageType))]
metadata:parameters[NSStringFromSelector(@selector(metadata))]
queryParameters:parameters[@"queryParam"]
completion:parameters[@"block"]];
Expand Down
12 changes: 12 additions & 0 deletions PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, strong) PNHistoryAPICallBuilder * (^limit)(NSUInteger limit);

/**
* @brief Messages' custom type flag.
*
* @note Message / signal and file messages may contain user-provided type.
*
*@param includeCustomMessageType Whether custom message type should be included in response or not.
*
* @return API call configuration builder.
*/
@property (nonatomic, readonly, strong) PNHistoryAPICallBuilder * (^includeCustomMessageType)(BOOL includeCustomMessageType);

/**
* @brief Events' time tokens presence flag.
*
Expand All @@ -91,6 +102,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, strong) PNHistoryAPICallBuilder * (^includeTimeToken)(BOOL includeTimeToken);


/**
* @brief Events' metadata presence flag.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ @implementation PNHistoryAPICallBuilder
};
}

- (PNHistoryAPICallBuilder * (^)(BOOL))includeCustomMessageType {
return ^PNHistoryAPICallBuilder * (BOOL includeCustomMessageType) {
[self setValue:@(includeCustomMessageType) forParameter:NSStringFromSelector(_cmd)];
return self;
};
}

- (PNHistoryAPICallBuilder * (^)(BOOL includeTimeToken))includeTimeToken {
return ^PNHistoryAPICallBuilder * (BOOL includeTimeToken) {
[self setValue:@(includeTimeToken) forParameter:NSStringFromSelector(_cmd)];
Expand Down
10 changes: 10 additions & 0 deletions PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^message)(id message);

/**
* @brief User-specified message type.
*
* \b Important: string limited by \b 3 - \b 50 case-sensitive alphanumeric characters with only \c - and \c _ special
* characters allowed.
*
* @return API call configuration builder.
*/
@property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^customMessageType)(NSString *customMessageType);

/**
* @brief Message metadata addition block.
*
Expand Down
10 changes: 10 additions & 0 deletions PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ @implementation PNPublishAPICallBuilder
};
}

- (PNPublishAPICallBuilder * (^)(NSString *customMessageType))customMessageType {
return ^PNPublishAPICallBuilder * (NSString *customMessageType) {
if ([customMessageType isKindOfClass:[NSString class]]) {
[self setValue:customMessageType forParameter:NSStringFromSelector(_cmd)];
}

return self;
};
}

- (PNPublishAPICallBuilder * (^)(NSDictionary *metadata))metadata {

return ^PNPublishAPICallBuilder * (NSDictionary *metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^message)(id message);

/**
* @brief User-specified message type.
*
* \b Important: string limited by \b 3 - \b 50 case-sensitive alphanumeric characters with only \c - and \c _ special
* characters allowed.
*
* @return API call configuration builder.
*/
@property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^customMessageType)(NSString *customMessageType);

/**
* @brief Message metadata.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ @implementation PNPublishFileMessageAPICallBuilder
};
}

- (PNPublishFileMessageAPICallBuilder * (^)(NSString *customMessageType))customMessageType {
return ^PNPublishFileMessageAPICallBuilder * (NSString *customMessageType) {
if ([customMessageType isKindOfClass:[NSString class]]) {
[self setValue:customMessageType forParameter:NSStringFromSelector(_cmd)];
}

return self;
};
}

- (PNPublishFileMessageAPICallBuilder * (^)(NSDictionary *metadata))metadata {
return ^PNPublishFileMessageAPICallBuilder * (NSDictionary *metadata) {
if ([metadata isKindOfClass:[NSDictionary class]]) {
Expand Down
10 changes: 10 additions & 0 deletions PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^message)(id message);

/**
* @brief User-specified message type.
*
* \b Important: string limited by \b 3 - \b 50 case-sensitive alphanumeric characters with only \c - and \c _ special
* characters allowed.
*
* @return API call configuration builder.
*/
@property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^customMessageType)(NSString *customMessageType);


#pragma mark - Execution

Expand Down
10 changes: 10 additions & 0 deletions PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ @implementation PNSignalAPICallBuilder
};
}

- (PNSignalAPICallBuilder * (^)(NSString * customMessageType))customMessageType {
return ^PNSignalAPICallBuilder * (NSString *customMessageType) {
if ([customMessageType isKindOfClass:[NSString class]]) {
[self setValue:customMessageType forParameter:NSStringFromSelector(_cmd)];
}

return self;
};
}


#pragma mark - Execution

Expand Down
6 changes: 6 additions & 0 deletions PubNub/Network/Requests/Files/PNSendFileRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ NS_ASSUME_NONNULL_BEGIN
/// `NSDictionary` with values which should be used by **PubNub** service to filter `file messages`.
@property(strong, nullable, nonatomic) NSDictionary *fileMessageMetadata;

/// User-specified message type.
///
/// > Important: string limited by **3**-**50** case-sensitive alphanumeric characters with only `-` and `_` special
/// characters allowed.
@property(copy, nullable, nonatomic) NSString *customMessageType;

/// Key which should be used for uploaded data `encryption`.
///
/// This property allows setting up data _encryption_ using a different cipher key than the one set during **PubNub**
Expand Down
Loading
Loading