Skip to content

Commit

Permalink
feat(message-type): add custom message type support
Browse files Browse the repository at this point in the history
Add custom message type support for the following APIs: publish, signal, share file, subscribe
and history.
  • Loading branch information
parfeon committed Nov 10, 2024
1 parent 31fdf33 commit f09cc59
Show file tree
Hide file tree
Showing 39 changed files with 3,376 additions and 89 deletions.
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
9 changes: 4 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ 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
runs-on: organization/macos-gh
strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -73,7 +72,7 @@ jobs:
acceptance-tests:
name: Run Acceptance tests
runs-on:
group: macos-gh
group: organization/macos-gh
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -132,7 +131,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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ NS_ASSUME_NONNULL_BEGIN
/// > Notes: Maximum 500 channels.
@property(copy, nonatomic, readonly) NSArray<NSString *> *channels;

/// Include messages' custom type flag.
///
/// Message / signal and file messages may contain user-provided type.
///
/// > Important: This option can be used only if a request created with `requestWithChannels` or `includeMessageActions`
/// options is set to `YES`.
@property(assign, nonatomic) BOOL includeCustomMessageType;

/// Include events' actions presence flag.
///
/// Each fetched entry will contain published data under `message` key and added `message actions` will be available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ - (NSDictionary *)query {
}

if (!self.multipleChannels && self.includeTimeToken) query[@"include_token"] = @"true";
if (self.includeCustomMessageType) query[@"include_custom_message_type"] = @"true";
if (self.arbitraryQueryParameters) [query addEntriesFromDictionary:self.arbitraryQueryParameters];

return query;
Expand Down
6 changes: 6 additions & 0 deletions PubNub/Network/Requests/Publish/PNBasePublishRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ NS_ASSUME_NONNULL_BEGIN
///clients on a channel.
@property(assign, nonatomic, getter = shouldReplicate) BOOL replicate;

/// 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;

/// Whether `published` data should be stored and available with history API or not.
@property(assign, nonatomic, getter = shouldStore) BOOL store;

Expand Down
Loading

0 comments on commit f09cc59

Please sign in to comment.