Skip to content

Commit

Permalink
Added customMessageType to Publish, Signal, Subscribe, History, File. (
Browse files Browse the repository at this point in the history
…#302)

* PubNub SDK v10.2.0 release.

---------

Co-authored-by: PubNub Release Bot <[email protected]>
  • Loading branch information
marcin-cebo and pubnub-release-bot authored Nov 18, 2024
1 parent 8fd0a4e commit 98544a8
Show file tree
Hide file tree
Showing 84 changed files with 992 additions and 166 deletions.
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: kotlin
version: 10.1.0
version: 10.2.0
schema: 1
scm: github.com/pubnub/kotlin
files:
- build/libs/pubnub-kotlin-10.1.0-all.jar
- build/libs/pubnub-kotlin-10.2.0-all.jar
sdks:
-
type: library
Expand All @@ -23,8 +23,8 @@ sdks:
-
distribution-type: library
distribution-repository: maven
package-name: pubnub-kotlin-10.1.0
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.1.0/pubnub-kotlin-10.1.0.jar
package-name: pubnub-kotlin-10.2.0
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.2.0/pubnub-kotlin-10.2.0.jar
supported-platforms:
supported-operating-systems:
Android:
Expand Down Expand Up @@ -114,6 +114,11 @@ sdks:
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
is-required: Required
changelog:
- date: 2024-11-18
version: v10.2.0
changes:
- type: feature
text: "Publish, signal, share file, subscribe, and history."
- date: 2024-11-06
version: v10.1.0
changes:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v10.2.0
November 18 2024

#### Added
- Publish, signal, share file, subscribe, and history.

## v10.1.0
November 06 2024

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
<dependency>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-kotlin</artifactId>
<version>10.1.0</version>
<version>10.2.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RELEASE_SIGNING_ENABLED=true
SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=false
GROUP=com.pubnub
VERSION_NAME=10.1.0
VERSION_NAME=10.2.0
POM_PACKAGING=jar

POM_NAME=PubNub SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.pubnub.api.java.v2.PNConfiguration
import com.pubnub.api.java.v2.callbacks.EventEmitter
import com.pubnub.api.java.v2.callbacks.StatusEmitter
import com.pubnub.api.java.v2.endpoints.pubsub.PublishBuilder
import com.pubnub.api.java.v2.endpoints.pubsub.SignalBuilder
import com.pubnub.api.java.v2.entities.Channel
import com.pubnub.api.java.v2.entities.ChannelGroup
import com.pubnub.api.java.v2.entities.ChannelMetadata
Expand Down Expand Up @@ -183,6 +184,10 @@ interface PubNub : EventEmitter, StatusEmitter {
* if more than 100 messages meet the timetoken values.
*
*/
@Deprecated(
level = DeprecationLevel.WARNING,
message = "Use fetchMessages() instead",
)
fun history(): History

/**
Expand Down Expand Up @@ -319,6 +324,11 @@ interface PubNub : EventEmitter, StatusEmitter {
* The message argument can contain any JSON serializable data, including: Objects, Arrays, Integers and Strings.
* Data should not contain special Java/Kotlin classes or functions as these will not serialize.
* String content can include any single-byte or multi-byte UTF-8 character.
*
* @param message The payload
* @param channel The channel to publish message to.
*
* @return [PublishBuilder]
*/
fun publish(message: Any, channel: String): PublishBuilder

Expand Down Expand Up @@ -360,8 +370,13 @@ interface PubNub : EventEmitter, StatusEmitter {
* By default, signals are limited to a message payload size of 30 bytes.
* This limit applies only to the payload, and not to the URI or headers.
* If you require a larger payload size, please [contact support](mailto:[email protected]).
*
* @param message The payload
* @param channel The channel to signal message to.
*
* @return [SignalBuilder]
*/
fun signal(message: Any, channel: String): com.pubnub.api.endpoints.pubsub.Signal
fun signal(message: Any, channel: String): SignalBuilder

/**
* Send a signal to all subscribers of a channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface FetchMessages extends Endpoint<PNFetchMessagesResult> {
FetchMessages includeMessageType(boolean includeMessageType);

FetchMessages includeUUID(boolean includeUUID);

FetchMessages includeCustomMessageType(boolean includeCustomMessageType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface PublishFileMessage extends Endpoint<PNPublishFileMessageResult>

PublishFileMessage shouldStore(Boolean shouldStore);

PublishFileMessage customMessageType(String customMessageType);

interface Builder extends BuilderSteps.ChannelStep<FilesBuilderSteps.FileNameStep<FilesBuilderSteps.FileIdStep<PublishFileMessage>>> {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface SendFile extends ExtendedRemoteAction<PNFileUploadResult> {

SendFile cipherKey(String cipherKey);

SendFile customMessageType(String customMessageType);

interface Builder extends BuilderSteps.ChannelStep<FilesBuilderSteps.FileNameStep<FilesBuilderSteps.InputStreamStep<SendFile>>> {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface Publish extends Endpoint<PNPublishResult> {
Publish replicate(boolean replicate);

Publish ttl(Integer ttl);

Publish customMessageType(String type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,63 @@
import com.pubnub.api.java.endpoints.Endpoint;
import com.pubnub.api.models.consumer.PNPublishResult;

/**
* Interface representing a builder for configuring a publish operation.
* This interface extends {@link Endpoint} to provide a fluent API for setting various parameters
* for the publish request.
*/
public interface PublishBuilder extends Endpoint<PNPublishResult> {
/**
* Specifies whether the message should be stored in the history of the channel.
*
* @param shouldStore Boolean indicating whether to store the message (true) or not (false). If not specified, then the history configuration of the key is used.
* @return The current instance of {@code PublishBuilder} for method chaining.
*/
PublishBuilder shouldStore(Boolean shouldStore);

/**
* Configures the publish request to use the POST HTTP method instead of GET.
*
* @param usePOST Boolean indicating whether to use POST (true) or GET (false) for the request. Default is `false`
* @return The current instance of {@code PublishBuilder} for method chaining.
*/
PublishBuilder usePOST(boolean usePOST);

/**
* Sets the metadata to be sent along with the message.
* Metadata can be any custom object.
*
* @param meta Metadata object which can be used with the filtering ability.
* @return The current instance of {@code PublishBuilder} for method chaining.
*/
PublishBuilder meta(Object meta);


/**
* Specifies whether the message should be replicated across datacenters.
*
* @param replicate Boolean indicating whether to replicate the message (true) or not (false). Default is true.
* @return The current instance of {@code PublishBuilder} for method chaining.
*/
PublishBuilder replicate(boolean replicate);

/**
* Sets the time-to-live (TTL) in Message Persistence.
* If shouldStore = true, and ttl = 0, the message is stored with no expiry time.
* If shouldStore = true and ttl = X (X is an Integer value), the message is stored with an expiry time of X hours.
* If shouldStore = false, the ttl parameter is ignored.
* If ttl is not specified, then expiration of the message defaults back to the expiry value for the key.
*
* @param ttl The TTL value in minutes for the message.
* @return The current instance of {@code PublishBuilder} for method chaining.
*/
PublishBuilder ttl(Integer ttl);

/**
* Specifies a custom message type for the message.
*
* @param customMessageType The custom message type as a string.
* @return The current instance of {@code PublishBuilder} for method chaining.
*/
PublishBuilder customMessageType(String customMessageType);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
package com.pubnub.api.java.v2.endpoints.pubsub;

import com.pubnub.api.java.endpoints.pubsub.Signal;
import com.pubnub.api.java.endpoints.Endpoint;
import com.pubnub.api.models.consumer.PNPublishResult;

public interface SignalBuilder extends Signal {
/**
* Interface representing a builder for configuring a signal operation.
* This interface extends {@link Endpoint} to provide a fluent API for setting parameters
* for the signal request.
*/
public interface SignalBuilder extends Endpoint<PNPublishResult> {
/**
* Specifies a custom message type for the signal.
*
* @param customMessageType The custom message type as a string.
* @return The current instance of {@code SignalBuilder} for method chaining.
*/
SignalBuilder customMessageType(String customMessageType);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pubnub.api.java.v2.entities

import com.pubnub.api.endpoints.pubsub.Signal
import com.pubnub.api.java.v2.endpoints.pubsub.PublishBuilder
import com.pubnub.api.java.v2.endpoints.pubsub.SignalBuilder
import com.pubnub.api.java.v2.subscriptions.Subscription
import com.pubnub.api.v2.subscriptions.SubscriptionOptions

Expand Down Expand Up @@ -90,6 +90,7 @@ interface Channel : Subscribable {
* - If `shouldStore = false`, the `ttl` parameter is ignored.
* - If ttl isn't specified, then expiration of the message defaults
* back to the expiry value for the key.
* @param customMessageType The custom type associated with the message.
*/
fun publish(message: Any): PublishBuilder

Expand All @@ -101,8 +102,9 @@ interface Channel : Subscribable {
* If you require a larger payload size, please [contact support](mailto:[email protected]).
*
* @param message The payload which will be serialized and sent.
* @param customMessageType The custom type associated with the message.
*/
fun signal(message: Any): Signal
fun signal(message: Any): SignalBuilder

/**
* Send a message to PubNub Functions Event Handlers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void doItAllFilesTest(boolean withCipher) throws PubNubException, Interru
String channel = randomChannel();
String content = "This is content";
String message = "This is message";
String customMessageType = "myType01-_";
String meta = "This is meta";
String fileName = "fileName" + channel + ".txt";
CountDownLatch connectedLatch = new CountDownLatch(1);
Expand All @@ -61,7 +62,7 @@ public void status(@NotNull PubNub pubnub, @NotNull PNStatus pnStatus) {

@Override
public void file(@NotNull PubNub pubnub, @NotNull PNFileEventResult pnFileEventResult) {
if (pnFileEventResult.getFile().getName().equals(fileName)) {
if (pnFileEventResult.getFile().getName().equals(fileName) && pnFileEventResult.getCustomMessageType().equals(customMessageType)) {
fileEventReceived.countDown();
}
}
Expand All @@ -79,6 +80,7 @@ public void file(@NotNull PubNub pubnub, @NotNull PNFileEventResult pnFileEventR
.fileName(fileName)
.inputStream(is)
.message(message)
.customMessageType(customMessageType)
.meta(meta)
.sync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ public void testHistorySingleChannel_Meta_Timetoken() throws PubNubException {
@Test
public void testFetchSingleChannel() throws PubNubException {
final String expectedChannelName = random();
final String customMessageType = "myType_" + random();

publishMixed(pubNub, 10, expectedChannelName);
publishMixed(pubNub, 10, expectedChannelName, customMessageType);

final PNFetchMessagesResult fetchMessagesResult = pubNub.fetchMessages()
.channels(Collections.singletonList(expectedChannelName))
.maximumPerChannel(25)
.includeCustomMessageType(true)
.sync();

pause(3);
Expand All @@ -137,6 +139,7 @@ public void testFetchSingleChannel() throws PubNubException {
assertNotNull(messageItem.getTimetoken());
assertNull(messageItem.getMeta());
assertNull(messageItem.getActions());
assertEquals(customMessageType, messageItem.getCustomMessageType());
}

}
Expand Down Expand Up @@ -168,8 +171,9 @@ public void testFetchSingleChannel_Meta() throws PubNubException {
@Test
public void testFetchSingleChannel_Actions() throws PubNubException {
final String expectedChannelName = random();
final String customMessageType = "myType_" + random();

final List<PNPublishResult> results = publishMixed(pubNub, 120, expectedChannelName);
final List<PNPublishResult> results = publishMixed(pubNub, 120, expectedChannelName, customMessageType);

pubNub.addMessageAction()
.channel(expectedChannelName)
Expand All @@ -184,6 +188,7 @@ public void testFetchSingleChannel_Actions() throws PubNubException {
.maximumPerChannel(25)
.includeMessageActions(true)
.includeMeta(false)
.includeCustomMessageType(true)
.sync();

assert fetchMessagesResult != null;
Expand All @@ -196,6 +201,7 @@ public void testFetchSingleChannel_Actions() throws PubNubException {
} else {
assertTrue(messageItem.getActions().isEmpty());
}
assertEquals(customMessageType, messageItem.getCustomMessageType());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pubnub.api.integration;

import com.pubnub.api.PubNubException;
import com.pubnub.api.integration.util.BaseIntegrationTest;
import com.pubnub.api.models.consumer.files.PNPublishFileMessageResult;
import org.junit.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class PublishFileMessageIntegrationTest extends BaseIntegrationTest {

@Test
public void can_publishFileMessage() throws PubNubException {
PNPublishFileMessageResult publishFileMessageResult = pubNub.publishFileMessage()
.channel("whatever")
.fileName("whatever")
.fileId("whatever")
.message("whatever")
.customMessageType("my-Custom")
.sync();

assertNotNull(publishFileMessageResult.getTimetoken());
}
}
Loading

0 comments on commit 98544a8

Please sign in to comment.