Skip to content

Commit

Permalink
Add custom message type support (#461)
Browse files Browse the repository at this point in the history
feat(message-type): add custom message type support

Add custom message type support for the following APIs: publish, signal, share file, subscribe
and history.
  • Loading branch information
parfeon authored Nov 18, 2024
1 parent 2efc7bc commit d4df02b
Show file tree
Hide file tree
Showing 52 changed files with 2,958 additions and 131 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -81,7 +81,7 @@ jobs:
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 Down
15 changes: 10 additions & 5 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
name: objective-c
scm: github.com/pubnub/objective-c
version: "5.6.1"
version: "5.7.0"
schema: 1
changelog:
- date: 2024-11-18
version: v5.7.0
changes:
- type: feature
text: "Add custom message type support for the following APIs: publish, signal, share file, subscribe and history."
- date: 2024-07-08
version: v5.6.1
changes:
Expand Down Expand Up @@ -1365,7 +1370,7 @@ sdks:
- distribution-type: source
distribution-repository: GitHub release
package-name: PubNub.framework
location: https://github.com/pubnub/objective-c/archive/refs/tags/v5.6.1.zip
location: https://github.com/pubnub/objective-c/archive/refs/tags/v5.7.0.zip
supported-platforms:
supported-operating-systems:
macOS:
Expand Down Expand Up @@ -1426,7 +1431,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: PubNub.ios.xcframework.tar.gz
location: https://github.com/pubnub/objective-c/releases/download/v5.6.1/PubNub.ios.xcframework.tar.gz
location: https://github.com/pubnub/objective-c/releases/download/v5.7.0/PubNub.ios.xcframework.tar.gz
supported-platforms:
supported-operating-systems:
iOS:
Expand All @@ -1445,7 +1450,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: PubNub.macos.framework.tar.gz
location: https://github.com/pubnub/objective-c/releases/download/v5.6.1/PubNub.macos.framework.tar.gz
location: https://github.com/pubnub/objective-c/releases/download/v5.7.0/PubNub.macos.framework.tar.gz
supported-platforms:
supported-operating-systems:
macOS:
Expand All @@ -1461,7 +1466,7 @@ sdks:
- distribution-type: library
distribution-repository: GitHub release
package-name: PubNub.tvos.xcframework.tar.gz
location: https://github.com/pubnub/objective-c/releases/download/v5.6.1/PubNub.tvos.xcframework.tar.gz
location: https://github.com/pubnub/objective-c/releases/download/v5.7.0/PubNub.tvos.xcframework.tar.gz
supported-platforms:
supported-operating-systems:
tvOS:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v5.7.0
November 18 2024

#### Added
- Add custom message type support for the following APIs: publish, signal, share file, subscribe and history.

## v5.6.1
July 08 2024

Expand Down
6 changes: 3 additions & 3 deletions Framework/PubNub/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>PubNub</string>
<key>CFBundleGetInfoString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleIdentifier</key>
<string>com.pubnub.pubnub-objc</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>NSHumanReadableCopyright</key>
<string>© 2010 - 2020 PubNub, Inc.</string>
<key>NSPrincipalClass</key>
Expand Down
6 changes: 3 additions & 3 deletions Framework/PubNub/PubNub-iOS-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>PubNub</string>
<key>CFBundleGetInfoString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleIdentifier</key>
<string>com.pubnub.pubnub-objc</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>NSHumanReadableCopyright</key>
<string>© 2010 - 2020 PubNub, Inc.</string>
<key>NSPrincipalClass</key>
Expand Down
6 changes: 3 additions & 3 deletions Framework/PubNub/PubNub-tvOS-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>PubNub</string>
<key>CFBundleGetInfoString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleIdentifier</key>
<string>com.pubnub.pubnub-objc</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>NSHumanReadableCopyright</key>
<string>© 2010 - 2020 PubNub, Inc.</string>
<key>NSPrincipalClass</key>
Expand Down
6 changes: 3 additions & 3 deletions Framework/PubNub/PubNub-watchOS-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>PubNub</string>
<key>CFBundleGetInfoString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleIdentifier</key>
<string>com.pubnub.pubnub-objc</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>5.6.1</string>
<string>5.7.0</string>
<key>NSHumanReadableCopyright</key>
<string>© 2010 - 2020 PubNub, Inc.</string>
<key>NSPrincipalClass</key>
Expand Down
2 changes: 1 addition & 1 deletion PubNub.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |spec|
spec.name = 'PubNub'
spec.version = '5.6.1'
spec.version = '5.7.0'
spec.summary = 'The PubNub Real-Time Network. Build real-time apps quickly and scale them globally.'
spec.homepage = 'https://github.com/pubnub/objective-c'

Expand Down
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
Loading

0 comments on commit d4df02b

Please sign in to comment.