Skip to content

Commit 98544a8

Browse files
Added customMessageType to Publish, Signal, Subscribe, History, File. (#302)
* PubNub SDK v10.2.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 8fd0a4e commit 98544a8

File tree

84 files changed

+992
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+992
-166
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: kotlin
2-
version: 10.1.0
2+
version: 10.2.0
33
schema: 1
44
scm: github.com/pubnub/kotlin
55
files:
6-
- build/libs/pubnub-kotlin-10.1.0-all.jar
6+
- build/libs/pubnub-kotlin-10.2.0-all.jar
77
sdks:
88
-
99
type: library
@@ -23,8 +23,8 @@ sdks:
2323
-
2424
distribution-type: library
2525
distribution-repository: maven
26-
package-name: pubnub-kotlin-10.1.0
27-
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.1.0/pubnub-kotlin-10.1.0.jar
26+
package-name: pubnub-kotlin-10.2.0
27+
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-kotlin/10.2.0/pubnub-kotlin-10.2.0.jar
2828
supported-platforms:
2929
supported-operating-systems:
3030
Android:
@@ -114,6 +114,11 @@ sdks:
114114
license-url: https://www.apache.org/licenses/LICENSE-2.0.txt
115115
is-required: Required
116116
changelog:
117+
- date: 2024-11-18
118+
version: v10.2.0
119+
changes:
120+
- type: feature
121+
text: "Publish, signal, share file, subscribe, and history."
117122
- date: 2024-11-06
118123
version: v10.1.0
119124
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v10.2.0
2+
November 18 2024
3+
4+
#### Added
5+
- Publish, signal, share file, subscribe, and history.
6+
17
## v10.1.0
28
November 06 2024
39

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2020
<dependency>
2121
<groupId>com.pubnub</groupId>
2222
<artifactId>pubnub-kotlin</artifactId>
23-
<version>10.1.0</version>
23+
<version>10.2.0</version>
2424
</dependency>
2525
```
2626

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RELEASE_SIGNING_ENABLED=true
1818
SONATYPE_HOST=DEFAULT
1919
SONATYPE_AUTOMATIC_RELEASE=false
2020
GROUP=com.pubnub
21-
VERSION_NAME=10.1.0
21+
VERSION_NAME=10.2.0
2222
POM_PACKAGING=jar
2323

2424
POM_NAME=PubNub SDK

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/PubNub.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import com.pubnub.api.java.v2.PNConfiguration
5757
import com.pubnub.api.java.v2.callbacks.EventEmitter
5858
import com.pubnub.api.java.v2.callbacks.StatusEmitter
5959
import com.pubnub.api.java.v2.endpoints.pubsub.PublishBuilder
60+
import com.pubnub.api.java.v2.endpoints.pubsub.SignalBuilder
6061
import com.pubnub.api.java.v2.entities.Channel
6162
import com.pubnub.api.java.v2.entities.ChannelGroup
6263
import com.pubnub.api.java.v2.entities.ChannelMetadata
@@ -183,6 +184,10 @@ interface PubNub : EventEmitter, StatusEmitter {
183184
* if more than 100 messages meet the timetoken values.
184185
*
185186
*/
187+
@Deprecated(
188+
level = DeprecationLevel.WARNING,
189+
message = "Use fetchMessages() instead",
190+
)
186191
fun history(): History
187192

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

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

366381
/**
367382
* Send a signal to all subscribers of a channel.

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/FetchMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public interface FetchMessages extends Endpoint<PNFetchMessagesResult> {
1818
FetchMessages includeMessageType(boolean includeMessageType);
1919

2020
FetchMessages includeUUID(boolean includeUUID);
21+
22+
FetchMessages includeCustomMessageType(boolean includeCustomMessageType);
2123
}

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/files/PublishFileMessage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface PublishFileMessage extends Endpoint<PNPublishFileMessageResult>
1515

1616
PublishFileMessage shouldStore(Boolean shouldStore);
1717

18+
PublishFileMessage customMessageType(String customMessageType);
19+
1820
interface Builder extends BuilderSteps.ChannelStep<FilesBuilderSteps.FileNameStep<FilesBuilderSteps.FileIdStep<PublishFileMessage>>> {
1921

2022
}

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/files/SendFile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public interface SendFile extends ExtendedRemoteAction<PNFileUploadResult> {
1717

1818
SendFile cipherKey(String cipherKey);
1919

20+
SendFile customMessageType(String customMessageType);
21+
2022
interface Builder extends BuilderSteps.ChannelStep<FilesBuilderSteps.FileNameStep<FilesBuilderSteps.InputStreamStep<SendFile>>> {
2123

2224
}

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/endpoints/pubsub/Publish.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ public interface Publish extends Endpoint<PNPublishResult> {
1717
Publish replicate(boolean replicate);
1818

1919
Publish ttl(Integer ttl);
20+
21+
Publish customMessageType(String type);
2022
}

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/v2/endpoints/pubsub/PublishBuilder.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,63 @@
33
import com.pubnub.api.java.endpoints.Endpoint;
44
import com.pubnub.api.models.consumer.PNPublishResult;
55

6+
/**
7+
* Interface representing a builder for configuring a publish operation.
8+
* This interface extends {@link Endpoint} to provide a fluent API for setting various parameters
9+
* for the publish request.
10+
*/
611
public interface PublishBuilder extends Endpoint<PNPublishResult> {
12+
/**
13+
* Specifies whether the message should be stored in the history of the channel.
14+
*
15+
* @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.
16+
* @return The current instance of {@code PublishBuilder} for method chaining.
17+
*/
718
PublishBuilder shouldStore(Boolean shouldStore);
819

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

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

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

46+
/**
47+
* Sets the time-to-live (TTL) in Message Persistence.
48+
* If shouldStore = true, and ttl = 0, the message is stored with no expiry time.
49+
* If shouldStore = true and ttl = X (X is an Integer value), the message is stored with an expiry time of X hours.
50+
* If shouldStore = false, the ttl parameter is ignored.
51+
* If ttl is not specified, then expiration of the message defaults back to the expiry value for the key.
52+
*
53+
* @param ttl The TTL value in minutes for the message.
54+
* @return The current instance of {@code PublishBuilder} for method chaining.
55+
*/
1556
PublishBuilder ttl(Integer ttl);
57+
58+
/**
59+
* Specifies a custom message type for the message.
60+
*
61+
* @param customMessageType The custom message type as a string.
62+
* @return The current instance of {@code PublishBuilder} for method chaining.
63+
*/
64+
PublishBuilder customMessageType(String customMessageType);
1665
}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
package com.pubnub.api.java.v2.endpoints.pubsub;
22

3-
import com.pubnub.api.java.endpoints.pubsub.Signal;
3+
import com.pubnub.api.java.endpoints.Endpoint;
4+
import com.pubnub.api.models.consumer.PNPublishResult;
45

5-
public interface SignalBuilder extends Signal {
6+
/**
7+
* Interface representing a builder for configuring a signal operation.
8+
* This interface extends {@link Endpoint} to provide a fluent API for setting parameters
9+
* for the signal request.
10+
*/
11+
public interface SignalBuilder extends Endpoint<PNPublishResult> {
12+
/**
13+
* Specifies a custom message type for the signal.
14+
*
15+
* @param customMessageType The custom message type as a string.
16+
* @return The current instance of {@code SignalBuilder} for method chaining.
17+
*/
18+
SignalBuilder customMessageType(String customMessageType);
619
}

pubnub-gson/pubnub-gson-api/src/main/java/com/pubnub/api/java/v2/entities/Channel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.pubnub.api.java.v2.entities
22

3-
import com.pubnub.api.endpoints.pubsub.Signal
43
import com.pubnub.api.java.v2.endpoints.pubsub.PublishBuilder
4+
import com.pubnub.api.java.v2.endpoints.pubsub.SignalBuilder
55
import com.pubnub.api.java.v2.subscriptions.Subscription
66
import com.pubnub.api.v2.subscriptions.SubscriptionOptions
77

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

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

107109
/**
108110
* Send a message to PubNub Functions Event Handlers.

pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/FilesIntegrationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void doItAllFilesTest(boolean withCipher) throws PubNubException, Interru
4646
String channel = randomChannel();
4747
String content = "This is content";
4848
String message = "This is message";
49+
String customMessageType = "myType01-_";
4950
String meta = "This is meta";
5051
String fileName = "fileName" + channel + ".txt";
5152
CountDownLatch connectedLatch = new CountDownLatch(1);
@@ -61,7 +62,7 @@ public void status(@NotNull PubNub pubnub, @NotNull PNStatus pnStatus) {
6162

6263
@Override
6364
public void file(@NotNull PubNub pubnub, @NotNull PNFileEventResult pnFileEventResult) {
64-
if (pnFileEventResult.getFile().getName().equals(fileName)) {
65+
if (pnFileEventResult.getFile().getName().equals(fileName) && pnFileEventResult.getCustomMessageType().equals(customMessageType)) {
6566
fileEventReceived.countDown();
6667
}
6768
}
@@ -79,6 +80,7 @@ public void file(@NotNull PubNub pubnub, @NotNull PNFileEventResult pnFileEventR
7980
.fileName(fileName)
8081
.inputStream(is)
8182
.message(message)
83+
.customMessageType(customMessageType)
8284
.meta(meta)
8385
.sync();
8486
}

pubnub-gson/pubnub-gson-impl/src/integrationTest/java/com/pubnub/api/integration/HistoryIntegrationTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ public void testHistorySingleChannel_Meta_Timetoken() throws PubNubException {
121121
@Test
122122
public void testFetchSingleChannel() throws PubNubException {
123123
final String expectedChannelName = random();
124+
final String customMessageType = "myType_" + random();
124125

125-
publishMixed(pubNub, 10, expectedChannelName);
126+
publishMixed(pubNub, 10, expectedChannelName, customMessageType);
126127

127128
final PNFetchMessagesResult fetchMessagesResult = pubNub.fetchMessages()
128129
.channels(Collections.singletonList(expectedChannelName))
129130
.maximumPerChannel(25)
131+
.includeCustomMessageType(true)
130132
.sync();
131133

132134
pause(3);
@@ -137,6 +139,7 @@ public void testFetchSingleChannel() throws PubNubException {
137139
assertNotNull(messageItem.getTimetoken());
138140
assertNull(messageItem.getMeta());
139141
assertNull(messageItem.getActions());
142+
assertEquals(customMessageType, messageItem.getCustomMessageType());
140143
}
141144

142145
}
@@ -168,8 +171,9 @@ public void testFetchSingleChannel_Meta() throws PubNubException {
168171
@Test
169172
public void testFetchSingleChannel_Actions() throws PubNubException {
170173
final String expectedChannelName = random();
174+
final String customMessageType = "myType_" + random();
171175

172-
final List<PNPublishResult> results = publishMixed(pubNub, 120, expectedChannelName);
176+
final List<PNPublishResult> results = publishMixed(pubNub, 120, expectedChannelName, customMessageType);
173177

174178
pubNub.addMessageAction()
175179
.channel(expectedChannelName)
@@ -184,6 +188,7 @@ public void testFetchSingleChannel_Actions() throws PubNubException {
184188
.maximumPerChannel(25)
185189
.includeMessageActions(true)
186190
.includeMeta(false)
191+
.includeCustomMessageType(true)
187192
.sync();
188193

189194
assert fetchMessagesResult != null;
@@ -196,6 +201,7 @@ public void testFetchSingleChannel_Actions() throws PubNubException {
196201
} else {
197202
assertTrue(messageItem.getActions().isEmpty());
198203
}
204+
assertEquals(customMessageType, messageItem.getCustomMessageType());
199205
}
200206
}
201207

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.pubnub.api.integration;
2+
3+
import com.pubnub.api.PubNubException;
4+
import com.pubnub.api.integration.util.BaseIntegrationTest;
5+
import com.pubnub.api.models.consumer.files.PNPublishFileMessageResult;
6+
import org.junit.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
10+
public class PublishFileMessageIntegrationTest extends BaseIntegrationTest {
11+
12+
@Test
13+
public void can_publishFileMessage() throws PubNubException {
14+
PNPublishFileMessageResult publishFileMessageResult = pubNub.publishFileMessage()
15+
.channel("whatever")
16+
.fileName("whatever")
17+
.fileId("whatever")
18+
.message("whatever")
19+
.customMessageType("my-Custom")
20+
.sync();
21+
22+
assertNotNull(publishFileMessageResult.getTimetoken());
23+
}
24+
}

0 commit comments

Comments
 (0)